Hey everyone,
My first time posting, and I’m a bit of a newb with Squirrel, but here goes:
I’ve built a device that is connected to the web via Imp. This device is posting data to Parse every so often, and is controlled from a web app. For now I’m able to send all commands to the imp, then pass off to my arduino via TX/RX, where the device then performs its function.
What I would like is a callback that verifies the physical pin status on the Arduino and returns it to my app. Right now the flow is like this:
Web App -> User input (button) -> Command sent to Imp -> HTTPrequest return success -> App receives 200, ok.
What I want is to then track the command as it moves along to the Arduino over TX/RX, and then have the arduino send back a “200,ok” of sorts. Have the IMP device pick that up, pass to Agent HTTPrequest, and include in the response back to app. God I hope that makes sense, lol.
I have TX/RX working on all ends and the devices are all able to communicate right now… but not all the way as a request/response type format. After the IMP request, it switches over to TX/RX to communicate with Arduino…
How do you get the Agent to wait for a response from the device before sending the Response to the httpRequest?
In a nut shell, I want to poll the actual pin state on Arduino, and have that returned as part of an HTTPrequest/response.
Any help would be greatly appreciated.
AGENT CODE ------
function requestHandler(request, response) { try { // check if the user myCommand led as a query parameter if ("myCommand" in request.query) { local myVar = request.query.myCommand; device.send("myCommand", myVar); ---->WAIT FOR DEVICE RESPONSE response.header("Access-Control-Allow-Origin", "*"); response.send(200, "OK, the command was sent: "+myVar); }else if ("light" in request.query) { local myVar = request.query.light; device.send("light", myVar); ---->WAIT FOR DEVICE RESPONSE response.header("Access-Control-Allow-Origin", "*"); response.send(200,"Command Sent to Arduino: Light "+myVar); }else if ("heat" in request.query) { local myVar = request.query.heat; device.send("heat", myVar); ---->WAIT FOR DEVICE RESPONSE response.header("Access-Control-Allow-Origin", "*"); response.send(200,"Command Sent to Arduino: Heat "+myVar); }else if ("water" in request.query) { local myVar = request.query.water; device.send("water", myVar); ---->WAIT FOR DEVICE RESPONSE response.header("Access-Control-Allow-Origin", "*"); response.send(200,"Command Sent to Arduino: Water "+myVar); }else{ response.header("Access-Control-Allow-Origin", "*"); response.send(500, "Invalid Command Sent"); } } catch (ex) { response.send(500, "Invalid Command Sent: " + ex); } }