Skip to content

Commit

Permalink
v5.2.4
Browse files Browse the repository at this point in the history
5.2.4 20170703
* Removed flash mode update after selecting different module solving
esp8285 related problems
* Add device type flag to sonoff_template.ino
* Change Sonoff Led Wakeup and add support for Sonoff BN-SZ01 Led
  • Loading branch information
arendst committed Jul 3, 2017
1 parent c768f7d commit 39a65e2
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 52 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Sonoff-Tasmota
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.

Current version is **5.2.3** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
Current version is **5.2.4** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.

### **** ATTENTION Version 5.x.x specific information ****

Expand Down Expand Up @@ -39,6 +39,7 @@ The following devices are supported:
- [iTead Sonoff Touch](http://sonoff.itead.cc/en/products/residential/sonoff-touch)
- [iTead Sonoff SC](http://sonoff.itead.cc/en/products/residential/sonoff-sc)
- [iTead Sonoff Led](http://sonoff.itead.cc/en/products/appliances/sonoff-led)
- [iTead Sonoff BN-SZ01 Led](http://sonoff.itead.cc/en/products/appliances/bn-sz01)
- [iTead Sonoff Dev](https://www.itead.cc/sonoff-dev.html)
- [iTead 1 Channel Switch 5V / 12V](https://www.itead.cc/smart-home/inching-self-locking-wifi-wireless-switch.html)
- [iTead Motor Clockwise/Anticlockwise](https://www.itead.cc/smart-home/motor-reversing-wifi-wireless-switch.html)
Expand Down
7 changes: 6 additions & 1 deletion sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/* 5.2.3 20170630
/* 5.2.4 20170703
* Removed flash mode update after selecting different module solving esp8285 related problems
* Add device type flag to sonoff_template.ino
* Change Sonoff Led Wakeup and add support for Sonoff BN-SZ01 Led
*
* 5.2.3 20170630
* Change Sonoff Led color conversion code
* Fix SetOption12 handling
* Simplify auto configuration upgrade
Expand Down
3 changes: 2 additions & 1 deletion sonoff/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ void setFlashMode(byte option, byte mode)
void setModuleFlashMode(byte option)
{
uint8_t mode = 0; // QIO - ESP8266
if ((SONOFF_TOUCH == sysCfg.module) || (SONOFF_4CH == sysCfg.module)) {
// if ((SONOFF_TOUCH == sysCfg.module) || (SONOFF_4CH == sysCfg.module)) {
if (sysCfg.my_module.flag &1) {
mode = 3; // DOUT - ESP8285
}
setFlashMode(option, mode);
Expand Down
54 changes: 32 additions & 22 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- Select IDE Tools - Flash size: "1M (no SPIFFS)"
====================================================*/

#define VERSION 0x05020300 // 5.2.3
#define VERSION 0x05020400 // 5.2.4

enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
enum week_t {Last, First, Second, Third, Fourth};
Expand Down Expand Up @@ -122,7 +122,8 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};

#define PWM_RANGE 1023 // 255..1023 needs to be devisible by 256
//#define PWM_FREQ 1000 // 100..1000 Hz led refresh
#define PWM_FREQ 910 // 100..1000 Hz led refresh (iTead value)
//#define PWM_FREQ 910 // 100..1000 Hz led refresh (iTead value)
#define PWM_FREQ 880 // 100..1000 Hz led refresh (BN-SZ01 value)

#define MAX_POWER_HOLD 10 // Time in SECONDS to allow max agreed power (Pow)
#define MAX_POWER_WINDOW 30 // Time in SECONDS to disable allow max agreed power (Pow)
Expand Down Expand Up @@ -294,6 +295,7 @@ uint8_t hlw_flg = 0; // Power monitor configured
uint8_t i2c_flg = 0; // I2C configured
uint8_t spi_flg = 0; // SPI configured
uint8_t pwm_flg = 0; // PWM configured
uint8_t sfl_flg = 0; // Sonoff Led flag (0 = No led, 1 = BN-SZ01, 2 = Sonoff Led)
uint8_t pwm_idxoffset = 0; // Allowed PWM command offset (change for Sonoff Led)

boolean mDNSbegun = false;
Expand Down Expand Up @@ -400,7 +402,7 @@ void setRelay(uint8_t rpower)
Serial.write('\n');
Serial.flush();
}
else if (SONOFF_LED == sysCfg.module) {
else if (sfl_flg) {
sl_setPower(rpower &1);
}
else if (EXS_RELAY == sysCfg.module) {
Expand Down Expand Up @@ -1006,7 +1008,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"BlinkCount\":%d}"), sysCfg.blinkcount);
}
else if ((SONOFF_LED == sysCfg.module) && sl_command(type, index, dataBufUc, data_len, payload, svalue, sizeof(svalue))) {
else if (sfl_flg && sl_command(type, index, dataBufUc, data_len, payload, svalue, sizeof(svalue))) {
// Serviced
}
else if (!strcmp_P(type,PSTR("SAVEDATA"))) {
Expand Down Expand Up @@ -1146,7 +1148,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
for (byte i = 0; i < MAX_GPIO_PIN; i++) {
sysCfg.my_module.gp.io[i] = 0;
}
setModuleFlashMode(0);
// setModuleFlashMode(0); // Fails on esp8285 based devices
}
restartflag = 2;
}
Expand Down Expand Up @@ -2074,7 +2076,7 @@ void stateloop()
}
}

if (SONOFF_LED == sysCfg.module) {
if (sfl_flg) { // Sonoff BN-SZ01 or Sonoff Led
sl_animate();
}

Expand Down Expand Up @@ -2302,7 +2304,7 @@ void stateloop()
if (90 == otaflag) { // Allow MQTT to reconnect
otaflag = 0;
if (otaok) {
setModuleFlashMode(1); // QIO - ESP8266, DOUT - ESP8285 (Sonoff 4CH and Touch)
setModuleFlashMode(1); // QIO - ESP8266, DOUT - ESP8285 (Sonoff 4CH, Touch and BN-SZ01)
snprintf_P(svalue, sizeof(svalue), PSTR("Successful. Restarting"));
} else {
snprintf_P(svalue, sizeof(svalue), PSTR("Failed %s"), ESPhttpUpdate.getLastErrorString().c_str());
Expand Down Expand Up @@ -2457,6 +2459,7 @@ void GPIO_init()
}

memcpy_P(&def_module, &modules[sysCfg.module], sizeof(def_module));
sysCfg.my_module.flag = def_module.flag;
strlcpy(my_module.name, def_module.name, sizeof(my_module.name));
for (byte i = 0; i < MAX_GPIO_PIN; i++) {
if (sysCfg.my_module.gp.io[i] > GPIO_NONE) {
Expand Down Expand Up @@ -2521,22 +2524,11 @@ void GPIO_init()
Maxdevice = 0;
Baudrate = 19200;
}
else if (SONOFF_BN == sysCfg.module) {
sfl_flg = 1;
}
else if (SONOFF_LED == sysCfg.module) {
pwm_idxoffset = 2;
pin[GPIO_WS2812] = 99; // I do not allow both Sonoff Led AND WS2812 led
if (!my_module.gp.io[4]) {
pinMode(4, OUTPUT); // Stop floating outputs
digitalWrite(4, LOW);
}
if (!my_module.gp.io[5]) {
pinMode(5, OUTPUT); // Stop floating outputs
digitalWrite(5, LOW);
}
if (!my_module.gp.io[14]) {
pinMode(14, OUTPUT); // Stop floating outputs
digitalWrite(14, LOW);
}
sl_init();
sfl_flg = 2;
}
else {
Maxdevice = 0;
Expand All @@ -2561,6 +2553,24 @@ void GPIO_init()
lastwallswitch[i] = digitalRead(pin[GPIO_SWT1 +i]); // set global now so doesn't change the saved power state on first switch check
}
}

if (sfl_flg) { // Sonoff Led or BN-SZ01
pwm_idxoffset = sfl_flg; // 1 for BN-SZ01, 2 for Sonoff Led
pin[GPIO_WS2812] = 99; // I do not allow both Sonoff Led AND WS2812 led
if (!my_module.gp.io[4]) {
pinMode(4, OUTPUT); // Stop floating outputs
digitalWrite(4, LOW);
}
if (!my_module.gp.io[5]) {
pinMode(5, OUTPUT); // Stop floating outputs
digitalWrite(5, LOW);
}
if (!my_module.gp.io[14]) {
pinMode(14, OUTPUT); // Stop floating outputs
digitalWrite(14, LOW);
}
sl_init();
}
for (byte i = pwm_idxoffset; i < 5; i++) {
if (pin[GPIO_PWM1 +i] < 99) {
pwm_flg = 1;
Expand Down
37 changes: 35 additions & 2 deletions sonoff/sonoff_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ enum module_t {
SONOFF_DEV,
H801,
SONOFF_SC,
SONOFF_BN,
MAXMODULE };

/********************************************************************************************/
Expand All @@ -156,13 +157,15 @@ typedef struct MYIO {
} myio;

typedef struct MYTMPLT {
char name[15];
char name[14];
uint8_t flag; // bit 0 = flashmode (0 = esp8266, 1 = esp8285)
myio gp;
} mytmplt;

// Default module settings
const mytmplt modules[MAXMODULE] PROGMEM = {
{ "Sonoff Basic", // Sonoff Basic (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
0, // GPIO02
Expand All @@ -183,6 +186,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0 // ADC0 Analog input
},
{ "Sonoff RF", // Sonoff RF (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
0,
Expand All @@ -196,6 +200,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0
},
{ "Sonoff SV", // Sonoff SV (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
0,
Expand All @@ -210,6 +215,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_ADC0 // ADC0 Analog input
},
{ "Sonoff TH", // Sonoff TH10/16 (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
0,
Expand All @@ -223,6 +229,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0
},
{ "Sonoff Dual", // Sonoff Dual (ESP8266)
0, // esp8266
0,
GPIO_TXD, // GPIO01 Relay control
0,
Expand All @@ -235,6 +242,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0, 0
},
{ "Sonoff Pow", // Sonoff Pow (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
0, 0, 0, 0,
GPIO_HLW_SEL, // GPIO05 HLW8012 Sel output
Expand All @@ -246,6 +254,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0
},
{ "Sonoff 4CH", // Sonoff 4CH (ESP8285)
1, // esp8285
GPIO_KEY1, // GPIO00 Button 1
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
GPIO_USER, // GPIO02 Optional sensor
Expand All @@ -263,6 +272,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0
},
{ "S20 Socket", // S20 Smart Socket (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
0,
Expand All @@ -274,6 +284,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0, 0
},
{ "Slampher", // Slampher (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
0,
Expand All @@ -285,6 +296,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0, 0
},
{ "Sonoff Touch", // Sonoff Touch (ESP8285)
1, // esp8285
GPIO_KEY1, // GPIO00 Button
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
0,
Expand All @@ -297,6 +309,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0, 0
},
{ "Sonoff LED", // Sonoff LED (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
0, 0, 0,
GPIO_USER, // GPIO04 Optional sensor (PWM3 Green)
Expand All @@ -309,14 +322,16 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0
},
{ "1 Channel", // 1 Channel Inching/Latching Relay using (PSA-B01 - ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
0, 0, 0, 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 Green Led (0 = On, 1 = Off)
0, 0, 0, 0
},
{ "4 Channel", // 4 Channel Inching/Latching Relays
{ "4 Channel", // 4 Channel Inching/Latching Relays (ESP8266)
0, // esp8266
0,
GPIO_TXD, // GPIO01 Relay control
0,
Expand All @@ -328,6 +343,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0, 0
},
{ "Motor C/AC", // Motor Clockwise / Anti clockwise (PSA-B01 - ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, // Flash connection
Expand All @@ -336,6 +352,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0, 0
},
{ "ElectroDragon", // ElectroDragon IoT Relay Board (ESP8266)
0, // esp8266
GPIO_KEY2, // GPIO00 Button 2
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
GPIO_KEY1, // GPIO02 Button 1
Expand All @@ -352,6 +369,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
},
{ "EXS Relay", // Latching relay https://ex-store.de/ESP8266-WiFi-Relay-V31 (ESP8266)
// Module Pin 1 VCC 3V3, Module Pin 6 GND
0, // esp8266
GPIO_KEY1, // GPIO00 Module Pin 8 - Button (firmware flash)
GPIO_USER, // GPIO01 Module Pin 2 = UART0_TXD
GPIO_USER, // GPIO02 Module Pin 7
Expand All @@ -367,6 +385,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0
},
{ "WiOn", // Indoor Tap https://www.amazon.com/gp/product/B00ZYLUBJU/ref=s9_acsd_al_bw_c_x_3_w (ESP8266)
0, // esp8266
GPIO_USER, // GPIO00 Optional sensor (pm clock)
0,
GPIO_LED1, // GPIO02 Green Led (1 = On, 0 = Off)
Expand All @@ -379,6 +398,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0
},
{ "WeMos D1 mini", // WeMos and NodeMCU hardware (ESP8266)
0, // esp8266
GPIO_USER, // GPIO00 D3 Wemos Button Shield
GPIO_USER, // GPIO01 TX Serial RXD
GPIO_USER, // GPIO02 D4 Wemos DHT Shield
Expand All @@ -394,6 +414,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_ADC0 // ADC0 A0 Analog input
},
{ "Sonoff Dev", // Sonoff Dev (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 E-FW Button
GPIO_USER, // GPIO01 TX Serial RXD and Optional sensor
0, // GPIO02
Expand All @@ -409,6 +430,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_ADC0 // ADC0 A0 Analog input
},
{ "H801", // Lixada H801 Wifi (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 E-FW Button
GPIO_LED1, // GPIO01 Green LED
GPIO_TXD, // GPIO02 RX - Pin next to TX on the PCB
Expand All @@ -423,6 +445,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0
},
{ "Sonoff SC", // Sonoff SC (ESP8266)
0, // esp8266
GPIO_KEY1, // GPIO00 Button
GPIO_TXD, // GPIO01 RXD to ATMEGA328P
GPIO_USER, // GPIO02 Optional sensor
Expand All @@ -432,6 +455,16 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0,
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
0, 0, 0, 0
},
{ "Sonoff BN-SZ", // Sonoff BN-SZ01 LED (ESP8285)
1, // esp8285
0, 0, 0, 0, 0, 0,
0, 0, 0, // Flash connection
0, 0, 0,
GPIO_PWM1, // GPIO12 Light
GPIO_LED1_INV, // GPIO13 Red Led (0 = On, 1 = Off)
0, 0,
0, 0
}
};

Loading

0 comments on commit 39a65e2

Please sign in to comment.