From c1f30da81ee71fcfb9b293997fb4d4b1dc75fe7f Mon Sep 17 00:00:00 2001 From: Federico Leoni Date: Mon, 23 Dec 2019 22:22:29 -0300 Subject: [PATCH 1/5] Add Moisture Sensor --- tasmota/i18n.h | 4 +++ tasmota/language/bg-BG.h | 1 + tasmota/language/cs-CZ.h | 1 + tasmota/language/de-DE.h | 1 + tasmota/language/el-GR.h | 1 + tasmota/language/en-GB.h | 1 + tasmota/language/es-ES.h | 1 + tasmota/language/fr-FR.h | 1 + tasmota/language/he-HE.h | 1 + tasmota/language/hu-HU.h | 1 + tasmota/language/it-IT.h | 1 + tasmota/language/ko-KO.h | 1 + tasmota/language/nl-NL.h | 1 + tasmota/language/pl-PL.h | 1 + tasmota/language/pt-BR.h | 1 + tasmota/language/pt-PT.h | 1 + tasmota/language/ru-RU.h | 1 + tasmota/language/sk-SK.h | 1 + tasmota/language/sv-SE.h | 1 + tasmota/language/tr-TR.h | 1 + tasmota/language/uk-UK.h | 1 + tasmota/language/zh-CN.h | 1 + tasmota/language/zh-TW.h | 1 + tasmota/tasmota_template.h | 2 ++ tasmota/xsns_02_analog.ino | 51 +++++++++++++++++++++++++++++++++----- tasmota/xsns_48_chirp.ino | 2 +- 26 files changed, 74 insertions(+), 7 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 68a19f75e..24b0e1f19 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -99,6 +99,7 @@ #define D_JSON_MEMORY_ERROR "Memory error" #define D_JSON_MINIMAL "minimal" #define D_JSON_MODEL "Model" +#define D_JSON_MOISTURE "Moisture" #define D_JSON_MQTT_COUNT "MqttCount" #define D_JSON_NO "No" #define D_JSON_NOISE "Noise" @@ -589,6 +590,7 @@ const char JSON_SNS_TEMP[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"; const char JSON_SNS_TEMPHUM[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s}"; const char JSON_SNS_ILLUMINANCE[] PROGMEM = ",\"%s\":{\"" D_JSON_ILLUMINANCE "\":%d}"; +const char JSON_SNS_MOISTURE[] PROGMEM = ",\"%s\":{\"" D_JSON_MOISTURE "\":%d}"; const char JSON_SNS_GNGPM[] PROGMEM = ",\"%s\":{\"" D_JSON_TOTAL_USAGE "\":%s,\"" D_JSON_FLOWRATE "\":%s}"; @@ -618,6 +620,8 @@ const char HTTP_SNS_CO2[] PROGMEM = "{s}%s " D_CO2 "{m}%d " D_UNIT_PARTS_PER_MIL const char HTTP_SNS_CO2EAVG[] PROGMEM = "{s}%s " D_ECO2 "{m}%d " D_UNIT_PARTS_PER_MILLION "{e}"; // {s} = , {m} = , {e} = const char HTTP_SNS_GALLONS[] PROGMEM = "{s}%s " D_TOTAL_USAGE "{m}%s " D_UNIT_GALLONS " {e}"; // {s} = , {m} = , {e} = const char HTTP_SNS_GPM[] PROGMEM = "{s}%s " D_FLOW_RATE "{m}%s " D_UNIT_GALLONS_PER_MIN" {e}"; // {s} = , {m} = , {e} = +const char HTTP_SNS_MOISTURE[] PROGMEM = "{s}%s " D_MOISTURE "{m}%d %%{e}"; // {s} = , {m} = , {e} = + const char S_MAIN_MENU[] PROGMEM = D_MAIN_MENU; const char S_CONFIGURATION[] PROGMEM = D_CONFIGURATION; diff --git a/tasmota/language/bg-BG.h b/tasmota/language/bg-BG.h index 12937ca6c..f2ac56402 100644 --- a/tasmota/language/bg-BG.h +++ b/tasmota/language/bg-BG.h @@ -113,6 +113,7 @@ #define D_LIGHT "Светлина" #define D_LWT "LWT" #define D_MODULE "Модул" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "неколкократно натискане" #define D_NOISE "Шум" diff --git a/tasmota/language/cs-CZ.h b/tasmota/language/cs-CZ.h index a297d7063..272e2c5ca 100644 --- a/tasmota/language/cs-CZ.h +++ b/tasmota/language/cs-CZ.h @@ -113,6 +113,7 @@ #define D_LIGHT "Světlo" #define D_LWT "LWT" #define D_MODULE "Modul" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "několikeré-stisknutí" #define D_NOISE "Hluk" diff --git a/tasmota/language/de-DE.h b/tasmota/language/de-DE.h index 663628cd1..89d36103d 100644 --- a/tasmota/language/de-DE.h +++ b/tasmota/language/de-DE.h @@ -113,6 +113,7 @@ #define D_LIGHT "Licht" #define D_LWT "LWT" #define D_MODULE "Modul" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "Mehrfachdruck" #define D_NOISE "Lautstärke" diff --git a/tasmota/language/el-GR.h b/tasmota/language/el-GR.h index d491d31a2..2b1e4748c 100644 --- a/tasmota/language/el-GR.h +++ b/tasmota/language/el-GR.h @@ -113,6 +113,7 @@ #define D_LIGHT "Φως" #define D_LWT "LWT" #define D_MODULE "Μονάδα" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "ανίχνευση για πολλαπλά πατήματα" #define D_NOISE "Θόρυβος" diff --git a/tasmota/language/en-GB.h b/tasmota/language/en-GB.h index 8ec56b16c..ab7f90cf8 100644 --- a/tasmota/language/en-GB.h +++ b/tasmota/language/en-GB.h @@ -113,6 +113,7 @@ #define D_LIGHT "Light" #define D_LWT "LWT" #define D_MODULE "Module" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "multi-press" #define D_NOISE "Noise" diff --git a/tasmota/language/es-ES.h b/tasmota/language/es-ES.h index 42f0991a6..e41b4cb32 100644 --- a/tasmota/language/es-ES.h +++ b/tasmota/language/es-ES.h @@ -113,6 +113,7 @@ #define D_LIGHT "Luz" #define D_LWT "LWT" #define D_MODULE "Módulo" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "multi-press" #define D_NOISE "Ruido" diff --git a/tasmota/language/fr-FR.h b/tasmota/language/fr-FR.h index a0e34da3e..840421ff3 100644 --- a/tasmota/language/fr-FR.h +++ b/tasmota/language/fr-FR.h @@ -113,6 +113,7 @@ #define D_LIGHT "Lumière" #define D_LWT "LWT" #define D_MODULE "Module" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "multi-pression" #define D_NOISE "Bruit" diff --git a/tasmota/language/he-HE.h b/tasmota/language/he-HE.h index d31d5380c..9e26a6c5e 100644 --- a/tasmota/language/he-HE.h +++ b/tasmota/language/he-HE.h @@ -113,6 +113,7 @@ #define D_LIGHT "אור" #define D_LWT "LWT" #define D_MODULE "מודול" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "לחיצה מרובה" #define D_NOISE "רעש" diff --git a/tasmota/language/hu-HU.h b/tasmota/language/hu-HU.h index 7cde76cbb..b7f33a549 100644 --- a/tasmota/language/hu-HU.h +++ b/tasmota/language/hu-HU.h @@ -113,6 +113,7 @@ #define D_LIGHT "Fény" #define D_LWT "LWT" #define D_MODULE "Modul" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "több lenyomás" #define D_NOISE "Zaj" diff --git a/tasmota/language/it-IT.h b/tasmota/language/it-IT.h index 7b6d7eed0..d3c55579a 100644 --- a/tasmota/language/it-IT.h +++ b/tasmota/language/it-IT.h @@ -113,6 +113,7 @@ #define D_LIGHT "Luce" #define D_LWT "LWT" #define D_MODULE "Modulo" +#define D_MOISTURE "Umidità" #define D_MQTT "MQTT" #define D_MULTI_PRESS "multi-pressione" #define D_NOISE "Rumore" diff --git a/tasmota/language/ko-KO.h b/tasmota/language/ko-KO.h index 5d15554de..a6c2088a1 100644 --- a/tasmota/language/ko-KO.h +++ b/tasmota/language/ko-KO.h @@ -113,6 +113,7 @@ #define D_LIGHT "밝게" #define D_LWT "LWT" #define D_MODULE "모듈" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "multi-press" #define D_NOISE "소음" diff --git a/tasmota/language/nl-NL.h b/tasmota/language/nl-NL.h index ec352f3e6..8fb492399 100644 --- a/tasmota/language/nl-NL.h +++ b/tasmota/language/nl-NL.h @@ -113,6 +113,7 @@ #define D_LIGHT "Licht" #define D_LWT "LWT" #define D_MODULE "Module" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "meervoudig" #define D_NOISE "Lawaai" diff --git a/tasmota/language/pl-PL.h b/tasmota/language/pl-PL.h index 9c547e29b..58168516d 100644 --- a/tasmota/language/pl-PL.h +++ b/tasmota/language/pl-PL.h @@ -113,6 +113,7 @@ #define D_LIGHT "Światło" #define D_LWT "LWT" #define D_MODULE "Moduł" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "Wielokrotne naciśnięcie" #define D_NOISE "Szum" diff --git a/tasmota/language/pt-BR.h b/tasmota/language/pt-BR.h index 7a8db0dca..0c9891323 100644 --- a/tasmota/language/pt-BR.h +++ b/tasmota/language/pt-BR.h @@ -113,6 +113,7 @@ #define D_LIGHT "Luz" #define D_LWT "LWT" #define D_MODULE "Módulo" +#define D_MOISTURE "Umidade" #define D_MQTT "MQTT" #define D_MULTI_PRESS "multi-pressão" #define D_NOISE "Ruído" diff --git a/tasmota/language/pt-PT.h b/tasmota/language/pt-PT.h index 8b9868bd8..210ef8e29 100644 --- a/tasmota/language/pt-PT.h +++ b/tasmota/language/pt-PT.h @@ -113,6 +113,7 @@ #define D_LIGHT "Luz" #define D_LWT "LWT" #define D_MODULE "Módulo" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "multi-pressão" #define D_NOISE "Ruído" diff --git a/tasmota/language/ru-RU.h b/tasmota/language/ru-RU.h index 610af6f3f..6696e0e48 100644 --- a/tasmota/language/ru-RU.h +++ b/tasmota/language/ru-RU.h @@ -113,6 +113,7 @@ #define D_LIGHT "Свет" #define D_LWT "LWT" #define D_MODULE "Модуль" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "многократное нажатие" #define D_NOISE "Шум" diff --git a/tasmota/language/sk-SK.h b/tasmota/language/sk-SK.h index 9aa428b69..21120179a 100644 --- a/tasmota/language/sk-SK.h +++ b/tasmota/language/sk-SK.h @@ -113,6 +113,7 @@ #define D_LIGHT "Svetlo" #define D_LWT "LWT" #define D_MODULE "Modul" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "multi-stlačenie" #define D_NOISE "Hluk" diff --git a/tasmota/language/sv-SE.h b/tasmota/language/sv-SE.h index 1a70704ee..117fb40ed 100644 --- a/tasmota/language/sv-SE.h +++ b/tasmota/language/sv-SE.h @@ -113,6 +113,7 @@ #define D_LIGHT "Ljus" #define D_LWT "LWT" #define D_MODULE "Modul" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "fler tryck" #define D_NOISE "Oväsen" diff --git a/tasmota/language/tr-TR.h b/tasmota/language/tr-TR.h index 6e9d9b9bf..9874688da 100644 --- a/tasmota/language/tr-TR.h +++ b/tasmota/language/tr-TR.h @@ -113,6 +113,7 @@ #define D_LIGHT "Işık" #define D_LWT "LWT" #define D_MODULE "Modül" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "multi-press" #define D_NOISE "Noise" diff --git a/tasmota/language/uk-UK.h b/tasmota/language/uk-UK.h index d4862c3c8..dbf58fe35 100644 --- a/tasmota/language/uk-UK.h +++ b/tasmota/language/uk-UK.h @@ -113,6 +113,7 @@ #define D_LIGHT "Світло" #define D_LWT "LWT" #define D_MODULE "Модуль" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "Багаторазове натискання" #define D_NOISE "Шум" diff --git a/tasmota/language/zh-CN.h b/tasmota/language/zh-CN.h index 886a7c918..7700e7e78 100644 --- a/tasmota/language/zh-CN.h +++ b/tasmota/language/zh-CN.h @@ -113,6 +113,7 @@ #define D_LIGHT "灯" #define D_LWT "LWT" #define D_MODULE "模块" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "多次按键" #define D_NOISE "嘈杂" diff --git a/tasmota/language/zh-TW.h b/tasmota/language/zh-TW.h index 61f82fb4c..34bb68e3d 100644 --- a/tasmota/language/zh-TW.h +++ b/tasmota/language/zh-TW.h @@ -113,6 +113,7 @@ #define D_LIGHT "燈" #define D_LWT "LWT" #define D_MODULE "模組" +#define D_MOISTURE "Moisture" #define D_MQTT "MQTT" #define D_MULTI_PRESS "多次按鍵" #define D_NOISE "雜訊" diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 3985884ef..6b936d14a 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -313,6 +313,7 @@ enum UserSelectableAdc0 { ADC0_BUTTON_INV, // ADC0_SWITCH, // Switch // ADC0_SWITCH_INV, + ADC0_MOIST, // Moisture ADC0_END }; // Programmer selectable ADC0 functionality @@ -326,6 +327,7 @@ const char kAdc0Names[] PROGMEM = D_SENSOR_NONE "|" D_ANALOG_INPUT "|" D_TEMPERATURE "|" D_LIGHT "|" D_SENSOR_BUTTON "|" D_SENSOR_BUTTON "i|" + D_MOISTURE "|" // D_SENSOR_SWITCH "|" D_SENSOR_SWITCH "i|" ; diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 1a4bc090b..4e75dbbe7 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -66,6 +66,12 @@ void AdcInit(void) Settings.adc_param2 = ANALOG_LDR_LUX_CALC_SCALAR; Settings.adc_param3 = ANALOG_LDR_LUX_CALC_EXPONENT * 10000; } + else if (ADC0_MOIST == my_adc0) { + Settings.adc_param_type = ADC0_MOIST; + Settings.adc_param1 = 0; + Settings.adc_param2 = 1023; + Settings.adc_param3 = 0; + } } } @@ -113,6 +119,20 @@ uint16_t AdcGetLux(void) return (uint16_t)ldrLux; } +uint16_t AdcGetMoist(void) +// formula for calibration: value, fromLow, fromHigh, toHigh, toLow +// Example: 632, 0, 1023, 100, 0 +// int( ( ( ( - ) / ( - ) ) * ( - ) ) + ) +// double amoist = ((Settings.adc_param2 - (double)adc) / (Settings.adc_param2 - Settings.adc_param1) * 100; +// int((((1023 - ) / ( 1023 - 0 )) * ( 100 - 0 )) + 0 ) + +{ + int adc = AdcRead(2); + double amoist = ((double)Settings.adc_param2 - (double)adc) / ((double)Settings.adc_param2 - (double)Settings.adc_param1) * 100; + //double amoist = ((1023 - (double)adc) / 1023) * 100; + return (uint16_t)amoist; +} + void AdcEverySecond(void) { if (ADC0_TEMP == my_adc0) { @@ -126,7 +146,7 @@ void AdcEverySecond(void) } void AdcShow(bool json) -{ +{ if (ADC0_INPUT == my_adc0) { uint16_t analog = AdcRead(5); @@ -173,9 +193,20 @@ void AdcShow(bool json) #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_SNS_ILLUMINANCE, "", adc_light); + #endif // USE_WEBSERVER } } + else if (ADC0_MOIST == my_adc0) { + uint16_t adc_moist = AdcGetMoist(); + if (json) { + ResponseAppend_P(JSON_SNS_MOISTURE, "ANALOG", adc_moist); +#ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_SNS_MOISTURE, "", adc_moist); +#endif // USE_WEBSERVER + } + } } /*********************************************************************************************\ @@ -217,7 +248,7 @@ void CmndAdcs(void) void CmndAdcParam(void) { if (XdrvMailbox.data_len) { - if ((ADC0_TEMP == XdrvMailbox.payload) || (ADC0_LIGHT == XdrvMailbox.payload)) { + if ((ADC0_TEMP == XdrvMailbox.payload) || (ADC0_LIGHT == XdrvMailbox.payload) || (ADC0_MOIST == XdrvMailbox.payload)) { // if ((XdrvMailbox.payload == my_adc0) && ((ADC0_TEMP == my_adc0) || (ADC0_LIGHT == my_adc0))) { if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry char sub_string[XdrvMailbox.data_len +1]; @@ -227,10 +258,13 @@ void CmndAdcParam(void) // Settings.adc_param_type = my_adc0; Settings.adc_param1 = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.adc_param2 = strtol(subStr(sub_string, XdrvMailbox.data, ",", 3), nullptr, 10); - Settings.adc_param3 = (int)(CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 4)) * 10000); + if (!ADC0_MOIST == XdrvMailbox.payload) { + Settings.adc_param3 = (int)(CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 4)) * 10000); + } } else { // Set default values based on current adc type // AdcParam 2 // AdcParam 3 + // AdcParam 6 Settings.adc_param_type = 0; AdcInit(); } @@ -246,8 +280,13 @@ void CmndAdcParam(void) } char param3[33]; dtostrfd(((double)Settings.adc_param3)/10000, precision, param3); - Response_P(PSTR("{\"" D_CMND_ADCPARAM "\":[%d,%d,%d,%s]}"), - Settings.adc_param_type, Settings.adc_param1, Settings.adc_param2, param3); + if ((ADC0_TEMP == my_adc0) || (ADC0_LIGHT == my_adc0)) { + Response_P(PSTR("{\"" D_CMND_ADCPARAM "\":[%d,%d,%d,%s]}"), + Settings.adc_param_type, Settings.adc_param1, Settings.adc_param2, param3); + } else if (ADC0_MOIST == my_adc0) { + Response_P(PSTR("{\"" D_CMND_ADCPARAM "\":[%d,%d,%d]}"), + Settings.adc_param_type, Settings.adc_param1, Settings.adc_param2); + } } /*********************************************************************************************\ @@ -263,7 +302,7 @@ bool Xsns02(uint8_t function) result = DecodeCommand(kAdcCommands, AdcCommand); break; default: - if ((ADC0_INPUT == my_adc0) || (ADC0_TEMP == my_adc0) || (ADC0_LIGHT == my_adc0)) { + if ((ADC0_INPUT == my_adc0) || (ADC0_TEMP == my_adc0) || (ADC0_LIGHT == my_adc0) || (ADC0_MOIST == my_adc0)) { switch (function) { #ifdef USE_RULES case FUNC_EVERY_250_MSECOND: diff --git a/tasmota/xsns_48_chirp.ino b/tasmota/xsns_48_chirp.ino index 84fcd4f66..131a0cc24 100644 --- a/tasmota/xsns_48_chirp.ino +++ b/tasmota/xsns_48_chirp.ino @@ -399,7 +399,7 @@ void ChirpEvery100MSecond(void) /********************************************************************************************/ // normaly in i18n.h -#define D_JSON_MOISTURE "Moisture" +// #define D_JSON_MOISTURE "Moisture" // on i18n.h #define D_JSON_DARKNESS "Darkness" #ifdef USE_WEBSERVER From def43784998c18f0821caef253326ced45455b36 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 24 Dec 2019 12:20:04 +0100 Subject: [PATCH 2/5] Add support for ADC0 Moisture Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309) --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 1 + tasmota/i18n.h | 55 +++++++++++++++++++------------------- tasmota/tasmota_template.h | 2 +- tasmota/xsns_02_analog.ino | 14 +++++----- tasmota/xsns_48_chirp.ino | 34 +++++++++++------------ 6 files changed, 52 insertions(+), 55 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 88442445a..3515a7433 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -57,6 +57,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Change number of rule ``Var``s and ``Mem``s from 5 to 16 (#4933) - Add support for max 150 characters in most command parameter strings (#3686, #4754) - Add support for GPS as NTP server by Christian Baars and Adrian Scillato +- Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309) - Add Zigbee coalesce sensor attributes into a single message - Add Zigbee better support for Xiaomi Double Switch and Xiaomi Vibration sensor - Add Deepsleep start delay based on Teleperiod if ``Teleperiod`` differs from 10 or 300 diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index cb2bfe0c5..372a2507f 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -4,6 +4,7 @@ - Changed Settings variable namings - Add Zigbee better support for Xiaomi Double Switch and Xiaomi Vibration sensor +- Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309) ### 8.0.0.1 20191221 diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 24b0e1f19..1ae20dcde 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -50,6 +50,7 @@ #define D_JSON_COUNT "Count" #define D_JSON_COUNTER "Counter" #define D_JSON_CURRENT "Current" // As in Voltage and Current +#define D_JSON_DARKNESS "Darkness" #define D_JSON_DATA "Data" #define D_JSON_DISTANCE "Distance" #define D_JSON_DNSSERVER "DNSServer" @@ -458,7 +459,6 @@ #define D_CMND_LONGITUDE "Longitude" // Commands xdrv_16_tuyadimmer.ino - #define D_CMND_TUYA_MCU "TuyaMCU" #define D_CMND_TUYA_MCU_SEND_STATE "TuyaSend" #define D_JSON_TUYA_MCU_RECEIVED "TuyaReceived" @@ -485,34 +485,33 @@ #define D_CMND_ZIGBEE_SEND "ZigbeeSend" #define D_JSON_ZIGBEE_ZCL_SENT "ZigbeeZCLSent" - // Commands xdrv_25_A4988_Stepper.ino - #ifdef USE_A4988_STEPPER - #define D_CMND_MOTOR "MOTOR" - #define D_JSON_MOTOR_MOVE "doMove" - #define D_JSON_MOTOR_ROTATE "doRotate" - #define D_JSON_MOTOR_TURN "doTurn" - #define D_JSON_MOTOR_SPR "setSPR" - #define D_JSON_MOTOR_RPM "setRPM" - #define D_JSON_MOTOR_MIS "setMIS" - #endif +// Commands xdrv_25_A4988_Stepper.ino +#define D_CMND_MOTOR "MOTOR" +#define D_JSON_MOTOR_MOVE "doMove" +#define D_JSON_MOTOR_ROTATE "doRotate" +#define D_JSON_MOTOR_TURN "doTurn" +#define D_JSON_MOTOR_SPR "setSPR" +#define D_JSON_MOTOR_RPM "setRPM" +#define D_JSON_MOTOR_MIS "setMIS" - // Commands xdrv_27_Shutter.ino - #ifdef USE_SHUTTER - #define D_PRFX_SHUTTER "Shutter" - #define D_CMND_SHUTTER_OPEN "Open" - #define D_CMND_SHUTTER_CLOSE "Close" - #define D_CMND_SHUTTER_STOP "Stop" - #define D_CMND_SHUTTER_POSITION "Position" - #define D_CMND_SHUTTER_OPENTIME "OpenDuration" - #define D_CMND_SHUTTER_CLOSETIME "CloseDuration" - #define D_CMND_SHUTTER_RELAY "Relay" - #define D_CMND_SHUTTER_SETHALFWAY "SetHalfway" - #define D_CMND_SHUTTER_SETCLOSE "SetClose" - #define D_CMND_SHUTTER_INVERT "Invert" - #define D_CMND_SHUTTER_CLIBRATION "Calibration" - #define D_CMND_SHUTTER_MOTORDELAY "MotorDelay" - #define D_CMND_SHUTTER_FREQUENCY "Frequency" - #endif +// Commands xdrv_27_Shutter.ino +#define D_PRFX_SHUTTER "Shutter" +#define D_CMND_SHUTTER_OPEN "Open" +#define D_CMND_SHUTTER_CLOSE "Close" +#define D_CMND_SHUTTER_STOP "Stop" +#define D_CMND_SHUTTER_POSITION "Position" +#define D_CMND_SHUTTER_OPENTIME "OpenDuration" +#define D_CMND_SHUTTER_CLOSETIME "CloseDuration" +#define D_CMND_SHUTTER_RELAY "Relay" +#define D_CMND_SHUTTER_SETHALFWAY "SetHalfway" +#define D_CMND_SHUTTER_SETCLOSE "SetClose" +#define D_CMND_SHUTTER_INVERT "Invert" +#define D_CMND_SHUTTER_CLIBRATION "Calibration" +#define D_CMND_SHUTTER_MOTORDELAY "MotorDelay" +#define D_CMND_SHUTTER_FREQUENCY "Frequency" + +// Commands xsns_02_analog.ino +#define D_CMND_ADCPARAM "AdcParam" /********************************************************************************************/ diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 6b936d14a..685546b91 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -311,9 +311,9 @@ enum UserSelectableAdc0 { ADC0_LIGHT, // Light sensor ADC0_BUTTON, // Button ADC0_BUTTON_INV, + ADC0_MOIST, // Moisture // ADC0_SWITCH, // Switch // ADC0_SWITCH_INV, - ADC0_MOIST, // Moisture ADC0_END }; // Programmer selectable ADC0 functionality diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 4e75dbbe7..3dd974918 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -146,7 +146,7 @@ void AdcEverySecond(void) } void AdcShow(bool json) -{ +{ if (ADC0_INPUT == my_adc0) { uint16_t analog = AdcRead(5); @@ -193,12 +193,12 @@ void AdcShow(bool json) #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_SNS_ILLUMINANCE, "", adc_light); - #endif // USE_WEBSERVER } } else if (ADC0_MOIST == my_adc0) { uint16_t adc_moist = AdcGetMoist(); + if (json) { ResponseAppend_P(JSON_SNS_MOISTURE, "ANALOG", adc_moist); #ifdef USE_WEBSERVER @@ -206,14 +206,13 @@ void AdcShow(bool json) WSContentSend_PD(HTTP_SNS_MOISTURE, "", adc_moist); #endif // USE_WEBSERVER } - } + } } /*********************************************************************************************\ * Commands \*********************************************************************************************/ -#define D_CMND_ADCPARAM "AdcParam" const char kAdcCommands[] PROGMEM = "|" // No prefix D_CMND_ADC "|" D_CMND_ADCS "|" D_CMND_ADCPARAM; @@ -248,7 +247,7 @@ void CmndAdcs(void) void CmndAdcParam(void) { if (XdrvMailbox.data_len) { - if ((ADC0_TEMP == XdrvMailbox.payload) || (ADC0_LIGHT == XdrvMailbox.payload) || (ADC0_MOIST == XdrvMailbox.payload)) { + if ((ADC0_TEMP == XdrvMailbox.payload) || (ADC0_LIGHT == XdrvMailbox.payload) || (ADC0_MOIST == XdrvMailbox.payload)) { // if ((XdrvMailbox.payload == my_adc0) && ((ADC0_TEMP == my_adc0) || (ADC0_LIGHT == my_adc0))) { if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry char sub_string[XdrvMailbox.data_len +1]; @@ -283,10 +282,11 @@ void CmndAdcParam(void) if ((ADC0_TEMP == my_adc0) || (ADC0_LIGHT == my_adc0)) { Response_P(PSTR("{\"" D_CMND_ADCPARAM "\":[%d,%d,%d,%s]}"), Settings.adc_param_type, Settings.adc_param1, Settings.adc_param2, param3); - } else if (ADC0_MOIST == my_adc0) { + } + else if (ADC0_MOIST == my_adc0) { Response_P(PSTR("{\"" D_CMND_ADCPARAM "\":[%d,%d,%d]}"), Settings.adc_param_type, Settings.adc_param1, Settings.adc_param2); - } + } } /*********************************************************************************************\ diff --git a/tasmota/xsns_48_chirp.ino b/tasmota/xsns_48_chirp.ino index 131a0cc24..f761e6afc 100644 --- a/tasmota/xsns_48_chirp.ino +++ b/tasmota/xsns_48_chirp.ino @@ -397,22 +397,17 @@ void ChirpEvery100MSecond(void) } /********************************************************************************************/ + // normaly in i18n.h - -// #define D_JSON_MOISTURE "Moisture" // on i18n.h -#define D_JSON_DARKNESS "Darkness" - #ifdef USE_WEBSERVER // {s} = , {m} = , {e} = - const char HTTP_SNS_MOISTURE[] PROGMEM = "{s} " D_JSON_MOISTURE "{m}%s %{e}"; - const char HTTP_SNS_DARKNESS[] PROGMEM = "{s} " D_JSON_DARKNESS "{m}%s %{e}"; - const char HTTP_SNS_CHIRPVER[] PROGMEM = "{s} CHIRP-sensor %u at address{m}0x%x{e}" - "{s} FW-version{m}%s {e}"; ; - const char HTTP_SNS_CHIRPSLEEP[] PROGMEM = "{s} {m} is sleeping ...{e}"; +const char HTTP_SNS_DARKNESS[] PROGMEM = "{s} " D_JSON_DARKNESS "{m}%s %%{e}"; +const char HTTP_SNS_CHIRPVER[] PROGMEM = "{s} CHIRP-sensor %u at address{m}0x%x{e}" + "{s} FW-version{m}%s {e}"; ; +const char HTTP_SNS_CHIRPSLEEP[] PROGMEM = "{s} {m} is sleeping ...{e}"; #endif // USE_WEBSERVER - /********************************************************************************************/ void ChirpShow(bool json) @@ -420,8 +415,6 @@ void ChirpShow(bool json) for (uint32_t i = 0; i < chirp_found_sensors; i++) { if (chirp_sensor[i].version) { // convert double values to string - char str_moisture[33]; - dtostrfd(chirp_sensor[i].moisture, 0, str_moisture); char str_temperature[33]; double t_temperature = ((double) chirp_sensor[i].temperature )/10.0; dtostrfd(t_temperature, Settings.flag2.temperature_resolution, str_temperature); @@ -434,9 +427,10 @@ void ChirpShow(bool json) else{ sprintf(str_version, "%x", chirp_sensor[i].version); } + if (json) { if(!chirp_sensor[i].explicitSleep) { - ResponseAppend_P(PSTR(",\"%s%u\":{\"" D_JSON_MOISTURE "\":%s"),chirp_name, i, str_moisture); + ResponseAppend_P(PSTR(",\"%s%u\":{\"" D_JSON_MOISTURE "\":%d"), chirp_name, i, chirp_sensor[i].moisture); if(chirp_sensor[i].temperature!=-1){ // this is the error code -> no temperature ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE "\":%s"),str_temperature); } @@ -447,9 +441,11 @@ void ChirpShow(bool json) } #ifdef USE_DOMOTICZ if (0 == tele_period) { - DomoticzTempHumSensor(str_temperature, str_moisture); - DomoticzSensor(DZ_ILLUMINANCE,chirp_sensor[i].light); // this is not LUX!! - } + char str_moisture[33]; + dtostrfd(chirp_sensor[i].moisture, 0, str_moisture); + DomoticzTempHumSensor(str_temperature, str_moisture); + DomoticzSensor(DZ_ILLUMINANCE,chirp_sensor[i].light); // this is not LUX!! + } #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { @@ -458,10 +454,10 @@ void ChirpShow(bool json) WSContentSend_PD(HTTP_SNS_CHIRPSLEEP); } else { - WSContentSend_PD(HTTP_SNS_MOISTURE, str_moisture); + WSContentSend_PD(HTTP_SNS_MOISTURE, "", chirp_sensor[i].moisture); WSContentSend_PD(HTTP_SNS_DARKNESS, str_light); - if(chirp_sensor[i].temperature!=-1){ // this is the error code -> no temperature - WSContentSend_PD(HTTP_SNS_TEMP, " ",str_temperature, TempUnit()); + if (chirp_sensor[i].temperature!=-1) { // this is the error code -> no temperature + WSContentSend_PD(HTTP_SNS_TEMP, "", str_temperature, TempUnit()); } } From a2478f9569a5411ad3660085c9ae5384c5e92358 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 24 Dec 2019 15:06:19 +0100 Subject: [PATCH 3/5] Change number of ``FriendlyName``s from 4 to 8 Change number of ``FriendlyName``s from 4 to 8 --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 1 + tasmota/settings.h | 2 +- tasmota/tasmota.h | 16 ++++++------- tasmota/xdrv_01_webserver.ino | 9 +++++--- tasmota/xdrv_09_timers.ino | 7 +++--- tasmota/xdrv_10_rules.ino | 6 ++--- tasmota/xdrv_10_scripter.ino | 12 ++++------ tasmota/xdsp_02_ssd1306.ino | 3 +-- tasmota/xdsp_07_sh1106.ino | 3 +-- tasmota/xdsp_09_SSD1351.ino | 3 +-- tasmota/xsns_41_max44009.ino | 3 +-- tasmota/xsns_42_scd30.ino | 43 ++++++++++++++++------------------- 13 files changed, 50 insertions(+), 59 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 3515a7433..c9293bb95 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -55,6 +55,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Change Settings text handling allowing variable length text within a total text pool of 699 characters - Change Smoother ``Fade`` using 100Hz instead of 20Hz animation (#7179) - Change number of rule ``Var``s and ``Mem``s from 5 to 16 (#4933) +- Change number of ``FriendlyName``s from 4 to 8 - Add support for max 150 characters in most command parameter strings (#3686, #4754) - Add support for GPS as NTP server by Christian Baars and Adrian Scillato - Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 372a2507f..d6b1d0ab7 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -3,6 +3,7 @@ ### 8.0.0.2 20191223 - Changed Settings variable namings +- Change number of ``FriendlyName``s from 4 to 8 - Add Zigbee better support for Xiaomi Double Switch and Xiaomi Vibration sensor - Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309) diff --git a/tasmota/settings.h b/tasmota/settings.h index af774a4c2..eddc4f04b 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -337,7 +337,7 @@ struct SYSCFG { SysBitfield3 flag3; // 3A0 uint8_t switchmode[MAX_SWITCHES]; // 3A4 (6.0.0b - moved from 0x4CA) - char ex_friendlyname[MAX_FRIENDLYNAMES][33]; // 3AC + char ex_friendlyname[4][33]; // 3AC char ex_switch_topic[33]; // 430 char serial_delimiter; // 451 diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 829a90871..2e539bb49 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -58,7 +58,6 @@ const uint8_t MAX_PWMS = 5; // Max number of PWM channels const uint8_t MAX_COUNTERS = 4; // Max number of counter sensors const uint8_t MAX_TIMERS = 16; // Max number of Timers const uint8_t MAX_PULSETIMERS = 8; // Max number of supported pulse timers -const uint8_t MAX_FRIENDLYNAMES = 4; // Max number of Friendly names const uint8_t MAX_DOMOTICZ_IDX = 4; // Max number of Domoticz device, key and switch indices const uint8_t MAX_DOMOTICZ_SNS_IDX = 12; // Max number of Domoticz sensors indices const uint8_t MAX_KNX_GA = 10; // Max number of KNX Group Addresses to read that can be set @@ -73,7 +72,10 @@ const uint8_t MAX_PCF8574 = 8; // Max number of PCF8574 devices const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 512 characters const uint16_t MAX_RULE_SIZE = 512; // Max number of characters in rules +// Changes to the following MAX_ defines need to be in line with enum SettingsTextIndex +const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names const uint8_t MAX_RULE_MEMS = 16; // Max number of saved vars + const uint8_t MAX_HUE_DEVICES = 15; // Max number of Philips Hue device per emulation const char MQTT_TOKEN_PREFIX[] PROGMEM = "%prefix%"; // To be substituted by mqtt_prefix[x] @@ -287,13 +289,11 @@ enum SettingsTextIndex { SET_OTAURL, SET_MEM1, SET_MEM2, SET_MEM3, SET_MEM4, SET_MEM5, SET_MEM6, SET_MEM7, SET_MEM8, SET_MEM9, SET_MEM10, SET_MEM11, SET_MEM12, SET_MEM13, SET_MEM14, SET_MEM15, SET_MEM16, SET_FRIENDLYNAME1, SET_FRIENDLYNAME2, SET_FRIENDLYNAME3, SET_FRIENDLYNAME4, - -// SET_FRIENDLYNAME5, SET_FRIENDLYNAME6, SET_FRIENDLYNAME7, SET_FRIENDLYNAME8, // Future extension -// SET_BUTTON1, SET_BUTTON2, SET_BUTTON3, SET_BUTTON4, // Future extension -// SET_BUTTON5, SET_BUTTON6, SET_BUTTON7, SET_BUTTON8, // Future extension -// SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12, // Future extension -// SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16, // Future extension - + SET_FRIENDLYNAME5, SET_FRIENDLYNAME6, SET_FRIENDLYNAME7, SET_FRIENDLYNAME8, + SET_BUTTON1, SET_BUTTON2, SET_BUTTON3, SET_BUTTON4, + SET_BUTTON5, SET_BUTTON6, SET_BUTTON7, SET_BUTTON8, + SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12, + SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16, SET_MAX }; enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_WEBCONSOLE, SRC_PULSETIMER, diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 104e71f67..c25cdc3f6 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1846,6 +1846,7 @@ void OtherSaveSettings(void) char tmp[TOPSZ]; char webindex[5]; char friendlyname[TOPSZ]; + char message[LOGSZ]; WebGetArg("wp", tmp, sizeof(tmp)); SettingsUpdateText(SET_WEBPWD, (!strlen(tmp)) ? "" : (strchr(tmp,'*')) ? SettingsText(SET_WEBPWD) : tmp); @@ -1854,15 +1855,17 @@ void OtherSaveSettings(void) WebGetArg("b2", tmp, sizeof(tmp)); Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp); #endif // USE_EMULATION - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME), GetStateText(Settings.flag.mqtt_enabled), Settings.flag2.emulation); + + snprintf_P(message, sizeof(message), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME), GetStateText(Settings.flag.mqtt_enabled), Settings.flag2.emulation); for (uint32_t i = 0; i < MAX_FRIENDLYNAMES; i++) { snprintf_P(webindex, sizeof(webindex), PSTR("a%d"), i); WebGetArg(webindex, tmp, sizeof(tmp)); snprintf_P(friendlyname, sizeof(friendlyname), PSTR(FRIENDLY_NAME"%d"), i +1); SettingsUpdateText(SET_FRIENDLYNAME1 +i, (!strlen(tmp)) ? (i) ? friendlyname : FRIENDLY_NAME : tmp); - snprintf_P(log_data, sizeof(log_data), PSTR("%s%s %s"), log_data, (i) ? "," : "", SettingsText(SET_FRIENDLYNAME1 +i)); + snprintf_P(message, sizeof(message), PSTR("%s%s %s"), message, (i) ? "," : "", SettingsText(SET_FRIENDLYNAME1 +i)); } - AddLog(LOG_LEVEL_INFO); + AddLog_P(LOG_LEVEL_INFO, message); + WebGetArg("t1", tmp, sizeof(tmp)); if (strlen(tmp)) { // {"NAME":"12345678901234","GPIO":[255,255,255,255,255,255,255,255,255,255,255,255,255],"FLAG":255,"BASE":255} char svalue[128]; diff --git a/tasmota/xdrv_09_timers.ino b/tasmota/xdrv_09_timers.ino index db1cde97e..a6c7b23a9 100644 --- a/tasmota/xdrv_09_timers.ino +++ b/tasmota/xdrv_09_timers.ino @@ -733,12 +733,13 @@ void HandleTimerConfiguration(void) void TimerSaveSettings(void) { char tmp[MAX_TIMERS *12]; // Need space for MAX_TIMERS x 10 digit numbers separated by a comma + char message[LOGSZ]; Timer timer; Settings.flag3.timers_enable = WebServer->hasArg("e0"); // CMND_TIMERS WebGetArg("t0", tmp, sizeof(tmp)); char *p = tmp; - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MQTT D_CMND_TIMERS " %d"), Settings.flag3.timers_enable); // CMND_TIMERS + snprintf_P(message, sizeof(message), PSTR(D_LOG_MQTT D_CMND_TIMERS " %d"), Settings.flag3.timers_enable); // CMND_TIMERS for (uint32_t i = 0; i < MAX_TIMERS; i++) { timer.data = strtol(p, &p, 10); p++; // Skip comma @@ -747,9 +748,9 @@ void TimerSaveSettings(void) Settings.timer[i].data = timer.data; if (flag) TimerSetRandomWindow(i); } - snprintf_P(log_data, sizeof(log_data), PSTR("%s,0x%08X"), log_data, Settings.timer[i].data); + snprintf_P(message, sizeof(message), PSTR("%s,0x%08X"), message, Settings.timer[i].data); } - AddLog(LOG_LEVEL_DEBUG); + AddLog_P(LOG_LEVEL_DEBUG, message); } #endif // USE_TIMERS_WEB #endif // USE_WEBSERVER diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 72276f94b..21c9de283 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -1400,8 +1400,7 @@ bool evaluateLogicalExpression(const char * expression, int len) memcpy(expbuff, expression, len); expbuff[len] = '\0'; - //snprintf_P(log_data, sizeof(log_data), PSTR("EvalLogic: |%s|"), expbuff); - //AddLog(LOG_LEVEL_DEBUG); + //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EvalLogic: |%s|"), expbuff); char * pointer = expbuff; LinkedList values; LinkedList logicOperators; @@ -1527,8 +1526,7 @@ void ExecuteCommandBlock(const char * commands, int len) memcpy(cmdbuff, commands, len); cmdbuff[len] = '\0'; - //snprintf_P(log_data, sizeof(log_data), PSTR("ExecCmd: |%s|"), cmdbuff); - //AddLog(LOG_LEVEL_DEBUG); + //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ExecCmd: |%s|"), cmdbuff); char oneCommand[len + 1]; //To put one command int insertPosition = 0; //When insert into backlog, we should do it by 0, 1, 2 ... char * pos = cmdbuff; diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index c6aedb80e..27d72c717 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -2203,8 +2203,7 @@ void Replace_Cmd_Vars(char *srcbuf,char *dstbuf,uint16_t dstsize) { void toLog(const char *str) { if (!str) return; - snprintf_P(log_data, sizeof(log_data), PSTR("%s"),str); - AddLog(LOG_LEVEL_INFO); + AddLog_P(LOG_LEVEL_INFO, str); } @@ -2681,8 +2680,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) { } cmd[count]=*lp++; } - //snprintf_P(log_data, sizeof(log_data), tmp); - //AddLog(LOG_LEVEL_INFO); + //AddLog_P(LOG_LEVEL_INFO, tmp); // replace vars in cmd char *tmp=cmdmem+SCRIPT_CMDMEM/2; Replace_Cmd_Vars(cmd,tmp,SCRIPT_CMDMEM/2); @@ -2694,8 +2692,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) { } else { if (!sflag) { tasm_cmd_activ=1; - snprintf_P(log_data, sizeof(log_data), PSTR("Script: performs \"%s\""), tmp); - AddLog(glob_script_mem.script_loglevel&0x7f); + AddLog_P2(glob_script_mem.script_loglevel&0x7f, PSTR("Script: performs \"%s\""), tmp); } else if (sflag==2) { // allow recursive call } else { @@ -3544,8 +3541,7 @@ void ScriptSaveSettings(void) { if (bitRead(Settings.rule_enabled, 0)) { int16_t res=Init_Scripter(); if (res) { - snprintf_P(log_data, sizeof(log_data), PSTR("script init error: %d"),res); - AddLog(LOG_LEVEL_INFO); + AddLog_P2(LOG_LEVEL_INFO, PSTR("script init error: %d"), res); return; } Run_Scripter(">B",2,0); diff --git a/tasmota/xdsp_02_ssd1306.ino b/tasmota/xdsp_02_ssd1306.ino index e263901bc..0bee9d10d 100644 --- a/tasmota/xdsp_02_ssd1306.ino +++ b/tasmota/xdsp_02_ssd1306.ino @@ -124,8 +124,7 @@ void Ssd1306PrintLog(void) strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols); DisplayFillScreen(last_row); - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); - AddLog(LOG_LEVEL_DEBUG); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); renderer->println(disp_screen_buffer[last_row]); renderer->Updateframe(); diff --git a/tasmota/xdsp_07_sh1106.ino b/tasmota/xdsp_07_sh1106.ino index eba56a442..00babbdf9 100644 --- a/tasmota/xdsp_07_sh1106.ino +++ b/tasmota/xdsp_07_sh1106.ino @@ -119,8 +119,7 @@ void SH1106PrintLog(void) strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols); DisplayFillScreen(last_row); - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); - AddLog(LOG_LEVEL_DEBUG); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); renderer->println(disp_screen_buffer[last_row]); renderer->Updateframe(); diff --git a/tasmota/xdsp_09_SSD1351.ino b/tasmota/xdsp_09_SSD1351.ino index ad7e86f99..0391bf8f4 100644 --- a/tasmota/xdsp_09_SSD1351.ino +++ b/tasmota/xdsp_09_SSD1351.ino @@ -112,8 +112,7 @@ void SSD1351PrintLog(void) strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols); DisplayFillScreen(last_row); - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); - AddLog(LOG_LEVEL_DEBUG); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); renderer->println(disp_screen_buffer[last_row]); renderer->Updateframe(); diff --git a/tasmota/xsns_41_max44009.ino b/tasmota/xsns_41_max44009.ino index 2cdf6b78d..e1ef99ee1 100644 --- a/tasmota/xsns_41_max44009.ino +++ b/tasmota/xsns_41_max44009.ino @@ -75,8 +75,7 @@ void Max4409Detect(void) if ((I2cValidRead8(&buffer1, max44009_address, REG_LOWER_THRESHOLD)) && (I2cValidRead8(&buffer2, max44009_address, REG_THRESHOLD_TIMER))) { - //snprintf(log_data, sizeof(log_data), "MAX44009 %x: %x, %x", max44009_address, (int)buffer1, (int)buffer2); - //AddLog(LOG_LEVEL_DEBUG_MORE); + //AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("MAX44009 %x: %x, %x"), max44009_address, (int)buffer1, (int)buffer2); if ((0x00 == buffer1) && (0xFF == buffer2)) { diff --git a/tasmota/xsns_42_scd30.ino b/tasmota/xsns_42_scd30.ino index d3bb5cbef..12ac95cd2 100644 --- a/tasmota/xsns_42_scd30.ino +++ b/tasmota/xsns_42_scd30.ino @@ -23,6 +23,8 @@ #define XSNS_42 42 #define XI2C_29 29 // See I2CDEVICES.md +//#define SCD30_DEBUG + #define SCD30_ADDRESS 0x61 #define SCD30_MAX_MISSED_READS 3 @@ -118,24 +120,23 @@ void Scd30Update(void) scd30ErrorState = SCD30_STATE_ERROR_DATA_CRC; scd30CrcError_count++; #ifdef SCD30_DEBUG - snprintf_P(log_data, sizeof(log_data), "SCD30: CRC error, CRC error: %ld, CO2 zero: %ld, good: %ld, no data: %ld, sc30_reset: %ld, i2c_reset: %ld", scd30CrcError_count, scd30Co2Zero_count, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); - AddLog(LOG_LEVEL_ERROR); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: CRC error, CRC error: %ld, CO2 zero: %ld, good: %ld, no data: %ld, sc30_reset: %ld, i2c_reset: %ld"), + scd30CrcError_count, scd30Co2Zero_count, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); #endif break; case ERROR_SCD30_CO2_ZERO: scd30Co2Zero_count++; #ifdef SCD30_DEBUG - snprintf_P(log_data, sizeof(log_data), "SCD30: CO2 zero, CRC error: %ld, CO2 zero: %ld, good: %ld, no data: %ld, sc30_reset: %ld, i2c_reset: %ld", scd30CrcError_count, scd30Co2Zero_count, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); - AddLog(LOG_LEVEL_ERROR); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: CO2 zero, CRC error: %ld, CO2 zero: %ld, good: %ld, no data: %ld, sc30_reset: %ld, i2c_reset: %ld"), + scd30CrcError_count, scd30Co2Zero_count, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); #endif break; default: { scd30ErrorState = SCD30_STATE_ERROR_READ_MEAS; #ifdef SCD30_DEBUG - snprintf_P(log_data, sizeof(log_data), "SCD30: Update: ReadMeasurement error: 0x%lX, counter: %ld", error, scd30Loop_count); - AddLog(LOG_LEVEL_ERROR); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: Update: ReadMeasurement error: 0x%lX, counter: %ld"), error, scd30Loop_count); #endif return; } @@ -147,10 +148,9 @@ void Scd30Update(void) case SCD30_STATE_ERROR_DATA_CRC: { //scd30IsDataValid = false; #ifdef SCD30_DEBUG - snprintf_P(log_data, sizeof(log_data), "SCD30: in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld", scd30ErrorState, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); - AddLog(LOG_LEVEL_ERROR); - snprintf_P(log_data, sizeof(log_data), "SCD30: got CRC error, try again, counter: %ld", scd30Loop_count); - AddLog(LOG_LEVEL_ERROR); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld"), + scd30ErrorState, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: got CRC error, try again, counter: %ld"), scd30Loop_count); #endif scd30ErrorState = ERROR_SCD30_NO_ERROR; } @@ -159,17 +159,15 @@ void Scd30Update(void) case SCD30_STATE_ERROR_READ_MEAS: { //scd30IsDataValid = false; #ifdef SCD30_DEBUG - snprintf_P(log_data, sizeof(log_data), "SCD30: in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld", scd30ErrorState, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); - AddLog(LOG_LEVEL_ERROR); - snprintf_P(log_data, sizeof(log_data), "SCD30: not answering, sending soft reset, counter: %ld", scd30Loop_count); - AddLog(LOG_LEVEL_ERROR); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld"), + scd30ErrorState, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: not answering, sending soft reset, counter: %ld"), scd30Loop_count); #endif scd30Reset_count++; error = scd30.softReset(); if (error) { #ifdef SCD30_DEBUG - snprintf_P(log_data, sizeof(log_data), "SCD30: resetting got error: 0x%lX", error); - AddLog(LOG_LEVEL_ERROR); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: resetting got error: 0x%lX"), error); #endif error >>= 8; if (error == 4) { @@ -186,18 +184,16 @@ void Scd30Update(void) case SCD30_STATE_ERROR_SOFT_RESET: { //scd30IsDataValid = false; #ifdef SCD30_DEBUG - snprintf_P(log_data, sizeof(log_data), "SCD30: in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld", scd30ErrorState, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); - AddLog(LOG_LEVEL_ERROR); - snprintf_P(log_data, sizeof(log_data), "SCD30: clearing i2c bus"); - AddLog(LOG_LEVEL_ERROR); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld"), + scd30ErrorState, scd30GoodMeas_count, scd30DataNotAvailable_count, scd30Reset_count, i2cReset_count); + AddLog_P(LOG_LEVEL_ERROR, PSTR("SCD30: clearing i2c bus")); #endif i2cReset_count++; error = scd30.clearI2CBus(); if (error) { scd30ErrorState = SCD30_STATE_ERROR_I2C_RESET; #ifdef SCD30_DEBUG - snprintf_P(log_data, sizeof(log_data), "SCD30: error clearing i2c bus: 0x%lX", error); - AddLog(LOG_LEVEL_ERROR); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: error clearing i2c bus: 0x%lX"), error); #endif } else { scd30ErrorState = ERROR_SCD30_NO_ERROR; @@ -342,8 +338,7 @@ bool Scd30CommandSensor() if (error) { #ifdef SCD30_DEBUG - snprintf_P(log_data, sizeof(log_data), "SCD30: error getting FW version: 0x%lX", error); - AddLog(LOG_LEVEL_ERROR); + AddLog_P2(LOG_LEVEL_ERROR, PSTR("SCD30: error getting FW version: 0x%lX"), error); #endif serviced = false; } From 29366222a538283fb86b94eb1000e8fc6cb17bee Mon Sep 17 00:00:00 2001 From: Hadinger Date: Tue, 24 Dec 2019 16:42:47 +0100 Subject: [PATCH 4/5] Re-enable mqttuser/mqttpassword for AWS IoT --- tasmota/xdrv_02_mqtt.ino | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index f9ff3e67d..910a2ea6f 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -32,9 +32,7 @@ const char kMqttCommands[] PROGMEM = "|" // No prefix #if defined(USE_MQTT_TLS) && !defined(USE_MQTT_TLS_CA_CERT) D_CMND_MQTTFINGERPRINT "|" #endif -#if !defined(USE_MQTT_TLS) || !defined(USE_MQTT_AWS_IOT) // user and password are disabled with AWS IoT D_CMND_MQTTUSER "|" D_CMND_MQTTPASSWORD "|" -#endif #if defined(USE_MQTT_TLS) && defined(USE_MQTT_AWS_IOT) D_CMND_TLSKEY "|" #endif @@ -46,9 +44,7 @@ void (* const MqttCommand[])(void) PROGMEM = { #if defined(USE_MQTT_TLS) && !defined(USE_MQTT_TLS_CA_CERT) &CmndMqttFingerprint, #endif -#if !defined(USE_MQTT_TLS) || !defined(USE_MQTT_AWS_IOT) // user and password are disabled with AWS IoT &CmndMqttUser, &CmndMqttPassword, -#endif #if defined(USE_MQTT_TLS) && defined(USE_MQTT_AWS_IOT) &CmndTlsKey, #endif @@ -640,7 +636,6 @@ void MqttReconnect(void) #endif #if defined(USE_MQTT_TLS) && defined(USE_MQTT_AWS_IOT) AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT "AWS IoT endpoint: %s"), SettingsText(SET_MQTT_HOST)); - //if (MqttClient.connect(mqtt_client, nullptr, nullptr, nullptr, 0, false, nullptr)) { if (MqttClient.connect(mqtt_client, nullptr, nullptr, stopic, 1, false, mqtt_data, MQTT_CLEAN_SESSION)) { #else if (MqttClient.connect(mqtt_client, mqtt_user, mqtt_pwd, stopic, 1, true, mqtt_data, MQTT_CLEAN_SESSION)) { @@ -737,7 +732,6 @@ void CmndMqttFingerprint(void) } #endif -#if !defined(USE_MQTT_TLS) || !defined(USE_MQTT_AWS_IOT) // user and password are disabled with AWS IoT void CmndMqttUser(void) { if (XdrvMailbox.data_len > 0) { @@ -757,7 +751,6 @@ void CmndMqttPassword(void) Response_P(S_JSON_COMMAND_ASTERISK, XdrvMailbox.command); } } -#endif // USE_MQTT_AWS_IOT void CmndMqttlog(void) { @@ -1171,10 +1164,8 @@ const char HTTP_FORM_MQTT1[] PROGMEM = "

