P1 goes Offline with Loop Error 1 or Loop Error 24 after fast reading multiple Particle.variables quickly

Hi,

I am running OS firmware version 3.3.1 on P1. Recently we have encountered an issue where the P1 goes offline after fast reading multiple Particle.variable() - calculated - after reading about 6 variables in quick succession.

The led keeps blinking like its cloud connected and also Particle.connected() returns true for about 5-15 sec after this happens but device ping fails from the console.

I did some debugging and found that the Particle.variable() reading cloud api when hit in quick succession without waiting for the P1 to return the variable value, due to multi-threading, the P1 gets busy servicing multiple concurrent variable requests and looses Particle cloud connection with Cloud Loop error 1 and sometimes loop error 24.

Additional info -
I have System Thread Enabled and System Mode Manual.
In this temporarily disconnected state, if I call a Particle.function() then P1 receives the function request.
Even when I hit the Device Signal Button from console the P1 led starts blinking rainbow but the P1 ceases to return the Particle.variable() request - giving a temporary cloud disconnection without apparent signs from the led nor from Particle.connected().

I have also tried the running the Particle.variable() function code inside a Single threaded block but cloud disconnection happens.

I have removed Particle.process() from the Particle.variable() function code assuming that the system thread wont kick in to receive a new Particle.variable() request but behaviour repeats.

The only possible solution is adding delays between each subsequent Particle.variable() reading cloud api or waiting for P1 to return the previous result and then hitting the next Particle.variable() reading api again for reading the next variable.

Any help is appreciated.

You should not be losing the cloud connection in that scenario, but the best solution is to make the variable calls sequentially, not concurrently. The device can’t handle the concurrent requests anyway.

Calculated variables are handled between calls to loop(), and won’t be called concurrently, though the request could be received by the system thread while another request is being handled.

Actually, the best solution, assuming your variables don’t exceed the 1024 byte publish size, is to combine all of the variable responses into a single variable using something like JSON or comma separated values. The reason is that each variable request is one data operation, and doing multiple data operations in sequence can add up quickly. This will also speed up the process as only one transaction to the device is required.

Thanks for the response.

Actually I have 3.5k data which is broken into 4 variables and another 1.5k data broken into 3 variables. So the reason of using so many variables is large amount of data.

Is there a way to block a new request when one request is already being processed?