Merge pull request #14581 from francescoadriani/development

Supports for MQ analog sensor for air quality
This commit is contained in:
Theo Arends 2022-01-24 17:00:28 +01:00 committed by GitHub
commit 6ecfc312b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 206 additions and 4 deletions

View File

@ -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 },

View File

@ -254,3 +254,4 @@ gpio.TFMINIPLUS_RX = 235
gpio.ZEROCROSS = 236
gpio.HALLEFFECT = 237
gpio.SENSOR_END = 238
gpio.ADC_MQ = 239

View File

@ -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}";

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"
@ -788,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"

View File

@ -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"
@ -788,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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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 {
@ -398,8 +399,9 @@ 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_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 };

View File

@ -111,6 +111,41 @@
// 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
#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
// lenght of filter
#define ANALOG_MQ_SAMPLES 60
struct {
uint8_t present = 0;
uint8_t type = 0;
@ -128,6 +163,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
@ -189,6 +226,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)) {
@ -200,7 +243,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)) {
@ -234,6 +277,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 +380,43 @@ 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;
float _RL = 10; //Value in KiloOhms
float _R0 = 10;
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.
float _ratio = _RS_Calc / _R0; // Get ratio RS_gas/RS_air
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);
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Ppm read. ADC-RAW: %2_f, ppm: %s,"), &voltage, ppm_chr);
return ppm;
}
float AdcGetPh(uint32_t idx) {
int adc = AdcRead(Adc[idx].pin, 2);
@ -425,6 +508,10 @@ void AdcEverySecond(void) {
else if (ADC_CT_POWER == Adc[idx].type) {
AdcGetCurrentPower(idx, 5);
}
else if (ADC_MQ == Adc[idx].type) {
AddSampleMq(idx);
AdcGetMq(idx);
}
}
}
@ -575,6 +662,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 +744,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 +799,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;