From a8b83aa0369623d7e017501227a9e096eab4d5b7 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Fri, 20 Apr 2018 16:55:27 +0200 Subject: [PATCH] Add support for Sonoff Pow R2 (#2340) 5.12.0m * Add support for Sonoff Pow R2 (#2340) --- README.md | 1 + sonoff/_releasenotes.ino | 2 ++ sonoff/sonoff.ino | 4 ++-- sonoff/sonoff_template.h | 19 ++++++++++++++++--- sonoff/xdrv_03_energy.ino | 6 +++--- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8d0d6b3d5..fd0d98f73 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ The following devices are supported: - [iTead Sonoff TH10/TH16 with temperature sensor](https://www.itead.cc/smart-home/sonoff-th.html) - [iTead Sonoff Dual (R2)](https://www.itead.cc/smart-home/sonoff-dual.html) - [iTead Sonoff Pow](https://www.itead.cc/smart-home/sonoff-pow.html) +- [iTead Sonoff Pow R2](https://www.itead.cc/sonoff-pow-r2.html) - [iTead Sonoff 4CH](https://www.itead.cc/smart-home/sonoff-4ch.html) - [iTead Sonoff 4CH Pro](https://www.itead.cc/smart-home/sonoff-4ch-pro.html) - [iTead S20 Smart Socket](https://www.itead.cc/smart-socket.html) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index b2145b6bf..1c2269538 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -3,7 +3,9 @@ * Add random window to timers (#2447) * Add optional KNX IP Protocol Support (#2402) * Add Greek language file (#2491) + * Add Bulgarian language file * Add support for sensor HC-SR04 ultrasonic (#113, #1964, #2444) + * Add support for Sonoff Pow R2 (#2340) * Fix compile error when using ESP/Arduino library v2.3.0 by reverting KNX async UDP library to default UDP library (#2488, #2492, #2493) * Fix configuration filename truncation when it contains spaces (#2484, #2490) * diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index df9997cfd..00850b891 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2041,9 +2041,9 @@ void SerialInput() } /*-------------------------------------------------------------------------------------------*\ - * Sonoff S31 4800 baud serial interface + * Sonoff S31 and Sonoff Pow R2 4800 baud serial interface \*-------------------------------------------------------------------------------------------*/ - if (SONOFF_S31 == Settings.module) { + if ((SONOFF_S31 == Settings.module) || (SONOFF_POW_R2 == Settings.module)) { if (CseSerialInput()) { serial_in_byte_counter = 0; Serial.flush(); diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 1efb95e7f..b3f95152f 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -184,6 +184,7 @@ enum SupportedModules { ARILUX_LC06, SONOFF_S31, ZENGGE_ZF_WF017, + SONOFF_POW_R2, MAXMODULE }; /********************************************************************************************/ @@ -208,6 +209,7 @@ const uint8_t kNiceList[MAXMODULE] PROGMEM = { SONOFF_DUAL, SONOFF_DUAL_R2, SONOFF_POW, + SONOFF_POW_R2, SONOFF_S31, SONOFF_4CH, SONOFF_4CHPRO, @@ -321,7 +323,7 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_USER, // GPIO14 Optional sensor 0, 0, 0 }, - { "Sonoff Pow", // Sonoff Pow (ESP8266) + { "Sonoff Pow", // Sonoff Pow (ESP8266 - HLW8012) GPIO_KEY1, // GPIO00 Button 0, 0, 0, 0, GPIO_HLW_SEL, // GPIO05 HLW8012 Sel output @@ -329,7 +331,7 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On) GPIO_HLW_CF1, // GPIO13 HLW8012 CF1 voltage / current GPIO_HLW_CF, // GPIO14 HLW8012 CF power - GPIO_LED1, // GPIO15 Green Led (0 = On, 1 = Off) + GPIO_LED1, // GPIO15 Blue Led (0 = On, 1 = Off) 0, 0 }, { "Sonoff 4CH", // Sonoff 4CH (ESP8285) @@ -784,7 +786,7 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_USER, // GPIO15 RGBW LED White 0, 0 }, - { "Sonoff S31", // Sonoff S31 (ESP8266) + { "Sonoff S31", // Sonoff S31 (ESP8266 - CSE7766) GPIO_KEY1, // GPIO00 Button 0, // GPIO01 Serial RXD 4800 baud 8E1 CSE7766 energy sensor 0, @@ -807,6 +809,17 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_PWM1, // GPIO13 RGB LED Red GPIO_PWM3, // GPIO14 RGB LED Blue 0, 0, 0 + }, + { "Sonoff Pow R2", // Sonoff Pow R2 (ESP8285 - CSE7766) + GPIO_KEY1, // GPIO00 Button + 0, // GPIO01 Serial RXD 4800 baud 8E1 CSE7766 energy sensor + 0, + 0, // GPIO03 Serial TXD + 0, 0, + 0, 0, 0, 0, 0, 0, // Flash connection + GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On) + GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off) + 0, 0, 0, 0 } }; diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index a1052a077..fc70751bf 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -252,7 +252,7 @@ void HlwInit() } /*********************************************************************************************\ - * CSE7766 - Energy (Sonoff S31) + * CSE7766 - Energy (Sonoff S31 and Sonoff Pow R2) * * Based on datasheet from http://www.chipsea.com/UploadFiles/2017/08/11144342F01B5662.pdf \*********************************************************************************************/ @@ -1015,9 +1015,9 @@ boolean EnergyCommand() void EnergyDrvInit() { energy_flg = ENERGY_NONE; - if ((pin[GPIO_HLW_SEL] < 99) && (pin[GPIO_HLW_CF1] < 99) && (pin[GPIO_HLW_CF] < 99)) { // Sonoff Pow + if ((pin[GPIO_HLW_SEL] < 99) && (pin[GPIO_HLW_CF1] < 99) && (pin[GPIO_HLW_CF] < 99)) { // Sonoff Pow or any HLW8012 based device energy_flg = ENERGY_HLW8012; - } else if (SONOFF_S31 == Settings.module) { // Sonoff S31 + } else if ((SONOFF_S31 == Settings.module) || (SONOFF_POW_R2 == Settings.module)) { // Sonoff S31 or Sonoff Pow R2 baudrate = 4800; serial_config = SERIAL_8E1; energy_flg = ENERGY_CSE7766;