I’m creating a web app, and I want to poll the status of some variables on the Imp. Something along the lines of:
web app requests data from agent
agent checks imp
imp repsonds to agent with data
agent responds to web app (responding to original http request)
I might be looking in the wrong place, or thinking about this the wrong way, but it doesn’t look like this can be done with the [agent|device].[on|send] combinations. Are there other functions for this that I’m just missing?
Agent puts the response to one side, using the timestamp as a key, while it checks the device.
Communicates with the device, sending the timestamp and receiving it back again from the device, using it a a kind of rudimentary session key.
response from device, agent looks up the http response it saved using the timestamp value, and “completes” the request, able to use data it has received form the device.
Thanks for the help. Got this working quite nicely with an iOS app for turning my central heating on and off
Another quick question - is the response.send function equivalent to a “return” statement? ie, will the function finish at the point the response is sent, or should I break out manually?
No - response.send simply sends a response back to whoever made the request. If you want the function to return immediately, you’ll need to return after it.