mirror of https://github.com/arendst/Tasmota.git
Refactor ESP32 sensors
This commit is contained in:
parent
7457d0b03c
commit
5cdf225fe0
|
@ -815,8 +815,6 @@ const float kSpeedConversionFactor[] = {1, // none
|
|||
#ifdef USE_WEBSERVER
|
||||
// {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
||||
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}";
|
||||
|
|
|
@ -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} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue