User code Priority (Running While Connecting to Wifi/Cloud)

Hello friends,

I Have a couple projects running in my house (3 Cores and 4 Photons), but now im decide to build an project to control my lights. The circuit it’s really simple, it consist in activate relays with momentary switches (optionally controlled over web), one click, the light goes on, click again and light goes off. Simple right? But here is the problem:

The code works really fine when the Photon is connected to the cloud, but when i lose my internet/Wifi connection (Or when i booting up without it) the Photon freezes my code trying to reconnect, and while it does it, i cant turn my light ON/OFF…

So i try different methods to solve this (Photon in Manual Mode / Make an interrupt to keep my lights working during the connection/ Turn Wifi.off() and many other), but without success.

Anyone has a clue to how i can do this? I just need to run my code in a “Separated Thread”, to keep my lights running, while Photon tries to reconnect :smile:

I hope i can solve this, Thank you guys!

Multithreading support in the photon is being worked on, and we are hoping for a beta availability release this week.

I am also looking at building a “maximum retries” when connecting to the cloud so that the application loop isn’t continually blocked.

While Mat answered your immediate question, I’d like to try working out an alternative route for your problem.

Are you sure that your interrupts will be blocked from fireing the whole time the device is connecting?
Just from feeling, I’d say interrupts should work, just be sure to do all the necessary things (and only these) inside the ISR.

Additionally, if you are using “flip-flopping” relays that just get toggled each time you provide a pulse to them, why not only “parallel wire” the HW switches? This way your lighting even works without the Particles.
Or did I misunderstand your HW setup?

Thank you MDMA, I will wait anxiously to test this beta, this feature will probably solve my problem.

I found these future features in the System Thread at Particle documentation, its a really nice implementation, congratulation for your work!

1 Like

Hello ScruffR, i made some more tests to make sure about the interruption, and it works when i simplify the ISR code! I will test the limits now. Thank you.

So, about the HW, I had already thought about Latching Relays, but i need to know the actual Out states to create some scenes or Macros, turn OFF my entire House for exemple, or to feed my WebApp Buttons.

Thank you!

If you have some relays in mind, which ones are you thinking of?
Do they have a reset pin? Or you could centrally cut the supply (via dedicated relay) to force them into defined state.