diff --git a/CHANGELOG.md b/CHANGELOG.md index bba30ffc2..02590a1ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] - Development -## [9.5.0.2] +## [9.5.0.3] +### Added +- Command ``SetSensor1..127 0|1`` to globally disable individual sensor driver + +## [9.5.0.2] 20210714 ### Added - Initial support for Tasmota Mesh (TasMesh) providing node/broker communication using ESP-NOW (#11939) - MQTT minimum password length restriction in GUI (#12553) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index e5a1c487a..9f28e171f 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -98,10 +98,11 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo [Complete list](BUILDS.md) of available feature and sensors. -## Changelog v9.5.0.2 +## Changelog v9.5.0.3 ### Added - Release of [Tasmota WebInstaller](https://arendst.github.io/Tasmota/) - Command ``SetOption127 1`` to force Wifi in no-sleep mode even if ``Sleep 0`` is not enabled +- Command ``SetSensor1..127 0|1`` to globally disable individual sensor driver - Initial support for Tasmota Mesh (TasMesh) providing node/broker communication using ESP-NOW [#11939](https://github.com/arendst/Tasmota/issues/11939) - Berry ESP32 partition manager [#12465](https://github.com/arendst/Tasmota/issues/12465) - Support for AM2320 Temperature and Humidity Sensor by Lars Wessels [#12485](https://github.com/arendst/Tasmota/issues/12485) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 6bf33d6a1..35a523234 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -257,6 +257,7 @@ #define D_CMND_PULSETIME "PulseTime" #define D_CMND_BLINKTIME "BlinkTime" #define D_CMND_BLINKCOUNT "BlinkCount" +#define D_CMND_SETSENSOR "SetSensor" #define D_CMND_SENSOR "Sensor" #define D_CMND_DRIVER "Driver" #define D_CMND_SAVEDATA "SaveData" diff --git a/tasmota/settings.h b/tasmota/settings.h index 7a18fcfb2..6ade9fc44 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -643,12 +643,7 @@ typedef struct { uint16_t sbaudrate; // 77A EnergyUsage energy_usage; // 77C - uint32_t ex_adc_param1; // 794 Free since 9.0.0.1 - uint32_t ex_adc_param2; // 798 Free since 9.0.0.1 - int ex_adc_param3; // 79C Free since 9.0.0.1 - - uint32_t monitors; // 7A0 - uint32_t sensors[4]; // 7A4 Normal WebSensor, Debug SetSensor + uint32_t sensors[2][4]; // 794 Disable individual (0) sensor drivers / (1) GUI sensor output uint32_t energy_kWhtotal_time; // 7B4 unsigned long weight_item; // 7B8 Weight of one item in gram * 10 uint16_t ledmask; // 7BC diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 3afdcab17..254ba106e 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -1122,7 +1122,7 @@ void SettingsDefaultSet2(void) { SettingsDefaultWebColor(); - memset(&Settings->monitors, 0xFF, 20); // Enable all possible monitors, displays and sensors + memset(&Settings->sensors, 0xFF, 32); // Enable all possible sensors SettingsEnableAllI2cDrivers(); // Tuya @@ -1361,7 +1361,6 @@ void SettingsDelta(void) { if (Settings->version < 0x09040006) { Settings->mqtt_wifi_timeout = MQTT_WIFI_CLIENT_TIMEOUT / 100; } - #ifdef CONFIG_IDF_TARGET_ESP32C3 if (Settings->version < 0x09050002) { if (Settings->cfg_size != sizeof(TSettings)) { @@ -1374,6 +1373,9 @@ void SettingsDelta(void) { } } #endif + if (Settings->version < 0x09050003) { + memset(&Settings->sensors, 0xFF, 16); // Enable all possible sensors + } Settings->version = VERSION; SettingsSave(1); diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index fbd023c4e..cad553579 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -42,7 +42,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix #endif // USE_DEVICE_GROUPS_SEND D_CMND_DEVGROUP_SHARE "|" D_CMND_DEVGROUPSTATUS "|" D_CMND_DEVGROUP_TIE "|" #endif // USE_DEVICE_GROUPS - D_CMND_SENSOR "|" D_CMND_DRIVER + D_CMND_SETSENSOR "|" D_CMND_SENSOR "|" D_CMND_DRIVER #ifdef ESP32 "|Info|" D_CMND_TOUCH_CAL "|" D_CMND_TOUCH_THRES "|" D_CMND_TOUCH_NUM "|" D_CMND_CPU_FREQUENCY #endif // ESP32 @@ -74,7 +74,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = { #endif // USE_DEVICE_GROUPS_SEND &CmndDevGroupShare, &CmndDevGroupStatus, &CmndDevGroupTie, #endif // USE_DEVICE_GROUPS - &CmndSensor, &CmndDriver + &CmndSetSensor, &CmndSensor, &CmndDriver #ifdef ESP32 , &CmndInfo, &CmndTouchCal, &CmndTouchThres, &CmndTouchNum, &CmndCpuFrequency #endif // ESP32 @@ -560,7 +560,7 @@ void CmndStatus(void) ResponseAppendFeatures(); XsnsDriverState(); ResponseAppend_P(PSTR(",\"Sensors\":")); - XsnsSensorState(); + XsnsSensorState(0); ResponseJsonEndEnd(); CmndStatusResponse(4); } @@ -2266,6 +2266,21 @@ void CmndDevGroupTie(void) } #endif // USE_DEVICE_GROUPS +void CmndSetSensor(void) +{ + if (XdrvMailbox.index < MAX_XSNS_DRIVERS) { + if (XdrvMailbox.payload >= 0) { + bitWrite(Settings->sensors[0][XdrvMailbox.index / 32], XdrvMailbox.index % 32, XdrvMailbox.payload &1); + if (1 == XdrvMailbox.payload) { + TasmotaGlobal.restart_flag = 2; // To safely re-enable a sensor currently most sensor need to follow complete restart init cycle + } + } + Response_P(PSTR("{\"" D_CMND_SETSENSOR "\":")); + XsnsSensorState(0); + ResponseJsonEnd(); + } +} + void CmndSensor(void) { XsnsCall(FUNC_COMMAND_SENSOR); diff --git a/tasmota/tasmota_version.h b/tasmota/tasmota_version.h index ce1a6e095..0f02b3d91 100644 --- a/tasmota/tasmota_version.h +++ b/tasmota/tasmota_version.h @@ -20,6 +20,6 @@ #ifndef _TASMOTA_VERSION_H_ #define _TASMOTA_VERSION_H_ -const uint32_t VERSION = 0x09050002; +const uint32_t VERSION = 0x09050003; #endif // _TASMOTA_VERSION_H_ diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 85a589a39..181240b01 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -3235,11 +3235,11 @@ void CmndWebSensor(void) { if (XdrvMailbox.index < MAX_XSNS_DRIVERS) { if (XdrvMailbox.payload >= 0) { - bitWrite(Settings->sensors[XdrvMailbox.index / 32], XdrvMailbox.index % 32, XdrvMailbox.payload &1); + bitWrite(Settings->sensors[1][XdrvMailbox.index / 32], XdrvMailbox.index % 32, XdrvMailbox.payload &1); } } Response_P(PSTR("{\"" D_CMND_WEBSENSOR "\":")); - XsnsSensorState(); + XsnsSensorState(1); ResponseJsonEnd(); } diff --git a/tasmota/xdrv_99_debug.ino b/tasmota/xdrv_99_debug.ino index 36345e5e4..6e33431a0 100644 --- a/tasmota/xdrv_99_debug.ino +++ b/tasmota/xdrv_99_debug.ino @@ -53,7 +53,6 @@ #define D_CMND_FREEMEM "FreeMem" #define D_CMND_HELP "Help" #define D_CMND_RTCDUMP "RtcDump" -#define D_CMND_SETSENSOR "SetSensor" #define D_CMND_I2CWRITE "I2CWrite" #define D_CMND_I2CREAD "I2CRead" #define D_CMND_I2CSTRETCH "I2CStretch" @@ -69,7 +68,7 @@ const char kDebugCommands[] PROGMEM = "|" // No prefix #ifdef DEBUG_THEO D_CMND_EXCEPTION "|" #endif - D_CMND_FLASHDUMP "|" D_CMND_FLASHMODE "|" D_CMND_FREEMEM"|" D_CMND_HELP "|" D_CMND_RTCDUMP "|" D_CMND_SETSENSOR "|" + D_CMND_FLASHDUMP "|" D_CMND_FLASHMODE "|" D_CMND_FREEMEM"|" D_CMND_HELP "|" D_CMND_RTCDUMP "|" #ifdef USE_I2C D_CMND_I2CWRITE "|" D_CMND_I2CREAD "|" D_CMND_I2CSTRETCH "|" D_CMND_I2CCLOCK #endif @@ -84,7 +83,7 @@ void (* const DebugCommand[])(void) PROGMEM = { #ifdef DEBUG_THEO &CmndException, #endif - &CmndFlashDump, &CmndFlashMode, &CmndFreemem, &CmndHelp, &CmndRtcDump, &CmndSetSensor, + &CmndFlashDump, &CmndFlashMode, &CmndFreemem, &CmndHelp, &CmndRtcDump, #ifdef USE_I2C &CmndI2cWrite, &CmndI2cRead, &CmndI2cStretch, &CmndI2cClock #endif @@ -558,21 +557,6 @@ void CmndFreemem(void) ResponseCmndNumber(CPU_show_freemem); } -void CmndSetSensor(void) -{ - if (XdrvMailbox.index < MAX_XSNS_DRIVERS) { - if (XdrvMailbox.payload >= 0) { - bitWrite(Settings->sensors[XdrvMailbox.index / 32], XdrvMailbox.index % 32, XdrvMailbox.payload &1); - if (1 == XdrvMailbox.payload) { - TasmotaGlobal.restart_flag = 2; // To safely re-enable a sensor currently most sensor need to follow complete restart init cycle - } - } - Response_P(PSTR("{\"" D_CMND_SETSENSOR "\":")); - XsnsSensorState(); - ResponseJsonEnd(); - } -} - void CmndFlashMode(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { diff --git a/tasmota/xsns_interface.ino b/tasmota/xsns_interface.ino index 081cbdf5e..bb9b35e1a 100644 --- a/tasmota/xsns_interface.ino +++ b/tasmota/xsns_interface.ino @@ -1055,7 +1055,9 @@ const uint8_t kXsnsList[] = { /*********************************************************************************************/ -bool XsnsEnabled(uint32_t sns_index) { +bool XsnsEnabled(uint32_t sensor_list, uint32_t sns_index) { + // sensor_list 0 = sensors + // sensor_list 1 = web_sensors if (sns_index < sizeof(kXsnsList)) { #ifdef XFUNC_PTR_IN_ROM uint32_t index = pgm_read_byte(kXsnsList + sns_index); @@ -1063,13 +1065,15 @@ bool XsnsEnabled(uint32_t sns_index) { uint32_t index = kXsnsList[sns_index]; #endif if (index < MAX_XSNS_DRIVERS) { - return bitRead(Settings->sensors[index / 32], index % 32); + return bitRead(Settings->sensors[sensor_list][index / 32], index % 32); } } return true; } -void XsnsSensorState(void) { +void XsnsSensorState(uint32_t sensor_list) { + // sensor_list 0 = sensors + // sensor_list 1 = web_sensors ResponseAppend_P(PSTR("\"")); // Use string for enable/disable signal for (uint32_t i = 0; i < sizeof(kXsnsList); i++) { #ifdef XFUNC_PTR_IN_ROM @@ -1079,7 +1083,7 @@ void XsnsSensorState(void) { #endif bool disabled = false; if (sensorid < MAX_XSNS_DRIVERS) { - disabled = !bitRead(Settings->sensors[sensorid / 32], sensorid % 32); + disabled = !bitRead(Settings->sensors[sensor_list][sensorid / 32], sensorid % 32); } ResponseAppend_P(PSTR("%s%s%d"), (i) ? "," : "", (disabled) ? "!" : "", sensorid); } @@ -1098,18 +1102,11 @@ bool XsnsNextCall(uint8_t Function, uint8_t &xsns_index) { xsns_index++; if (xsns_index == xsns_present) { xsns_index = 0; } - -#ifndef USE_DEBUG_DRIVER - if (FUNC_WEB_SENSOR == Function) { // Skip web info for disabled sensors -#endif - uint32_t max_disabled = xsns_present; - while (!XsnsEnabled(xsns_index) && max_disabled--) { // Perform at least one sensor - xsns_index++; - if (xsns_index == xsns_present) { xsns_index = 0; } - } -#ifndef USE_DEBUG_DRIVER + uint32_t max_disabled = xsns_present; + while ((!XsnsEnabled(0, xsns_index) || ((FUNC_WEB_SENSOR == Function) && !XsnsEnabled(1, xsns_index))) && max_disabled--) { // Perform at least one sensor + xsns_index++; + if (xsns_index == xsns_present) { xsns_index = 0; } } -#endif return xsns_func_ptr[xsns_index](Function); } @@ -1124,11 +1121,8 @@ bool XsnsCall(uint8_t Function) { #endif // PROFILE_XSNS_EVERY_SECOND for (uint32_t x = 0; x < xsns_present; x++) { -#ifdef USE_DEBUG_DRIVER - if (XsnsEnabled(x)) { // Skip disabled sensor in debug mode -#endif - - if ((FUNC_WEB_SENSOR == Function) && !XsnsEnabled(x)) { continue; } // Skip web info for disabled sensors + if (XsnsEnabled(0, x)) { // Skip disabled sensor + if ((FUNC_WEB_SENSOR == Function) && !XsnsEnabled(1, x)) { continue; } // Skip web info for disabled sensors #ifdef PROFILE_XSNS_SENSOR_EVERY_SECOND uint32_t profile_start_millis = millis(); @@ -1150,9 +1144,7 @@ bool XsnsCall(uint8_t Function) { )) { break; } -#ifdef USE_DEBUG_DRIVER } -#endif } #ifdef PROFILE_XSNS_EVERY_SECOND