How to queue a message on agent when device is sleeping?

onconnect/ondisconnect have had bugs, and the bugs in that daemon have had little love as it’s being replaced with Erlang.

If anyone on the Erlang server sees issues with those features, shout loudly. We’ve not seen issues ourselves.

@hugo, smittyone’s code has the same problem that I was seeing in my code. Basically, the device goes off to sleep before it can receive the message from the device.onconnect handler. I went with the “raw” solution suggested by @aron i.e. send a message from device to agent and then an “ack” message back before going to sleep.

It will certainly help to update the device.onconnect documentation to reflect it’s behavior. I could have saved some time :slight_smile:

So how will this feature improve once you migrate to Erlang?

The change to erlang doesn’t help per-se with the imp staying awake long enough to get messages from the agent; you would still need to send a “sleep now” message - it just makes onconnect/ondisconnect reliable.

I have some ideas for the server to cache a “ok to sleep now” flag which would minimize wake times (because there would be no round trip to the agent), but these are not implemented yet.