Failed Particle.connect() attempt resets WiFi connection in manual mode

Hi,

I’m attempting to use manual mode on the Photon to manage behavior for different states of WiFi/cloud connectedness. I’m finding, however, that some of the connection behavior isn’t truly manual. I’m currently attempting to connect to a WiFi router that is disconnected from the internet in order to test behavior when we’re connected to a local network but not the Particle Cloud. I’m finding that, when Particle.connect() fails to establish a connection with the cloud, our connection to the WiFi network is reset. At this point the module will once again connect to WiFi, attempt to connect to the cloud, fail, and be disconnected from the WiFi network, rinse and repeat.

I can understand this behavior for automatic mode, but it seems like manual mode should give us the ability to handle the Particle.connect() failure in the user-code. Regardless of cloud connectivity, we want to be able to communicate with our device over the local network, and so we need to be able to maintain our WiFi connection when our cloud connection fails. I understand that, once the connection fails the first time, we can call Particle.disconnect() to stop the WiFi disconnect/reconnect loop, but it’s very inconvenient to have a potential disconnect/reconnect every time we try to connect to the cloud. We use manual mode so that we have finer control over state management as it pertains to WiFi/cloud connectedness, but this case doesn’t provide us that control.

Thanks,
Derek

You could try to not rely on the implicit WiFi.connect() that’s part of Particle.connect().

It apears logical to me that when you want a Particle.connect() but this fails all steps taken to get there will be rolled back to their previous state before the attempt.
So if WiFi was not connected, but just got activated to get onto the cloud, it’s fine to switch it back off, if the intended state is unreachable anyway.

On the other hand, if WiFi was connected (by an explicit call to WiFi.connect()) and was WiFi.ready() a subsequent failing Particle.connect() should revert to this state.

Just give it a try - I’d be curious if I’m wrong there (or not :sunglasses:)

@ScruffR Sorry, should have been clearer about our connection process. Our attempt to Particle.connect() only occurs after a successful WiFi.connect(). That is, we confirm that WiFi.ready() is true, as you suggested, before our call to Particle.connect().

I’d love to look into this. Could you make a minimum test application that shows the problem?

1 Like

@mdma I dug into the firmware a bit, and discovered that the SPARK_WLAN_RESET flag is set by handle_cfod() in system_task.cpp after a number of failed cloud connection attempts. I’ve raised a GitHub issue here: https://github.com/spark/firmware/issues/748

Thanks. I was going to suggest that’s what the cause is.