SYSTEM_THREAD question

Hi,
I have a perfectly working firmware.
Now I want to make it more robust so I add this line of code:
SYSTEM_THREAD(ENABLED);

Once I flash this updated firmware, my photon led stays solid cyan and it goes offline. The only way out is safe mode.

What could I be doing wrong?
I thought by enabling the system thread the wifi connection would be done in a separate thread, but somehow the wifi connection is not done at all or stuck somewhere.

Recovery: once I put the photon in safe mode, I comment out the SYSTEM_THREAD line in the firmware and flash again, my photon goes back to normal execution.

thank you for any tips,
Gustavo.
PS: you can find the firmware here: https://github.com/gusgonnet/minimalistThermostat

With SYSTEM_THREAD(ENABLED) your Particle.publish() statements in setup() will attempt to get hold of the WiFi before the cloud connection is established which might lead to a deadlock between the two threads.

1 Like

hum, ok, thanks for the tip.
I will read more about these threads before trying to enable it again.
Gustavo.

Can you run this code on a photon without any connected hardware (without threading). If so, then I can try to reproduce the problem - system threading shouldn’t stall like that. I suspect a stack overflow somewhere.

Hi Matthew,
yes you can run this code without any hardware connected.
thanks for the offer and let me know if I can help in any way!
Gustavo.