Imp to Imp Communication

Can anyone point me to an example of inter-imp communication. Have got the communication from Device<–>Agent working fine, but now I want to have one agent talk to another.

I tried the following

Agent 1 -
local url = "https://agent.electricimp.com/************"; local body = "test"; local response = http.post(url, {} ,body);

and the receiver, Agent 2,
http.onrequest(function(request,res){ if(request.body == "test"){ server.log("Test request received..."); device.send("switch",request.body);

The http request never seems to make it over to the second agent. :frowning:

You’re not actually issuing the request. http.post() generates a request but doesn’t dispatch it.

Change this:

local response = http.post(url, {} ,body);

to

local response = http.post(url, {} ,body).sendsync();

…if you want it to be sent. You may want to do a non-blocking async send too.

Here is a really simple project using an Imp with a PIR sensor attached that sends a command to an Imp powering an strip of LEDs. Take a look at the agent code.

Thanks. Working beautifully now.