Http.onrequest working differently in new firmware?

Recently, the code segment below stop working with my garage door, and I wanted to make sure it was something to do with a firmware upgrade or if I had accidentally changed something. I can’t find anything wrong with my code, so I am assuming the former. I used to be able to do a device.send within a block, and the agent would wait for the returning device.on before it would reply. Now, it is replying immediately and not waiting for the device.on. Is that intentional? I can update my code to non-blocking if need be, but this worked and was quite simple.

Code segment from http.onrequest()

else if (data.action == "toggle") { device.send("toggleDoor", data.action); device.on("doorToggled", function(data) { doorState = data; local json = "{ \"status\" : { \"doorState\" : \"" + doorState + "\" }}"; server.log("Response: " + json); response.send(200, json); });

There hasn’t been any intentional change there.

When you say it is “replying immediately”, what reply do you get? It won’t be executing the “response.send(200…)” line until it receives the doorToggled message from the imp. Are you sure you haven’t got out of step with toggleDoor/doorToggled – perhaps you’re seeing the “doorToggled” message from a previous toggleDoor message? Try including a sequence number in the toggleDoor/doorToggled messages.

Peter

Sorry, I think something changed on the iOS side. I’m not sure what yet, but I believe the agent is replying correctly.

Here is the Xcode log: Something is responding to the app immediately. Look at the time difference between the request and response:

2013-12-07 17:30:59.502 Pitchfork[5579:a0b] Sending: {
action = toggle;
}
2013-12-07 17:30:59.635 Pitchfork[5579:a0b] Response string:
2013-12-07 17:30:59.635 Pitchfork[5579:a0b] Error parsing JSON: Error Domain=NSCocoaErrorDomain Code=3840 “The operation couldn’t be completed. (Cocoa error 3840.)” (No value.) UserInfo=0x994fcb0 {NSDebugDescription=No value.}

And this is what is going on at the Imp:

2013-12-07 17:30:59 UTC-5: [Agent] Incoming request: {“action”:“toggle”}
2013-12-07 17:30:59 UTC-5: [Device] Received request: toggle
2013-12-07 17:31:09 UTC-5: [Device] Door Closed.
2013-12-07 17:31:09 UTC-5: [Agent] Response: { “status” : { “doorState” : “closed” }}

It takes about 10 seconds for my garage door to close.

It works correctly if I ask the agent for just the door status, as that never goes to the device, since I keep doorState at the agent as well, but the toggle request gets an immediate reply with no value.

That does look strange to me. There’s 123ms between Pitchform sending and receiving the response. That’s sort of delay is something you’d attribute to network latency, ie, the time to hit the agent from your phone and back again. (EDIT: indicating that your app is in fact, getting to the EI network, and not just doing something within itself).

Can you post your entire agent code?

Also, can you try doing a POST (if that’s what it is) from a browser, or curl or something? This would help eliminate issue with your phone. Via a different ISP would be even better!

Arrrgh. My apologies… entirely my mistake. I had added code to reply with HTML if there was nothing in the body, and for some reason at the bottom I had an additional response statement. It worked fine for a status request, because that went off first, but a toggle request would wait for the door, and then the extra empty response was sent. #-o