" D_PORT " (" STR(MQTT_PORT) ")

" "

" D_CLIENT " (%s)

"; const char HTTP_FORM_MQTT2[] PROGMEM = -#if !defined(USE_MQTT_TLS) || !defined(USE_MQTT_AWS_IOT) // user and password disabled with AWS IoT "

" D_USER " (" MQTT_USER ")

" "

" D_PASSWORD "

" -#endif // USE_MQTT_AWS_IOT "

" D_TOPIC " = %%topic%% (%s)

" "

" D_FULL_TOPIC " (%s)

"; From b66cc3479f363b61b53104aa40d841467062fe51 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 24 Dec 2019 17:10:50 +0100 Subject: [PATCH 5/5] Add support for user defined GUI button text Add commands ``WebButton1`` until ``WebButton16`` to support user defined GUI button text (#7166) --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 1 + tasmota/i18n.h | 1 + tasmota/settings.ino | 13 +++++----- tasmota/support_command.ino | 2 +- tasmota/tasmota.h | 9 +++---- tasmota/xdrv_01_webserver.ino | 47 +++++++++++++++++++++++++++++------ 7 files changed, 54 insertions(+), 20 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index c9293bb95..6be1dfa9f 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -56,6 +56,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Change Smoother ``Fade`` using 100Hz instead of 20Hz animation (#7179) - Change number of rule ``Var``s and ``Mem``s from 5 to 16 (#4933) - Change number of ``FriendlyName``s from 4 to 8 +- Add commands ``WebButton1`` until ``WebButton16`` to support user defined GUI button text (#7166) - Add support for max 150 characters in most command parameter strings (#3686, #4754) - Add support for GPS as NTP server by Christian Baars and Adrian Scillato - Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index d6b1d0ab7..0c12ed15c 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -6,6 +6,7 @@ - Change number of ``FriendlyName``s from 4 to 8 - Add Zigbee better support for Xiaomi Double Switch and Xiaomi Vibration sensor - Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309) +- Add commands ``WebButton1`` until ``WebButton16`` to support user defined GUI button text (#7166) ### 8.0.0.1 20191221 diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 1ae20dcde..e726fdf5d 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -334,6 +334,7 @@ #define D_CMND_WEBREFRESH "WebRefresh" #define D_CMND_WEBSEND "WebSend" #define D_CMND_WEBCOLOR "WebColor" +#define D_CMND_WEBBUTTON "WebButton" #define D_CMND_WEBSENSOR "WebSensor" #define D_CMND_EMULATION "Emulation" #define D_CMND_SENDMAIL "Sendmail" diff --git a/tasmota/settings.ino b/tasmota/settings.ino index ce6c33ff4..6412d3fc9 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -551,13 +551,14 @@ bool SettingsUpdateText(uint32_t index, const char* replace_me) char* SettingsText(uint32_t index) { - if (index >= SET_MAX) { - return nullptr; // Setting not supported - internal error - } - char* position = Settings.text_pool; - for (;index > 0; index--) { - while (*position++ != '\0') { } + + if (index >= SET_MAX) { + position += settings_text_size -1; // Setting not supported - internal error - return empty string + } else { + for (;index > 0; index--) { + while (*position++ != '\0') { } + } } return position; } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 265926b59..f6413dd57 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1311,7 +1311,7 @@ void CmndFriendlyname(void) } else { snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME "%d"), XdrvMailbox.index); } - SettingsUpdateText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1, (SC_DEFAULT == Shortcut()) ? stemp1 : XdrvMailbox.data); + SettingsUpdateText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : (SC_DEFAULT == Shortcut()) ? stemp1 : XdrvMailbox.data); } ResponseCmndIdxChar(SettingsText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1)); } diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 2e539bb49..c0231d3c9 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -73,8 +73,9 @@ const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 5 const uint16_t MAX_RULE_SIZE = 512; // Max number of characters in rules // Changes to the following MAX_ defines need to be in line with enum SettingsTextIndex -const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names const uint8_t MAX_RULE_MEMS = 16; // Max number of saved vars +const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names +const uint8_t MAX_BUTTON_TEXT = 16; // Max number of GUI button labels const uint8_t MAX_HUE_DEVICES = 15; // Max number of Philips Hue device per emulation @@ -290,10 +291,8 @@ enum SettingsTextIndex { SET_OTAURL, SET_MEM9, SET_MEM10, SET_MEM11, SET_MEM12, SET_MEM13, SET_MEM14, SET_MEM15, SET_MEM16, SET_FRIENDLYNAME1, SET_FRIENDLYNAME2, SET_FRIENDLYNAME3, SET_FRIENDLYNAME4, SET_FRIENDLYNAME5, SET_FRIENDLYNAME6, SET_FRIENDLYNAME7, SET_FRIENDLYNAME8, - SET_BUTTON1, SET_BUTTON2, SET_BUTTON3, SET_BUTTON4, - SET_BUTTON5, SET_BUTTON6, SET_BUTTON7, SET_BUTTON8, - SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12, - SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16, + SET_BUTTON1, SET_BUTTON2, SET_BUTTON3, SET_BUTTON4, SET_BUTTON5, SET_BUTTON6, SET_BUTTON7, SET_BUTTON8, + SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12, SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16, SET_MAX }; enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_WEBCONSOLE, SRC_PULSETIMER, diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index c25cdc3f6..d86562bb3 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1014,7 +1014,7 @@ void HandleRoot(void) AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_MAIN_MENU); - char stemp[10]; + char stemp[33]; WSContentStart_P(S_MAIN_MENU); #ifdef USE_SCRIPT_WEB_DISPLAY @@ -1106,14 +1106,19 @@ void HandleRoot(void) WSContentSend_P(PSTR("")); #ifdef USE_SONOFF_IFAN if (IsModuleIfan()) { - WSContentSend_P(HTTP_DEVICE_CONTROL, 36, 1, D_BUTTON_TOGGLE, ""); + WSContentSend_P(HTTP_DEVICE_CONTROL, 36, 1, + (strlen(SettingsText(SET_BUTTON1))) ? SettingsText(SET_BUTTON1) : D_BUTTON_TOGGLE, + ""); for (uint32_t i = 0; i < MaxFanspeed(); i++) { snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i); - WSContentSend_P(HTTP_DEVICE_CONTROL, 16, i +2, stemp, ""); + WSContentSend_P(HTTP_DEVICE_CONTROL, 16, i +2, + (strlen(SettingsText(SET_BUTTON2 + i))) ? SettingsText(SET_BUTTON2 + i) : stemp, + ""); } } else { #endif // USE_SONOFF_IFAN for (uint32_t idx = 1; idx <= devices_present; idx++) { + bool set_button = ((idx <= MAX_BUTTON_TEXT) && strlen(SettingsText(SET_BUTTON1 + idx -1))); #ifdef USE_SHUTTER if (Settings.flag3.shutter_mode) { // SetOption80 - Enable shutter support bool shutter_used = false; @@ -1124,13 +1129,17 @@ void HandleRoot(void) } } if (shutter_used) { - WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, (idx % 2) ? "▲" : "▼" , ""); + WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, + (set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (idx % 2) ? "▲" : "▼", + ""); continue; } } #endif // USE_SHUTTER snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx); - WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, (devices_present < 5) ? D_BUTTON_TOGGLE : "", (devices_present > 1) ? stemp : ""); + WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, + (set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (devices_present < 5) ? D_BUTTON_TOGGLE : "", + (set_button) ? "" : (devices_present > 1) ? stemp : ""); } #ifdef USE_SONOFF_IFAN } @@ -1146,7 +1155,9 @@ void HandleRoot(void) if (idx > 0) { WSContentSend_P(PSTR("")); } for (uint32_t j = 0; j < 4; j++) { idx++; - WSContentSend_P(PSTR(""), idx, idx); // &k is related to WebGetArg("k", tmp, sizeof(tmp)); + snprintf_P(stemp, sizeof(stemp), PSTR("%d"), idx); + WSContentSend_P(PSTR(""), idx, // &k is related to WebGetArg("k", tmp, sizeof(tmp)); + (strlen(SettingsText(SET_BUTTON1 + idx -1))) ? SettingsText(SET_BUTTON1 + idx -1) : stemp); } } WSContentSend_P(PSTR("")); @@ -2733,7 +2744,8 @@ const char kWebCommands[] PROGMEM = "|" // No prefix #ifdef USE_SENDMAIL D_CMND_SENDMAIL "|" #endif - D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBREFRESH "|" D_CMND_WEBSEND "|" D_CMND_WEBCOLOR "|" D_CMND_WEBSENSOR "|" D_CMND_CORS; + D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBREFRESH "|" D_CMND_WEBSEND "|" D_CMND_WEBCOLOR "|" + D_CMND_WEBSENSOR "|" D_CMND_WEBBUTTON "|" D_CMND_CORS; void (* const WebCommand[])(void) PROGMEM = { #ifdef USE_EMULATION @@ -2742,7 +2754,8 @@ void (* const WebCommand[])(void) PROGMEM = { #ifdef USE_SENDMAIL &CmndSendmail, #endif - &CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor, &CmndWebSensor, &CmndCors }; + &CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor, + &CmndWebSensor, &CmndWebButton, &CmndCors }; /*********************************************************************************************\ * Commands @@ -2863,6 +2876,24 @@ void CmndWebSensor(void) ResponseJsonEnd(); } +void CmndWebButton(void) +{ + if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_BUTTON_TEXT)) { + if (!XdrvMailbox.usridx) { + mqtt_data[0] = '\0'; + for (uint32_t i = 0; i < MAX_BUTTON_TEXT; i++) { + ResponseAppend_P(PSTR("%c\"WebButton%d\":\"%s\""), (i) ? ',' : '{', i +1, SettingsText(SET_BUTTON1 +i)); + } + ResponseJsonEnd(); + } else { + if (XdrvMailbox.data_len > 0) { + SettingsUpdateText(SET_BUTTON1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data); + } + ResponseCmndIdxChar(SettingsText(SET_BUTTON1 + XdrvMailbox.index -1)); + } + } +} + void CmndCors(void) { if (XdrvMailbox.data_len > 0) {