Add timeout setting in web interface
This commit is contained in:
parent
4f65b284b3
commit
6e1b12f892
|
@ -74,15 +74,17 @@ enum UpdateStatus {
|
||||||
#define PIN_CONFIG 0
|
#define PIN_CONFIG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WIFI_TIMEOUT 10000
|
|
||||||
#define UPDATE_START_DELAY 3000
|
#define UPDATE_START_DELAY 3000
|
||||||
#define EEPROM_SIZE 128
|
#define EEPROM_SIZE 129
|
||||||
|
|
||||||
|
#define DEFAULT_HOSTNAME "xatLabs-WiFi-Module"
|
||||||
|
#define DEFAULT_STA_TIMEOUT 10
|
||||||
|
|
||||||
/*
|
/*
|
||||||
GLOBAL VARIABLES
|
GLOBAL VARIABLES
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned long FW_VERSION = 1907010001; // Changes with each release; must always increase
|
unsigned long FW_VERSION = 2011110001; // Changes with each release; must always increase
|
||||||
unsigned long SP_VERSION = 0; // Loaded from SPIFFS; changed with each SPIFFS build; must always increase (uses timestamp as version)
|
unsigned long SP_VERSION = 0; // Loaded from SPIFFS; changed with each SPIFFS build; must always increase (uses timestamp as version)
|
||||||
|
|
||||||
// FW & SPIFFS update settings
|
// FW & SPIFFS update settings
|
||||||
|
@ -111,6 +113,7 @@ String STA_PASS;
|
||||||
String STA_HOSTNAME;
|
String STA_HOSTNAME;
|
||||||
char STA_HOSTNAME_CHAR[33];
|
char STA_HOSTNAME_CHAR[33];
|
||||||
bool STA_SETUP = false;
|
bool STA_SETUP = false;
|
||||||
|
unsigned char STA_TIMEOUT = DEFAULT_STA_TIMEOUT;
|
||||||
|
|
||||||
// Variables for Access Point WiFi
|
// Variables for Access Point WiFi
|
||||||
String AP_SSID = "xatLabs WiFi Module";
|
String AP_SSID = "xatLabs WiFi Module";
|
||||||
|
@ -208,8 +211,9 @@ bool loadConfig() {
|
||||||
STA_HOSTNAME += curChar;
|
STA_HOSTNAME += curChar;
|
||||||
hostnameSetup = true;
|
hostnameSetup = true;
|
||||||
}
|
}
|
||||||
if (STA_HOSTNAME == "") STA_HOSTNAME = "xatLabs-WiFi-Module";
|
if (STA_HOSTNAME == "") STA_HOSTNAME = DEFAULT_HOSTNAME;
|
||||||
STA_HOSTNAME.toCharArray(STA_HOSTNAME_CHAR, 32);
|
STA_HOSTNAME.toCharArray(STA_HOSTNAME_CHAR, 32);
|
||||||
|
STA_TIMEOUT = EEPROM.read(128);
|
||||||
STA_SETUP = (ssidSetup && passSetup);
|
STA_SETUP = (ssidSetup && passSetup);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -236,6 +240,7 @@ bool saveConfig() {
|
||||||
for (byte i = 0; i < STA_HOSTNAME.length(); i++) {
|
for (byte i = 0; i < STA_HOSTNAME.length(); i++) {
|
||||||
EEPROM.write(i + 96, STA_HOSTNAME.charAt(i));
|
EEPROM.write(i + 96, STA_HOSTNAME.charAt(i));
|
||||||
}
|
}
|
||||||
|
EEPROM.write(128, STA_TIMEOUT);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -357,6 +362,9 @@ void handleRoot() {
|
||||||
c += "<table>";
|
c += "<table>";
|
||||||
c += "<tr><td>Network Name</td><td><input type='text' name='ssid' maxlength='32' /></td></tr>";
|
c += "<tr><td>Network Name</td><td><input type='text' name='ssid' maxlength='32' /></td></tr>";
|
||||||
c += "<tr><td>Password</td><td><input type='password' name='password' maxlength='64' /></td></tr>";
|
c += "<tr><td>Password</td><td><input type='password' name='password' maxlength='64' /></td></tr>";
|
||||||
|
c += "<tr><td>Timeout</td><td><input type='text' name='timeout' maxlength='3' value='";
|
||||||
|
c += String(STA_TIMEOUT);
|
||||||
|
c += "' /> sec (5 to 254)</td></tr>";
|
||||||
c += "<tr><td><input type='submit' value='Save and Reboot' /></td></tr>";
|
c += "<tr><td><input type='submit' value='Save and Reboot' /></td></tr>";
|
||||||
c += "</table>";
|
c += "</table>";
|
||||||
c += "</form>";
|
c += "</form>";
|
||||||
|
@ -388,6 +396,9 @@ void handleRoot() {
|
||||||
void handle_wifi_setup() {
|
void handle_wifi_setup() {
|
||||||
STA_SSID = server.arg("ssid");
|
STA_SSID = server.arg("ssid");
|
||||||
STA_PASS = server.arg("password");
|
STA_PASS = server.arg("password");
|
||||||
|
String timeoutStr = server.arg("timeout");
|
||||||
|
unsigned int timeout = atoi(timeoutStr.c_str());
|
||||||
|
STA_TIMEOUT = (timeout >= 5 && timeout <= 254) ? timeout : STA_TIMEOUT;
|
||||||
STA_SETUP = true;
|
STA_SETUP = true;
|
||||||
saveConfig();
|
saveConfig();
|
||||||
server.sendHeader("Location", "/", true);
|
server.sendHeader("Location", "/", true);
|
||||||
|
@ -545,10 +556,11 @@ void printIPAddress() {
|
||||||
IBIS_GSP(1, "WLAN-Modul", IP_ADDRESS);
|
IBIS_GSP(1, "WLAN-Modul", IP_ADDRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetWiFiCredentials() {
|
void resetWiFiSettings() {
|
||||||
STA_SSID = "";
|
STA_SSID = "";
|
||||||
STA_PASS = "";
|
STA_PASS = "";
|
||||||
STA_HOSTNAME = "xatLabs-WiFi-Module";
|
STA_HOSTNAME = DEFAULT_HOSTNAME;
|
||||||
|
STA_TIMEOUT = DEFAULT_STA_TIMEOUT;
|
||||||
STA_SETUP = false;
|
STA_SETUP = false;
|
||||||
saveConfig();
|
saveConfig();
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
@ -729,13 +741,19 @@ void setup() {
|
||||||
pinMode(PIN_CONFIG, INPUT_PULLUP);
|
pinMode(PIN_CONFIG, INPUT_PULLUP);
|
||||||
//attachInterrupt(digitalPinToInterrupt(PIN_CONFIG), ISR_config, CHANGE);
|
//attachInterrupt(digitalPinToInterrupt(PIN_CONFIG), ISR_config, CHANGE);
|
||||||
|
|
||||||
EEPROM.begin(EEPROM_SIZE); // 32 for SSID, 64 for PSK, 32 for hostname
|
EEPROM.begin(EEPROM_SIZE); // 32 for SSID, 64 for PSK, 32 for hostname, 1 for timeout
|
||||||
|
|
||||||
// Reset hostname area of EEPROM if required
|
// Reset hostname area of EEPROM if required
|
||||||
if (EEPROM.read(96) == 0xff) {
|
if (EEPROM.read(96) == 0xff) {
|
||||||
reset_EEPROM(96, 128);
|
reset_EEPROM(96, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset timeout byte of EEPROM if required
|
||||||
|
if (EEPROM.read(128) == 0xff) {
|
||||||
|
EEPROM.write(128, STA_TIMEOUT);
|
||||||
|
EEPROM.commit();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef INIT_EEPROM
|
#ifdef INIT_EEPROM
|
||||||
reset_EEPROM();
|
reset_EEPROM();
|
||||||
#endif
|
#endif
|
||||||
|
@ -755,7 +773,7 @@ void setup() {
|
||||||
WiFi.begin(STA_SSID.c_str(), STA_PASS.c_str());
|
WiFi.begin(STA_SSID.c_str(), STA_PASS.c_str());
|
||||||
wifiTimer = millis();
|
wifiTimer = millis();
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
if ((millis() - wifiTimer) > WIFI_TIMEOUT) {
|
if ((millis() - wifiTimer) > STA_TIMEOUT * 1000) {
|
||||||
wifiTimedOut = true;
|
wifiTimedOut = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -920,7 +938,7 @@ void loop() {
|
||||||
}
|
}
|
||||||
case 10: {
|
case 10: {
|
||||||
// Reset WiFi Credentials
|
// Reset WiFi Credentials
|
||||||
resetWiFiCredentials();
|
resetWiFiSettings();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -929,4 +947,3 @@ void loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
firmware1.bin
BIN
firmware1.bin
Binary file not shown.
|
@ -1 +1 @@
|
||||||
1907010001
|
2011110001
|
BIN
firmware2.bin
BIN
firmware2.bin
Binary file not shown.
|
@ -1 +1 @@
|
||||||
1907010001
|
2011110001
|
Loading…
Reference in New Issue