Particle Function (Electron) reported as not called

I’m working on a feature that requires pulling down about 200KB of data from an http server small chunks at a time. I’m triggering the download from a Particle function. All the function call does is change a state variable and return. The updated state triggers the start of the download from the main loop. I have set SYSTEM_THREAD(ENABLED) and so expected that the function would return immediately since the call itself doesn’t do anything. However about 60% of the time, the Console reports “Bummer” function couldn’t be called. This thing is supposed to be threaded… even if the main thread blocks, shouldn’t the system thread be able to return the function call result so the Console/server knows the call was successful? Am I missing something? I’m building using Workbench and running 0.8.0-rc.10. From debug printf()s I can see the http request go out, and the data start being returned while the Console is waiting for the return value. Do I need to delay some amount of time before sending the request so that the function call return value can make it back to the server? That seems dumb.

Any chance you could share the code so we have something to look at/test with?

It’s for a commercial product so I might be able to post a sanitized version, but I’m not sure. Will have to ask powers-that-be.

Without seeing your code it’s hard to tell, but execution of Particle.function() happens on the application thread not on the system thread.
In order do receive requests your application needs to call Particle.process() regularly while performing time comsuming chores to “give up” the application thread for pending requests.

1 Like

Interesting. It looks like the HTTPClient library is taking so long to send the bytes of the http request, that it’s blocking the return value from the Particle.function() call making it out to the cloud/console in time. If I change my app’s state machine so that the Particle.function() call triggers a delay(1000) in the main loop before the http request is sent, the return value always makes it to the cloud.

I’m not sure how to solve this in a better way yet… seems like I shouldn’t have to go putting Particle.process() calls down inside library code.