From 5cdf225fe009fb51c674a18a1cd9bf1d0fb8b87b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 12 Apr 2021 16:50:04 +0200 Subject: [PATCH] Refactor ESP32 sensors --- tasmota/i18n.h | 3 +-- tasmota/xsns_87_esp32_sensors.ino | 20 +++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 9799fbe90..c435348a8 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -815,8 +815,6 @@ const float kSpeedConversionFactor[] = {1, // none #ifdef USE_WEBSERVER // {s} = , {m} = , {e} = const char HTTP_SNS_F_TEMP[] PROGMEM = "{s}%s " D_TEMPERATURE "{m}%*_f " D_UNIT_DEGREE "%c{e}"; -//const char HTTP_SNS_TEMP[] PROGMEM = "{s}%s " D_TEMPERATURE "{m}%s " D_UNIT_DEGREE "%c{e}"; - const char HTTP_SNS_HUM[] PROGMEM = "{s}%s " D_HUMIDITY "{m}%s " D_UNIT_PERCENT "{e}"; const char HTTP_SNS_DEW[] PROGMEM = "{s}%s " D_DEWPOINT "{m}%s " D_UNIT_DEGREE "%c{e}"; const char HTTP_SNS_PRESSURE[] PROGMEM = "{s}%s " D_PRESSURE "{m}%s " "%s{e}"; @@ -832,6 +830,7 @@ const char HTTP_SNS_RANGE_CHR[] PROGMEM = "{s}%s " D_RANGE "{ const char HTTP_SNS_RANGE[] PROGMEM = "{s}%s " D_RANGE "{m}%d" "{e}"; const char HTTP_SNS_DISTANCE[] PROGMEM = "{s}%s " D_DISTANCE "{m}%d " D_UNIT_MILLIMETER "{e}"; const char HTTP_SNS_DISTANCE_CM[] PROGMEM = "{s}%s " D_DISTANCE "{m}%s " D_UNIT_CENTIMETER "{e}"; +const char HTTP_SNS_HALL_EFFECT[] PROGMEM = "{s}%s " D_HALL_EFFECT "{m}%d" "{e}"; const char HTTP_SNS_VOLTAGE[] PROGMEM = "{s}" D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}"; const char HTTP_SNS_CURRENT[] PROGMEM = "{s}" D_CURRENT "{m}%s " D_UNIT_AMPERE "{e}"; const char HTTP_SNS_POWER[] PROGMEM = "{s}" D_POWERUSAGE "{m}%s " D_UNIT_WATT "{e}"; diff --git a/tasmota/xsns_87_esp32_sensors.ino b/tasmota/xsns_87_esp32_sensors.ino index 6ab5b9820..c5fc80d52 100644 --- a/tasmota/xsns_87_esp32_sensors.ino +++ b/tasmota/xsns_87_esp32_sensors.ino @@ -19,9 +19,9 @@ #ifdef ESP32 /*********************************************************************************************\ - * ESP32 CPU Temperature - * ESP32 internal Hall Effect sensor connected to both GPIO36 and GPIO39 + * ESP32 CPU Temperature and optional Hall Effect sensor * + * ESP32 internal Hall Effect sensor connected to both GPIO36 and GPIO39 * To enable set * GPIO36 as HallEffect 1 * GPIO39 as HallEffect 2 @@ -47,14 +47,10 @@ void Esp32SensorInit(void) { } } -#ifdef USE_WEBSERVER -// {s} = , {m} = , {e} = -const char HTTP_SNS_HALL_EFFECT[] PROGMEM = "{s}" D_HALL_EFFECT "{m}%d{e}"; -#endif // USE_WEBSERVER - #endif // CONFIG_IDF_TARGET_ESP32 void Esp32SensorShow(bool json) { + float t = CpuTemperature(); #if CONFIG_IDF_TARGET_ESP32 int value = 0; @@ -67,7 +63,7 @@ void Esp32SensorShow(bool json) { #endif // CONFIG_IDF_TARGET_ESP32 if (json) { - float t = CpuTemperature(); + bool temperature_present = (strstr_P(TasmotaGlobal.mqtt_data, PSTR(D_JSON_TEMPERATURE)) != nullptr); ResponseAppend_P(PSTR(",\"ESP32\":{\"" D_JSON_TEMPERATURE "\":%*_f"), Settings.flag2.temperature_resolution, &t); #if CONFIG_IDF_TARGET_ESP32 @@ -77,9 +73,11 @@ void Esp32SensorShow(bool json) { #endif // CONFIG_IDF_TARGET_ESP32 ResponseJsonEnd(); - #ifdef USE_DOMOTICZ if (0 == TasmotaGlobal.tele_period) { + if (!temperature_present) { // Only send if no other sensor already did + DomoticzFloatSensor(DZ_TEMP, t); + } #if CONFIG_IDF_TARGET_ESP32 if (HEData.present) { @@ -91,10 +89,11 @@ void Esp32SensorShow(bool json) { #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { + WSContentSend_Temp("ESP32", t); #if CONFIG_IDF_TARGET_ESP32 if (HEData.present) { - WSContentSend_P(HTTP_SNS_HALL_EFFECT, value); + WSContentSend_P(HTTP_SNS_HALL_EFFECT, "ESP32", value); } #endif // CONFIG_IDF_TARGET_ESP32 @@ -121,7 +120,6 @@ bool Xsns87(uint8_t function) { case FUNC_INIT: Esp32SensorInit(); break; - } return result; }