Transmit JSON via HTTP: PUT

Hello Electric Imp Forums. I did some searching and I believe this is not redundant.

I’m trying to have my imp control the philips hue system. Using REST clients I am successfully doing this, but when I translate that http:put request into squirrelcode, I don’t seem to be having much success.

imp.configure(“HTTP PUT”, [], []);

device.on(“changeLight”, function(time){
server.log ("changelight called at : "+time);

local x = “{“on”:false}”;
server.log(x); // check to see that it looks good
// server.log(http.jsonencode(x)); tried jsonencode just cause. no success with this
local url = “”; // url
local headers={ “Content-Type”: “application/json”,“Content-Length”:“12”}; // properly formatted - looked at the docs
// above, content-length may not be necessary - it is from Arduino but not from other RESTful clients
local body = x;

server.log(url); // making sure URL looks good

local request = http.put(url, headers, body); // send req. right from example.
local response = request.sendsync();



my logs look like
2013-10-06 22:20:44 UTC-4: [Device] sending changelight from device
2013-10-06 22:20:44 UTC-4: [Agent] changelight called at : 8639
2013-10-06 22:20:44 UTC-4: [Agent] {“on”:false}
2013-10-06 22:20:44 UTC-4: [Agent]

also, ive tried the URL with a slash at the end > …/1/state/ but that doesn’t work, either.

hopefully I find some help, because I’m at a loss. pre-emptive thanks.

The problem you’re running into is that the imp agent isn’t within the imp, it’s sitting up in AWS somewhere. It has no access to your local network, and so can’t get to

You’d either need to talk to the Hue internet hub (which allows you to control your lights from when you’re not on your home wifi) or open a port in your firewall to get to the hue hub. I’m not sure if the first option has been reverse-engineered as yet, but I know it exists.

Well i think this is pinpointing the one and large drawback with the IMP:s, its not possible do do any communication without “full” internet connection. And I would not even dream about reducing my firewall rules to a level where its possible for an unauthorized “client” (without a valid certificate) to get one bit inside.
So pleas add some means of local communication http, or some simple sockets.

We don’t see this as a drawback, it’s just not what the imp is designed to do. The imp is a two-part system, giving you cloud processing for service integration and local processing for hardware integration.

If you want a wifi module that talks on the local network, there are many to choose from, but the imp was never intended to do local networking and so does not address this at all.

What a shame, I bought a kit to do just this same thing (configurable hue control)

Esp as I didn’t really understand the separation between between vimp and imp stuff when I ordered. (This would also be useful as I could send requests without relying on the imp servers)

vimp == old name for agents. You still have vimps!

Yes, but before having a play with the kit I’d kind of assumed I could run the same code on an imp as a ‘virtual’ imp / agent.

Its a shame that there is this limitation though. Would have made my life easier, not just for this, but also for a number of other HA projects I had in mind.

(I was hoping to just use the agent as the external facing api, with the device performing most of the work)

Jay I found these 2 articles on going via the meethue website

Is this what you went for?


how’s performance?

ps i think i might go this route -> when they release… no idea if it’s as good as the imp (battery life, programmability etc) though (seems like a similar product), but there will alledgedly be local http

Performance is good.