Changed command ``Sleep 0``

Changed command ``Sleep 0`` removes any sleep from wifi modem except when ESP32 BLE is active
This commit is contained in:
Theo Arends 2021-01-14 17:03:01 +01:00
parent fa4326b6b0
commit fdbd1dcc0a
7 changed files with 41 additions and 44 deletions

View File

@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
### Changed ### Changed
- Force initial default state ``SetOption57 1`` to scan wifi network every 44 minutes for strongest signal (#10395) - Force initial default state ``SetOption57 1`` to scan wifi network every 44 minutes for strongest signal (#10395)
- Command ``Sleep 0`` removes any sleep from wifi modem except when ESP32 BLE is active
## [9.2.0.2] 20210105 ## [9.2.0.2] 20210105
### Added ### Added

View File

@ -96,6 +96,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
- Replaced RA8876 GPIO selection from ``SPI CS`` by ``RA8876 CS`` - Replaced RA8876 GPIO selection from ``SPI CS`` by ``RA8876 CS``
### Changed ### Changed
- Command ``Sleep 0`` removes any sleep from wifi modem except when ESP32 BLE is active
- Logging from heap to stack freeing 700 bytes RAM - Logging from heap to stack freeing 700 bytes RAM
- Disabled ``USE_LIGHT`` light support for ZBBridge saving 17.6kB [#10374](https://github.com/arendst/Tasmota/issues/10374) - Disabled ``USE_LIGHT`` light support for ZBBridge saving 17.6kB [#10374](https://github.com/arendst/Tasmota/issues/10374)
- Force initial default state ``SetOption57 1`` to scan wifi network every 44 minutes for strongest signal [#10395](https://github.com/arendst/Tasmota/issues/10395) - Force initial default state ``SetOption57 1`` to scan wifi network every 44 minutes for strongest signal [#10395](https://github.com/arendst/Tasmota/issues/10395)

View File

@ -967,8 +967,9 @@ void CmndSetoption(void)
bitWrite(Settings.flag5.data, pindex, XdrvMailbox.payload); bitWrite(Settings.flag5.data, pindex, XdrvMailbox.payload);
switch (pindex) { switch (pindex) {
case 1: // SetOption115 - Enable ESP32 MI32 case 1: // SetOption115 - Enable ESP32 MI32
Settings.flag3.sleep_normal = 1; // SetOption60 - Enable normal sleep instead of dynamic sleep if (0 == XdrvMailbox.payload) {
TasmotaGlobal.restart_flag = 2; TasmotaGlobal.restart_flag = 2;
}
break; break;
} }
} }

View File

@ -160,15 +160,14 @@ void WiFiSetSleepMode(void)
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Disable sleep (Esp8288/Arduino core and sdk default) WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Disable sleep (Esp8288/Arduino core and sdk default)
} }
*/ */
if (TasmotaGlobal.sleep && Settings.flag3.sleep_normal) { // SetOption60 - Enable normal sleep instead of dynamic sleep if (0 == TasmotaGlobal.sleep) {
if (!TasmotaGlobal.wifi_stay_asleep) {
WiFi.setSleepMode(WIFI_NONE_SLEEP); // Disable sleep
}
} else {
if (Settings.flag3.sleep_normal) { // SetOption60 - Enable normal sleep instead of dynamic sleep
WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times
} else { } else {
#ifdef ESP8266
if (0 == TasmotaGlobal.sleep) {
WiFi.setSleepMode(WIFI_NONE_SLEEP); // Disable sleep
} else
#endif
{
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Sleep (Esp8288/Arduino core and sdk default) WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Sleep (Esp8288/Arduino core and sdk default)
} }
} }

View File

@ -125,6 +125,7 @@ struct {
bool skip_light_fade; // Temporarily skip light fading bool skip_light_fade; // Temporarily skip light fading
bool restart_halt; // Do not restart but stay in wait loop bool restart_halt; // Do not restart but stay in wait loop
bool module_changed; // Indicate module changed since last restart bool module_changed; // Indicate module changed since last restart
bool wifi_stay_asleep; // Allow sleep only incase of ESP32 BLE
StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits) StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits)
uint8_t spi_enabled; // SPI configured uint8_t spi_enabled; // SPI configured

