mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-27 20:48:36 +00:00
Made wifi sleep mode configurable
This commit is contained in:
@@ -24,6 +24,7 @@ bool AmsConfiguration::getWiFiConfig(WiFiConfig& config) {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.get(CONFIG_WIFI_START, config);
|
||||
EEPROM.end();
|
||||
if(config.sleep > 2) config.sleep = 0xFF;
|
||||
return true;
|
||||
} else {
|
||||
clearWifi(config);
|
||||
@@ -33,6 +34,7 @@ bool AmsConfiguration::getWiFiConfig(WiFiConfig& config) {
|
||||
|
||||
bool AmsConfiguration::setWiFiConfig(WiFiConfig& config) {
|
||||
WiFiConfig existing;
|
||||
if(config.sleep > 2) config.sleep = 0xFF;
|
||||
if(getWiFiConfig(existing)) {
|
||||
wifiChanged |= strcmp(config.ssid, existing.ssid) != 0;
|
||||
wifiChanged |= strcmp(config.psk, existing.psk) != 0;
|
||||
@@ -45,6 +47,7 @@ bool AmsConfiguration::setWiFiConfig(WiFiConfig& config) {
|
||||
}
|
||||
wifiChanged |= strcmp(config.hostname, existing.hostname) != 0;
|
||||
wifiChanged |= config.power != existing.power;
|
||||
wifiChanged |= config.sleep != existing.sleep;
|
||||
} else {
|
||||
wifiChanged = true;
|
||||
}
|
||||
@@ -70,6 +73,7 @@ void AmsConfiguration::clearWifi(WiFiConfig& config) {
|
||||
#endif
|
||||
strcpy(config.hostname, (String("ams-") + String(chipId, HEX)).c_str());
|
||||
config.mdns = true;
|
||||
config.sleep = 0xFF;
|
||||
}
|
||||
|
||||
void AmsConfiguration::clearWifiIp(WiFiConfig& config) {
|
||||
|
||||
@@ -54,7 +54,8 @@ struct WiFiConfig {
|
||||
char hostname[32];
|
||||
bool mdns;
|
||||
uint8_t power;
|
||||
}; // 210
|
||||
uint8_t sleep;
|
||||
}; // 211
|
||||
|
||||
struct MqttConfig86 {
|
||||
char host[128];
|
||||
|
||||
@@ -1054,7 +1054,6 @@ void WiFi_connect() {
|
||||
}
|
||||
#endif
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setSleep(WIFI_PS_MAX_MODEM);
|
||||
#if defined(ESP32)
|
||||
if(wifi.power >= 195)
|
||||
WiFi.setTxPower(WIFI_POWER_19_5dBm);
|
||||
@@ -1115,6 +1114,9 @@ void WiFi_connect() {
|
||||
WiFi.setAutoReconnect(true);
|
||||
WiFi.persistent(true);
|
||||
if(WiFi.begin(wifi.ssid, wifi.psk)) {
|
||||
if(wifi.sleep <= 2) {
|
||||
WiFi.setSleep(wifi.sleep);
|
||||
}
|
||||
yield();
|
||||
} else {
|
||||
if (Debug.isActive(RemoteDebug::ERROR)) debugI("Unable to start WiFi");
|
||||
|
||||
@@ -444,6 +444,9 @@ void AmsWebServer::configWifiHtml() {
|
||||
html.replace(F("{h}"), wifi.hostname);
|
||||
html.replace(F("{m}"), wifi.mdns ? F("checked") : F(""));
|
||||
html.replace(F("{w}"), String(wifi.power / 10.0, 1));
|
||||
html.replace(F("{z0}"), wifi.sleep == 0 ? "selected" : "");
|
||||
html.replace(F("{z1}"), wifi.sleep == 1 ? "selected" : "");
|
||||
html.replace(F("{z2}"), wifi.sleep == 2 ? "selected" : "");
|
||||
#if defined(ESP32)
|
||||
html.replace(F("{wm}"), "19.5");
|
||||
#elif defined(ESP8266)
|
||||
@@ -1256,6 +1259,7 @@ void AmsWebServer::handleSave() {
|
||||
strcpy(wifi.hostname, server.arg(F("h")).c_str());
|
||||
}
|
||||
wifi.power = server.arg(F("w")).toFloat() * 10;
|
||||
wifi.sleep = server.arg(F("z")).toInt();
|
||||
config->setWiFiConfig(wifi);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user