From d7c64741044040f39edabf805bebf299134bd6f5 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 27 Jul 2024 17:11:25 +0200 Subject: [PATCH] Add Analog Voltage and Current --- tasmota/include/tasmota_template.h | 41 ++++++---- tasmota/language/af_AF.h | 2 + tasmota/language/bg_BG.h | 2 + tasmota/language/ca_AD.h | 2 + tasmota/language/cs_CZ.h | 2 + tasmota/language/de_DE.h | 2 + tasmota/language/el_GR.h | 2 + tasmota/language/en_GB.h | 2 + tasmota/language/es_ES.h | 2 + tasmota/language/fr_FR.h | 2 + tasmota/language/fy_NL.h | 2 + tasmota/language/he_HE.h | 2 + tasmota/language/hu_HU.h | 2 + tasmota/language/it_IT.h | 2 + tasmota/language/ko_KO.h | 2 + tasmota/language/nl_NL.h | 2 + tasmota/language/pl_PL.h | 2 + tasmota/language/pt_BR.h | 2 + tasmota/language/pt_PT.h | 2 + tasmota/language/ro_RO.h | 2 + tasmota/language/ru_RU.h | 2 + tasmota/language/sk_SK.h | 2 + tasmota/language/sv_SE.h | 2 + tasmota/language/tr_TR.h | 2 + tasmota/language/uk_UA.h | 2 + tasmota/language/vi_VN.h | 2 + tasmota/language/zh_CN.h | 2 + tasmota/language/zh_TW.h | 2 + .../tasmota_xsns_sensor/xsns_02_analog.ino | 82 ++++++++++++++++++- .../tasmota_xx2c_global/xnrg_interface.ino | 6 +- 30 files changed, 161 insertions(+), 22 deletions(-) diff --git a/tasmota/include/tasmota_template.h b/tasmota/include/tasmota_template.h index dd3187040..e2a4dbe99 100644 --- a/tasmota/include/tasmota_template.h +++ b/tasmota/include/tasmota_template.h @@ -222,6 +222,7 @@ enum UserSelectablePins { GPIO_TCP_TX_EN, // TCP to serial bridge, EN pin GPIO_ASR650X_TX, GPIO_ASR650X_RX, // ASR650X LoRaWan node Serial interface GPIO_WOOLIIS_RX, // Wooliis Battery capacity monitor Serial RX + GPIO_ADC_VOLTAGE, GPIO_ADC_CURRENT, // Analog Voltage and Current GPIO_SENSOR_END }; // Error as warning to rethink GPIO usage with max 2045 @@ -491,6 +492,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_TCP_TXD_EN "|" D_GPIO_ASR650X_TX "|" D_GPIO_ASR650X_RX "|" D_SENSOR_WOOLIIS_RX "|" + D_SENSOR_ADC_VOLTAGE "|" D_SENSOR_ADC_CURRENT "|" ; const char kSensorNamesFixed[] PROGMEM = @@ -1224,6 +1226,11 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_ETH_PHY_MDC), AGPIO(GPIO_ETH_PHY_MDIO), // Ethernet #endif // USE_ETHERNET +#ifdef USE_BIOPDU + AGPIO(GPIO_BIOPDU_PZEM0XX_TX), // Biomine BioPDU pins + AGPIO(GPIO_BIOPDU_PZEM016_RX), + AGPIO(GPIO_BIOPDU_BIT) + 3, +#endif /*-------------------------------------------------------------------------------------------*\ * ESP32 multiple Analog / Digital converter inputs @@ -1239,12 +1246,8 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_ADC_JOY) + MAX_ADCS, // Joystick AGPIO(GPIO_ADC_PH) + MAX_ADCS, // Analog PH Sensor AGPIO(GPIO_ADC_MQ) + MAX_ADCS, // Analog MQ Sensor - -#ifdef USE_BIOPDU - AGPIO(GPIO_BIOPDU_PZEM0XX_TX), // Biomine BioPDU pins - AGPIO(GPIO_BIOPDU_PZEM016_RX), - AGPIO(GPIO_BIOPDU_BIT) + 3, -#endif + AGPIO(GPIO_ADC_VOLTAGE) + MAX_ADCS, // Voltage + AGPIO(GPIO_ADC_CURRENT) + MAX_ADCS, // Current #endif // ESP32 }; @@ -1265,22 +1268,26 @@ const uint16_t kAdcNiceList[] PROGMEM = { AGPIO(GPIO_ADC_JOY), // Joystick AGPIO(GPIO_ADC_PH), // Analog PH Sensor AGPIO(GPIO_ADC_MQ), // Analog MQ Sensor + AGPIO(GPIO_ADC_VOLTAGE), // Voltage + AGPIO(GPIO_ADC_CURRENT), // Current }; #endif // ESP8266 // User selectable ADC functionality enum UserSelectableAdc { - ADC_NONE, // Not used - ADC_INPUT, // Analog input - ADC_TEMP, // Thermistor - ADC_LIGHT, // Light sensor - ADC_BUTTON, // Button - ADC_BUTTON_INV, - ADC_RANGE, // Range - ADC_CT_POWER, // Current - ADC_JOY, // Joystick - ADC_PH, // Analog PH Sensor - ADC_MQ, // Analog MQ Sensor + ADC_NONE, // 0 = Not used + ADC_INPUT, // 1 = Analog input + ADC_TEMP, // 2 = Thermistor + ADC_LIGHT, // 3 =Light sensor + ADC_BUTTON, // 4 =Button + ADC_BUTTON_INV, // 5 = Inverted button + ADC_RANGE, // 6 = Range + ADC_CT_POWER, // 7 = Current + ADC_JOY, // 8 = Joystick + ADC_PH, // 9 = Analog PH Sensor + ADC_MQ, // 10 = Analog MQ Sensor + ADC_VOLTAGE, // 11 = Voltage + ADC_CURRENT, // 12 = Current // ADC_SWITCH, // Switch // ADC_SWITCH_INV, ADC_END }; diff --git a/tasmota/language/af_AF.h b/tasmota/language/af_AF.h index 9418defc2..d98293d85 100644 --- a/tasmota/language/af_AF.h +++ b/tasmota/language/af_AF.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/bg_BG.h b/tasmota/language/bg_BG.h index d417e5277..e7784ea41 100644 --- a/tasmota/language/bg_BG.h +++ b/tasmota/language/bg_BG.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/ca_AD.h b/tasmota/language/ca_AD.h index 884ec2801..1eaface65 100644 --- a/tasmota/language/ca_AD.h +++ b/tasmota/language/ca_AD.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/cs_CZ.h b/tasmota/language/cs_CZ.h index f37b34d11..b08c48b8c 100644 --- a/tasmota/language/cs_CZ.h +++ b/tasmota/language/cs_CZ.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/de_DE.h b/tasmota/language/de_DE.h index 376b76d11..b754515fc 100644 --- a/tasmota/language/de_DE.h +++ b/tasmota/language/de_DE.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/el_GR.h b/tasmota/language/el_GR.h index e1acea42e..61566829d 100644 --- a/tasmota/language/el_GR.h +++ b/tasmota/language/el_GR.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/en_GB.h b/tasmota/language/en_GB.h index 5cee6cabb..82d509835 100644 --- a/tasmota/language/en_GB.h +++ b/tasmota/language/en_GB.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/es_ES.h b/tasmota/language/es_ES.h index d6e684e6f..10c40cd0e 100644 --- a/tasmota/language/es_ES.h +++ b/tasmota/language/es_ES.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/fr_FR.h b/tasmota/language/fr_FR.h index 0cb251777..2c5937d7a 100644 --- a/tasmota/language/fr_FR.h +++ b/tasmota/language/fr_FR.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Manette" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PwDn" #define D_GPIO_WEBCAM_RESET "CAM_Reset" #define D_GPIO_WEBCAM_XCLK "CAM_XClk" diff --git a/tasmota/language/fy_NL.h b/tasmota/language/fy_NL.h index 895aa3c2e..5b3b69898 100644 --- a/tasmota/language/fy_NL.h +++ b/tasmota/language/fy_NL.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/he_HE.h b/tasmota/language/he_HE.h index 08dc58b3b..9ae1525d6 100644 --- a/tasmota/language/he_HE.h +++ b/tasmota/language/he_HE.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/hu_HU.h b/tasmota/language/hu_HU.h index fb80a10dd..8c3dbb393 100644 --- a/tasmota/language/hu_HU.h +++ b/tasmota/language/hu_HU.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/it_IT.h b/tasmota/language/it_IT.h index fe6c3346d..67394954c 100644 --- a/tasmota/language/it_IT.h +++ b/tasmota/language/it_IT.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC - Joystick" #define D_SENSOR_ADC_PH "ADC - pH" #define D_SENSOR_ADC_MQ "ADC - MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "Webcam - PWDN" #define D_GPIO_WEBCAM_RESET "Webcam - RESET" #define D_GPIO_WEBCAM_XCLK "Webcam - XCLK" diff --git a/tasmota/language/ko_KO.h b/tasmota/language/ko_KO.h index 3df859d14..7f3dbb0ad 100644 --- a/tasmota/language/ko_KO.h +++ b/tasmota/language/ko_KO.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/nl_NL.h b/tasmota/language/nl_NL.h index 16e6019e4..a181aa1ad 100644 --- a/tasmota/language/nl_NL.h +++ b/tasmota/language/nl_NL.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/pl_PL.h b/tasmota/language/pl_PL.h index 43778efe0..4e6c8c845 100644 --- a/tasmota/language/pl_PL.h +++ b/tasmota/language/pl_PL.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Dżojstik" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/pt_BR.h b/tasmota/language/pt_BR.h index 77575b807..602062bd8 100644 --- a/tasmota/language/pt_BR.h +++ b/tasmota/language/pt_BR.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "Joystick ADC" #define D_SENSOR_ADC_PH "pH ADC" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/pt_PT.h b/tasmota/language/pt_PT.h index 875c2f0ca..ab1b20e23 100644 --- a/tasmota/language/pt_PT.h +++ b/tasmota/language/pt_PT.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "Joystick ADC" #define D_SENSOR_ADC_PH "pH ADC" #define D_SENSOR_ADC_MQ "MQ ADC" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/ro_RO.h b/tasmota/language/ro_RO.h index bc9193511..7e9b8272c 100644 --- a/tasmota/language/ro_RO.h +++ b/tasmota/language/ro_RO.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/ru_RU.h b/tasmota/language/ru_RU.h index 348b1ae93..6e1031d02 100644 --- a/tasmota/language/ru_RU.h +++ b/tasmota/language/ru_RU.h @@ -914,6 +914,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/sk_SK.h b/tasmota/language/sk_SK.h index 22614f5d7..fbaa7b824 100644 --- a/tasmota/language/sk_SK.h +++ b/tasmota/language/sk_SK.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/sv_SE.h b/tasmota/language/sv_SE.h index 84ef0df3b..a433d033d 100644 --- a/tasmota/language/sv_SE.h +++ b/tasmota/language/sv_SE.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/tr_TR.h b/tasmota/language/tr_TR.h index d3e74b550..d6b560b85 100644 --- a/tasmota/language/tr_TR.h +++ b/tasmota/language/tr_TR.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/uk_UA.h b/tasmota/language/uk_UA.h index 07c836441..761bae707 100644 --- a/tasmota/language/uk_UA.h +++ b/tasmota/language/uk_UA.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/vi_VN.h b/tasmota/language/vi_VN.h index 56847d382..1af378629 100644 --- a/tasmota/language/vi_VN.h +++ b/tasmota/language/vi_VN.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/zh_CN.h b/tasmota/language/zh_CN.h index 7cc247d77..a64634c24 100644 --- a/tasmota/language/zh_CN.h +++ b/tasmota/language/zh_CN.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/language/zh_TW.h b/tasmota/language/zh_TW.h index 340b18f1b..0909ad140 100644 --- a/tasmota/language/zh_TW.h +++ b/tasmota/language/zh_TW.h @@ -913,6 +913,8 @@ #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" #define D_SENSOR_ADC_MQ "ADC MQ" +#define D_SENSOR_ADC_VOLTAGE "ADC Voltage" +#define D_SENSOR_ADC_CURRENT "ADC Current" #define D_GPIO_WEBCAM_PWDN "CAM_PWDN" #define D_GPIO_WEBCAM_RESET "CAM_RESET" #define D_GPIO_WEBCAM_XCLK "CAM_XCLK" diff --git a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino index e25ef6592..8fd6f5a38 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino @@ -25,6 +25,7 @@ \*********************************************************************************************/ #define XSNS_02 2 +#define XNRG_33 33 #ifdef ESP32 #include "esp32-hal-adc.h" @@ -246,6 +247,18 @@ void AdcInitParams(uint8_t idx) { Adc[idx].param3 = (int)(ANALOG_MQ_B * ANALOG_MQ_DECIMAL_MULTIPLIER); // Exponential regression Adc[idx].param4 = (int)(ANALOG_MQ_RatioMQCleanAir * ANALOG_MQ_DECIMAL_MULTIPLIER); // Exponential regression } + else if (ADC_VOLTAGE == Adc[idx].type) { + Adc[idx].param1 = 0; + Adc[idx].param2 = ANALOG_RANGE; + Adc[idx].param3 = 0; + Adc[idx].param4 = ANALOG_V33 * 10000; + } + else if (ADC_CURRENT == Adc[idx].type) { + Adc[idx].param1 = 0; + Adc[idx].param2 = ANALOG_RANGE; + Adc[idx].param3 = 0; + Adc[idx].param4 = ANALOG_V33 * 10000; + } } if ((Adcs.type != Adc[idx].type) || (0 == Adc[idx].param1) || (Adc[idx].param1 > ANALOG_RANGE)) { if ((ADC_BUTTON == Adc[idx].type) || (ADC_BUTTON_INV == Adc[idx].type)) { @@ -297,6 +310,12 @@ void AdcInit(void) { if (PinUsed(GPIO_ADC_MQ, i)) { AdcAttach(Pin(GPIO_ADC_MQ, i), ADC_MQ); } + if (PinUsed(GPIO_ADC_VOLTAGE, i)) { + AdcAttach(Pin(GPIO_ADC_VOLTAGE, i), ADC_VOLTAGE); + } + if (PinUsed(GPIO_ADC_CURRENT, i)) { + AdcAttach(Pin(GPIO_ADC_CURRENT, i), ADC_CURRENT); + } } for (uint32_t i = 0; i < MAX_KEYS; i++) { if (PinUsed(GPIO_ADC_BUTTON, i)) { @@ -540,6 +559,8 @@ void AdcGetCurrentPower(uint8_t idx, uint8_t factor) { } void AdcEverySecond(void) { + uint32_t voltage_index = 0; + uint32_t current_index = 0; for (uint32_t idx = 0; idx < Adcs.present; idx++) { if (ADC_TEMP == Adc[idx].type) { int adc = AdcRead(Adc[idx].pin, 2); @@ -572,7 +593,27 @@ void AdcEverySecond(void) { AddSampleMq(idx); AdcGetMq(idx); } +#ifdef USE_ENERGY_SENSOR + else if (ADC_VOLTAGE == Adc[idx].type) { + Energy->voltage_available = true; + Energy->voltage[voltage_index++] = AdcGetRange(idx) / 10000; + } + else if (ADC_CURRENT == Adc[idx].type) { + Energy->current_available = true; + Energy->current[current_index++] = AdcGetRange(idx) / 10000; + } +#endif // USE_ENERGY_SENSOR } +#ifdef USE_ENERGY_SENSOR + if (voltage_index && current_index) { + for (uint32_t phase = 0; phase < current_index; phase++) { + uint32_t voltage_phase = (voltage_index == current_index) ? phase : 0; + Energy->active_power[phase] = Energy->voltage[voltage_phase] * Energy->current[phase]; + Energy->kWhtoday_delta[phase] += (uint32_t)(Energy->active_power[phase] * 1) / 36; + } + EnergyUpdateToday(); + } +#endif // USE_ENERGY_SENSOR } void AdcShowContinuation(bool *jsonflg) { @@ -769,14 +810,18 @@ void CmndAdcParam(void) { AdcGetSettings(idx); if (ArgC() > 3) { // Process parameter entry char argument[XdrvMailbox.data_len]; - // AdcParam 2, 32000, 10000, 3350 ADC_TEMP Shelly mode - // AdcParam 2, 32000, 10000, 3350, 1 ADC_TEMP Alternate mode + // AdcParam 2, 32000, 10000, 3350 ADC_TEMP Shelly mode + // AdcParam 2, 32000, 10000, 3350, 1 ADC_TEMP Alternate mode // AdcParam 3, 10000, 12518931, -1.405 // AdcParam 4, 128, 0, 0 // AdcParam 5, 128, 0, 0 - // AdcParam 6, 0, ANALOG_RANGE, 0, 100 + // AdcParam 6, 0, ANALOG_RANGE, 0, 100 ADC_RANGE // AdcParam 7, 0, 2146, 0.23 // AdcParam 8, 1000, 0, 0 + // AdcParam 9, ADC_PH + // AdcParam 10, ADC_MQ + // AdcParam 11, 0, ANALOG_RANGE, 0, 33000 ADC_VOLTAGE + // AdcParam 12, 0, ANALOG_RANGE, 0, 33000 ADC_CURRENT Adc[idx].type = XdrvMailbox.payload; Adc[idx].param1 = strtol(ArgV(argument, 2), nullptr, 10); Adc[idx].param2 = strtol(ArgV(argument, 3), nullptr, 10); @@ -889,7 +934,36 @@ void CmndAdcParam(void) { } /*********************************************************************************************\ - * Interface + * Energy Interface +\*********************************************************************************************/ + +#ifdef USE_ENERGY_SENSOR +bool Xnrg33(uint32_t function) { + bool result = false; + + if (FUNC_PRE_INIT == function) { + uint32_t voltage_count = 0; + uint32_t current_count = 0; + for (uint32_t idx = 0; idx < Adcs.present; idx++) { + if (ADC_VOLTAGE == Adc[idx].type) { voltage_count++; } + if (ADC_CURRENT == Adc[idx].type) { current_count++; } + } + if (voltage_count || current_count) { + Energy->type_dc = true; + Energy->phase_count = (voltage_count > current_count) ? voltage_count : current_count; + Energy->current_available = false; + Energy->voltage_available = false; + Energy->voltage_common = (1 == voltage_count); + Energy->use_overtemp = true; // Use global temperature for overtemp detection + TasmotaGlobal.energy_driver = XNRG_33; + } + } + return result; +} +#endif // USE_ENERGY_SENSOR + +/*********************************************************************************************\ + * Sensor Interface \*********************************************************************************************/ bool Xsns02(uint32_t function) { diff --git a/tasmota/tasmota_xx2c_global/xnrg_interface.ino b/tasmota/tasmota_xx2c_global/xnrg_interface.ino index 60c45a5d1..769096686 100644 --- a/tasmota/tasmota_xx2c_global/xnrg_interface.ino +++ b/tasmota/tasmota_xx2c_global/xnrg_interface.ino @@ -150,7 +150,11 @@ bool (* const xnrg_func_ptr[])(uint32_t) = { // Energy driver Function Pointer #endif #ifdef XNRG_32 // Reserved for use by xdrv_16_tuyamcu.ino - &Xnrg32 + &Xnrg32, +#endif + +#ifdef XNRG_33 // Reserved for use by xsns_02_analog.ino + &Xnrg33 #endif };