(Photon) running program when cloud/wifi fails

photon
Tags: #<Tag:0x00007f1ca5feb7a8>

#1

Hi All,

I’m having some problems with figuring how to keep my program running on my Photon in case the photon disconnects from the cloud or wifi for whatever reason. [I have come across semi-automatic/manual to be further complicated with SYSTEM_THREAD(ENABLED)/ WiFi.off()/ WiFi.disconnect()………]

A lot of the threads are many many years old and even refer to the core so I’m not sure if the photon 2019 has the same issues. Apparently it was not going to be like this when the photon came out?

My photon receives serial data from a wiegand key pad (or fob) and then activates an electric strike allowing the door to be opened if the password is correct.

I have added a Blynk terminal so I can change the password from a far and also if someone presses any keys/time stamps etc it will show up in the Blynk terminal on my phone.

I will rarely change the password but someone has to come through the door at least 10 times per day. Can’t afford for the program to block and to be locked outside.

An offline version on an Arduino has been running fine for about 6 months with no problems, minus any of the online fun stuff. And it’s such a pain to change the password - I have to get up a ladder with a laptop.

What I need is for my program to run all the time even if there are problems with the net/router/cloud etc. And then to reconnect by itself once the problems go away.

[I could use an Arduino to open and close the door then just use a photon to change the password etc. but I was hoping to use as few components as possible.]

Can this be done on just photon? [I already have it running well on the photon, it’s just the blocking issue]

Thanks


#2

Have you tried those solutions? Because those are actually the solutions, regardless of how long ago you found them.


#3

Sounds like you need to be using SYSTEM_THREAD(ENABLED) with SYSTEM_MODE(AUTOMATIC). Both are well documented here:

https://docs.particle.io/reference/device-os/firmware/photon/#system-modes
https://docs.particle.io/reference/device-os/firmware/photon/#system-thread

You really only need to enable the system threading since the default behavior is system mode Automatic. Have you tried enabling the system threading? This all works for the Photon. At the top of the system documentation, there is a place where you can choose your hardware version. Both links I provided go straight to the Photon reference.


#4

Thank you for your reply Moors7 - I have not tried anything yet as I was still researching and still wondering if it was even possible. Now I know it’s possible I will try a bit harder and try to add the code.


#5

Thank you very much for the reply ninjatill - I would never have guessed I would have needed to use SYSTEM_MODE(AUTOMATIC). I thought we were trying to get out of that automatic mode! From the treads that I have read they were switching to SEMI_AUTOMATIC.


#6

With SYSTEM_THREAD(ENABLED), your device will be able to keep running without blocking, even if the wifi/cloud become unavailable.

The only caveat is that you may need to do things like waitFor(Particle.connected, 10000) before performing some network functions. You can find the necessary details in the reference documentation on System Thread


#7

I guess you would have to link another post for a better explanation of why they were switching to semi auto mode. Semi auto mode would make the photon not connect to the cloud at boot but then you would have to tell it when to connect. However, you didn’t state any desire to control when the photon connects to the cloud. So Automatic seemed the best fit. So the most effective setting to change for your scenario is to enable the system thread so that it won’t block your user code when the cloud is lost.


#8

Thank you dougal - I was just about to type SYSTEM_THREAD(ENABLED) thinking this is going to be a quick fix. Nothings ever that easy I guess.

I have just tested my setup without any corrections, and sure enough it stopped working. Turned the router back on and eventually it connected and went back to normal.

Will try to modify the code now.


#9

I have added SYSTEM_THREAD(ENABLED) - when i turn off the router my program kept working as normal.

Sadly when I turn the router back on it seems to try to connect again but it seems stuck on flashing green. It flashes green rapidly and then seems to flash green a bit slower, it repeats this.

Guess there is more work to do.


#10

oh dear - tried it again twice and this time it connected by itself.