[SOLVED] Photon fails to reconnect to web

So there’s already a very long thread about this here: https://community.particle.io/t/long-term-photon-connection-stability/13925/222 which was finally locked by a Particle employee (no1089) with the suggestion that I open a support ticket about my Photon failing to reconnect to the web after losing a connection (but if you restart the device it connects instantly). So I did that.

And was told to go to the communiy forums and post my question there. So I’m baaaack. And I still have no clue why this is happening, nor how to figure it out. I’m not calling SYSTEM_MODE and haven’t changed my code recently so I have to assume that there is something in the Particle 1.52 firmware that is hanging.

But I have no way of identifying that. I considered adding debugging print lines to my code (like I used to do back in the 70’s with my punch card Fortran programs) but it seems like at this late date there ought to be something more sophisticated available.

Even if I find that my code stopped running at line nnnn, the failure is in whatever Particle calls their wi-fi reconnect routine. It’s not a signal strength issue. I see this happen even with the Photon sitting on my desk four feet from the router.

It was also suggested that interrupts could be causing this. But if that’s the case then the Particle is useless for controlling a weather station so I might as well give up.

I’m not even asking for a solution, but how to go about finding the cause of this vexing problem.

@Michele,

Refer to this post: WiFi reconnection issue - what does this trace mean?

Specifically this comment: WiFi reconnection issue - what does this trace mean?

Hopefully this will help.

Thanks for an interesting link. So the crux of the matter seems to be this:

"has been (re) solved today.

In short:

  • Implement a WiFi connection state machine
  • Ensure that there is enough heap memory"

Starting with no. 2,, this is what I'm getting. I'm not sure which of these is heap memory:

Output of arm-none-eabi-size:

|text|data|bss|dec|hex|
| --- | --- | --- | --- | --- |
|47488|256|12832|60576|NaN|

In a nutshell:
Flash used 47744 bytes
RAM used 13088 bytes

As for implementing a WiFi connection state machine, I have no idea how to do that. I tried the following, called every six minutes, but it doesn't work:

void checkWiFi()
  {
   IPAddress ip = WiFi.resolve("www.google.com");

   if (ip[0] == 0)
     {
      // USBSerial1.printf("Resetting WiFi\n");
      WiFi.off() ;
      delay(5000) ;
      WiFi.on() ;
      delay(1000) ;
      WiFi.connect() ;
     }
  } // end checkWiFi

I think I'd rather just revert to one of last year's firmwares (1.3 - 1.4) before this problem started happening. If there's a way to do this s.t. it won't automatically revert to the latest version every time I reboot it.

In the meantime, I have sprinkled my code with a few print statements. The last one I get before the wifi drops is a call to "getWeather", the routine that samples all the sensors (wind speed, wind direction, rain, temperature, humidity, pressure, snow, ambient sound).

UPDATE

After more testing, it appears that the main loop keeps running, the checkWiFi function above gets called, but the Photon refuses to reconnect. It sits there fast-blinking magenta until I reboot it. This doesn't sound like an issue with my code. It's a Particle problem. I wish someone would address this. Meanwhile I will try to figure out how to downgrade from 1.5.2 back to 1.4.

Re determining heap memory, call freeMemory(), https://docs.particle.io/reference/device-os/firmware/photon/#freememory-

Re the state machine, refer to [SOLVED] TCPCLIENT intranet connection fails if no cloud connection which quotes the @rickkas7 WiFi state machine technique.

3 Likes

I put the state machine code in my Photon weather station and I can confirm that this fix does indeed work with firmware 1.5.2. It’s been running for a week and the Photon now automatically reconnects to the web instead of just blinking cyan forever. So a super big thank you to @rickkas7 for the solution and to @UMD for pointing that out. This had been vexing me for months now.

Excellent!

Out of interest, I have found it very rare to come up against an insurmountable roadblock with the Photon/P1 due to the Particle ecosystem eg community contributions, Particle support, documentation, DeviceOS, etc.

That said, it is a long road!

1 Like

Yes, the Particle community is truly its saving grace. I never cease to be amazed at the expertise here and how generous people are with their time. Thanks again to all the Particle stars (you, Peekay, ScruffR, rickkas7, and all the rest) who have helped me over the years.

3 Likes