I have set up 10 Flic Hubs to run a code that sends a ping to my API. The code runs in an infinite loop with 1 hour sleep so I've had a ping every hour from every device.
All seemed perfect until all of the devices stopped working around the same time.
I've got below error on the SDK:
SyntaxError: unterminated statement (line 2)
at [anon] (root/heartbeat/main.js:2) internal
at [anon] (duktape.c:71822) internal
at loadAndCompileUserModule () native strict preventsyield
at require (init.js:122)
at [anon] (init.js:139) preventsyield
at runInit () native strict preventsyield
at handlePacket (pipe_communication.js:48)
at readCallback (pipe_communication.js:93) preventsyield
Line to corresponds to either of below lines:
var buttonManager = require("buttons");
var buttons = buttonManager.getButtons();
Here is how my code looks like:
// Heartbeat.js
var buttonManager = require("buttons");
var buttons = buttonManager.getButtons();
var http = require("http");
var url = "my_api_url";
var DEVICE_ID = 'hub_id'
function myLoop() {
setTimeout(function() {
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i];
http.makeRequest({
url: url,
method: "POST",
headers: {
"Content-Type": "application/json"
},
content: JSON.stringify({
'pressedAt': Date.now(),
'batteryStatus': button.batteryStatus,
'button_sn': button.serialNumber,
'activeDisconnect': button.activeDisconnect,
'connected': button.connected,
'batteryStatus': button.batteryStatus,
'uuid': button.uuid,
'flicVersion': button.flicVersion,
'firmwareVersion': button.firmwareVersion,
'key': button.key,
'passiveMode': button.passiveMode,
'device_sn': DEVICE_ID,
'dataType': 'heartbeat'
}),
}, function(err, res) {
console.log("request status: " + JSON.stringify(res));
});
}
myLoop();
}, 1000 * 60 * 60)
}
myLoop();
console.log("Started");
Anyone have any ideas?
Thanks.