Can you show us some code? I tried with the following code, and it appears to be working (not that it won’t work the first time you run it since it needs to download the code first):
Agent code: device.onconnect(function() { server.log("Device came online"); });
Logs:
Fri Jun 14 2013 09:42:08 GMT-0700 (PDT): Device came online
Fri Jun 14 2013 09:42:08 GMT-0700 (PDT): Device booting
Fri Jun 14 2013 09:42:09 GMT-0700 (PDT): Device configured to be “HTTP In Example”
If the imp has only been offline only a short time, the first the server hears about it might be when it sees the same imp reconnect – which means the first connection can’t any longer be valid.
When one end of a TCP connection just vanishes without sending a FIN (i.e., when the imp gets unplugged), and no data is flowing at the time, the peer TCP won’t notice anything until it next misses a keep-alive, which could be half an hour later. The imp server sends ping messages from time to time, which will detect a missing imp, but even that is only at 10-minute intervals.
Well all I want to establish is that the agent knows, when the device is actually online (for the first time) so that I can start the agent activities. In my case, the device has to wait till a sensor is ready. Unfortunately, if the sensor is ready before the network is there, the sensor ready call is missed by the agent, therefore I need to wait for the network to be established.
The recommended code above worked, then stopped working by the event callback not firing anymore.
Are you sure the event callback isn’t firing anymore?
What if you unplug the Imp from the socket and reinsert it?
Hitting ‘Run’ on the IDE does not appear to drop and re-establish a connection, the only way I could get the event to fire was by removing the Imp from its socket and reinserting it. I suppose a power cycle of the Imp carrier would achieve the same.
Yes, but i am not looking for a re-insert event, but for the connect event. If that doesn’t exist in that form, then I won’t have a solution.
Unless I do a by-foot handover setting via agent or so.