Hello,
I am using the RETURN_ON_ERROR timeout policy. My callback in my connect calls looks like the code below. The sendStateLog() function is one that simply logs the send error according to the code returned. What sometimes happens is that the device logs the “Connecting due to: SendData” and does not log anything else until it disconnects on connect timeout. Sometimes this timeout also extends for some mysterious 9 minutes (the timeout was put to 5 seconds). But what concerns me the most is this apparent blocking while sending. So the Agent’s on.device() callback is not firing, the sendStateLog() function is not logging anything and I assume that it is because the agent.send() is not returning any value nor sending any message.
This only happens sometimes. Most of the times it goes as it should.
Do you know anything about this?
Thank you truly for your attention!
`function connectCallback(state){
local connectReasons = split(nv.connectReasons, “&&”);
local afterSendSleep = true;
local updatedConnectReasons = “”;
local failedAnySend = false;
if(state == SERVER_CONNECTED){
for(local i = 0; i < connectReasons.len(); i++){
server.log("Connecting due to: " + connectReasons[i]);
if(connectReasons[i] == "SendData"){
if(sendStateLog(agent.send("EGGYHourlyFridgeData", nv.bulkdataString)) == 0){
server.log("Accumulated data sent to agent!");
//Flushes the bulk data string
nv.bulkdataString = "";
}
else{
failedAnySend = true;
updatedConnectReasons = updatedConnectReasons + "SendData" + "&&";
}
}
[...]
}
//Updates connect reasons
//(Flushes it if no error occurred)
nv.connectReasons = updatedConnectReasons;
//If all sents were successfull
if(!failedAnySend)
nv.failedConnect = false;
else
nv.failedConnect = true;
if(afterSendSleep){
server.disconnect();
//Waits 1000ms just to assure the sending of the agent messages before deep sleeping
imp.sleep(1);
imp.onidle(function(){ imp.deepsleepfor(nv.sleepPeriod) });
}
}
else{
nv.failedConnect = true;
server.disconnect();
imp.onidle(function(){ imp.deepsleepfor(nv.sleepPeriod) });
}
}
`