From 3f4320b95d9d59292f4e114ebcb5d3a4c8028105 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 21 Oct 2018 16:30:05 +0200 Subject: [PATCH 1/2] Add optional HX711 GUI Add optional HX711 scale interface to web GUI demonstrating easy GUI plug-in --- sonoff/API.md => API.md | 6 +- sonoff/_changelog.ino | 1 + sonoff/language/bg-BG.h | 7 ++ sonoff/language/cs-CZ.h | 7 ++ sonoff/language/de-DE.h | 7 ++ sonoff/language/el-GR.h | 7 ++ sonoff/language/en-GB.h | 7 ++ sonoff/language/es-AR.h | 7 ++ sonoff/language/fr-FR.h | 7 ++ sonoff/language/he-HE.h | 7 ++ sonoff/language/hu-HU.h | 7 ++ sonoff/language/it-IT.h | 7 ++ sonoff/language/nl-NL.h | 7 ++ sonoff/language/pl-PL.h | 7 ++ sonoff/language/pt-BR.h | 7 ++ sonoff/language/pt-PT.h | 7 ++ sonoff/language/ru-RU.h | 7 ++ sonoff/language/tr-TR.h | 7 ++ sonoff/language/uk-UK.h | 7 ++ sonoff/language/zh-CN.h | 7 ++ sonoff/language/zh-TW.h | 7 ++ sonoff/user_config.h | 1 + sonoff/xdrv_01_webserver.ino | 11 ++- sonoff/xsns_34_hx711.ino | 143 ++++++++++++++++++++++++++++++++--- sonoff/xsns_35_tx20.ino | 8 +- 25 files changed, 280 insertions(+), 23 deletions(-) rename sonoff/API.md => API.md (95%) diff --git a/sonoff/API.md b/API.md similarity index 95% rename from sonoff/API.md rename to API.md index 68442970f..9b43a1456 100644 --- a/sonoff/API.md +++ b/API.md @@ -32,9 +32,9 @@ FUNC_RULES_PROCESS | x | 6.0.0 | x | | | Process spe FUNC_SERIAL | x | | x | | x | Process serial data FUNC_FREE_MEM | | | x | | | Show free memory for debugging FUNC_BUTTON_PRESSED | x | 6.2.1.18 | x | | | When a button is pressed -FUNC_WEB_ADD_BUTTON | | 6.2.1.14 | x | | | Add a Configuration Button to GUI -FUNC_WEB_ADD_MAIN_BUTTON | | 6.2.1.14 | x | | | Add a main button to GUI -FUNC_WEB_ADD_HANDLER | | 6.2.1.14 | x | | | Add a webserver handler +FUNC_WEB_ADD_BUTTON | | 6.2.1.14 | x | x | | Add a Configuration Button to GUI +FUNC_WEB_ADD_MAIN_BUTTON | | 6.2.1.14 | x | x | | Add a main button to GUI +FUNC_WEB_ADD_HANDLER | | 6.2.1.14 | x | x | | Add a webserver handler ## Display Call back Ids The following table lists all Callback Ids for a Display service. diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 85951dbae..e6a95eae2 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,6 +1,7 @@ /* 6.2.1.18 20181019 * Add more API callbacks and document API.md * Add support for La Crosse TX20 Anemometer (#2654, #3146) + * Add optional HX711 scale interface to web GUI demonstrating easy GUI plug-in * * 6.2.1.17 20181017 * Enable updated non-blocking PubSubClient as default MQTT client diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index 689707bbd..1d66ec783 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index 23c01a1b3..8a495a1e9 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Vložte referenční zátěž" #define D_HX_CAL_DONE "Zkalibrováno" #define D_HX_CAL_FAIL "Chyba kalibrace" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Směr větru" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index 91d99374d..41f4d20c4 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Referenzgewicht auflegen" #define D_HX_CAL_DONE "kalibriert" #define D_HX_CAL_FAIL "Kalibrierung fehlgeschlagen" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index bdc4313de..3a648f86f 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index d93e1f237..9ddead578 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index b1c608a63..d2531dbf5 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Poner Peso de Referencia" #define D_HX_CAL_DONE "Calibrado" #define D_HX_CAL_FAIL "Falló Calibración" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index 5fb4b50b7..c38f08b17 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/he-HE.h b/sonoff/language/he-HE.h index f4ed8fffb..c04b28f73 100644 --- a/sonoff/language/he-HE.h +++ b/sonoff/language/he-HE.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index a5376c5e2..603ddd19a 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 009fd6ebc..1bf79502d 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index ca40e56fe..ecec2e39e 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Plaats ijkgewicht" #define D_HX_CAL_DONE "Ge-ijkt" #define D_HX_CAL_FAIL "Ijken is mislukt" +#define D_RESET_HX711 "Nulstelling weegschaal" +#define D_CONFIGURE_HX711 "Configureer Weegschaal" +#define D_HX711_PARAMETERS "Weegschaal parameters" +#define D_ITEM_WEIGHT "Gewicht van onderdeel" +#define D_REFERENCE_WEIGHT "Ijkgewicht" +#define D_CALIBRATE "Ijken" +#define D_CALIBRATION "Ijken" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Windrichting" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index 73b71d475..951d9a970 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index 3831a9399..79792c15b 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index abf47783c..b2b88fd7a 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index 22cf17b5d..3a607ad35 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/tr-TR.h b/sonoff/language/tr-TR.h index 9d0d3fe6a..d51e87486 100755 --- a/sonoff/language/tr-TR.h +++ b/sonoff/language/tr-TR.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h index 5976f1628..dbc3b575f 100644 --- a/sonoff/language/uk-UK.h +++ b/sonoff/language/uk-UK.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index e24ae4a0d..32ee2ccf4 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index 52376aa49..46b910654 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -461,6 +461,13 @@ #define D_HX_CAL_REFERENCE "Load reference weigth" #define D_HX_CAL_DONE "Calibrated" #define D_HX_CAL_FAIL "Calibration failed" +#define D_RESET_HX711 "Reset Scale" +#define D_CONFIGURE_HX711 "Configure Scale" +#define D_HX711_PARAMETERS "Scale parameters" +#define D_ITEM_WEIGHT "Item weight" +#define D_REFERENCE_WEIGHT "Reference weigth" +#define D_CALIBRATE "Calibrate" +#define D_CALIBRATION "Calibration" //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 3eca64536..4c0b4fdb3 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -375,6 +375,7 @@ //#define USE_TM1638 // Add support for TM1638 switches copying Switch1 .. Switch8 (+1k code) #define USE_HX711 // Add support for HX711 load cell (+1k5 code) +// #define USE_HX711_GUI // Add optional web GUI to HX711 as scale (+1k8 code) #define USE_RF_FLASH // Add support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB (+3k code) diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index 894806919..3cb2b31cb 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -77,10 +77,10 @@ const char HTTP_HEAD[] PROGMEM = "lt=setTimeout(la,{a});" // Settings.web_refresh "}" "function lb(p){" - "la('?d='+p);" + "la('?d='+p);" // ?d related to WebGetArg("d", tmp, sizeof(tmp)); "}" "function lc(p){" - "la('?t='+p);" // ?t related to WebGetArg("t", tmp, sizeof(tmp)); + "la('?t='+p);" // ?t related to WebGetArg("t", tmp, sizeof(tmp)); "}"; const char HTTP_HEAD_RELOAD[] PROGMEM = @@ -293,7 +293,7 @@ const char HTTP_END[] PROGMEM = "" ""; -const char HTTP_DEVICE_CONTROL[] PROGMEM = ""; +const char HTTP_DEVICE_CONTROL[] PROGMEM = ""; // ?o is related to WebGetArg("o", tmp, sizeof(tmp)); const char HTTP_DEVICE_STATE[] PROGMEM = "%s%s"; // {c} = %'>
"), idx, idx); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR(""), idx, idx); // ?k is related to WebGetArg("k", tmp, sizeof(tmp)); page += mqtt_data; } } @@ -606,6 +607,7 @@ void HandleRoot() #ifndef BE_MINIMAL mqtt_data[0] = '\0'; XdrvCall(FUNC_WEB_ADD_MAIN_BUTTON); + XsnsCall(FUNC_WEB_ADD_MAIN_BUTTON); page += String(mqtt_data); #endif // Not BE_MINIMAL @@ -711,6 +713,7 @@ void HandleConfiguration() mqtt_data[0] = '\0'; XdrvCall(FUNC_WEB_ADD_BUTTON); + XsnsCall(FUNC_WEB_ADD_BUTTON); page += String(mqtt_data); page += FPSTR(HTTP_BTN_MENU4); diff --git a/sonoff/xsns_34_hx711.ino b/sonoff/xsns_34_hx711.ino index 91d987ba5..64736f574 100644 --- a/sonoff/xsns_34_hx711.ino +++ b/sonoff/xsns_34_hx711.ino @@ -32,25 +32,30 @@ * - Execute command Sensor34 2 and follow messages shown \*********************************************************************************************/ -#define XSNS_34 34 +#define XSNS_34 34 #ifndef HX_MAX_WEIGHT -#define HX_MAX_WEIGHT 20000 // Default max weight in gram +#define HX_MAX_WEIGHT 20000 // Default max weight in gram #endif #ifndef HX_REFERENCE -#define HX_REFERENCE 250 // Default reference weight for calibration in gram +#define HX_REFERENCE 250 // Default reference weight for calibration in gram #endif #ifndef HX_SCALE -#define HX_SCALE 120 // Default result of measured weight / reference weight when scale is 1 +#define HX_SCALE 120 // Default result of measured weight / reference weight when scale is 1 #endif -#define HX_TIMEOUT 120 // A reading at default 10Hz (pin RATE to Gnd on HX711) can take up to 100 milliseconds -#define HX_SAMPLES 10 // Number of samples for average calculation -#define HX_CAL_TIMEOUT 15 // Calibration step window in number of seconds +#define HX_TIMEOUT 120 // A reading at default 10Hz (pin RATE to Gnd on HX711) can take up to 100 milliseconds +#define HX_SAMPLES 10 // Number of samples for average calculation +#define HX_CAL_TIMEOUT 15 // Calibration step window in number of seconds -#define HX_GAIN_128 1 // Channel A, gain factor 128 -#define HX_GAIN_32 2 // Channel B, gain factor 32 -#define HX_GAIN_64 3 // Channel A, gain factor 64 +#define HX_GAIN_128 1 // Channel A, gain factor 128 +#define HX_GAIN_32 2 // Channel B, gain factor 32 +#define HX_GAIN_64 3 // Channel A, gain factor 64 + +#define D_JSON_WEIGHT_REF "WeightRef" +#define D_JSON_WEIGHT_CAL "WeightCal" +#define D_JSON_WEIGHT_MAX "WeightMax" +#define D_JSON_WEIGHT_ITEM "WeightItem" enum HxCalibrationSteps { HX_CAL_END, HX_CAL_LIMBO, HX_CAL_FINISH, HX_CAL_FAIL, HX_CAL_DONE, HX_CAL_FIRST, HX_CAL_RESET, HX_CAL_START }; @@ -169,7 +174,7 @@ bool HxCommand() hx_calibrate_timer = 1; HxCalibrationStateTextJson(3); break; - case 3: // WeightSet to user reference + case 3: // WeightRef to user reference if (strstr(XdrvMailbox.data, ",")) { Settings.weight_reference = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), NULL, 10); } @@ -201,7 +206,7 @@ bool HxCommand() if (show_parms) { char item[10]; dtostrfd((float)Settings.weight_item / 10, 1, item); - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"Sensor34\":{\"WeightSet\":%d,\"WeightCal\":%d,\"WeightMax\":%d,\"WeightItem\":%s}}"), + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"Sensor34\":{\"" D_JSON_WEIGHT_REF "\":%d,\"" D_JSON_WEIGHT_CAL "\":%d,\"" D_JSON_WEIGHT_MAX "\":%d,\"" D_JSON_WEIGHT_ITEM "\":%s}}"), Settings.weight_reference, Settings.weight_calibration, Settings.weight_max * 1000, item); } @@ -353,6 +358,109 @@ void HxShow(boolean json) } } +#ifdef USE_WEBSERVER +#ifdef USE_HX711_GUI +/*********************************************************************************************\ + * Optional GUI +\*********************************************************************************************/ + +#define WEB_HANDLE_HX711 "s34" + +const char S_CONFIGURE_HX711[] PROGMEM = D_CONFIGURE_HX711; + +const char HTTP_BTN_MENU_MAIN_HX711[] PROGMEM = + "
"; + +const char HTTP_BTN_MENU_HX711[] PROGMEM = + "
"; + +const char HTTP_FORM_HX711[] PROGMEM = + "
 " D_CALIBRATION " " + "
