Using Particle App to pass variable values


Hey all,

Myself and a team of other engineering students are trying to use Photon to collect temperature data from a sensor, and send push notifications when the temperature exceeds certain bounds. We have created successful code, now, we want to be able to set the temperature threshold values through the Particle App.

My initial idea was to create a particle.function that takes the threshold value as a string command, converts it to integer, and then uses it in an infinite while loop that contains our if statement to send push notifications if the value is exceeded. However, when I called the function through Particle, I received an error message, presumably because the function is an infinite loop.

Does anybody have any ideas on how we could send a value to a variable from the Particle App? We are trying not to involve other applications in order to keep our project as simple as possible, but if this isn’t possible, that would be good to know as well.



Particle.function() is the way to go, but why do you use an infinite while() and not just let loop() do the looping?
If you trap the code flow in a prolonged loop you either need to regularly call Particle.process() or go with SYSTEM_THREAD(ENABLED). But as already said, avoiding prolonged loops completely would be better practice.

Also the callback function for your Particle.function() should return as quickly as possible (and return a useful integer value) to let the cloud know execution was successful.
So the intended way would be to parse the incoming string, store it in a global variable and then return control to loop() to act upon the updated value.