1

I have been trying to use WiFi.h, WebServer.h and EEPROM.h together with ArduinoIoTCloud.h and Arduino_ConnectionHandler.h to be able to change the WiFi credentials if required without changing the sketch and reuploading it. The problem is when moving;

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS)

inside void setup() wouldn't work whether with constant char of the credentials or after modifying it to read from the EEPROM, like

WiFiConnectionHandler ArduinoIoTPreferredConnection(esid.c_str(), epass.c_str());

Please, is there any way to change the WiFi credentials from a browser?

The code

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char DEVICE_LOGIN_NAME[]  = "********************";

const char SSID[]               = SECRET_SSID;    // Network SSID (name)
const char PASS[]               = SECRET_OPTIONAL_PASS;    // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[]  = SECRET_DEVICE_KEY;    // Secret device password

void onTemperatureChange();

float temperature;

void initProperties()
{
  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.addProperty(temperature, READWRITE, ON_CHANGE, onTemperatureChange);
}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

void setup() {
  Serial.begin(9600);
  delay(1500); 
  initProperties();

  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  

  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update(); 
}


void onTemperatureChange()  {
}

So, when I add the code for the access point to write and read from the EEPROM, I then, o my knowledge, need to move this line inside the void setup.

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

For example

void setup() {

  Serial.begin(9600);
  delay(1500); 
// Code for reading from EEPROM and the eeprom_SSID and eeprom_SSID_PASS will then pass to SSID and PASS Chars
//
  initProperties();
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  

  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

After that, the ESP will be pushed to restart as the IoT library doesn't find the SSID and PASS.

I have tried to do so with Blynk and many other libraries, and it worked; I could enter the credentials by activating a server and creating an access point to do so, and then blynk read from that and connected perfectly. The problem is that I have to use the Arduino IoT cloud, not Blynk. Thanks for your support.

  • Why did storing the credentials in eeprom not work? At some point the credentials need to be stored in non-volatile storage. – Kartman Dec 04 '22 at 11:00
  • Thanks for asking; the problem is not with storing the credentials in the EEPROM; the issue is with the IOTcloud library that is not reading the SSID and PASS from the void setup. I tried what I could unless the credentials were defined before executing the code, and there was no way to connect to the wifi. I edited the post and added the code. – Hayder Ismael Dec 12 '22 at 08:42
  • You have no code to tell the wifi to connect. It took me seconds to find an esp32 example of an arduino cloud project for the esp32. – Kartman Dec 12 '22 at 11:26
  • Thanks, @Kartman, The code was already with the post above. Arduino IoT library just works like that. in this case, if I move the devise to another place or I need to change the wifi credentials, I must edit the code and reupload it. – Hayder Ismael Dec 12 '22 at 15:15

0 Answers0