Skip to content

Commit

Permalink
Initial support for Sonoff MS01
Browse files Browse the repository at this point in the history
Initial support for Sonoff MS01 (#15335)
  • Loading branch information
arendst committed Apr 10, 2022
1 parent a5ead29 commit c7323ee
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 5 deletions.
1 change: 1 addition & 0 deletions tasmota/language/af_AF.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/bg_BG.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/cs_CZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/de_DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/el_GR.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/en_GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/es_ES.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/fr_FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/fy_NL.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/he_HE.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/hu_HU.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
3 changes: 2 additions & 1 deletion tasmota/language/it_IT.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
* Use online command Prefix to translate cmnd, stat and tele.
*
* Updated until v10.1.0.6 - Last update 09.04.2022
* Updated until v11.0.0.7 - Last update 10.04.2022
\*********************************************************************/

#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English)
Expand Down Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/ko_KO.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/nl_NL.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/pl_PL.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/pt_BR.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/pt_PT.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/ro_RO.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/ru_RU.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/sk_SK.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/sv_SE.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/tr_TR.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/uk_UA.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/vi_VN.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/zh_CN.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/zh_TW.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
#define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301"
#define D_SENSOR_SI7021 "SI7021"
#define D_SENSOR_MS01 "MS01"
#define D_SENSOR_DS18X20 "DS18x20"
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
Expand Down
3 changes: 3 additions & 0 deletions tasmota/tasmota_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ enum UserSelectablePins {
GPIO_BL6523_TX, GPIO_BL6523_RX, // BL6523 based Watt meter Serial interface
GPIO_ADE7880_IRQ, // ADE7880 IRQ
GPIO_RESET, // Generic reset
GPIO_MS01, // Sonoff MS01 Moisture Sensor 1wire interface
GPIO_SENSOR_END };

enum ProgramSelectablePins {
Expand Down Expand Up @@ -409,6 +410,7 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_BL6523_TX "|" D_SENSOR_BL6523_RX "|"
D_SENSOR_ADE7880_IRQ "|"
D_SENSOR_RESET "|"
D_SENSOR_MS01 "|"
;

const char kSensorNamesFixed[] PROGMEM =
Expand Down Expand Up @@ -599,6 +601,7 @@ const uint16_t kGpioNiceList[] PROGMEM = {
AGPIO(GPIO_DHT11), // DHT11
AGPIO(GPIO_DHT22), // DHT21, DHT22, AM2301, AM2302, AM2321
AGPIO(GPIO_SI7021), // iTead SI7021
AGPIO(GPIO_MS01), // Sonoff MS01
AGPIO(GPIO_DHT11_OUT), // Pseudo Single wire DHT11, DHT21, DHT22, AM2301, AM2302, AM2321
#endif
#ifdef USE_DS18x20
Expand Down
50 changes: 46 additions & 4 deletions tasmota/xsns_06_dht.ino
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ bool DhtRead(uint32_t sensor) {
case GPIO_SI7021: // iTead SI7021
delayMicroseconds(500);
break;
case GPIO_MS01: // Sonoff MS01
delayMicroseconds(450);
break;
}

if (!dht_dual_mode) {
Expand All @@ -101,6 +104,7 @@ bool DhtRead(uint32_t sensor) {
delayMicroseconds(50);
break;
case GPIO_SI7021: // iTead SI7021
case GPIO_MS01: // Sonoff MS01
delayMicroseconds(30); // See: https://github.com/letscontrolit/ESPEasy/issues/1798 and 20210524: https://github.com/arendst/Tasmota/issues/12180
break;
}
Expand Down Expand Up @@ -152,14 +156,39 @@ bool DhtRead(uint32_t sensor) {
*/
break;
case GPIO_DHT22: // DHT21, DHT22, AM2301, AM2302, AM2321
case GPIO_SI7021: // iTead SI7021
case GPIO_SI7021: { // iTead SI7021
humidity = ((dht_data[0] << 8) | dht_data[1]) * 0.1;
// DHT21/22 (Adafruit):
int16_t temp16 = dht_data[2] << 8 | dht_data[3]; // case 1 : signed 16 bits
if ((dht_data[2] & 0xF0) == 0x80) // case 2 : negative when high nibble = 0x80
if ((dht_data[2] & 0xF0) == 0x80) { // case 2 : negative when high nibble = 0x80
temp16 = -(0xFFF & temp16);
}
temperature = 0.1f * temp16;
break;
}
case GPIO_MS01: { // Sonoff MS01
uint32_t voltage = ((dht_data[0] << 8) | dht_data[1]);

// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("DHT: MS01 %d"), voltage);

// Rough approximate of soil moisture % (based on values observed in the eWeLink app)
// Observed values are available here: https://gist.github.com/minovap/654cdcd8bc37bb0d2ff338f8d144a509

float x;
if (voltage < 15037) {
x = voltage - 15200;
humidity = - FastPrecisePowf(0.0024 * x, 3) - 0.0004 * x + 20.1;
}
else if (voltage < 22300) {
humidity = - 0.00069 * voltage + 30.6;
}
else {
x = voltage - 22800;
humidity = - FastPrecisePowf(0.00046 * x, 3) - 0.0004 * x + 15;
}
temperature = 0;
break;
}
}
if (isnan(temperature) || isnan(humidity)) {
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT "Invalid reading"));
Expand All @@ -178,7 +207,8 @@ bool DhtRead(uint32_t sensor) {
/********************************************************************************************/

bool DhtPinState() {
if ((XdrvMailbox.index >= AGPIO(GPIO_DHT11)) && (XdrvMailbox.index <= AGPIO(GPIO_SI7021))) {
if (((XdrvMailbox.index >= AGPIO(GPIO_DHT11)) && (XdrvMailbox.index <= AGPIO(GPIO_SI7021))) ||
(XdrvMailbox.index == AGPIO(GPIO_MS01))) {
if (dht_sensors < DHT_MAX_SENSORS) {
Dht[dht_sensors].pin = XdrvMailbox.payload;
Dht[dht_sensors].type = BGPIO(XdrvMailbox.index);
Expand Down Expand Up @@ -232,7 +262,19 @@ void DhtEverySecond(void) {

void DhtShow(bool json) {
for (uint32_t i = 0; i < dht_sensors; i++) {
TempHumDewShow(json, ((0 == TasmotaGlobal.tele_period) && (0 == i)), Dht[i].stype, Dht[i].t, Dht[i].h);
if (GPIO_MS01 == Dht[i].type) {
if (json) {
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_HUMIDITY "\":%*_f}"), Dht[i].stype, Settings->flag2.humidity_resolution, &Dht[i].h);
#ifdef USE_WEBSERVER
} else {
char parameter[FLOATSZ];
dtostrfd(Dht[i].h, Settings->flag2.humidity_resolution, parameter);
WSContentSend_PD(HTTP_SNS_HUM, Dht[i].stype, parameter);
#endif // USE_WEBSERVER
}
} else {
TempHumDewShow(json, ((0 == TasmotaGlobal.tele_period) && (0 == i)), Dht[i].stype, Dht[i].t, Dht[i].h);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions tools/lv_gpio/lv_gpio_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ RFRECV = GPIO_RFRECV
DHT11 = GPIO_DHT11
DHT22 = GPIO_DHT22
SI7021 = GPIO_SI7021
MS01 = GPIO_MS01
DHT11_OUT = GPIO_DHT11_OUT
DSB = GPIO_DSB
DSB_OUT = GPIO_DSB_OUT
Expand Down

0 comments on commit c7323ee

Please sign in to comment.