Add wifi sleep toggle (implements #672 )

This commit is contained in:
cschwinne 2020-02-20 17:08:56 +01:00
parent 9dbd1b2a1b
commit c1a8fde9a0
8 changed files with 38 additions and 10 deletions

View File

@ -129,7 +129,7 @@ build_flags =
lib_deps =
${common.lib_deps_external}
lib_compat_mode = strict
lib_ignore = AsynTCP
lib_ignore = AsyncTCP
[env:d1_mini]
board = d1_mini
@ -143,7 +143,7 @@ build_flags =
lib_deps =
${common.lib_deps_external}
lib_compat_mode = strict
lib_ignore = AsynTCP
lib_ignore = AsyncTCP
[env:esp01_1m]
board = esp01_1m
@ -159,7 +159,7 @@ build_flags =
lib_deps =
${common.lib_deps_external}
lib_compat_mode = strict
lib_ignore = AsynTCP
lib_ignore = AsyncTCP
[env:esp01]
board = esp01
@ -174,7 +174,7 @@ build_flags =
lib_deps =
${common.lib_deps_external}
lib_compat_mode = strict
lib_ignore = AsynTCP
lib_ignore = AsyncTCP
[env:esp07]
board = esp07
@ -188,7 +188,7 @@ build_flags =
lib_deps =
${common.lib_deps_external}
lib_compat_mode = strict
lib_ignore = AsynTCP
lib_ignore = AsyncTCP
# see: http://docs.platformio.org/en/latest/platforms/espressif32.html
[env:esp32dev]
@ -220,7 +220,7 @@ build_flags =
lib_deps =
${common.lib_deps_external}
lib_compat_mode = strict
lib_ignore = AsynTCP
lib_ignore = AsyncTCP
[env:esp8285_4CH_H801]
board = esp8285
@ -237,7 +237,7 @@ build_flags =
lib_deps =
${common.lib_deps_external}
lib_compat_mode = strict
lib_ignore = AsynTCP
lib_ignore = AsyncTCP
[env:esp8285_5CH_H801]
board = esp8285
@ -255,5 +255,5 @@ build_flags =
lib_deps =
${common.lib_deps_external}
lib_compat_mode = strict
lib_ignore = AsynTCP
lib_ignore = AsyncTCP

View File

@ -62,7 +62,12 @@ AP opens:
<option value="1">Disconnected</option>
<option value="2">Always</option>
<option value="3">Never (not recommended)</option></select><br>
AP IP: <span class="sip"> Not active </span><hr>
AP IP: <span class="sip"> Not active </span><br>
<h3>Experimental</h3>
Disable WiFi sleep: <input type="checkbox" name="WS"><br>
<i>Can help with connectivity issues.<br>
Do not enable if WiFi is working correctly, increases power consumption.</i>
<hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button>
</form>
</body>

View File

@ -38,6 +38,9 @@
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESPAsyncTCP.h>
extern "C" {
#include <user_interface.h>
}
#else
#include <WiFi.h>
#include "esp_wifi.h"
@ -120,6 +123,8 @@ byte apBehavior = AP_BEHAVIOR_BOOT_NO_CONN; //access point opens when no conne
IPAddress staticIP(0, 0, 0, 0); //static IP of ESP
IPAddress staticGateway(0, 0, 0, 0); //gateway (router) IP
IPAddress staticSubnet(255, 255, 255, 0); //most common subnet in home networks
bool noWifiSleep = false; //disabling modem sleep modes will increase heat output and power usage, but may help with connection issues
//LED CONFIG
uint16_t ledCount = 30; //overcurrent prevented by ABL

View File

@ -6,7 +6,7 @@
#define EEPSIZE 2560
//eeprom Version code, enables default settings instead of 0 init on update
#define EEPVER 15
#define EEPVER 16
//0 -> old version, default
//1 -> 0.4p 1711272 and up
//2 -> 0.4p 1711302 and up
@ -23,6 +23,7 @@
//13-> 0.9.0-dev
//14-> 0.9.0-b1
//15-> 0.9.0-b3
//16-> 0.9.1
void commit()
{
@ -131,6 +132,8 @@ void saveSettingsToEEPROM()
EEPROM.write(368, abs(arlsOffset));
EEPROM.write(369, turnOnAtBoot);
EEPROM.write(370, noWifiSleep);
EEPROM.write(372, useRGBW);
EEPROM.write(374, strip.paletteFade);
EEPROM.write(375, strip.milliampsPerLed); //was apWaitTimeSecs up to 0.8.5
@ -484,6 +487,11 @@ void loadSettingsFromEEPROM(bool first)
DMXMode = DMX_MODE_MULTIPLE_RGB;
}
//if (lastEEPROMversion > 15)
//{
noWifiSleep = EEPROM.read(370);
//}
receiveDirect = !EEPROM.read(2200);
notifyMacro = EEPROM.read(2201);

View File

@ -194,6 +194,8 @@ void getSettingsJS(byte subPage, char* dest)
sappends('s',"AP",fapass);
sappend('v',"AC",apChannel);
sappend('c',"WS",noWifiSleep);
if (WiFi.localIP()[0] != 0) //is connected
{

View File

@ -46,6 +46,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
if (passlen == 0 || (passlen > 7 && !isAsterisksOnly(request->arg("AP").c_str(), 65))) strlcpy(apPass, request->arg("AP").c_str(), 65);
int t = request->arg("AC").toInt(); if (t > 0 && t < 14) apChannel = t;
noWifiSleep = request->hasArg("WS");
char k[3]; k[2] = 0;
for (int i = 0; i<4; i++)
{

View File

@ -190,9 +190,14 @@ void initConnection()
#ifdef ESP8266
WiFi.hostname(serverDescription);
#endif
WiFi.begin(clientSSID, clientPass);
#ifdef ARDUINO_ARCH_ESP32
if (noWifiSleep) WiFi.setSleep(false);
WiFi.setHostname(serverDescription);
#else
if (noWifiSleep) wifi_set_sleep_type(NONE_SLEEP_T);
#endif
}

View File

@ -129,6 +129,7 @@ bool initMqtt()
strcpy(mqttStatusTopic, mqttDeviceTopic);
strcat(mqttStatusTopic, "/status");
mqtt->setWill(mqttStatusTopic, 0, true, "offline");
mqtt->setKeepAlive(60);
mqtt->connect();
return true;
}