Detecting if device.send does not work

I am trying to write some agent code to send a command to an Imp. This is working. What I cannot work out how to do is to determine if the device.send() function has actually worked.

It may be that device.send() actually returns immediately, regardless of the status of the device itself, but I would love some clarification of this. Sure, I can use device.isconnected(), but that does not cover the situation where things fail after I have issued the device.isconnected() function.

If there is presently no way to determine this, that is fine, but it would be great to know this so I can work around it

Thanks. Darryl

I do this by pinging an acknowledgement message right back, eg.

agent.on("message.from.agent", function (data) { // Acknowledge receipt agent.send("ack", true) // Process data sent by agent } )

That’s in the device code; the agent needs to register a handler for the “ack” message too, of course.

Thanks. I was planning on doing it that way, but I was hoping that there was something cleaner

There isn’t anything more elegant at this point; different users have different requirements here so we thought it was best to leave this to the application.

We have a class for this :slight_smile: It’s called Bullwinkle, and can be found here:

Bullwinkle is aimed at extending the agent/device communication mechanism to make it easier to do things like make sure messages are acked (which happens in the background automagically with this class), and “reply” to messages that you receive.

The example folder has code for a simple model that demonstrates some of the functionality, and the explains very simple usage.

Feel free to shoot me any questions you might have :slight_smile:

That class looks cool - Thanks for that.

Taking this a bit further. From the agent, if I do a
am I guaranteed to either get:
delivery of the message to the Imp device.disconnect();

Put another way, does a Timeout generate a disconnect. I can imagine it might, but I have not been able to find this documented


A bullwinkle timeout does not generate a disconnect.

You are guaranteed either:

delivery of the message to the Imp, or the timeout handler executes