View File

@ -279,16 +279,13 @@ void ESP32Init() {
if (TasmotaGlobal.global_state.wifi_down) { return; } if (TasmotaGlobal.global_state.wifi_down) { return; }
TasmotaGlobal.wifi_stay_asleep = true;
if (WiFi.getSleep() == false) { if (WiFi.getSleep() == false) {
if (0 == Settings.flag3.sleep_normal) { AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: Put WiFi modem in sleep mode"),"BLE");
AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: About to restart to put WiFi modem in sleep mode"),"BLE"); WiFi.setSleep(true); // Sleep
Settings.flag3.sleep_normal = 1; // SetOption60 - Enable normal sleep instead of dynamic sleep
TasmotaGlobal.restart_flag = 2;
}
return;
} }
AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: Initializing Blueetooth..."),"BLE"); AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: Initializing Bluetooth..."),"BLE");
if (!ESP32BLE.mode.init) { if (!ESP32BLE.mode.init) {
NimBLEDevice::init(""); NimBLEDevice::init("");

View File

@ -589,17 +589,17 @@ int MI32_decryptPacket(char *_buf, uint16_t _bufSize, uint32_t _type){
MI32_ReverseMAC(packet->MAC); MI32_ReverseMAC(packet->MAC);
uint8_t _bindkey[16] = {0x0}; uint8_t _bindkey[16] = {0x0};
bool foundNoKey = true; bool foundNoKey = true;
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: search key for MAC: %02x %02x %02x %02x %02x %02x"), packet->MAC[0], packet->MAC[1], packet->MAC[2], packet->MAC[3], packet->MAC[4], packet->MAC[5]); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Search key for MAC: %02x %02x %02x %02x %02x %02x"), packet->MAC[0], packet->MAC[1], packet->MAC[2], packet->MAC[3], packet->MAC[4], packet->MAC[5]);
for(uint32_t i=0; i<MIBLEbindKeys.size(); i++){ for(uint32_t i=0; i<MIBLEbindKeys.size(); i++){
if(memcmp(packet->MAC,MIBLEbindKeys[i].MAC,sizeof(packet->MAC))==0){ if(memcmp(packet->MAC,MIBLEbindKeys[i].MAC,sizeof(packet->MAC))==0){
memcpy(_bindkey,MIBLEbindKeys[i].key,sizeof(_bindkey)); memcpy(_bindkey,MIBLEbindKeys[i].key,sizeof(_bindkey));
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: decryption Key found")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Decryption Key found"));
foundNoKey = false; foundNoKey = false;
break; break;
} }
} }
if(foundNoKey){ if(foundNoKey){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: no Key found !!")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: No Key found !!"));
return -2; return -2;
} }
@ -619,7 +619,7 @@ int MI32_decryptPacket(char *_buf, uint16_t _bufSize, uint32_t _type){
ret = br_ccm_check_tag(&ctx, &tag); ret = br_ccm_check_tag(&ctx, &tag);
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: Err:%i, Decrypted : %02x %02x %02x %02x %02x "), ret, packet->payload[1],packet->payload[2],packet->payload[3],packet->payload[4],packet->payload[5]); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Err:%i, Decrypted : %02x %02x %02x %02x %02x "), ret, packet->payload[1],packet->payload[2],packet->payload[3],packet->payload[4],packet->payload[5]);
return ret-1; return ret-1;
} }
#endif // USE_MI_DECRYPTION #endif // USE_MI_DECRYPTION
@ -660,7 +660,7 @@ uint32_t MIBLEgetSensorSlot(uint8_t (&_MAC)[6], uint16_t _type, uint8_t counter)
bool _success = false; bool _success = false;
for (uint32_t i=0;i<MI32_TYPES;i++){ // i < sizeof(kMI32DeviceID) gives compiler warning for (uint32_t i=0;i<MI32_TYPES;i++){ // i < sizeof(kMI32DeviceID) gives compiler warning
if(_type == kMI32DeviceID[i]){ if(_type == kMI32DeviceID[i]){
DEBUG_SENSOR_LOG(PSTR("MI32: ID is type %u"), i); DEBUG_SENSOR_LOG(PSTR("M32: ID is type %u"), i);
_type = i+1; _type = i+1;
_success = true; _success = true;
} }
@ -779,26 +779,23 @@ void MI32PreInit(void) {
MI32.option.showRSSI = 1; MI32.option.showRSSI = 1;
MI32.option.ignoreBogusBattery = 1; // from advertisements MI32.option.ignoreBogusBattery = 1; // from advertisements
MI32.option.holdBackFirstAutodiscovery = 1; MI32.option.holdBackFirstAutodiscovery = 1;
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: pre-init")); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: pre-init"));
} }
void MI32Init(void) { void MI32Init(void) {
if (MI32.mode.init) { return; } if (MI32.mode.init) { return; }
if (TasmotaGlobal.global_state.wifi_down) { return; } if (TasmotaGlobal.global_state.wifi_down) { return; }
TasmotaGlobal.wifi_stay_asleep = true;
if (WiFi.getSleep() == false) { if (WiFi.getSleep() == false) {
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: WiFi modem not in sleep mode, BLE cannot start yet")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Put WiFi modem in sleep mode"));
if (0 == Settings.flag3.sleep_normal) { WiFi.setSleep(true); // Sleep
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: About to restart to put WiFi modem in sleep mode"));
Settings.flag3.sleep_normal = 1; // SetOption60 - Enable normal sleep instead of dynamic sleep
TasmotaGlobal.restart_flag = 2;
}
return;
} }
if (!MI32.mode.init) { if (!MI32.mode.init) {
NimBLEDevice::init(""); NimBLEDevice::init("");
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: init BLE device")); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Init BLE device"));
MI32.mode.canScan = 1; MI32.mode.canScan = 1;
MI32.mode.init = 1; MI32.mode.init = 1;
MI32.period = Settings.tele_period; MI32.period = Settings.tele_period;
@ -1286,7 +1283,7 @@ void MI32parseMiBeacon(char * _buf, uint32_t _slot, uint16_t _bufSize){
break; break;
} }
if(decryptRet!=0){ if(decryptRet!=0){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: decryption failed with error: %d"),decryptRet); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Decryption failed with error: %d"),decryptRet);
return; return;
} }
#endif //USE_MI_DECRYPTION #endif //USE_MI_DECRYPTION
@ -1459,7 +1456,7 @@ void MI32parseCGD1Packet(char * _buf, uint32_t length, uint8_t addr[6], int RSSI
} }
break; break;
default: default:
DEBUG_SENSOR_LOG(PSTR("MI32: unexpected CGD1-packet")); DEBUG_SENSOR_LOG(PSTR("M32: Unexpected CGD1-packet"));
} }
if(MIBLEsensors[_slot].eventType.raw == 0) return; if(MIBLEsensors[_slot].eventType.raw == 0) return;
MIBLEsensors[_slot].shallSendMQTT = 1; MIBLEsensors[_slot].shallSendMQTT = 1;
@ -1491,7 +1488,7 @@ void MI32ParseResponse(char *buf, uint16_t bufsize, uint8_t addr[6], int RSSI) {
* @param UUID * @param UUID
*/ */
void MI32ParseGenericBeacon(uint8_t* payload, size_t payloadLength, uint16_t* CID, uint16_t*SVC, uint16_t* UUID){ void MI32ParseGenericBeacon(uint8_t* payload, size_t payloadLength, uint16_t* CID, uint16_t*SVC, uint16_t* UUID){
AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("MI32: Beacon:____________")); AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Beacon:____________"));
for (uint32_t i = 0; i<payloadLength;){ for (uint32_t i = 0; i<payloadLength;){
uint32_t ADtype = payload[i+1]; uint32_t ADtype = payload[i+1];
uint32_t offset = payload[i]; uint32_t offset = payload[i];
@ -1549,13 +1546,13 @@ void MI32HandleGenericBeacon(uint8_t* payload, size_t payloadLength, int RSSI, u
} }
// else handle scan // else handle scan
if(MIBLEscanResult.size()>19) { if(MIBLEscanResult.size()>19) {
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: Scan buffer full")); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Scan buffer full"));
MI32.state.beaconScanCounter = 1; MI32.state.beaconScanCounter = 1;
return; return;
} }
for(auto _scanResult : MIBLEscanResult){ for(auto _scanResult : MIBLEscanResult){
if(memcmp(addr,_scanResult.MAC,6)==0){ if(memcmp(addr,_scanResult.MAC,6)==0){
// AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: known device")); // AddLog_P(LOG_LEVEL_INFO,PSTR("M32: known device"));
return; return;
} }
} }
@ -1585,12 +1582,12 @@ void MI32addBeacon(uint8_t index, char* data){
_new.time = 0; _new.time = 0;
if(memcmp(_empty,_new.MAC,6) == 0){ if(memcmp(_empty,_new.MAC,6) == 0){
_new.active = false; _new.active = false;
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: beacon%u deactivated"), index); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Beacon%u deactivated"), index);
} }
else{ else{
_new.active = true; _new.active = true;
MI32.mode.activeBeacon = 1; MI32.mode.activeBeacon = 1;
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: beacon added with MAC: %s"), _MAC); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Beacon added with MAC: %s"), _MAC);
} }
} }
@ -1845,7 +1842,7 @@ void CmndMi32Time(void) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (MIBLEsensors.size() > XdrvMailbox.payload) { if (MIBLEsensors.size() > XdrvMailbox.payload) {
if ((LYWSD02 == MIBLEsensors[XdrvMailbox.payload].type) || (MHOC303 == MIBLEsensors[XdrvMailbox.payload].type)) { if ((LYWSD02 == MIBLEsensors[XdrvMailbox.payload].type) || (MHOC303 == MIBLEsensors[XdrvMailbox.payload].type)) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("MI32: will set Time")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Will set Time"));
MI32.state.sensor = XdrvMailbox.payload; MI32.state.sensor = XdrvMailbox.payload;
MI32.mode.canScan = 0; MI32.mode.canScan = 0;
MI32.mode.canConnect = 0; MI32.mode.canConnect = 0;
@ -1875,7 +1872,7 @@ void CmndMi32Unit(void) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (MIBLEsensors.size() > XdrvMailbox.payload) { if (MIBLEsensors.size() > XdrvMailbox.payload) {
if ((LYWSD02 == MIBLEsensors[XdrvMailbox.payload].type) || (MHOC303 == MIBLEsensors[XdrvMailbox.payload].type)) { if ((LYWSD02 == MIBLEsensors[XdrvMailbox.payload].type) || (MHOC303 == MIBLEsensors[XdrvMailbox.payload].type)) {
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: will set Unit")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Will set Unit"));
MI32.state.sensor = XdrvMailbox.payload; MI32.state.sensor = XdrvMailbox.payload;
MI32.mode.canScan = 0; MI32.mode.canScan = 0;
MI32.mode.canConnect = 0; MI32.mode.canConnect = 0;
@ -1925,11 +1922,11 @@ void CmndMi32Block(void){
switch (XdrvMailbox.index) { switch (XdrvMailbox.index) {
case 0: case 0:
MIBLEBlockList.clear(); MIBLEBlockList.clear();
// AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: size of ilist: %u"), MIBLEBlockList.size()); // AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Size of ilist: %u"), MIBLEBlockList.size());
ResponseCmndIdxChar(PSTR("block list cleared")); ResponseCmndIdxChar(PSTR("Block list cleared"));
break; break;
case 1: case 1:
ResponseCmndIdxChar(PSTR("show block list")); ResponseCmndIdxChar(PSTR("Show block list"));
break; break;
} }
} }
@ -1955,7 +1952,7 @@ void CmndMi32Block(void){
ResponseCmndIdxChar(XdrvMailbox.data); ResponseCmndIdxChar(XdrvMailbox.data);
MI32removeMIBLEsensor(_MACasBytes.buf); MI32removeMIBLEsensor(_MACasBytes.buf);
} }
// AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: size of ilist: %u"), MIBLEBlockList.size()); // AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Size of ilist: %u"), MIBLEBlockList.size());
break; break;
} }
} }