I’d dare to contradict. That’s a solution, you just have to lay out the rest of your project right.
My original statement states a prerequisite and is not a fix in its own righ and it doesnot break local network use cases by itself either.
You check for internet connection (or loss thereof) and act accordingly before the “safety net” hits.
When you look at the log timestamps you get a feeling about the time you’ve got to take matters in your own hand before the system jumps in.
BTW, the OP has stated his network has NO internet connection, so for his demand that also is the solution, I’d think.
Am running in SEMI_AUTOMATIC_MODE, but I am calling Particle.connect() within setup() and in loop() as part of the @rickkas7 strategy described within my ticket:
I had added Particle.connect(); to this block (not realising the WiFi disconnect side effect until your comments above).
// Do any one-time initialization here like calling udp.begin() or tcpServer.begin()
// Also connect to the Particle cloud
Particle.connect(); // <=== I added this....
wifiState = WIFI_STATE_RUNNING;
So, a solution is, as you said, don’t call Particle.connect() for this use case. Too easy!
That said, @Elco’s point regarding “great to have Particle cloud when it is there” is also a very good point, so it would be nice to solve that problem.
@Elco, wondering if this sorts out your request: pinging some external IP and only if you get a successful return, call Particle.connect()? Something like this:
int rc = WiFi.ping(IpAddress(8,8,8,8));
if (rc > 0)
@UMD, your ping approach would have been the way on my mind too.
You just also need to monitor the cloud connection and issue a Particle.disconnect() as soon you see a “persistent” loss of connection to prevent the system from trying to reestablish the desired (connected) state over and over eventually running into the failsafe which assumes the WiFi module must have some issue and resetting it to cure this “non-issue” (which the system doesn’t really know is not the cause).
I just read up on that “old” thread and as it turns out @rickkas7’s solution from back then silently accepts the fact that consistently failing cloud-connection attempts will eventually also reset the WiFi module. But since his client/server combo seems to not rely on persistent connections that’s fine for that use case.
But if you require a persistent connection or have any other reason to avoid a WiFi disconnect at all cost, extra work will be needed.
BTW, since actual WiFi outages have to be considered inevitable, explicit, graceful management of these situations may also need some thought. Just as with the cloud connection silently accepting the loss of WiFi connection is possible since the system does have some “brute force” failsafe in place, but then you may need to put up with the side effects of that too.
Sorry, that could indeed be a solution for his issue.
My point should be that the solution Particle chose “reset the entire WiFi stack if there is no cloud connection” will make the device go haywire when the LAN loses Internet. What I’d like to have is a solution that connects to the Particle cloud if possible but doesn’t go haywire if it can’t.
Wow, this might explain my problems with the TCP server. My system can go into a state where the TCP server is not accepting new connections. I have set it up to listen for new connections and drop the existing connection on a new connect. But I see a problem with the connection being refused or time out after a while, even though the device still responds to ping. Perhaps the WiFi reset is related.
I have spent my entire weekend debugging Particle WiFi again. This shouldn’t be my job Particle, it should be yours. Please take over.
Here is a bug report that contains my test code, which prints out a lot of helpful system state to debug WiFi issues. It is also my best effort yet to maintain a TCP in bad conditions.
And here is a new issue for the topic of this thread:
I am trying to build a demo application that:
Communicates over TCP without the Particle cloud
Doesn’t crash when WiFi goes down temporarily
Reconnects when WiFi is back up
Doesn’t stop working when there is no cloud connection
Can use a cloud connection when it is available.
Doesn’t block the application loop under any circumstances
Direct link to the code:
If others want to join me in my battle, I can split off the code from the BrewPi repo into its own repository so it is easier to fork. The current version works fine on Intranet only, but as soon as a Particle.connect() call is added, the system will keep resetting WiFi until the cloud is back (issue #1491 above)