At what frequency can I make function calls to my Spark Core? [Solved]

At what frequency can I make function calls to my Spark Core?

I have read a couple of different threads on how frequently I can make web requests in the cloud service without flooding the cloud service.

I have a sumobot I am trying to control using an accelerometer. I would like to send commands to my Spark Core over the cloud API, but from what I have read on variables, you should not call those more than once a second, or in a burst of four a second. The accelerometer I am using has a refresh rate of 10hz.

Home many requests can I send to my core a second for function calls?

Thanks,
David

I believe you have answered your question. About one per second, with bursts up to 4 per second.
Thats per spark.publish().
I am not really sure what “At what frequency can I make function calls to my Spark Core?” means.
From an external device, miles away?

It is my understanding that Publish is limited to one per second, with an occasional burst of up to 4/sec. However, I don’t believe that Variable and Function calls are rate limited.

1 Like

@Muskie, so, does that mean, “it pretty much depends on the internet”?
You expect it could be anywhere between 100 times a second, to once ever 3 seconds?

Hi @davidfekke

As others have pointed out, publish is rate-limited to an average once per second with a burst of four allowed.

Variables and functions are not rate-limited but in my experience somewhere around once per second from a Javascript web page is about all I can get to work reliably. If you look for my tutorial with a servo you will see that since I am about 125ms from the cloud, the best case I could possibly achieve would be a 250ms round-trip time and a realistic time including all overhead is about once per second.

Alternatives include you own local Particle cloud or straight TCP or UDP.

1 Like

I suppose it will be limited by lots of factors in practice, but it is not artificially limited by Particle.

1 Like

I have a web app (PHP) that queries 16 variables from 5 cores and it takes about 8 seconds to execute. So my results in this instance are a little better.

2 Likes

Good info guys. So, it normally requires 0.5 seconds - 1.5 seconds (but can vary) based on your info.

I was doing the same thing for my HVAC Motor Controller here:

Basically for each possible HVAC state (15 total), I was calling a function through the Particle API which would read a EEPROM value. It worked, but there was a delay while all 15 variables where read.

Because I am picky, I wanted a faster response. So what I did was created a Particle Variable which contained a STRING. This STRING was basically all of my EEPROM values (that I needed) put together. Now with a single call to the Particle API's, I can get all states.

// Global
char speedSettings[50] = "";

// In Setup()
Spark.variable("getspeed", speedSettings, STRING);

void postSpeedSettings() {
    
    // Clears out previous data
    for(uint8_t i=0; i<50; i++) {
       speedSettings[i] = 0; 
    }
    
    
    for(uint8_t i=0; i<16; i++) {
        int data = 0;
        data = EEPROM.read(i);
        sprintf( speedSettings, "%s%d ", speedSettings, data);
       
    } 
}

Hope this helps.

I am not sure I asked the question correctly. I am making a call to a spark function from a node application.

_POST /v1/devices/{DEVICE_ID}/{FUNCTION}

How many times a second can I make this HTTP request?

service -> Particle Cloud API -> my Spark Core.

@davidfekke, as @bko said, the Particle Cloud will not limit you but the internet might, along with your Core's turn-around time.

1 Like

Hi @davidfekke

I understood your question previously and my answer is 1-3 function calls per second. This depends on the how “far” you are from the cloud and other factors including if you are also polling a variable to get feedback. It will be faster if you run “open-loop” with no feedback but that seems unlikely to work well in the real world.

As you heard above, combining all sensors into one string is a good approach.

1 Like

I am sending everything in the same string so I can make a single call.

1 Like

I think my Core's turn-around time is less than 1/1000 of a second.

What is your Core's turn-around time? @peekay123 ?

If you have no guess, then, no need to respond.

I think this thread has been answered. (0.5 seconds to 1.5 seconds). If the OP is satisfied, they can edit the title to say [SOLVED].
Great discourse guys/gals.