How are people polling imps from the agent

I have a app sending commands to an imp through an agent but currently I have no way to know the command hasn’t been received by the imp except for the fact I won’t receive html response at all ( As it is sent from a agent.send initiated by the imp). I would prefer to have a timeout for the device.send call so I can still send a response to my app from the agent instead of it getting ignored.
Is there a way for me to generate some sort of callback after x seconds without using a blocking loop on my agent remembering that I can’t use the timing features of the imp as it could be offline?

When the imp receives the message passed using the device.send() issued in response to the app-issued command, you can send a message back to the agent, using agent.send(), to acknowledge receipt.

The function registered by the agent’s device.on() watching for the acknowledgement can make use of the httpresponse object provided to your http.onrequest() handler.

Something along these lines:

`function request_handler(request, response)
if (“command” in request.query)
save_response = response
device.send(“”, true)
timer = imp.wakeup(timeout, no_ack)
response.send(500, “Error”)

function send_app_ack(value)
// Imp has acknowledged receipt

imp.cancelwakeup(timer)    // Cancel timer as it's no longer needed

// Tell app imp has acknowledged

save_response.send(200, "Imp has received data request")


function no_ack(value)
// No ack received within timeout period

save_response.send(500, "Imp has not acknowledged")


timeout <- 30.0 // Timeout in seconds
timer <- nil // Pointer to any wakeup time we start
save_response <- nil // Place to save the auto-generated http response


device.on(“ack”, send_app_ack)`

On the device side, you’d have:

`function send_ack(value)
// Acknowledge receipt

agent.send("ack", true)

// Gather data to send or whatever the command requires

. . .

agent.on(“”, send_ack)`

Awesome, the short answer is Imp.wakeup is available on the agent. Some of this stuff is hard to find unless you know where to look.
Thanks smittytone.

No problem, @pebble. Always check the API Docs for a specific method as it’ll tell you whether it works on device, agent or (as in imp.wakeup()'s case) both.

I’m working on a series of notes for the Dev Center to provide solutions for ‘how do I… ?’ type questions, so that should soon provide a place to search for help too.