ESP8266 WiFi connector & configuration manager.
Configuration parameters:
Parameter | Description |
---|---|
Title | Title displayed in the config web interface |
APSSID | Access Point SSID (for config when wifi connection fails) |
APPassword | Access Point password (at least 8 characters) |
CustomParMax | Number of Custom Parameters |
ConfigPin | Pin used to enter config mode during startup. When pressed it will enter config mode. Set to 0 when not used! Set to -1 to enter config mode on power on (duration set with APtimeout). |
UseWifi | true = Use normal Wifi connection for config mode. false = Use AP mode for config mode. |
Setting are stored on the LittleFS filesystem in a file named "config.json". Make sure if you need to use a filesystem, you also choose LittleFS and do not use a file called "config.json"!
Download the library here.
Example how to use it:
/*************************************************************************************************************************
* Project : Wifi Config 3 - Example
* Version : 1.0
* Date : 2024-06-21
* Author : MeneerKlaas
*************************************************************************************************************************/
#include
//===============================================================
// GLOBAL VARIABLES
//===============================================================
String sTitle = "Wifi Config Example"; // Title displayed in Config menu.
String sAPSSID = "ESPConfigWifiExample"; // Access Point for config when wifi connection fails.
String sAPPassword = "configesp"; // Access Point password (at least 8 characters).
byte iWifiConfigState; // Wifi Config State
const int iConfigPin = -1; // Pin used to enter config mode. Set to 0 when not used! Set to -1 to enter config mode on power on.
const bool bUseWifi = true; // Use normal Wifi connection for config mode.
const int iCustomParMax = 5; // Number of custom parameters.
String sPar[5]; // Parameters [0..4]
// Parameter ID's
#define idPar1 1
#define idPar2 2
#define idPar3 3
#define idPar4 4
#define idPar5 5
WifiConfig3 oWC(sTitle, sAPSSID, sAPPassword, iCustomParMax, iConfigPin, bUseWifi ); // Init WifiConfig object.
//==============================================================================================================
// SETUP
//==============================================================================================================
void setup() {
// On reset, ESP8266 hardware default baud rate depends on the crystal choice. With a 40MHz crystal you get 115200bps.
// With a 26MHz crystal you get proportionally less, 74880bps (115200*26/40).
// Almost everyone (including Espressif) ships hardware with a 26MHz crystal, so almost everyone gets 74880bps by default.
// I prefer to set the comminication speed to this value to also get the boot details.
Serial.begin(74880);
oWC.enableDebug();
// Add Custom Parameters
if (!oWC.addCustomPar(idPar1, "Test Parameter 1", "")) { Serial.println("Error: Parameter not added"); }
if (!oWC.addCustomPar(idPar2, "Test Parameter 2", "")) { Serial.println("Error: Parameter not added"); }
if (!oWC.addCustomPar(idPar3, "Test Parameter 3", "")) { Serial.println("Error: Parameter not added"); }
if (!oWC.addCustomPar(idPar4, "Test Parameter 4", "")) { Serial.println("Error: Parameter not added"); }
if (!oWC.addCustomPar(idPar5, "Test Parameter 5", "")) { Serial.println("Error: Parameter not added"); }
Serial.println("");
Serial.println("-------------------------------------");
Serial.println("Wifi Config Example");
Serial.println("-------------------------------------");
// Connect to Wi-Fi
iWifiConfigState = oWC.startWifi(false);
switch (iWifiConfigState) {
case 0: // 0 - Config loaded and Wifi Connected
break;
case 1: // 1 - Config loaded but no Wifi Connection
// No WifiConnection could be made. Try again in 1 minute.
ESP.deepSleep(60000);
break;
}
// Get th parameter values (those are always Strings).
sPar[0] = oWC.getCustomParValue(idPar1);
sPar[1] = oWC.getCustomParValue(idPar2);
sPar[2] = oWC.getCustomParValue(idPar3);
sPar[3] = oWC.getCustomParValue(idPar4);
sPar[4] = oWC.getCustomParValue(idPar5);
// Normal part of code here. Not in config mode and Wifi connection has been made.
} //END: setup
//==============================================================================================================
// LOOP
//==============================================================================================================
void loop() {
Serial.println("Wifi State: " + String(iWifiConfigState));
for (int i=0; i<5; i++) {
Serial.println("Parameter ["+String(i)+"]: " + sPar[i]);
}
Serial.println("-------------------------------------");
delay(5000);
} //END: loop