From e72248899e1d73a0cb593130c2536538a465dcda Mon Sep 17 00:00:00 2001 From: rice103 <90975508+francescoadriani@users.noreply.github.com> Date: Sun, 23 Jan 2022 17:10:35 +0100 Subject: [PATCH 1/7] Supports for MQ analog sensor for air quality It's support the analog sensor for quality air (also for esp-32) -added on list of assignable pins in module -with adcparams can choose wich mqx you have with seconds param ex: adcparam 10 4 (you have the mq-04) --- tasmota/i18n.h | 1 + tasmota/language/af_AF.h | 2 + tasmota/language/bg_BG.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/ko_KO.h | 2 + tasmota/language/nl_NL.h | 2 + tasmota/language/pl_PL.h | 2 + tasmota/language/pt_BR.h | 1 + tasmota/language/pt_PT.h | 1 + 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/tasmota_template.h | 7 ++- tasmota/xsns_02_analog.ino | 120 ++++++++++++++++++++++++++++++++++++- 28 files changed, 174 insertions(+), 2 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 423011238..38c4e4216 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -872,6 +872,7 @@ const char HTTP_SNS_CURRENT[] PROGMEM = "{s}" D_CURRENT "{ const char HTTP_SNS_POWER[] PROGMEM = "{s}" D_POWERUSAGE "{m}%s " D_UNIT_WATT "{e}"; const char HTTP_SNS_ENERGY_TOTAL[] PROGMEM = "{s}" D_ENERGY_TOTAL "{m}%s " D_UNIT_KILOWATTHOUR "{e}"; const char HTTP_SNS_PH[] PROGMEM = "{s}%s " D_PH "{m}%s " "{e}"; +const char HTTP_SNS_MQ[] PROGMEM = "{s}" D_MQ"-%s" "{m}%s " D_UNIT_PARTS_PER_MILLION "{e}"; const char HTTP_SNS_ORP[] PROGMEM = "{s}%s " D_ORP "{m}%s " D_UNIT_MILLIVOLT "{e}"; const char HTTP_SNS_EC[] PROGMEM = "{s}%s " D_EC "{m}%s " D_UNIT_MICROSIEMENS_PER_CM "{e}"; const char HTTP_SNS_O2[] PROGMEM = "{s}%s " D_O2 "{m}%s " D_UNIT_PERCENT "{e}"; diff --git a/tasmota/language/af_AF.h b/tasmota/language/af_AF.h index 7e1220f7f..4b72c6837 100644 --- a/tasmota/language/af_AF.h +++ b/tasmota/language/af_AF.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Wagwoord" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Poort" #define D_POWER_FACTOR "Krag faktor" #define D_POWERUSAGE "Krag" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 376b8db07..7e7cf52d0 100644 --- a/tasmota/language/bg_BG.h +++ b/tasmota/language/bg_BG.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Парола" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Порт" #define D_POWER_FACTOR "Фактор на мощността" #define D_POWERUSAGE "Мощност" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 1ef2fe374..cfa6c5625 100644 --- a/tasmota/language/cs_CZ.h +++ b/tasmota/language/cs_CZ.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Heslo" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Účiník" #define D_POWERUSAGE "Příkon" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 dd5ddd31d..b67a77851 100644 --- a/tasmota/language/de_DE.h +++ b/tasmota/language/de_DE.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Passwort" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Leistungsfaktor" #define D_POWERUSAGE "Leistung" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 4c19ca029..1ce06a5bb 100644 --- a/tasmota/language/el_GR.h +++ b/tasmota/language/el_GR.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Κωδικός" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Θύρα" #define D_POWER_FACTOR "Συντελεστής Ισχύος" #define D_POWERUSAGE "Ισχύς" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 20c2b8107..45a0ca3ca 100644 --- a/tasmota/language/en_GB.h +++ b/tasmota/language/en_GB.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Password" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Power Factor" #define D_POWERUSAGE "Power" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 240bbc588..621f97679 100644 --- a/tasmota/language/es_ES.h +++ b/tasmota/language/es_ES.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Clave" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Puerto" #define D_POWER_FACTOR "Factor de Potencia" #define D_POWERUSAGE "Potencia" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Potencia" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 fa158ef23..83b2063c9 100644 --- a/tasmota/language/fr_FR.h +++ b/tasmota/language/fr_FR.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Mot de passe" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Fact de puiss" #define D_POWERUSAGE "Puissance" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Manette" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 21a74f934..86be5540a 100644 --- a/tasmota/language/fy_NL.h +++ b/tasmota/language/fy_NL.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Wachtwurd" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Poort" #define D_POWER_FACTOR "Krêftfaktor" #define D_POWERUSAGE "Krêft" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 e824acbc6..649df5e4b 100644 --- a/tasmota/language/he_HE.h +++ b/tasmota/language/he_HE.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "סיסמא" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "פורט" #define D_POWER_FACTOR "גורם כוח" #define D_POWERUSAGE "כוח" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 aed1a2501..d09d68b55 100644 --- a/tasmota/language/hu_HU.h +++ b/tasmota/language/hu_HU.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Jelszó" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Teljesítménytényező" #define D_POWERUSAGE "Energiafelhasználás" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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/ko_KO.h b/tasmota/language/ko_KO.h index ad580f71b..e503f55d4 100644 --- a/tasmota/language/ko_KO.h +++ b/tasmota/language/ko_KO.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "비밀번호" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "포트" #define D_POWER_FACTOR "Power Factor" #define D_POWERUSAGE "전원" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 39011d352..afe73ad75 100644 --- a/tasmota/language/nl_NL.h +++ b/tasmota/language/nl_NL.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Wachtwoord" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Poort" #define D_POWER_FACTOR "Arbeidsfactor" #define D_POWERUSAGE "Vermogen" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 c5b1bcacf..e69836af6 100644 --- a/tasmota/language/pl_PL.h +++ b/tasmota/language/pl_PL.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Hasło" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Cosinus fi" #define D_POWERUSAGE "Moc" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC Moc CT" #define D_SENSOR_ADC_JOYSTICK "ADC Dżojstik" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 2e7791647..45a32b6da 100644 --- a/tasmota/language/pt_BR.h +++ b/tasmota/language/pt_BR.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Senha" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Porta" #define D_POWER_FACTOR "Fator de potência" #define D_POWERUSAGE "Potência" diff --git a/tasmota/language/pt_PT.h b/tasmota/language/pt_PT.h index eec578950..5ba030dee 100644 --- a/tasmota/language/pt_PT.h +++ b/tasmota/language/pt_PT.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Palavra Chave" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Porta" #define D_POWER_FACTOR "Factor de Potência" #define D_POWERUSAGE "Potência" diff --git a/tasmota/language/ro_RO.h b/tasmota/language/ro_RO.h index 3904106aa..e2f01aff9 100644 --- a/tasmota/language/ro_RO.h +++ b/tasmota/language/ro_RO.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Parolă" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Factor de Putere" #define D_POWERUSAGE "Putere" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 e5a20d29a..ad70639de 100644 --- a/tasmota/language/ru_RU.h +++ b/tasmota/language/ru_RU.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Пароль" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Порт" #define D_POWER_FACTOR "Коэффициент мощности" #define D_POWERUSAGE "Мощность" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 bbcc04877..e61bc00ec 100644 --- a/tasmota/language/sk_SK.h +++ b/tasmota/language/sk_SK.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Heslo" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Účinník" #define D_POWERUSAGE "Príkon" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 a8294d2a7..8f47e8be7 100644 --- a/tasmota/language/sv_SE.h +++ b/tasmota/language/sv_SE.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Lösenord" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Spänningsfaktor" #define D_POWERUSAGE "Spänning" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 34f8730c8..70c6c958a 100644 --- a/tasmota/language/tr_TR.h +++ b/tasmota/language/tr_TR.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Şifre" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Port" #define D_POWER_FACTOR "Güç Faktörü" #define D_POWERUSAGE "Güç" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 6f1ff7728..a2903fdc6 100644 --- a/tasmota/language/uk_UA.h +++ b/tasmota/language/uk_UA.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Гасло" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Порт" #define D_POWER_FACTOR "Коефіцієнт потужності" #define D_POWERUSAGE "Потужність" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 ac8b43d06..fb91d7201 100644 --- a/tasmota/language/vi_VN.h +++ b/tasmota/language/vi_VN.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "Mật khẩu" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "Cổng" #define D_POWER_FACTOR "Hệ số công suất" #define D_POWERUSAGE "Công suất" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 e4a0d40c8..c7cc7a136 100644 --- a/tasmota/language/zh_CN.h +++ b/tasmota/language/zh_CN.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "密码" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "端口" #define D_POWER_FACTOR "功率因数" #define D_POWERUSAGE "功率" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 f89b9b670..563e2f666 100644 --- a/tasmota/language/zh_TW.h +++ b/tasmota/language/zh_TW.h @@ -137,6 +137,7 @@ #define D_ORP "ORP" #define D_PASSWORD "密碼" #define D_PH "pH" +#define D_MQ "MQ" #define D_PORT "通訊埠" #define D_POWER_FACTOR "功率因數" #define D_POWERUSAGE "用電量" @@ -788,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC CT Power" #define D_SENSOR_ADC_JOYSTICK "ADC Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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_template.h b/tasmota/tasmota_template.h index 737788a13..0047c8b30 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -180,6 +180,7 @@ enum UserSelectablePins { GPIO_SOLAXX1_RTS, // Solax Inverter Serial interface GPIO_OPTION_E, // Emulated module GPIO_SDM230_TX, GPIO_SDM230_RX, // SDM230 Serial interface + GPIO_ADC_MQ, // Analog MQ Sensor GPIO_SENSOR_END }; enum ProgramSelectablePins { @@ -399,7 +400,8 @@ const char kSensorNames[] PROGMEM = D_SENSOR_SOLAXX1_RTS "|" D_SENSOR_OPTION " E|" D_SENSOR_SDM230_TX "|" D_SENSOR_SDM230_RX -; + D_SENSOR_ADC_MQ "|" + ; const char kSensorNamesFixed[] PROGMEM = D_SENSOR_USER; @@ -973,6 +975,7 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_ADC_CT_POWER) + MAX_ADCS, // Current 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 #endif // ESP32 #ifdef USE_SHIFT595 @@ -999,6 +1002,7 @@ const uint16_t kAdcNiceList[] PROGMEM = { AGPIO(GPIO_ADC_CT_POWER), // Current AGPIO(GPIO_ADC_JOY), // Joystick AGPIO(GPIO_ADC_PH), // Analog PH Sensor + AGPIO(GPIO_ADC_MQ), // Analog MQ Sensor }; #endif // ESP8266 @@ -1014,6 +1018,7 @@ enum UserSelectableAdc { ADC_CT_POWER, // Current ADC_JOY, // Joystick ADC_PH, // Analog PH Sensor + ADC_MQ, // Analog MQ Sensor // ADC_SWITCH, // Switch // ADC_SWITCH_INV, ADC_END }; diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 25670ffaa..e1e4654db 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -28,6 +28,7 @@ #define ANALOG_RESOLUTION 10 // 12 = 4095, 11 = 2047, 10 = 1023 #define ANALOG_RANGE 1023 // 4095 = 12, 2047 = 11, 1023 = 10 #define ANALOG_PERCENT 10 // backward compatible div10 range +#define ANALOG_BOARD "ESP8266" #endif // ESP8266 #ifdef ESP32 #undef ANALOG_RESOLUTION @@ -36,6 +37,8 @@ #define ANALOG_RANGE 4095 // 4095 = 12, 2047 = 11, 1023 = 10 #undef ANALOG_PERCENT #define ANALOG_PERCENT ((ANALOG_RANGE + 50) / 100) // approximation to 1% ADC range +#undef ANALOG_BOARD +#define ANALOG_BOARD "ESP-32" #endif // ESP32 #define TO_CELSIUS(x) ((x) - 273.15) @@ -111,6 +114,30 @@ // Multiplier used to store pH with 2 decimal places in a non decimal datatype #define ANALOG_PH_DECIMAL_MULTIPLIER 100.0 +//means mq type (ex for mq-02 use 2, mq-131 use 131) +#define ANALOG_MQ_TYPE 2 +//exponential regression a params +#define ANALOG_MQ_A 574.25 +//exponential regression b params +#define ANALOG_MQ_B -2.222 +/* + Exponential regression: + Gas | a | b + LPG | 44771 | -3.245 + CH4 | 2*10^31| 19.01 + CO | 521853 | -3.821 + Alcohol| 0.3934 | -1.504 + Benzene| 4.8387 | -2.68 + Hexane | 7585.3 | -2.849 + NOx | -462.43 | -2.204 + CL2 | 47.209 | -1.186 + O3 | 23.943 | -1.11 +*/ +//ratio for alarm, NOT USED yet (RS / R0 = 15 ppm) +#define ANALOG_MQ_RatioMQCleanAir 15.0 +// Multiplier used to store pH with 2 decimal places in a non decimal datatype +#define ANALOG_MQ_DECIMAL_MULTIPLIER 100.0 + struct { uint8_t present = 0; uint8_t type = 0; @@ -189,6 +216,12 @@ void AdcInitParams(uint8_t idx) { Adc[idx].param3 = ANALOG_PH_CALSOLUTION_HIGH_PH * ANALOG_PH_DECIMAL_MULTIPLIER; // PH of the calibration solution 2, which is the one with the higher PH Adc[idx].param4 = ANALOG_PH_CALSOLUTION_HIGH_ANALOG_VALUE; // Reading of AnalogInput while probe is in solution 2 } + else if (ADC_MQ == Adc[idx].type) { + Adc[idx].param1 = ANALOG_MQ_TYPE; // Could be MQ-002, MQ-004, MQ-131 .... + Adc[idx].param2 = (int)(ANALOG_MQ_A * ANALOG_MQ_DECIMAL_MULTIPLIER); // Exponential regression + 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 + } } 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)) { @@ -234,6 +267,9 @@ void AdcInit(void) { if (PinUsed(GPIO_ADC_PH, i)) { AdcAttach(Pin(GPIO_ADC_PH, i), ADC_PH); } + if (PinUsed(GPIO_ADC_MQ, i)) { + AdcAttach(Pin(GPIO_ADC_MQ, i), ADC_MQ); + } } for (uint32_t i = 0; i < MAX_KEYS; i++) { if (PinUsed(GPIO_ADC_BUTTON, i)) { @@ -334,6 +370,32 @@ uint16_t AdcGetLux(uint32_t idx) { return (uint16_t)ldrLux; } +float AdcGetMq(uint32_t idx) { + float avg = 0.0; + int retries = 5; + int retries_delay = 20; + float _RL = 10; //Value in KiloOhms + float _R0 = 10; + int _adc = AdcRead(Adc[idx].pin, 2); + avg += _adc; + for (int i = 0; i < retries-1; i ++) { + delay(retries_delay); + _adc = AdcRead(Adc[idx].pin, 2); + avg += _adc; + } + float voltage = (avg/ retries) * ANALOG_V33 / ((pow(2, ANALOG_RESOLUTION)) - 1); + + float _RS_Calc = ((ANALOG_V33 * _RL) / voltage) -_RL; //Get value of RS in a gas + if (_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted. + float _ratio = _RS_Calc / _R0; // Get ratio RS_gas/RS_air + float ppm= Adc[idx].param2/ANALOG_MQ_DECIMAL_MULTIPLIER*pow(_ratio, Adc[idx].param3/ANALOG_MQ_DECIMAL_MULTIPLIER); // <- Source excel analisis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents + if(ppm < 0) ppm = 0; //No negative values accepted or upper datasheet recomendation. + char ppm_chr[6]; + dtostrfd(ppm, 2, ppm_chr); + AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "ppm read. ADC-RAW: %d, ppm: %d,"), voltage, ppm_chr); + return ppm; +} + float AdcGetPh(uint32_t idx) { int adc = AdcRead(Adc[idx].pin, 2); @@ -575,6 +637,25 @@ void AdcShow(bool json) { #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_SNS_PH, "", ph_chr); + #endif // USE_WEBSERVER + } + break; + } + case ADC_MQ: { + float mq = AdcGetMq(idx); + char mq_chr[6]; + dtostrfd(mq, 2, mq_chr); + + float mqnumber =Adc[idx].param1; + char mqnumber_chr[6]; + dtostrfd(mqnumber, 0, mqnumber_chr); + + if (json) { + AdcShowContinuation(&jsonflg); + ResponseAppend_P(PSTR("\"MQ%d_%d\":%s"), Adc[idx].param1, idx + offset, mq_chr); + #ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_SNS_MQ, mqnumber_chr, mq_chr); #endif // USE_WEBSERVER } break; @@ -638,6 +719,43 @@ void CmndAdcParam(void) { Adc[idx].param1 ^= CT_FLAG_ENERGY_RESET; // Cancel energy reset flag } } + if (ADC_MQ == XdrvMailbox.payload) { + float a = CharToFloat(ArgV(argument, 3)); + float b = CharToFloat(ArgV(argument, 4)); + float ratioMQCleanAir = CharToFloat(ArgV(argument, 5)); + if (a==0 && b==0 && ratioMQCleanAir==0) + { + if (Adc[idx].param1==2) + { + a=574.25; + b=-2.222 + ratioMQCleanAir=9.83 + } + if (Adc[idx].param1==4) + { + a=1012.7 + b=-2.786 + ratioMQCleanAir=4.4 + } + if (Adc[idx].param1==7) + { + a=99.042 + b=-1.518 + ratioMQCleanAir=27.5 + } + if (Adc[idx].param1==131) + { + a=23.943 + b=-1.11 + ratioMQCleanAir=15 + } + } + Adc[idx].param2 = (int)(a * ANALOG_MQ_DECIMAL_MULTIPLIER); // Exponential regression + Adc[idx].param3 = (int)(b * ANALOG_MQ_DECIMAL_MULTIPLIER); // Exponential regression + Adc[idx].param4 = (int)(ratioMQCleanAir * ANALOG_MQ_DECIMAL_MULTIPLIER); // Exponential regression + AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION "Analog MQ reset: mq%d, a=%2_f, b=%2_f, ratioMQCleanAir=%2_f"), + Adc[idx].param1, &a, &b, &ratioMQCleanAir); + } } else { // Set default values based on current adc type // AdcParam 2 // AdcParam 3 @@ -656,7 +774,7 @@ void CmndAdcParam(void) { // AdcParam AdcGetSettings(idx); Response_P(PSTR("{\"" D_CMND_ADCPARAM "%d\":[%d,%d,%d"), idx +1, Adcs.type, Adc[idx].param1, Adc[idx].param2); - if (ADC_RANGE == Adc[idx].type) { + if ((ADC_RANGE == Adc[idx].type) || (ADC_MQ == Adc[idx].type)){ ResponseAppend_P(PSTR(",%d,%d"), Adc[idx].param3, Adc[idx].param4); } else { int value = Adc[idx].param3; From 496de57c07daf4215af8ae3bb8ccc9d4b9a9337f Mon Sep 17 00:00:00 2001 From: rice103 <90975508+francescoadriani@users.noreply.github.com> Date: Sun, 23 Jan 2022 17:28:13 +0100 Subject: [PATCH 2/7] bug fix --- tasmota/xsns_02_analog.ino | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index e1e4654db..9c845561c 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -728,26 +728,26 @@ void CmndAdcParam(void) { if (Adc[idx].param1==2) { a=574.25; - b=-2.222 - ratioMQCleanAir=9.83 + b=-2.222; + ratioMQCleanAir=9.83; } if (Adc[idx].param1==4) { - a=1012.7 - b=-2.786 - ratioMQCleanAir=4.4 + a=1012.7; + b=-2.786; + ratioMQCleanAir=4.4; } if (Adc[idx].param1==7) { - a=99.042 - b=-1.518 - ratioMQCleanAir=27.5 + a=99.042; + b=-1.518; + ratioMQCleanAir=27.5; } if (Adc[idx].param1==131) { - a=23.943 - b=-1.11 - ratioMQCleanAir=15 + a=23.943; + b=-1.11; + ratioMQCleanAir=15; } } Adc[idx].param2 = (int)(a * ANALOG_MQ_DECIMAL_MULTIPLIER); // Exponential regression From 06617c7fcb6a6fcd0cccb06859e833535df427d5 Mon Sep 17 00:00:00 2001 From: rice103 <90975508+francescoadriani@users.noreply.github.com> Date: Sun, 23 Jan 2022 18:27:32 +0100 Subject: [PATCH 3/7] Using FastPrecisePow instead of pow --- tasmota/xsns_02_analog.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 9c845561c..e934decad 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -383,12 +383,12 @@ float AdcGetMq(uint32_t idx) { _adc = AdcRead(Adc[idx].pin, 2); avg += _adc; } - float voltage = (avg/ retries) * ANALOG_V33 / ((pow(2, ANALOG_RESOLUTION)) - 1); + float voltage = (avg/ retries) * ANALOG_V33 / ((FastPrecisePow(2, ANALOG_RESOLUTION)) - 1); float _RS_Calc = ((ANALOG_V33 * _RL) / voltage) -_RL; //Get value of RS in a gas if (_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted. float _ratio = _RS_Calc / _R0; // Get ratio RS_gas/RS_air - float ppm= Adc[idx].param2/ANALOG_MQ_DECIMAL_MULTIPLIER*pow(_ratio, Adc[idx].param3/ANALOG_MQ_DECIMAL_MULTIPLIER); // <- Source excel analisis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents + float ppm= Adc[idx].param2/ANALOG_MQ_DECIMAL_MULTIPLIER*FastPrecisePow(_ratio, Adc[idx].param3/ANALOG_MQ_DECIMAL_MULTIPLIER); // <- Source excel analisis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents if(ppm < 0) ppm = 0; //No negative values accepted or upper datasheet recomendation. char ppm_chr[6]; dtostrfd(ppm, 2, ppm_chr); From d45c8d3d24325a9c13d9cd4c90b4966640ba30ac Mon Sep 17 00:00:00 2001 From: rice103 <90975508+francescoadriani@users.noreply.github.com> Date: Sun, 23 Jan 2022 18:36:53 +0100 Subject: [PATCH 4/7] Removed unused ANALOG_BOARD --- tasmota/xsns_02_analog.ino | 3 --- 1 file changed, 3 deletions(-) diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index e934decad..e2d440b23 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -28,7 +28,6 @@ #define ANALOG_RESOLUTION 10 // 12 = 4095, 11 = 2047, 10 = 1023 #define ANALOG_RANGE 1023 // 4095 = 12, 2047 = 11, 1023 = 10 #define ANALOG_PERCENT 10 // backward compatible div10 range -#define ANALOG_BOARD "ESP8266" #endif // ESP8266 #ifdef ESP32 #undef ANALOG_RESOLUTION @@ -37,8 +36,6 @@ #define ANALOG_RANGE 4095 // 4095 = 12, 2047 = 11, 1023 = 10 #undef ANALOG_PERCENT #define ANALOG_PERCENT ((ANALOG_RANGE + 50) / 100) // approximation to 1% ADC range -#undef ANALOG_BOARD -#define ANALOG_BOARD "ESP-32" #endif // ESP32 #define TO_CELSIUS(x) ((x) - 273.15) From d20aad968e1d27391b6575035e51013a8cae3da1 Mon Sep 17 00:00:00 2001 From: rice103 <90975508+francescoadriani@users.noreply.github.com> Date: Sun, 23 Jan 2022 19:19:32 +0100 Subject: [PATCH 5/7] Supports refresh each seconds of mq --- tasmota/xsns_02_analog.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index e2d440b23..444021efd 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -484,6 +484,9 @@ void AdcEverySecond(void) { else if (ADC_CT_POWER == Adc[idx].type) { AdcGetCurrentPower(idx, 5); } + else if (ADC_MQ == Adc[idx].type) { + AdcGetMq(idx); + } } } From 2bf3ac417b69e07fb684d8abf40144902dccdf2b Mon Sep 17 00:00:00 2001 From: rice103 <90975508+francescoadriani@users.noreply.github.com> Date: Sun, 23 Jan 2022 23:54:29 +0100 Subject: [PATCH 6/7] bug fix, implements filter to make average of data --- tasmota/berry/include/be_gpio_defines.h | 1 + tasmota/berry/internal/gpio.be | 1 + tasmota/language/it_IT.h | 1 + tasmota/language/pt_BR.h | 1 + tasmota/language/pt_PT.h | 1 + tasmota/tasmota_template.h | 4 +-- tasmota/xsns_02_analog.ino | 40 +++++++++++++++++-------- 7 files changed, 35 insertions(+), 14 deletions(-) diff --git a/tasmota/berry/include/be_gpio_defines.h b/tasmota/berry/include/be_gpio_defines.h index e40219dc4..8906f90a0 100644 --- a/tasmota/berry/include/be_gpio_defines.h +++ b/tasmota/berry/include/be_gpio_defines.h @@ -14,6 +14,7 @@ const be_const_member_t lv_gpio_constants[] = { { "ADC_INPUT", (int32_t) GPIO_ADC_INPUT }, { "ADC_JOY", (int32_t) GPIO_ADC_JOY }, { "ADC_LIGHT", (int32_t) GPIO_ADC_LIGHT }, + { "ADC_MQ", (int32_t) GPIO_ADC_MQ }, { "ADC_PH", (int32_t) GPIO_ADC_PH }, { "ADC_RANGE", (int32_t) GPIO_ADC_RANGE }, { "ADC_TEMP", (int32_t) GPIO_ADC_TEMP }, diff --git a/tasmota/berry/internal/gpio.be b/tasmota/berry/internal/gpio.be index 3c589a046..a1816dfc7 100644 --- a/tasmota/berry/internal/gpio.be +++ b/tasmota/berry/internal/gpio.be @@ -254,3 +254,4 @@ gpio.TFMINIPLUS_RX = 235 gpio.ZEROCROSS = 236 gpio.HALLEFFECT = 237 gpio.SENSOR_END = 238 +gpio.ADC_MQ = 239 diff --git a/tasmota/language/it_IT.h b/tasmota/language/it_IT.h index 2c7f37b61..5d200f748 100644 --- a/tasmota/language/it_IT.h +++ b/tasmota/language/it_IT.h @@ -788,6 +788,7 @@ #define D_SENSOR_ADC_CT_POWER "ADC - CTR alimentazione" #define D_SENSOR_ADC_JOYSTICK "ADC - Joystick" #define D_SENSOR_ADC_PH "ADC pH" +#define D_SENSOR_ADC_MQ "ADC MQ" #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/pt_BR.h b/tasmota/language/pt_BR.h index 45a32b6da..4ab70c0b6 100644 --- a/tasmota/language/pt_BR.h +++ b/tasmota/language/pt_BR.h @@ -789,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "Potência do TC ADC" #define D_SENSOR_ADC_JOYSTICK "Joystick ADC" #define D_SENSOR_ADC_PH "pH ADC" +#define D_SENSOR_ADC_MQ "ADC MQ" #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 5ba030dee..c7d398fbb 100644 --- a/tasmota/language/pt_PT.h +++ b/tasmota/language/pt_PT.h @@ -789,6 +789,7 @@ #define D_SENSOR_ADC_CT_POWER "Potência do TC ADC" #define D_SENSOR_ADC_JOYSTICK "Joystick ADC" #define D_SENSOR_ADC_PH "pH ADC" +#define D_SENSOR_ADC_MQ "MQ ADC" #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_template.h b/tasmota/tasmota_template.h index 0047c8b30..86efb5c41 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -399,8 +399,8 @@ const char kSensorNames[] PROGMEM = D_GPIO_SHIFT595_SRCLK "|" D_GPIO_SHIFT595_RCLK "|" D_GPIO_SHIFT595_OE "|" D_GPIO_SHIFT595_SER "|" D_SENSOR_SOLAXX1_RTS "|" D_SENSOR_OPTION " E|" - D_SENSOR_SDM230_TX "|" D_SENSOR_SDM230_RX - D_SENSOR_ADC_MQ "|" + D_SENSOR_SDM230_TX "|" D_SENSOR_SDM230_RX "|" + D_SENSOR_ADC_MQ ; const char kSensorNamesFixed[] PROGMEM = diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 444021efd..444a3d0b4 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -134,6 +134,8 @@ #define ANALOG_MQ_RatioMQCleanAir 15.0 // Multiplier used to store pH with 2 decimal places in a non decimal datatype #define ANALOG_MQ_DECIMAL_MULTIPLIER 100.0 +// lenght of filter +#define ANALOG_MQ_SAMPLES 60 struct { uint8_t present = 0; @@ -152,6 +154,8 @@ struct { uint16_t last_value = 0; uint8_t type = 0; uint8_t pin = 0; + float mq_samples[ANALOG_MQ_SAMPLES]; + int indexOfPointer = -1; } Adc[MAX_ADCS]; #ifdef ESP8266 @@ -230,7 +234,7 @@ void AdcInitParams(uint8_t idx) { } } -void AdcAttach(uint8_t pin, uint8_t type) { +void AdcAttach(uint32_t pin, uint8_t type) { if (Adcs.present == MAX_ADCS) { return; } Adc[Adcs.present].pin = pin; if (adcAttachPin(Adc[Adcs.present].pin)) { @@ -367,20 +371,31 @@ uint16_t AdcGetLux(uint32_t idx) { return (uint16_t)ldrLux; } +void AddSampleMq(uint32_t idx){ + AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Adding sample for mq-sensor")); + int _adc = AdcRead(Adc[idx].pin, 2); + // init af array at same value + if (Adc[idx].indexOfPointer==-1) + { + AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Init samples for mq-sensor")); + for (int i = 0; i < ANALOG_MQ_SAMPLES; i ++) + Adc[idx].mq_samples[i] = _adc; + } + else + Adc[idx].mq_samples[Adc[idx].indexOfPointer] = _adc; + Adc[idx].indexOfPointer++; + if (Adc[idx].indexOfPointer==ANALOG_MQ_SAMPLES) + Adc[idx].indexOfPointer=0; +} + float AdcGetMq(uint32_t idx) { + AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Getting value for mq-sensor")); float avg = 0.0; - int retries = 5; - int retries_delay = 20; float _RL = 10; //Value in KiloOhms float _R0 = 10; - int _adc = AdcRead(Adc[idx].pin, 2); - avg += _adc; - for (int i = 0; i < retries-1; i ++) { - delay(retries_delay); - _adc = AdcRead(Adc[idx].pin, 2); - avg += _adc; - } - float voltage = (avg/ retries) * ANALOG_V33 / ((FastPrecisePow(2, ANALOG_RESOLUTION)) - 1); + for (int i = 0; i < ANALOG_MQ_SAMPLES; i ++) + avg += Adc[idx].mq_samples[i]; + float voltage = (avg / ANALOG_MQ_SAMPLES) * ANALOG_V33 / ((FastPrecisePow(2, ANALOG_RESOLUTION)) - 1); float _RS_Calc = ((ANALOG_V33 * _RL) / voltage) -_RL; //Get value of RS in a gas if (_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted. @@ -389,7 +404,7 @@ float AdcGetMq(uint32_t idx) { if(ppm < 0) ppm = 0; //No negative values accepted or upper datasheet recomendation. char ppm_chr[6]; dtostrfd(ppm, 2, ppm_chr); - AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "ppm read. ADC-RAW: %d, ppm: %d,"), voltage, ppm_chr); + AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Ppm read. ADC-RAW: %2_f, ppm: %s,"), &voltage, ppm_chr); return ppm; } @@ -485,6 +500,7 @@ void AdcEverySecond(void) { AdcGetCurrentPower(idx, 5); } else if (ADC_MQ == Adc[idx].type) { + AddSampleMq(idx); AdcGetMq(idx); } } From 3191ecc6830f62af8d628419d632e7b9e9a56133 Mon Sep 17 00:00:00 2001 From: rice103 <90975508+francescoadriani@users.noreply.github.com> Date: Mon, 24 Jan 2022 11:21:01 +0100 Subject: [PATCH 7/7] Added wiring diagram --- tasmota/xsns_02_analog.ino | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 444a3d0b4..4ba748f86 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -111,6 +111,15 @@ // Multiplier used to store pH with 2 decimal places in a non decimal datatype #define ANALOG_PH_DECIMAL_MULTIPLIER 100.0 +// MQ-X sensor (MQ-02, MQ-03, MQ-04, MQ-05, MQ-06, MQ-07, MQ-08, MQ-09, MQ-131, MQ-135) +// +// A0 ------------------- +// | +// GND ----------- | +// | | +// VCC --- | | +// | | | +// 3V3 GND ADC <- (A0 for nodemcu, wemos; GPIO34,35,36,39 and other analog IN/OUT pin for esp32) //means mq type (ex for mq-02 use 2, mq-131 use 131) #define ANALOG_MQ_TYPE 2 //exponential regression a params