@hugo Thank you for the reply. I am asking for additional assistance given my experience below, because it is very time-consuming to write and test custom Squirrel code (especially something so specific to the impOS like this), and test it, and make sure it is right.
The time it would require for me to do all this by myself is less than using Particle for cellular and a separate ESP8266 for WiFi - but, I want to use imp006 for this deployment.
I also think this question will come up against as ElectricImp grows, so I am not being selfish (and least not totally).
Here is what I tried with an unsatisfactory result:
cm <- ConnectionManager({
"stayConnected": true,
"connectTimeout": 600.0,
"retryOnTimeout" : true
});
imp.setwificonfiguration("wifi", "password")
imp.net.setserverinterfaces(["wifi", "cell"]);
I was under the impression this would automatically revert to WiFi connection when, having established a cellular back-up connection in the necessity (i.e., momentary WiFi loss), the WiFi became available again.
But I have found my device seemingly permanently in cell mode using the above code even when there was strong WiFi.
Then I encountered the following fine-print (it is cathartic for me to use the term “fine print” and please do not take offense as I have no accusation) from the docs,
"imp.net.setserverinterfaces([“wifi”, “cell”]);
In this case, impOS will first attempt to connect to the server through any available WiFi interface. If that fails, however, impOS will attempt to connect via any available cellular interface. To ensure that the imp connects to WiFi when it can, your code may need to manually disconnect after any cellular connection is made."
So the built-in functionality doesn’t do what I need. It just prioritizes WiFi over cell on the initial connection but not throughout the course of eternal microcontroller life (unlike a Windows PC program or web browser application, I am building a 24/7/365 connected monitoring software so the software needs to have eternal execution built into its design). So with any inevitable drop in WiFi, it will permanently go to cellular and spend money that can be avoided with WiFi.
Question: Could you generously share code which reverts back to WiFi once it becomes available, having previously switched-over to cellular? We can forget about my original two-WiFi-networks requirement. I can just program the deployment network credentials later.
Thank you. Given the whole ConnectionManager and extensive documentation, it would be difficult and unwise for me to take a stab at this on my own. And it seems like very basic behavior that will benefit other users. Thank you Hugo I know you’re busy and you’ve already been very generous to me.