Unexpected device-agent communication patterns:
I have received some unexpected device-agent communication, and I am wondering if anyone can explain what’s going on. In the following code, the device posts a message to server.log, then sends data to the agent, and loops every five seconds. The agent receives the data, and also posts a message to server.log. What’s unexpected is that sometimes (but not all the time), the agent message is posted in server.log before the device message. Why would that be, and what can I do to make sure the server.log messages from the device and agent are posted in chronological order? Thanks for any comments.
Here is the device code, the agent code, and server.log (note the second set of messages are out of order) :
Device Code:
function loop() {
server.log(“This is the device”)
agent.send(“data”,“unused”)
imp.wakeup(5.0,loop)
}
loop()
Agent Code:
function receivedata(unused) {
server.log(“This is the Agent”); server.log(" ")
}
device.on(“data”,receivedata)
Server.log:
2015-12-06 16:24:49 UTC-6 [Device] This is the device
2015-12-06 16:24:49 UTC-6 [Agent] This is the Agent
2015-12-06 16:24:49 UTC-6 [Agent]
2015-12-06 16:24:54 UTC-6 [Agent] This is the Agent
2015-12-06 16:24:54 UTC-6 [Agent]
2015-12-06 16:24:54 UTC-6 [Device] This is the device
2015-12-06 16:24:59 UTC-6 [Device] This is the device
2015-12-06 16:24:59 UTC-6 [Agent] This is the Agent
2015-12-06 16:24:59 UTC-6 [Agent]