Using the ArduinoIOTCloud library as in the examples, the cloud connection is regularly being lost, despite remaining on the WiFi connection. Disconnecting/reconnecting the WiFi appears to reconnect to cloud. Any ideas?
PS I would ideally like to connect to ArduinoIOTCloud using one of several possible WiFi networks, but this doesn’t seem possible, having to use the PrefferredConnection method.
@sj2, I am working on something similar. I am trying to write code that gets the wifi SSID and PASS from the EEPROM instead of being hardcoded in "thingProperties.h".
Here is the code I wrote inside setup()
#define WIFISSID_LENGHT 32 // Max lenght of the wifi ssid
#define WIFIPASS_LENGHT 64 // Max lenght of the wifi password
char c;
// Initialasing EEPROM (need to #include "EEPROM.h" at the top)
EEPROM.begin(512);
// Read wifi SSID and paswword from eeprom
// The test of the \255 character is necessary because eeprom values before
// being writen for the first time have the value \255
for (int i = 0; i < WIFISSID_LENGHT; i++) {
c = EEPROM.read(i);
WifiSsid[i] = (c == '\255' ? '\0' : c);
}
WifiSsid[WIFISSID_LENGHT] = '\0';
for (int i = 0; i < WIFIPASS_LENGHT; i++) {
c = EEPROM.read(i + WIFISSID_LENGHT + 1);
WifiPass[i] = (c == '\255' ? '\0' : c);
}
WifiPass[WIFISSID_LENGHT + 1 + WIFIPASS_LENGHT] = '\0';
// This next statement needs to be added here and commented in "thingProperties.h"
// This change is necessary for using SSID and PASS from EEPROM
// rather then being hardcoded in "thingProperties.h"
WiFiConnectionHandler ArduinoIoTPreferredConnection(WifiSsid, WifiPass);
I dindn't test this code yet!
What I still have to do is to code for writing in the EEPROM the SSID and PASS.
The way to do it is start the device with wifi configered for AP, start a webserver and write a html page that can be accessed from a web browser that allows entering the SSID and PASS. then the program will write these in the EEPROM.
char WifiSsid[WIFISSID_LENGHT + 1]; // SSID of the wifi AP where we want the device to connect to
char WifiPass[WIFIPASS_LENGHT + 1]; // Password of the wifi AP where we want the device to connect to