" + "
" D_REFERENCE_WEIGHT " (" D_UNIT_KILOGRAM ")

" + "

" + "
" + "


" + + "
 " D_HX711_PARAMETERS " " + "
" + "
" D_ITEM_WEIGHT " (" D_UNIT_KILOGRAM ")

"; + +void HandleHxAction() +{ + if (HttpUser()) { return; } + if (!WebAuthenticate()) { return WebServer->requestAuthentication(); } + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_HX711); + + if (WebServer->hasArg("save")) { + HxSaveSettings(); + HandleConfiguration(); + return; + } + + char tmp[100]; + + if (WebServer->hasArg("reset")) { + snprintf_P(tmp, sizeof(tmp), PSTR("Sensor34 1")); // Reset + ExecuteWebCommand(tmp, SRC_WEBGUI); + + HandleRoot(); // Return to main screen + return; + } + + if (WebServer->hasArg("calibrate")) { + WebGetArg("p1", tmp, sizeof(tmp)); + Settings.weight_reference = (!strlen(tmp)) ? 0 : (unsigned long)(CharToDouble(tmp) * 1000); + + HxLogUpdates(); + + snprintf_P(tmp, sizeof(tmp), PSTR("Sensor34 2")); // Start calibration + ExecuteWebCommand(tmp, SRC_WEBGUI); + + HandleRoot(); // Return to main screen + return; + } + + String page = FPSTR(HTTP_HEAD); + page.replace(F("{v}"), FPSTR(D_CONFIGURE_HX711)); + page += FPSTR(HTTP_HEAD_STYLE); + page += FPSTR(HTTP_FORM_HX711); + dtostrfd((float)Settings.weight_reference / 1000, 3, tmp); + page.replace("{1", String(tmp)); + dtostrfd((float)Settings.weight_item / 10000, 4, tmp); + page.replace("{2", String(tmp)); + + page += FPSTR(HTTP_FORM_END); + page += FPSTR(HTTP_BTN_CONF); + ShowPage(page); +} + +void HxSaveSettings() +{ + char tmp[100]; + + WebGetArg("p2", tmp, sizeof(tmp)); + Settings.weight_item = (!strlen(tmp)) ? 0 : (uint16_t)(CharToDouble(tmp) * 10000); + + HxLogUpdates(); +} + +void HxLogUpdates() +{ + char weigth_ref_chr[10]; + char weigth_item_chr[10]; + + dtostrfd((float)Settings.weight_reference / 1000, Settings.flag2.weight_resolution, weigth_ref_chr); + dtostrfd((float)Settings.weight_item / 10000, 4, weigth_item_chr); + + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_JSON_WEIGHT_REF " %s, " D_JSON_WEIGHT_ITEM " %s"), + weigth_ref_chr, weigth_item_chr); + AddLog(LOG_LEVEL_INFO); +} + +#endif // USE_HX711_GUI +#endif // USE_WEBSERVER + /*********************************************************************************************\ * Interface \*********************************************************************************************/ @@ -381,6 +489,17 @@ boolean Xsns34(byte function) case FUNC_WEB_APPEND: HxShow(0); break; +#ifdef USE_HX711_GUI + case FUNC_WEB_ADD_MAIN_BUTTON: + strncat_P(mqtt_data, HTTP_BTN_MENU_MAIN_HX711, sizeof(mqtt_data)); + break; + case FUNC_WEB_ADD_BUTTON: + strncat_P(mqtt_data, HTTP_BTN_MENU_HX711, sizeof(mqtt_data)); + break; + case FUNC_WEB_ADD_HANDLER: + WebServer->on("/" WEB_HANDLE_HX711, HandleHxAction); + break; +#endif // USE_HX711_GUI #endif // USE_WEBSERVER } } diff --git a/sonoff/xsns_35_tx20.ino b/sonoff/xsns_35_tx20.ino index d24575a64..d87c6de25 100644 --- a/sonoff/xsns_35_tx20.ino +++ b/sonoff/xsns_35_tx20.ino @@ -38,10 +38,10 @@ extern "C" { #ifdef USE_WEBSERVER const char HTTP_SNS_TX20[] PROGMEM = "%s" - "{s} " D_TX20_WIND_SPEED "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" - "{s} " D_TX20_WIND_SPEED_AVG "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" - "{s} " D_TX20_WIND_SPEED_MAX "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" - "{s} " D_TX20_WIND_DIRECTION "{m}%s {e}"; + "{s}TX20 " D_TX20_WIND_SPEED "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" + "{s}TX20 " D_TX20_WIND_SPEED_AVG "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" + "{s}TX20 " D_TX20_WIND_SPEED_MAX "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" + "{s}TX20 " D_TX20_WIND_DIRECTION "{m}%s{e}"; #endif // USE_WEBSERVER From b4162baa6315d023327b784ee57c85d204620342 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 21 Oct 2018 16:48:10 +0200 Subject: [PATCH 2/2] Admin --- RELEASENOTES.md | 10 ++++++++++ sonoff/sonoff_post.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 212e3a7da..a98f96b33 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -79,9 +79,11 @@ See [Tasmota ESP/Arduino library version related issues](https://github.com/aren | USE_LM75AD | - | - | x | x | x | | USE_APDS9960 | - | - | - | - | - | | USE_MCP230xx | - | - | - | - | - | +| USE_PCA9685 | - | - | - | - | - | | USE_MPR121 | - | - | - | - | - | | USE_CCS811 | - | - | - | - | - | | USE_MPU6050 | - | - | - | - | - | +| USE_DS3231 | - | - | - | - | - | | | | | | | | | Feature or Sensor | minimal | classic | sonoff | knx | sensors | | USE_SPI | - | - | - | - | - | @@ -90,9 +92,13 @@ See [Tasmota ESP/Arduino library version related issues](https://github.com/aren | USE_PMS5003 | - | - | x | x | x | | USE_NOVA_SDS | - | - | x | x | x | | USE_PZEM004T | - | - | x | x | x | +| USE_PZEM_AC | - | - | x | x | x | +| USE_PZEM_DC | - | - | x | x | x | +| USE_MCP39F501 | - | - | x | x | x | | USE_SERIAL_BRIDGE | - | - | x | x | x | | USE_SDM120 | - | - | - | - | x | | USE_SDM630 | - | - | - | - | x | +| USE_MP3_PLAYER | - | - | - | - | - | | USE_IR_REMOTE | - | - | x | x | x | | USE_IR_HVAC | - | - | - | - | x | | USE_IR_RECEIVE | - | - | x | x | x | @@ -101,7 +107,11 @@ See [Tasmota ESP/Arduino library version related issues](https://github.com/aren | USE_ARILUX_RF | - | - | x | x | x | | USE_SR04 | - | - | x | x | x | | USE_TM1638 | - | - | - | - | - | +| USE_HX711 | - | - | x | x | x | | USE_RF_FLASH | - | - | x | x | x | +| USE_TUYA_DIMMER | - | - | x | x | x | +| USE_TX20_WIND_SENSOR | - | - | x | x | x | +| USE_DISPLAY | - | - | - | - | - | ## Changelog Version 6.2.1 20180905 diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h index 3db21b48f..62b3fc88a 100755 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -148,6 +148,8 @@ void KNX_CB_Action(message_t const &msg, void *arg); #undef USE_TM1638 // Disable support for TM1638 switches copying Switch1 .. Switch8 #undef USE_HX711 // Disable support for HX711 load cell #undef USE_RF_FLASH // Disable support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB +#undef USE_TUYA_DIMMER // Disable support for Tuya Serial Dimmer +#undef USE_TX20_WIND_SENSOR // Disable support for La Crosse TX20 anemometer #undef DEBUG_THEO // Disable debug code #undef USE_DEBUG_DRIVER // Disable debug code #endif // USE_CLASSIC @@ -243,6 +245,8 @@ void KNX_CB_Action(message_t const &msg, void *arg); #undef USE_TM1638 // Disable support for TM1638 switches copying Switch1 .. Switch8 #undef USE_HX711 // Disable support for HX711 load cell #undef USE_RF_FLASH // Disable support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB +#undef USE_TUYA_DIMMER // Disable support for Tuya Serial Dimmer +#undef USE_TX20_WIND_SENSOR // Disable support for La Crosse TX20 anemometer #undef DEBUG_THEO // Disable debug code #undef USE_DEBUG_DRIVER // Disable debug code #endif // BE_MINIMAL