diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino
index 79b1693d2..bfabfeed0 100644
--- a/sonoff/_releasenotes.ino
+++ b/sonoff/_releasenotes.ino
@@ -1,10 +1,11 @@
/* 5.10.0b
- * Add optional support for PZEM004T energy sensor
+ * Add support for PZEM004T energy sensor to be enabled with define USE_PZEM004T in user_config.h
* Change Sonoff Pow Energy MQTT data message and consolidate Status 8 into Status 10
* Change Wemo SetBinaryState to distinguish from GetBinaryState (#1357)
- * Change output of HTTP command to valid JSON only (#1363)
- * Change output to valid JSON Array if needed (#1363)
- * Add support for sensor MH-Z19(B) to be enabled with define USE_MHZ19 in user_config.h (#561, #1248)
+ * Change output of HTTP command to valid JSON and Array only (#1363)
+ * Add support for MH-Z19(B) CO2 sensor to be enabled with define USE_MHZ19 in user_config.h (#561, #1248)
+ * Add support for senseair S8 CO2 sensor to be enabled with define USE_SENSEAIR in user_config.h
+ * Add support for Domoticz Air Quality sensor to be used by MH-Z19(B) and SenseAir sensors
*
* 5.10.0a
* Add (experimental) support for sensor SHT3x
diff --git a/sonoff/i18n.h b/sonoff/i18n.h
index f7bebbbf8..3c3fd66be 100644
--- a/sonoff/i18n.h
+++ b/sonoff/i18n.h
@@ -1,7 +1,7 @@
/*
i18n.h - internationalization for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -121,6 +121,10 @@ const char HTTP_SNS_PRESSURE[] PROGMEM = "%s{s}%s " D_PRESSURE "{m}%s " D_UNIT_P
const char HTTP_SNS_SEAPRESSURE[] PROGMEM = "%s{s}%s " D_PRESSUREATSEALEVEL "{m}%s " D_UNIT_PRESSURE "{e}"; // {s} =
, {m} = | , {e} = |
const char HTTP_SNS_ANALOG[] PROGMEM = "%s{s}%s " D_ANALOG_INPUT "%d{m}%d{e}"; // {s} = , {m} = | , {e} = |
+#if defined(USE_MHZ19) || defined(USE_SENSEAIR)
+const char HTTP_SNS_CO2[] PROGMEM = "%s{s}%s " D_CO2 "{m}%d " D_UNIT_PPM "{e}"; // {s} = , {m} = | , {e} = |
+#endif // USE_WEBSERVER
+
const char S_MAIN_MENU[] PROGMEM = D_MAIN_MENU;
const char S_CONFIGURATION[] PROGMEM = D_CONFIGURATION;
const char S_CONFIGURE_MODULE[] PROGMEM = D_CONFIGURE_MODULE;
diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h
index 8576b8ed1..18a7a5d61 100644
--- a/sonoff/language/de-DE.h
+++ b/sonoff/language/de-DE.h
@@ -1,7 +1,7 @@
/*
de-DE.h - localization for German - Germany for Sonoff-Tasmota
- Copyright (C) 2017 VinceMasuka
+ Copyright (C) 2018 VinceMasuka
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -66,7 +66,7 @@
#define D_BUTTON "Knopf"
#define D_BY "von" // Written by me
#define D_CELSIUS "Celsius"
-#define D_CO2 "CO2"
+#define D_CO2 "Kohlenstoffdioxid"
#define D_CODE "code" // Button code
#define D_COLDLIGHT "kalt"
#define D_COMMAND "Befehl"
@@ -118,6 +118,7 @@
#define D_INITIALIZED "initialisiert"
#define D_IP_ADDRESS "IP-Addresse"
#define D_LIGHT "Licht"
+#define D_LIMIT "Grenzwert"
#define D_LOCAL_TIME "lokale Zeit"
#define D_LOW "niedrig"
#define D_LWT "LWT"
@@ -386,6 +387,7 @@
#define D_DOMOTICZ_COUNT "Count"
#define D_DOMOTICZ_VOLTAGE "Voltage"
#define D_DOMOTICZ_CURRENT "Current"
+ #define D_DOMOTICZ_AIRQUALITY "AirQuality"
#define D_DOMOTICZ_UPDATE_TIMER "Update timer"
// xdrv_irremote.ino
@@ -473,12 +475,14 @@
#define D_SENSOR_RELAY "Relay " // Suffix "1i"
#define D_SENSOR_LED "LED " // Suffix "1i"
#define D_SENSOR_PWM "PWM " // Suffix "1"
-#define D_SENSOR_COUNTER "Counter" // Suffix "1"
+#define D_SENSOR_COUNTER "Counter" // Suffix "1"
#define D_SENSOR_IRRECV "IRRecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
+#define D_SENSOR_SAIR_RX "SAir Rx"
+#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
#define D_SENSOR_SPI_DC "SPI DC"
#define D_SENSOR_BACKLIGHT "BLight"
diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h
index 571fff023..497654872 100644
--- a/sonoff/language/en-GB.h
+++ b/sonoff/language/en-GB.h
@@ -1,7 +1,7 @@
/*
en-GB.h - localization for English - United Kingdom for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -66,7 +66,7 @@
#define D_BUTTON "Button"
#define D_BY "by" // Written by me
#define D_CELSIUS "Celsius"
-#define D_CO2 "CO2"
+#define D_CO2 "Carbon dioxide"
#define D_CODE "code" // Button code
#define D_COLDLIGHT "Cold"
#define D_COMMAND "Command"
@@ -118,6 +118,7 @@
#define D_INITIALIZED "Initialized"
#define D_IP_ADDRESS "IP Address"
#define D_LIGHT "Light"
+#define D_LIMIT "Limit"
#define D_LOCAL_TIME "Local"
#define D_LOW "Low"
#define D_LWT "LWT"
@@ -386,6 +387,7 @@
#define D_DOMOTICZ_COUNT "Count"
#define D_DOMOTICZ_VOLTAGE "Voltage"
#define D_DOMOTICZ_CURRENT "Current"
+ #define D_DOMOTICZ_AIRQUALITY "AirQuality"
#define D_DOMOTICZ_UPDATE_TIMER "Update timer"
// xdrv_irremote.ino
@@ -479,6 +481,8 @@
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
+#define D_SENSOR_SAIR_RX "SAir Rx"
+#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
#define D_SENSOR_SPI_DC "SPI DC"
#define D_SENSOR_BACKLIGHT "BLight"
diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h
index 13b1b49cb..a6f3b020e 100644
--- a/sonoff/language/nl-NL.h
+++ b/sonoff/language/nl-NL.h
@@ -1,7 +1,7 @@
/*
nl-NL.h - localization for Dutch - Nederland for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -66,7 +66,7 @@
#define D_BUTTON "DrukKnop"
#define D_BY "door" // Written by me
#define D_CELSIUS "Celsius"
-#define D_CO2 "CO2"
+#define D_CO2 "Koolstofdioxide"
#define D_CODE "code" // Button code
#define D_COLDLIGHT "Koud"
#define D_COMMAND "Opdracht"
@@ -118,6 +118,7 @@
#define D_INITIALIZED "Geinitialiseerd"
#define D_IP_ADDRESS "IP Adres"
#define D_LIGHT "Ligt"
+#define D_LIMIT "Grenswaarde"
#define D_LOCAL_TIME "Plaatselijk"
#define D_LOW "Laag"
#define D_LWT "LWT"
@@ -386,6 +387,7 @@
#define D_DOMOTICZ_COUNT "Count"
#define D_DOMOTICZ_VOLTAGE "Spanning"
#define D_DOMOTICZ_CURRENT "Stroom"
+ #define D_DOMOTICZ_AIRQUALITY "AirQuality"
#define D_DOMOTICZ_UPDATE_TIMER "Bijwerk timer"
// xdrv_irremote.ino
@@ -474,11 +476,13 @@
#define D_SENSOR_LED "Led" // Suffix "1i"
#define D_SENSOR_PWM "PWM" // Suffix "1"
#define D_SENSOR_COUNTER "Teller" // Suffix "1"
+#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
-#define D_SENSOR_IRRECV "IRrecv"
+#define D_SENSOR_SAIR_RX "SAir Rx"
+#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
#define D_SENSOR_SPI_DC "SPI DC"
#define D_SENSOR_BACKLIGHT "BLight"
diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h
index 4fd42d4fc..51281d0fd 100644
--- a/sonoff/language/pl-PL.h
+++ b/sonoff/language/pl-PL.h
@@ -1,7 +1,7 @@
/*
pl-PL.h - localization for Polish without fonetick - Poland for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends (translated by roblad - Robert L.)
+ Copyright (C) 2018 Theo Arends (translated by roblad - Robert L.)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -66,7 +66,7 @@
#define D_BUTTON "Przycisk"
#define D_BY "by" // Written by me
#define D_CELSIUS "Celsiusza"
-#define D_CO2 "CO2"
+#define D_CO2 "Dwutlenku węgla"
#define D_CODE "kod" // Button code
#define D_COLDLIGHT "Zimny"
#define D_COMMAND "Komenda"
@@ -118,6 +118,7 @@
#define D_INITIALIZED "Zainicjowany"
#define D_IP_ADDRESS "Adres IP"
#define D_LIGHT "Swiatlo"
+#define D_LIMIT "Wartość graniczna"
#define D_LOCAL_TIME "Lokalny"
#define D_LOW "Niski"
#define D_LWT "LWT"
@@ -386,6 +387,7 @@
#define D_DOMOTICZ_COUNT "Licznik"
#define D_DOMOTICZ_VOLTAGE "Napiecie"
#define D_DOMOTICZ_CURRENT "Prad"
+ #define D_DOMOTICZ_AIRQUALITY "AirQuality"
#define D_DOMOTICZ_UPDATE_TIMER "Zaktualizuj czasomierz"
// xdrv_irremote.ino
@@ -479,6 +481,8 @@
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
+#define D_SENSOR_SAIR_RX "SAir Rx"
+#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
#define D_SENSOR_SPI_DC "SPI DC"
#define D_SENSOR_BACKLIGHT "BLight"
diff --git a/sonoff/settings.h b/sonoff/settings.h
index 049d6a000..b718bf005 100644
--- a/sonoff/settings.h
+++ b/sonoff/settings.h
@@ -1,7 +1,7 @@
/*
settings.h - setting variables for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -201,8 +201,8 @@ struct SYSCFG {
byte free_451[2]; // 451
uint8_t sleep; // 453
- uint16_t domoticz_switch_idx[MAX_DOMOTICZ_IDX]; // 454
- uint16_t domoticz_sensor_idx[12]; // 45C
+ uint16_t domoticz_switch_idx[MAX_DOMOTICZ_IDX]; // 454
+ uint16_t domoticz_sensor_idx[MAX_DOMOTICZ_SNS_IDX]; // 45C
uint8_t module; // 474
uint8_t ws_color[4][3]; // 475
diff --git a/sonoff/settings.ino b/sonoff/settings.ino
index a177e86e4..53eb67eff 100644
--- a/sonoff/settings.ino
+++ b/sonoff/settings.ino
@@ -1,7 +1,7 @@
/*
settings.ino - user settings for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h
index 92725a58b..f18c5820c 100644
--- a/sonoff/sonoff.h
+++ b/sonoff/sonoff.h
@@ -1,7 +1,7 @@
/*
sonoff.h - Master header file for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -46,6 +46,7 @@ typedef unsigned long power_t; // Power (Relay) type
#define MAX_PULSETIMERS 8 // Max number of supported pulse timers
#define MAX_FRIENDLYNAMES 4 // Max number of Friendly names
#define MAX_DOMOTICZ_IDX 4 // Max number of Domoticz device, key and switch indices
+#define MAX_DOMOTICZ_SNS_IDX 12 // Max number of Domoticz sensors indices
#define MODULE SONOFF_BASIC // [Module] Select default model
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 6ddf00e05..005dff5fa 100644
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -1,7 +1,7 @@
/*
sonoff.ino - Sonoff-Tasmota firmware for iTead Sonoff, Wemos and NodeMCU hardware
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h
index 7a16e17d0..56e696573 100644
--- a/sonoff/sonoff_post.h
+++ b/sonoff/sonoff_post.h
@@ -1,7 +1,7 @@
/*
sonoff_post.h - Post header file for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h
index cbe0037a7..14893593e 100644
--- a/sonoff/sonoff_template.h
+++ b/sonoff/sonoff_template.h
@@ -1,7 +1,7 @@
/*
sonoff_template.h - template settings for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -82,6 +82,8 @@ enum UserSelectablePins {
GPIO_MHZ_RXD, // MH-Z19 Serial interface
GPIO_PZEM_TX, // PZEM004T Serial interface
GPIO_PZEM_RX, // PZEM004T Serial interface
+ GPIO_SAIR_TX, // SenseAir Serial interface
+ GPIO_SAIR_RX, // SenseAir Serial interface
GPIO_SENSOR_END };
// Text in webpage Module Parameters and commands GPIOS and GPIO
@@ -145,7 +147,9 @@ const char kSensors[GPIO_SENSOR_END][9] PROGMEM = {
D_SENSOR_MHZ_TX,
D_SENSOR_MHZ_RX,
D_SENSOR_PZEM_TX,
- D_SENSOR_PZEM_RX
+ D_SENSOR_PZEM_RX,
+ D_SENSOR_SAIR_TX,
+ D_SENSOR_SAIR_RX
};
// Programmer selectable GPIO functionality offset by user selectable GPIOs
diff --git a/sonoff/support.ino b/sonoff/support.ino
index 9ae7af452..35ff9966b 100644
--- a/sonoff/support.ino
+++ b/sonoff/support.ino
@@ -1,7 +1,7 @@
/*
support.ino - support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/user_config.h b/sonoff/user_config.h
index ebc248699..6bd035ec3 100644
--- a/sonoff/user_config.h
+++ b/sonoff/user_config.h
@@ -1,7 +1,7 @@
/*
user_config.h - user specific configuration for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -192,7 +192,8 @@
#define USE_WS2812_CTYPE 1 // WS2812 Color type (0 - RGB, 1 - GRB, 2 - RGBW, 3 - GRBW)
// #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial RXD) (+1k mem). When USE_WS2812_DMA is enabled expect Exceptions on Pow
-//#define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+1k8 code)
+//#define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+1k8 code)
+//#define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+1k8 code)
#define USE_ARILUX_RF // Add support for Arilux RF remote controller (+0k8 code)
diff --git a/sonoff/user_config_override.h b/sonoff/user_config_override.h
index 37fe10e6c..1008faf72 100644
--- a/sonoff/user_config_override.h
+++ b/sonoff/user_config_override.h
@@ -1,7 +1,7 @@
/*
user_config_override.h - user configuration overrides user_config.h for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino
index 54fb26f19..a71d332f6 100644
--- a/sonoff/webserver.ino
+++ b/sonoff/webserver.ino
@@ -1,7 +1,7 @@
/*
webserver.ino - webserver for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xdrv_domoticz.ino b/sonoff/xdrv_domoticz.ino
index 1a0a1c0ac..f1e478d1f 100644
--- a/sonoff/xdrv_domoticz.ino
+++ b/sonoff/xdrv_domoticz.ino
@@ -1,7 +1,7 @@
/*
xdrv_domoticz.ino - domoticz support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,10 +40,14 @@ enum DomoticzCommands {
const char kDomoticzCommands[] PROGMEM =
D_CMND_IDX "|" D_CMND_KEYIDX "|" D_CMND_SWITCHIDX "|" D_CMND_SENSORIDX "|" D_CMND_UPDATETIMER ;
-enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_MAX_SENSORS};
+enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_MAX_SENSORS};
+
+#if MAX_DOMOTICZ_SNS_IDX < DZ_MAX_SENSORS
+ #error "Domoticz: Too many sensors or change settings.h layout"
+#endif
const char kDomoticzSensors[] PROGMEM =
- D_DOMOTICZ_TEMP "|" D_DOMOTICZ_TEMP_HUM "|" D_DOMOTICZ_TEMP_HUM_BARO "|" D_DOMOTICZ_POWER_ENERGY "|" D_DOMOTICZ_ILLUMINANCE "|" D_DOMOTICZ_COUNT "|" D_DOMOTICZ_VOLTAGE "|" D_DOMOTICZ_CURRENT ;
+ D_DOMOTICZ_TEMP "|" D_DOMOTICZ_TEMP_HUM "|" D_DOMOTICZ_TEMP_HUM_BARO "|" D_DOMOTICZ_POWER_ENERGY "|" D_DOMOTICZ_ILLUMINANCE "|" D_DOMOTICZ_COUNT "|" D_DOMOTICZ_VOLTAGE "|" D_DOMOTICZ_CURRENT "|" D_DOMOTICZ_AIRQUALITY ;
const char S_JSON_DOMOTICZ_COMMAND_INDEX_NVALUE[] PROGMEM = "{\"" D_CMND_DOMOTICZ "%s%d\":%d}";
@@ -254,6 +258,19 @@ boolean DomoticzButton(byte key, byte device, byte state, byte svalflg)
/*********************************************************************************************\
* Sensors
+ *
+ * Source : https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
+ * https://www.domoticz.com/wiki/MQTT
+ *
+ * Percentage, Barometric, Air Quality:
+ * {\"idx\":%d,\"nvalue\":%s}, Idx, Value
+ *
+ * Humidity:
+ * {\"idx\":%d,\"nvalue\":%s,\"svalue\":\"%s\"}, Idx, Humidity, HumidityStatus
+ *
+ * All other:
+ * {\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s\"}, Idx, Value(s)
+ *
\*********************************************************************************************/
uint8_t DomoticzHumidityState(char *hum)
@@ -268,8 +285,11 @@ void DomoticzSensor(byte idx, char *data)
char dmess[64];
memcpy(dmess, mqtt_data, sizeof(dmess));
- snprintf_P(mqtt_data, sizeof(dmess), PSTR("{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s\"}"),
- Settings.domoticz_sensor_idx[idx], data);
+ if (DZ_AIRQUALITY == idx) {
+ snprintf_P(mqtt_data, sizeof(dmess), PSTR("{\"idx\":%d,\"nvalue\":%s}"), Settings.domoticz_sensor_idx[idx], data);
+ } else {
+ snprintf_P(mqtt_data, sizeof(dmess), PSTR("{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s\"}"), Settings.domoticz_sensor_idx[idx], data);
+ }
MqttPublish(domoticz_in_topic);
memcpy(mqtt_data, dmess, sizeof(dmess));
}
@@ -353,6 +373,7 @@ void HandleDomoticzConfiguration()
void DomoticzSaveSettings()
{
char stemp[20];
+ char ssensor_indices[6 * MAX_DOMOTICZ_SNS_IDX];
for (byte i = 0; i < MAX_DOMOTICZ_IDX; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("r%d"), i +1);
@@ -362,20 +383,19 @@ void DomoticzSaveSettings()
snprintf_P(stemp, sizeof(stemp), PSTR("s%d"), i +1);
Settings.domoticz_switch_idx[i] = (!strlen(WebServer->arg(stemp).c_str())) ? 0 : atoi(WebServer->arg(stemp).c_str());
}
+ ssensor_indices[0] = '\0';
for (byte i = 0; i < DZ_MAX_SENSORS; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("l%d"), i +1);
Settings.domoticz_sensor_idx[i] = (!strlen(WebServer->arg(stemp).c_str())) ? 0 : atoi(WebServer->arg(stemp).c_str());
+ snprintf_P(ssensor_indices, sizeof(ssensor_indices), PSTR("%s%s%d"), ssensor_indices, (strlen(ssensor_indices)) ? "," : "", Settings.domoticz_sensor_idx[i]);
}
Settings.domoticz_update_timer = (!strlen(WebServer->arg("ut").c_str())) ? DOMOTICZ_UPDATE_TIMER : atoi(WebServer->arg("ut").c_str());
- snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_CMND_IDX " %d, %d, %d, %d, " D_CMND_UPDATETIMER " %d"),
+
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_CMND_IDX " %d,%d,%d,%d, " D_CMND_KEYIDX " %d,%d,%d,%d, " D_CMND_SWITCHIDX " %d,%d,%d,%d, " D_CMND_SENSORIDX " %s, " D_CMND_UPDATETIMER " %d"),
Settings.domoticz_relay_idx[0], Settings.domoticz_relay_idx[1], Settings.domoticz_relay_idx[2], Settings.domoticz_relay_idx[3],
- Settings.domoticz_update_timer);
- AddLog(LOG_LEVEL_INFO);
- snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_CMND_KEYIDX " %d, %d, %d, %d, " D_CMND_SWITCHIDX " %d, %d, %d, %d, " D_CMND_SENSORIDX " %d, %d, %d, %d, %d, %d, %d, %d"),
Settings.domoticz_key_idx[0], Settings.domoticz_key_idx[1], Settings.domoticz_key_idx[2], Settings.domoticz_key_idx[3],
Settings.domoticz_switch_idx[0], Settings.domoticz_switch_idx[1], Settings.domoticz_switch_idx[2], Settings.domoticz_switch_idx[3],
- Settings.domoticz_sensor_idx[0], Settings.domoticz_sensor_idx[1], Settings.domoticz_sensor_idx[2], Settings.domoticz_sensor_idx[3],
- Settings.domoticz_sensor_idx[4], Settings.domoticz_sensor_idx[5], Settings.domoticz_sensor_idx[6], Settings.domoticz_sensor_idx[7]);
+ ssensor_indices, Settings.domoticz_update_timer);
AddLog(LOG_LEVEL_INFO);
}
#endif // USE_WEBSERVER
diff --git a/sonoff/xdrv_irremote.ino b/sonoff/xdrv_irremote.ino
index 423270684..8a54adf8b 100644
--- a/sonoff/xdrv_irremote.ino
+++ b/sonoff/xdrv_irremote.ino
@@ -1,7 +1,7 @@
/*
xdrv_irremote.ino - infra red support for Sonoff-Tasmota
- Copyright (C) 2017 Heiko Krupp, Lazar Obradovic and Theo Arends
+ Copyright (C) 2018 Heiko Krupp, Lazar Obradovic and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xdrv_light.ino b/sonoff/xdrv_light.ino
index 2eff11895..3b82f74cf 100644
--- a/sonoff/xdrv_light.ino
+++ b/sonoff/xdrv_light.ino
@@ -1,7 +1,7 @@
/*
xdrv_light.ino - PWM, WS2812 and sonoff led support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xdrv_snfbridge.ino b/sonoff/xdrv_snfbridge.ino
index d475860dd..6c7993cd4 100644
--- a/sonoff/xdrv_snfbridge.ino
+++ b/sonoff/xdrv_snfbridge.ino
@@ -1,7 +1,7 @@
/*
xdrv_snfbridge.ino - sonoff RF bridge 433 support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xdrv_wemohue.ino b/sonoff/xdrv_wemohue.ino
index 05d4ed7ef..14d86b05a 100755
--- a/sonoff/xdrv_wemohue.ino
+++ b/sonoff/xdrv_wemohue.ino
@@ -1,7 +1,7 @@
/*
xdrv_wemohue.ino - wemo and hue support for Sonoff-Tasmota
- Copyright (C) 2017 Heiko Krupp and Theo Arends
+ Copyright (C) 2018 Heiko Krupp and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xdrv_ws2812.ino b/sonoff/xdrv_ws2812.ino
index 8add8c513..2aea22054 100644
--- a/sonoff/xdrv_ws2812.ino
+++ b/sonoff/xdrv_ws2812.ino
@@ -1,7 +1,7 @@
/*
xdrv_ws2812.ino - ws2812 led string support for Sonoff-Tasmota
- Copyright (C) 2017 Heiko Krupp and Theo Arends
+ Copyright (C) 2018 Heiko Krupp and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_01_counter.ino b/sonoff/xsns_01_counter.ino
index 7b3f72d9f..743822af6 100644
--- a/sonoff/xsns_01_counter.ino
+++ b/sonoff/xsns_01_counter.ino
@@ -1,7 +1,7 @@
/*
xsns_01_counter.ino - Counter sensors (water meters, electricity meters etc.) sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Maarten Damen and Theo Arends
+ Copyright (C) 2018 Maarten Damen and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_03_energy.ino b/sonoff/xsns_03_energy.ino
index c23664873..cc02fef11 100644
--- a/sonoff/xsns_03_energy.ino
+++ b/sonoff/xsns_03_energy.ino
@@ -1,7 +1,7 @@
/*
xsns_03_energy.ino - HLW8012 (Sonoff Pow) and PZEM004T energy sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_04_snfsc.ino b/sonoff/xsns_04_snfsc.ino
index 98ff02c0f..04a552ac5 100644
--- a/sonoff/xsns_04_snfsc.ino
+++ b/sonoff/xsns_04_snfsc.ino
@@ -1,7 +1,7 @@
/*
xsns_04_snfsc.ino - sonoff SC support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_05_ds18b20.ino b/sonoff/xsns_05_ds18b20.ino
index 343b42fea..19281349e 100644
--- a/sonoff/xsns_05_ds18b20.ino
+++ b/sonoff/xsns_05_ds18b20.ino
@@ -1,7 +1,7 @@
/*
xsns_05_ds18b20.ino - DS18B20 temperature sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_05_ds18x20.ino b/sonoff/xsns_05_ds18x20.ino
index 0e7553940..c0bd66673 100644
--- a/sonoff/xsns_05_ds18x20.ino
+++ b/sonoff/xsns_05_ds18x20.ino
@@ -1,7 +1,7 @@
/*
xsns_05_ds18x20.ino - DS18x20 temperature sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_05_ds18x20_legacy.ino b/sonoff/xsns_05_ds18x20_legacy.ino
index 5d6553f6d..0a389300c 100644
--- a/sonoff/xsns_05_ds18x20_legacy.ino
+++ b/sonoff/xsns_05_ds18x20_legacy.ino
@@ -1,7 +1,7 @@
/*
xsns_05_ds18x20_legacy.ino - DS18x20 temperature sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Heiko Krupp and Theo Arends
+ Copyright (C) 2018 Heiko Krupp and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_06_dht.ino b/sonoff/xsns_06_dht.ino
index 64d8baf78..3598c40f2 100644
--- a/sonoff/xsns_06_dht.ino
+++ b/sonoff/xsns_06_dht.ino
@@ -1,7 +1,7 @@
/*
xsns_06_dht.ino - DHTxx, AM23xx and SI7021 temperature and humidity sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_07_sht1x.ino b/sonoff/xsns_07_sht1x.ino
index 9b74d31a0..dad419f5e 100644
--- a/sonoff/xsns_07_sht1x.ino
+++ b/sonoff/xsns_07_sht1x.ino
@@ -1,7 +1,7 @@
/*
xsns_07_sht1x.ino - SHT1x temperature and sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_08_htu21.ino b/sonoff/xsns_08_htu21.ino
index 7bafad1d9..4950be405 100644
--- a/sonoff/xsns_08_htu21.ino
+++ b/sonoff/xsns_08_htu21.ino
@@ -1,7 +1,7 @@
/*
xsns_08_htu21.ino - HTU21 temperature and humidity sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Heiko Krupp and Theo Arends
+ Copyright (C) 2018 Heiko Krupp and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_09_bmp.ino b/sonoff/xsns_09_bmp.ino
index 74e310ef1..f3130abde 100644
--- a/sonoff/xsns_09_bmp.ino
+++ b/sonoff/xsns_09_bmp.ino
@@ -1,7 +1,7 @@
/*
xsns_09_bmp.ino - BMP pressure, temperature, humidity and gas sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Heiko Krupp and Theo Arends
+ Copyright (C) 2018 Heiko Krupp and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_10_bh1750.ino b/sonoff/xsns_10_bh1750.ino
index f8be2cfbb..1a8873647 100644
--- a/sonoff/xsns_10_bh1750.ino
+++ b/sonoff/xsns_10_bh1750.ino
@@ -1,7 +1,7 @@
/*
xsns_10_bh1750.ino - BH1750 ambient light sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_11_veml6070.ino b/sonoff/xsns_11_veml6070.ino
index cc62771c1..aafd0da74 100644
--- a/sonoff/xsns_11_veml6070.ino
+++ b/sonoff/xsns_11_veml6070.ino
@@ -1,7 +1,7 @@
/*
xsns_11_veml6070.ino - VEML6070 ultra violet light sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_12_ads1115.ino b/sonoff/xsns_12_ads1115.ino
index 675b15101..447ad98c9 100644
--- a/sonoff/xsns_12_ads1115.ino
+++ b/sonoff/xsns_12_ads1115.ino
@@ -1,7 +1,7 @@
/*
xsns_12_ads1115_ada.ino - ADS1115 A/D Converter support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_12_ads1115_i2cdev.ino b/sonoff/xsns_12_ads1115_i2cdev.ino
index 8856da70f..0d599f0a5 100644
--- a/sonoff/xsns_12_ads1115_i2cdev.ino
+++ b/sonoff/xsns_12_ads1115_i2cdev.ino
@@ -1,7 +1,7 @@
/*
xsns_12_ads1115.ino - ADS1x15 A/D Converter support for Sonoff-Tasmota
- Copyright (C) 2017 Stefan Bode and Theo Arends
+ Copyright (C) 2018 Stefan Bode and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_13_ina219.ino b/sonoff/xsns_13_ina219.ino
index 485c91452..4848b383b 100644
--- a/sonoff/xsns_13_ina219.ino
+++ b/sonoff/xsns_13_ina219.ino
@@ -1,7 +1,7 @@
/*
xsns_13_ina219.ino - INA219 Current Sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Stefan Bode and Theo Arends
+ Copyright (C) 2018 Stefan Bode and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_14_sht3x.ino b/sonoff/xsns_14_sht3x.ino
index f58fc3999..35800adf2 100644
--- a/sonoff/xsns_14_sht3x.ino
+++ b/sonoff/xsns_14_sht3x.ino
@@ -1,7 +1,7 @@
/*
xsns_14_sht3x.ino - SHT3X temperature and humidity sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_14_sht3x_v2.ino b/sonoff/xsns_14_sht3x_v2.ino
index 0ed9d0bd8..f794d971b 100644
--- a/sonoff/xsns_14_sht3x_v2.ino
+++ b/sonoff/xsns_14_sht3x_v2.ino
@@ -1,7 +1,7 @@
/*
xsns_14_sht3x.ino - SHT3X temperature and humidity sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_14_sht3x_v3.ino b/sonoff/xsns_14_sht3x_v3.ino
index a078fff91..e165fbf01 100644
--- a/sonoff/xsns_14_sht3x_v3.ino
+++ b/sonoff/xsns_14_sht3x_v3.ino
@@ -1,7 +1,7 @@
/*
xsns_14_sht3x.ino - SHT3X temperature and humidity sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_15_mhz19.ino b/sonoff/xsns_15_mhz19.ino
index 9789d0f81..4b5b24ec3 100644
--- a/sonoff/xsns_15_mhz19.ino
+++ b/sonoff/xsns_15_mhz19.ino
@@ -1,5 +1,5 @@
/*
- xsns_15_mhz.ino - MH-Z19(B) CO2 sensor support for Sonoff-Tasmota
+ xsns_15_mhz19.ino - MH-Z19(B) CO2 sensor support for Sonoff-Tasmota
Copyright (C) 2018 Theo Arends
@@ -227,7 +227,7 @@ bool Mhz19CheckAndApplyFilter(uint16_t ppm, uint8_t s)
return true;
}
-void Mhz19222ms()
+void Mhz19Ticker()
{
uint8_t mhz19_response[9];
@@ -314,26 +314,24 @@ void Mhz19Init()
if ((pin[GPIO_MHZ_RXD] < 99) && (pin[GPIO_MHZ_TXD] < 99)) {
if (Mhz19Serial(pin[GPIO_MHZ_RXD], pin[GPIO_MHZ_TXD])) {
mhz19_type = 1;
- mhz19_ticker.attach_ms(222, Mhz19222ms);
+ mhz19_ticker.attach_ms(222, Mhz19Ticker);
}
}
}
-#ifdef USE_WEBSERVER
-const char HTTP_SNS_CO2[] PROGMEM =
- "%s{s}%s " D_CO2 "{m}%d " D_UNIT_PPM "{e}"; // {s} = , {m} = | , {e} = |
-#endif // USE_WEBSERVER
-
void Mhz19Show(boolean json)
{
char temperature[10];
dtostrfd(mhz19_temperature, Settings.flag2.temperature_resolution, temperature);
GetTextIndexed(mhz19_types, sizeof(mhz19_types), mhz19_type -1, kMhz19Types);
+// uint8_t co2_limit = (mhz19_last_ppm > 1200) ? 3 : (mhz19_last_ppm > 800) ? 2 : 1;
+// uint16_t co2_limit = mhz19_last_ppm / 400; // <800 = 1(Green), <1200 = 2(Orange), >1200 = 3(Red)
if (json) {
+// snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_CO2 "\":%d,\"" D_LIMIT "\":%d,\"" D_TEMPERATURE "\":%s}"), mqtt_data, mhz19_types, mhz19_last_ppm, co2_limit, temperature);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_CO2 "\":%d,\"" D_TEMPERATURE "\":%s}"), mqtt_data, mhz19_types, mhz19_last_ppm, temperature);
#ifdef USE_DOMOTICZ
- DomoticzSensor(DZ_COUNT, mhz19_last_ppm);
+ DomoticzSensor(DZ_AIRQUALITY, mhz19_last_ppm);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
diff --git a/sonoff/xsns_16_tsl2561.ino b/sonoff/xsns_16_tsl2561.ino
index 2769b9a1d..12c0b15c2 100644
--- a/sonoff/xsns_16_tsl2561.ino
+++ b/sonoff/xsns_16_tsl2561.ino
@@ -1,7 +1,7 @@
/*
xsns_16_tsl2561.ino - TSL2561 light sensor support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends
+ Copyright (C) 2018 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/sonoff/xsns_17_senseair.ino b/sonoff/xsns_17_senseair.ino
new file mode 100644
index 000000000..56ab7595f
--- /dev/null
+++ b/sonoff/xsns_17_senseair.ino
@@ -0,0 +1,361 @@
+/*
+ xsns_17_senseair_s8.ino - SenseAir S8 CO2 sensor support for Sonoff-Tasmota
+
+ Copyright (C) 2018 Theo Arends
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+
+#ifdef USE_SENSEAIR
+/*********************************************************************************************\
+ * SenseAir S8 - CO2 sensor
+ *
+ * Adapted from EspEasy plugin P052 by Mikael Trieb (mikael__AT__triebconsulting.se)
+ **********************************************************************************************
+ * Filter usage
+ *
+ * Select filter usage on low stability readings
+\*********************************************************************************************/
+
+#define SENSEAIR_BAUDRATE 9600
+
+const char kSenseairTypes[] PROGMEM = "Kx0|S8";
+
+uint8_t senseair_type = 1;
+char senseair_types[7];
+
+uint16_t senseair_co2 = 0;
+float senseair_temperature = 0;
+float senseair_humidity = 0;
+
+Ticker senseair_ticker;
+
+/*********************************************************************************************\
+ * Subset SoftwareSerial
+\*********************************************************************************************/
+
+#define SENSEAIR_SERIAL_BUFFER_SIZE 20
+#define SENSEAIR_SERIAL_WAIT { while (ESP.getCycleCount() -start < wait) optimistic_yield(1); wait += senseair_serial_bit_time; }
+
+uint8_t senseair_serial_rx_pin;
+uint8_t senseair_serial_tx_pin;
+uint8_t senseair_serial_in_pos = 0;
+uint8_t senseair_serial_out_pos = 0;
+uint8_t senseair_serial_buffer[SENSEAIR_SERIAL_BUFFER_SIZE];
+unsigned long senseair_serial_bit_time;
+unsigned long senseair_serial_bit_time_start;
+
+bool SenseairSerialValidGpioPin(uint8_t pin) {
+ return (pin >= 0 && pin <= 5) || (pin >= 9 && pin <= 10) || (pin >= 12 && pin <= 15);
+}
+
+bool SenseairSerial(uint8_t receive_pin, uint8_t transmit_pin)
+{
+ if (!((SenseairSerialValidGpioPin(receive_pin)) && (SenseairSerialValidGpioPin(transmit_pin) || transmit_pin == 16))) {
+ return false;
+ }
+ senseair_serial_rx_pin = receive_pin;
+ pinMode(senseair_serial_rx_pin, INPUT);
+ attachInterrupt(senseair_serial_rx_pin, SenseairSerialRxRead, FALLING);
+
+ senseair_serial_tx_pin = transmit_pin;
+ pinMode(senseair_serial_tx_pin, OUTPUT);
+ digitalWrite(senseair_serial_tx_pin, 1);
+
+ senseair_serial_bit_time = ESP.getCpuFreqMHz() *1000000 /SENSEAIR_BAUDRATE; // 8333
+ senseair_serial_bit_time_start = senseair_serial_bit_time + senseair_serial_bit_time /3 -500; // 10610 ICACHE_RAM_ATTR start delay
+// senseair_serial_bit_time_start = senseair_serial_bit_time; // Non ICACHE_RAM_ATTR start delay (experimental)
+
+ return true;
+}
+
+int SenseairSerialRead() {
+ if (senseair_serial_in_pos == senseair_serial_out_pos) {
+ return -1;
+ }
+ int ch = senseair_serial_buffer[senseair_serial_out_pos];
+ senseair_serial_out_pos = (senseair_serial_out_pos +1) % SENSEAIR_SERIAL_BUFFER_SIZE;
+ return ch;
+}
+
+int SenseairSerialAvailable() {
+ int avail = senseair_serial_in_pos - senseair_serial_out_pos;
+ if (avail < 0) {
+ avail += SENSEAIR_SERIAL_BUFFER_SIZE;
+ }
+ return avail;
+}
+
+void SenseairSerialFlush()
+{
+ senseair_serial_in_pos = 0;
+ senseair_serial_out_pos = 0;
+}
+
+size_t SenseairSerialTxWrite(uint8_t b)
+{
+ unsigned long wait = senseair_serial_bit_time;
+ digitalWrite(senseair_serial_tx_pin, HIGH);
+ unsigned long start = ESP.getCycleCount();
+ // Start bit;
+ digitalWrite(senseair_serial_tx_pin, LOW);
+ SENSEAIR_SERIAL_WAIT;
+ for (int i = 0; i < 8; i++) {
+ digitalWrite(senseair_serial_tx_pin, (b & 1) ? HIGH : LOW);
+ SENSEAIR_SERIAL_WAIT;
+ b >>= 1;
+ }
+ // Stop bit
+ digitalWrite(senseair_serial_tx_pin, HIGH);
+ SENSEAIR_SERIAL_WAIT;
+ return 1;
+}
+
+size_t SenseairSerialWrite(const uint8_t *buffer, size_t size = 1) {
+ size_t n = 0;
+ while(size--) {
+ n += SenseairSerialTxWrite(*buffer++);
+ }
+ return n;
+}
+
+//void SenseairSerialRxRead() ICACHE_RAM_ATTR; // Add 215 bytes to iram usage
+void SenseairSerialRxRead() {
+ // Advance the starting point for the samples but compensate for the
+ // initial delay which occurs before the interrupt is delivered
+ unsigned long wait = senseair_serial_bit_time_start;
+ unsigned long start = ESP.getCycleCount();
+ uint8_t rec = 0;
+ for (int i = 0; i < 8; i++) {
+ SENSEAIR_SERIAL_WAIT;
+ rec >>= 1;
+ if (digitalRead(senseair_serial_rx_pin)) {
+ rec |= 0x80;
+ }
+ }
+ // Stop bit
+ SENSEAIR_SERIAL_WAIT;
+ // Store the received value in the buffer unless we have an overflow
+ int next = (senseair_serial_in_pos +1) % SENSEAIR_SERIAL_BUFFER_SIZE;
+ if (next != senseair_serial_out_pos) {
+ senseair_serial_buffer[senseair_serial_in_pos] = rec;
+ senseair_serial_in_pos = next;
+ }
+ // Must clear this bit in the interrupt register,
+ // it gets set even when interrupts are disabled
+ GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << senseair_serial_rx_pin);
+}
+
+/*********************************************************************************************/
+
+void ModbusSend(uint8_t function_code, uint16_t start_address, uint16_t register_count)
+{
+ uint8_t frame[8];
+
+ frame[0] = 0xFE; // Any Address
+ frame[1] = function_code;
+ frame[2] = (uint8_t)(start_address >> 8);
+ frame[3] = (uint8_t)(start_address);
+ frame[4] = (uint8_t)(register_count >> 8);
+ frame[5] = (uint8_t)(register_count);
+ uint16_t crc = 0xFFFF;
+ for (uint8_t pos = 0; pos < sizeof(frame) -2; pos++) {
+ crc ^= (uint16_t)frame[pos]; // XOR byte into least sig. byte of crc
+ for (uint8_t i = 8; i != 0; i--) { // Loop over each bit
+ if ((crc & 0x0001) != 0) { // If the LSB is set
+ crc >>= 1; // Shift right and XOR 0xA001
+ crc ^= 0xA001;
+ }
+ else { // Else LSB is not set
+ crc >>= 1; // Just shift right
+ }
+ }
+ }
+ frame[7] = (uint8_t)((crc >> 8) & 0xFF);
+ frame[6] = (uint8_t)(crc & 0xFF);
+
+ SenseairSerialFlush();
+ SenseairSerialWrite(frame, sizeof(frame));
+}
+
+bool ModbusReceiveReady()
+{
+ return (SenseairSerialAvailable() >= 5); // 5 - Error frame, 7 - Ok frame
+}
+
+uint8_t ModbusReceive(uint16_t *value)
+{
+ uint8_t buffer[7];
+
+ uint8_t len = 0;
+ while (SenseairSerialAvailable() > 0) {
+ buffer[len++] = (uint8_t)SenseairSerialRead();
+ if (3 == len) {
+ if (buffer[1] & 0x80) { // fe 84 02 f2 f1
+ return buffer[2]; // 1 = Illegal Function, 2 = Illegal Data Address, 3 = Illegal Data Value
+ }
+ }
+ }
+ if (len != sizeof(buffer)) {
+ return 9; // 9 = Unexpected result
+ }
+ *value = (buffer[3] << 8) | buffer[4];
+ return 0; // 0 = No error
+}
+
+/*********************************************************************************************/
+
+const uint8_t start_addresses[] { 0x1A, 0x00, 0x03, 0x04, 0x05, 0x1C, 0x0A };
+
+uint8_t senseair_read_state = 0;
+uint8_t senseair_send_retry = 0;
+
+void SenseairTicker()
+{
+ uint16_t value = 0;
+ bool data_ready = ModbusReceiveReady();
+
+ if (data_ready) {
+ uint8_t error = ModbusReceive(&value);
+ if (error) {
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "SenseAir response error %d"), error);
+ AddLog(LOG_LEVEL_DEBUG);
+ } else {
+ switch(senseair_read_state) {
+ case 0: // 0x1A (26) READ_TYPE_LOW - S8: fe 04 02 01 77 ec 92
+ senseair_type = 2;
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "SenseAir type id low %04X"), value);
+ AddLog(LOG_LEVEL_DEBUG);
+ break;
+ case 1: // 0x00 (0) READ_ERRORLOG - fe 04 02 00 00 ad 24
+ if (value) {
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "SenseAir error %04X"), value);
+ AddLog(LOG_LEVEL_DEBUG);
+ }
+ break;
+ case 2: // 0x03 (3) READ_CO2 - fe 04 02 06 2c af 59
+ senseair_co2 = value;
+ break;
+ case 3: // 0x04 (4) READ_TEMPERATURE - S8: fe 84 02 f2 f1 - Illegal Data Address
+ senseair_temperature = ConvertTemp((float)value / 100);
+ break;
+ case 4: // 0x05 (5) READ_HUMIDITY - S8: fe 84 02 f2 f1 - Illegal Data Address
+ senseair_humidity = (float)value / 100;
+ break;
+ case 5: // 0x1C (28) READ_RELAY_STATE - S8: fe 04 02 01 54 ad 4b - firmware version
+ {
+ bool relay_state = value >> 8 & 1;
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "SenseAir relay state %d"), relay_state);
+ AddLog(LOG_LEVEL_DEBUG);
+ break;
+ }
+ case 6: // 0x0A (10) READ_TEMP_ADJUSTMENT - S8: fe 84 02 f2 f1 - Illegal Data Address
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "SenseAir temp adjustment %d"), value);
+ AddLog(LOG_LEVEL_DEBUG);
+ break;
+ }
+ }
+ senseair_read_state++;
+ if (2 == senseair_type) { // S8
+ if (3 == senseair_read_state) {
+ senseair_read_state = 1;
+ }
+ } else { // K30, K70
+ if (sizeof(start_addresses) == senseair_read_state) {
+ senseair_read_state = 1;
+ }
+ }
+ }
+
+ if (0 == senseair_send_retry || data_ready) {
+ senseair_send_retry = 5;
+ ModbusSend(0x04, (uint16_t)start_addresses[senseair_read_state], 1);
+ } else {
+ senseair_send_retry--;
+ }
+}
+
+/*********************************************************************************************/
+
+void SenseairInit()
+{
+ senseair_type = 0;
+ if ((pin[GPIO_SAIR_RX] < 99) && (pin[GPIO_SAIR_TX] < 99)) {
+ if (SenseairSerial(pin[GPIO_SAIR_RX], pin[GPIO_SAIR_TX])) {
+ senseair_type = 1;
+ senseair_ticker.attach_ms(510, SenseairTicker);
+ }
+ }
+}
+
+void SenseairShow(boolean json)
+{
+ char temperature[10];
+ char humidity[10];
+ dtostrfd(senseair_temperature, Settings.flag2.temperature_resolution, temperature);
+ dtostrfd(senseair_humidity, Settings.flag2.temperature_resolution, humidity);
+ GetTextIndexed(senseair_types, sizeof(senseair_types), senseair_type -1, kSenseairTypes);
+// uint8_t co2_limit = (senseair_co2 > 1200) ? 3 : (senseair_co2 > 800) ? 2 : 1;
+// uint16_t co2_limit = senseair_co2 / 400; // <800 = 1(Green), <1200 = 2(Orange), >1200 = 3(Red)
+
+ if (json) {
+// snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_CO2 "\":%d,\"" D_LIMIT "\":%d"), mqtt_data, senseair_types, senseair_co2, co2_limit);
+ snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_CO2 "\":%d"), mqtt_data, senseair_types, senseair_co2);
+ if (senseair_type != 2) {
+ snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_TEMPERATURE "\":%s,\"" D_HUMIDITY "\":%s"), mqtt_data, temperature, humidity);
+ }
+ snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
+#ifdef USE_DOMOTICZ
+ DomoticzSensor(DZ_AIRQUALITY, senseair_co2);
+#endif // USE_DOMOTICZ
+#ifdef USE_WEBSERVER
+ } else {
+ snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_CO2, mqtt_data, senseair_types, senseair_co2);
+ if (senseair_type != 2) {
+ snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, senseair_types, temperature, TempUnit());
+ snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_HUM, mqtt_data, senseair_types, humidity);
+ }
+#endif // USE_WEBSERVER
+ }
+}
+
+/*********************************************************************************************\
+ * Interface
+\*********************************************************************************************/
+
+#define XSNS_17
+
+boolean Xsns17(byte function)
+{
+ boolean result = false;
+
+ if (senseair_type) {
+ switch (function) {
+ case FUNC_XSNS_INIT:
+ SenseairInit();
+ break;
+ case FUNC_XSNS_JSON_APPEND:
+ SenseairShow(1);
+ break;
+#ifdef USE_WEBSERVER
+ case FUNC_XSNS_WEB_APPEND:
+ SenseairShow(0);
+ break;
+#endif // USE_WEBSERVER
+ }
+ }
+ return result;
+}
+
+#endif // USE_SENSEAIR
diff --git a/sonoff/xsns_interface.ino b/sonoff/xsns_interface.ino
index c7d5c3e2f..d07982037 100644
--- a/sonoff/xsns_interface.ino
+++ b/sonoff/xsns_interface.ino
@@ -1,7 +1,7 @@
/*
xsns_interface.ino - External sensor interface support for Sonoff-Tasmota
- Copyright (C) 2017 Theo Arends inspired by ESPEasy
+ Copyright (C) 2018 Theo Arends inspired by ESPEasy
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by