So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By jdavies
#63107 Thanks for replying to this. I ended up writing my configuration struct to eeprom memory. Turns out to be quite simple. Here is a code snippet for anyone else that may have the same question I did:

Code: Select all#include <EEPROM.h>

// Device configuration
struct Configuration {
  char deviceID[32];  // Make and model of the device. For example "Bleu Farms ResDefender"
  char version[8];   // <major>.<minor>.<build> Example: 1.2.1
  char name[16];      // The name of this device. Example: "Tub 1"
  char location[32];  // The location of this device. Example: "Garage"
  byte macAddress[6];  // MAC address of the wemos D1, if used
  char unitOfMeasure;   // M = Metric, I = Imperial
  char ssid[32];    // SSID of the wifi we want to connect to
  char pw[32];      // Password for the WiFi we want to connect to
};

int eepromAddress = 0;   //Location we want the configuration to be stored.
Configuration myConfig;

void writeConfig() {
  EEPROM.put(eepromAddress, myConfig);
}

void readConfig() {
  EEPROM.get(eepromAddress, myConfig);
}
User avatar
By domfe
#63123 I'm using this library, it does all the job about storing and reading credentials
https://github.com/tzapu/WiFiManager

Code: Select all  WiFiManager wifiManager;
  wifiManager.setSTAStaticIPConfig(ip, gateway, subnet);

  {
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP" with password "password"
  //and goes into a blocking loop awaiting configuration
    if (!wifiManager.autoConnect("AutoConnectAP", "password")) {
      Serial.println(F("failed to connect, we should reset as see if it connects"));
      delay(3000);
      ESP.reset();
      delay(5000);
    }
  }