Sending to multiple imps

Hi Everyone,

i’m a real beginner with coding and the electric imp so please be gentle,

i have 3 imps/april, i’m trying to send 2 integers (sensor states) from 1 imp to the other 2,
i can send from one imp to another , but i am stuck trying to send to multiple imps,

also what does ‘429: rate limit exceeded’ mean?, how do i recover from it, and how do i avoid it, (pretty much what am i doing wrong?.. beside everything… >.<

thank you

I’m assuming you’re sending messages between imps with HTTP requests. If you want to send a message from 1 imp to two other imps, you simply need to do 2 HTTP requests instead of 1 (1 request to each of the imp’s agent url).

“429: rate limit exceeded” means you are making too many HTTP requests to an agent too quickly. You can make about 10 requests per second before you get that message, so you likely want to make sure you’re blasting messages quicker than that.

Oh thank you,

i’ve’d made the changes u advised but the agent code is getting very busy now, (i think),


`server.log(“agent active”)

const SonAgentUrl = “

const DaughterAgentUrl = “

local accstate = 0;
local flexstate = 0;

function axis(accvalue){

local xread = accvalue[0];
local yread = accvalue[1];
local fread = accvalue[3];
if ( xread < 20000 || xread > 40000){
    accstate= 1;
    server.log("xread true");

if ( yread < 25000 || yread > 45000){
    accstate = 2;
    server.log("yread true");

if ( fread < 1000 || fread >2200){
    flexstate = 1;
    server.log("flex bent");
} else {
      flexstate = 0;
      server.log("flex straight");
server.log("accstate: " + accstate + "   flexstate: " + flexstate);

local url1 = format("%s?accstate=%i", SonAgentUrl, accstate);
local url2 = format("%s?flexstate=%i", SonAgentUrl, flexstate);
local url3 = format("%s?accstate=%i", DaughterAgentUrl, accstate);
local url4 = format("%s?flexstate=%i", DaughterAgentUrl, flexstate);

// make the request, and call the inline function
// when we get a response
http.get(url).sendasync(function(resp) {
    // log the response, should be 200: OK is things worked
    server.log(format("%i: %s", resp.statuscode, resp.body));

http.get(url2).sendasync(function(resp) {
    server.log(format("%i: %s", resp.statuscode, resp.body));

http.get(url3).sendasync(function(resp) {
    server.log(format("%i: %s", resp.statuscode, resp.body));

http.get(url4).sendasync(function(resp) {
    server.log(format("%i: %s", resp.statuscode, resp.body));


device.on(“acc”, axis);`

What would be a better method to package and send??

thank you.

Why not combine your calls to the same url?
local url1 = format("%s?accstate=%i&flexstate=%i", SonAgentUrl, accstate,flexstate);

That will halve the traffic.

Hi Coverdriven,

i’ve tried that previously and no luck, i just tried it agian and no luck as well,

i don’t know how the son’s agent code will breakdown that the accstate integer will correspond with the accstate call, and the same for the flexstate,

when i combine the call, i get a ‘404 no http handler’, i assume this is becuase the son’s agent req.query code no longer suited to the new call format…

this is the son’s current agent code:

`server.log(“agent active”);

local ledstate = 0;
local RGBstate = 0;

function httpHandler(req, resp) {
server.log(“igota reqest”);

if ("accstate" in req.query) {     
     RGBstate = req.query.accstate.tointeger();
if ("flexstate" in req.query) {        
     ledstate = req.query.flexstate.tointeger();
 server.log("RBGstate: " + RGBstate + " ledstate: " + ledstate);

local sensorstate = [RGBstate, ledstate];
device.send("ledOn", sensorstate )

resp.send(200, "son says hi");



how can i get the son’s req.query to read the new call format??

i would really like to package the call better as i would like to add more imps, and it’s just getting too much and keep running into the '429 rate limit exceeded problem
any advice is appreciated…

I wrapped you code in Code tags (the “C” icon above the text entry box).

The only reason you get 404 messages is if your agent does not have a request handler, or you have mis-typed the agent URL you are making a request to - are you 100% positive you typed the Agent URL correctly?

The easiest way to test requests made with Query parameters is to browse to the Agent URL you are making a request to in this case, SonAgentURL and DaughterAgentURL). You can easily do this by going to their agent and clicking on the agent url. Once you have that URL, you shoudl be able the parameters you want to the end of it :

this happened to me

upper case i I
lower case L l

in my browser the agent url had one of these and it was not distinguishable with the font being used.

Thank u beardedinventor for the tip,
thank u coverdriven for the format code

local url1 = format("%s?accstate=%i&flexstate=%i", SonAgentUrl, accstate,flexstate);

it’s working now! greatly appreciated!

1 Like