Skip to content

Commit 39a65e2

Browse files
committed
v5.2.4
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
1 parent c768f7d commit 39a65e2

File tree

8 files changed

+117
-52
lines changed

8 files changed

+117
-52
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Sonoff-Tasmota
22
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.
33

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

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

@@ -39,6 +39,7 @@ The following devices are supported:
3939
- [iTead Sonoff Touch](http://sonoff.itead.cc/en/products/residential/sonoff-touch)
4040
- [iTead Sonoff SC](http://sonoff.itead.cc/en/products/residential/sonoff-sc)
4141
- [iTead Sonoff Led](http://sonoff.itead.cc/en/products/appliances/sonoff-led)
42+
- [iTead Sonoff BN-SZ01 Led](http://sonoff.itead.cc/en/products/appliances/bn-sz01)
4243
- [iTead Sonoff Dev](https://www.itead.cc/sonoff-dev.html)
4344
- [iTead 1 Channel Switch 5V / 12V](https://www.itead.cc/smart-home/inching-self-locking-wifi-wireless-switch.html)
4445
- [iTead Motor Clockwise/Anticlockwise](https://www.itead.cc/smart-home/motor-reversing-wifi-wireless-switch.html)

sonoff/_releasenotes.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
/* 5.2.3 20170630
1+
/* 5.2.4 20170703
2+
* Removed flash mode update after selecting different module solving esp8285 related problems
3+
* Add device type flag to sonoff_template.ino
4+
* Change Sonoff Led Wakeup and add support for Sonoff BN-SZ01 Led
5+
*
6+
* 5.2.3 20170630
27
* Change Sonoff Led color conversion code
38
* Fix SetOption12 handling
49
* Simplify auto configuration upgrade

sonoff/settings.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ void setFlashMode(byte option, byte mode)
174174
void setModuleFlashMode(byte option)
175175
{
176176
uint8_t mode = 0; // QIO - ESP8266
177-
if ((SONOFF_TOUCH == sysCfg.module) || (SONOFF_4CH == sysCfg.module)) {
177+
// if ((SONOFF_TOUCH == sysCfg.module) || (SONOFF_4CH == sysCfg.module)) {
178+
if (sysCfg.my_module.flag &1) {
178179
mode = 3; // DOUT - ESP8285
179180
}
180181
setFlashMode(option, mode);

sonoff/sonoff.ino

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- Select IDE Tools - Flash size: "1M (no SPIFFS)"
2525
====================================================*/
2626

27-
#define VERSION 0x05020300 // 5.2.3
27+
#define VERSION 0x05020400 // 5.2.4
2828

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

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

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

299301
boolean mDNSbegun = false;
@@ -400,7 +402,7 @@ void setRelay(uint8_t rpower)
400402
Serial.write('\n');
401403
Serial.flush();
402404
}
403-
else if (SONOFF_LED == sysCfg.module) {
405+
else if (sfl_flg) {
404406
sl_setPower(rpower &1);
405407
}
406408
else if (EXS_RELAY == sysCfg.module) {
@@ -1006,7 +1008,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
10061008
}
10071009
snprintf_P(svalue, sizeof(svalue), PSTR("{\"BlinkCount\":%d}"), sysCfg.blinkcount);
10081010
}
1009-
else if ((SONOFF_LED == sysCfg.module) && sl_command(type, index, dataBufUc, data_len, payload, svalue, sizeof(svalue))) {
1011+
else if (sfl_flg && sl_command(type, index, dataBufUc, data_len, payload, svalue, sizeof(svalue))) {
10101012
// Serviced
10111013
}
10121014
else if (!strcmp_P(type,PSTR("SAVEDATA"))) {
@@ -1146,7 +1148,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
11461148
for (byte i = 0; i < MAX_GPIO_PIN; i++) {
11471149
sysCfg.my_module.gp.io[i] = 0;
11481150
}
1149-
setModuleFlashMode(0);
1151+
// setModuleFlashMode(0); // Fails on esp8285 based devices
11501152
}
11511153
restartflag = 2;
11521154
}
@@ -2074,7 +2076,7 @@ void stateloop()
20742076
}
20752077
}
20762078

2077-
if (SONOFF_LED == sysCfg.module) {
2079+
if (sfl_flg) { // Sonoff BN-SZ01 or Sonoff Led
20782080
sl_animate();
20792081
}
20802082

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

24592461
memcpy_P(&def_module, &modules[sysCfg.module], sizeof(def_module));
2462+
sysCfg.my_module.flag = def_module.flag;
24602463
strlcpy(my_module.name, def_module.name, sizeof(my_module.name));
24612464
for (byte i = 0; i < MAX_GPIO_PIN; i++) {
24622465
if (sysCfg.my_module.gp.io[i] > GPIO_NONE) {
@@ -2521,22 +2524,11 @@ void GPIO_init()
25212524
Maxdevice = 0;
25222525
Baudrate = 19200;
25232526
}
2527+
else if (SONOFF_BN == sysCfg.module) {
2528+
sfl_flg = 1;
2529+
}
25242530
else if (SONOFF_LED == sysCfg.module) {
2525-
pwm_idxoffset = 2;
2526-
pin[GPIO_WS2812] = 99; // I do not allow both Sonoff Led AND WS2812 led
2527-
if (!my_module.gp.io[4]) {
2528-
pinMode(4, OUTPUT); // Stop floating outputs
2529-
digitalWrite(4, LOW);
2530-
}
2531-
if (!my_module.gp.io[5]) {
2532-
pinMode(5, OUTPUT); // Stop floating outputs
2533-
digitalWrite(5, LOW);
2534-
}
2535-
if (!my_module.gp.io[14]) {
2536-
pinMode(14, OUTPUT); // Stop floating outputs
2537-
digitalWrite(14, LOW);
2538-
}
2539-
sl_init();
2531+
sfl_flg = 2;
25402532
}
25412533
else {
25422534
Maxdevice = 0;
@@ -2561,6 +2553,24 @@ void GPIO_init()
25612553
lastwallswitch[i] = digitalRead(pin[GPIO_SWT1 +i]); // set global now so doesn't change the saved power state on first switch check
25622554
}
25632555
}
2556+
2557+
if (sfl_flg) { // Sonoff Led or BN-SZ01
2558+
pwm_idxoffset = sfl_flg; // 1 for BN-SZ01, 2 for Sonoff Led
2559+
pin[GPIO_WS2812] = 99; // I do not allow both Sonoff Led AND WS2812 led
2560+
if (!my_module.gp.io[4]) {
2561+
pinMode(4, OUTPUT); // Stop floating outputs
2562+
digitalWrite(4, LOW);
2563+
}
2564+
if (!my_module.gp.io[5]) {
2565+
pinMode(5, OUTPUT); // Stop floating outputs
2566+
digitalWrite(5, LOW);
2567+
}
2568+
if (!my_module.gp.io[14]) {
2569+
pinMode(14, OUTPUT); // Stop floating outputs
2570+
digitalWrite(14, LOW);
2571+
}
2572+
sl_init();
2573+
}
25642574
for (byte i = pwm_idxoffset; i < 5; i++) {
25652575
if (pin[GPIO_PWM1 +i] < 99) {
25662576
pwm_flg = 1;

sonoff/sonoff_template.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ enum module_t {
145145
SONOFF_DEV,
146146
H801,
147147
SONOFF_SC,
148+
SONOFF_BN,
148149
MAXMODULE };
149150

150151
/********************************************************************************************/
@@ -156,13 +157,15 @@ typedef struct MYIO {
156157
} myio;
157158

158159
typedef struct MYTMPLT {
159-
char name[15];
160+
char name[14];
161+
uint8_t flag; // bit 0 = flashmode (0 = esp8266, 1 = esp8285)
160162
myio gp;
161163
} mytmplt;
162164

163165
// Default module settings
164166
const mytmplt modules[MAXMODULE] PROGMEM = {
165167
{ "Sonoff Basic", // Sonoff Basic (ESP8266)
168+
0, // esp8266
166169
GPIO_KEY1, // GPIO00 Button
167170
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
168171
0, // GPIO02
@@ -183,6 +186,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
183186
0 // ADC0 Analog input
184187
},
185188
{ "Sonoff RF", // Sonoff RF (ESP8266)
189+
0, // esp8266
186190
GPIO_KEY1, // GPIO00 Button
187191
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
188192
0,
@@ -196,6 +200,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
196200
0, 0, 0
197201
},
198202
{ "Sonoff SV", // Sonoff SV (ESP8266)
203+
0, // esp8266
199204
GPIO_KEY1, // GPIO00 Button
200205
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
201206
0,
@@ -210,6 +215,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
210215
GPIO_ADC0 // ADC0 Analog input
211216
},
212217
{ "Sonoff TH", // Sonoff TH10/16 (ESP8266)
218+
0, // esp8266
213219
GPIO_KEY1, // GPIO00 Button
214220
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
215221
0,
@@ -223,6 +229,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
223229
0, 0, 0
224230
},
225231
{ "Sonoff Dual", // Sonoff Dual (ESP8266)
232+
0, // esp8266
226233
0,
227234
GPIO_TXD, // GPIO01 Relay control
228235
0,
@@ -235,6 +242,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
235242
0, 0, 0, 0
236243
},
237244
{ "Sonoff Pow", // Sonoff Pow (ESP8266)
245+
0, // esp8266
238246
GPIO_KEY1, // GPIO00 Button
239247
0, 0, 0, 0,
240248
GPIO_HLW_SEL, // GPIO05 HLW8012 Sel output
@@ -246,6 +254,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
246254
0, 0
247255
},
248256
{ "Sonoff 4CH", // Sonoff 4CH (ESP8285)
257+
1, // esp8285
249258
GPIO_KEY1, // GPIO00 Button 1
250259
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
251260
GPIO_USER, // GPIO02 Optional sensor
@@ -263,6 +272,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
263272
0, 0
264273
},
265274
{ "S20 Socket", // S20 Smart Socket (ESP8266)
275+
0, // esp8266
266276
GPIO_KEY1, // GPIO00 Button
267277
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
268278
0,
@@ -274,6 +284,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
274284
0, 0, 0, 0
275285
},
276286
{ "Slampher", // Slampher (ESP8266)
287+
0, // esp8266
277288
GPIO_KEY1, // GPIO00 Button
278289
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
279290
0,
@@ -285,6 +296,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
285296
0, 0, 0, 0
286297
},
287298
{ "Sonoff Touch", // Sonoff Touch (ESP8285)
299+
1, // esp8285
288300
GPIO_KEY1, // GPIO00 Button
289301
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
290302
0,
@@ -297,6 +309,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
297309
0, 0, 0, 0
298310
},
299311
{ "Sonoff LED", // Sonoff LED (ESP8266)
312+
0, // esp8266
300313
GPIO_KEY1, // GPIO00 Button
301314
0, 0, 0,
302315
GPIO_USER, // GPIO04 Optional sensor (PWM3 Green)
@@ -309,14 +322,16 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
309322
0, 0
310323
},
311324
{ "1 Channel", // 1 Channel Inching/Latching Relay using (PSA-B01 - ESP8266)
325+
0, // esp8266
312326
GPIO_KEY1, // GPIO00 Button
313327
0, 0, 0, 0, 0,
314328
0, 0, 0, 0, 0, 0, // Flash connection
315329
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
316330
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
317331
0, 0, 0, 0
318332
},
319-
{ "4 Channel", // 4 Channel Inching/Latching Relays
333+
{ "4 Channel", // 4 Channel Inching/Latching Relays (ESP8266)
334+
0, // esp8266
320335
0,
321336
GPIO_TXD, // GPIO01 Relay control
322337
0,
@@ -328,6 +343,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
328343
0, 0, 0, 0
329344
},
330345
{ "Motor C/AC", // Motor Clockwise / Anti clockwise (PSA-B01 - ESP8266)
346+
0, // esp8266
331347
GPIO_KEY1, // GPIO00 Button
332348
0, 0, 0, 0, 0,
333349
0, 0, 0, 0, 0, 0, // Flash connection
@@ -336,6 +352,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
336352
0, 0, 0, 0
337353
},
338354
{ "ElectroDragon", // ElectroDragon IoT Relay Board (ESP8266)
355+
0, // esp8266
339356
GPIO_KEY2, // GPIO00 Button 2
340357
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
341358
GPIO_KEY1, // GPIO02 Button 1
@@ -352,6 +369,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
352369
},
353370
{ "EXS Relay", // Latching relay https://ex-store.de/ESP8266-WiFi-Relay-V31 (ESP8266)
354371
// Module Pin 1 VCC 3V3, Module Pin 6 GND
372+
0, // esp8266
355373
GPIO_KEY1, // GPIO00 Module Pin 8 - Button (firmware flash)
356374
GPIO_USER, // GPIO01 Module Pin 2 = UART0_TXD
357375
GPIO_USER, // GPIO02 Module Pin 7
@@ -367,6 +385,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
367385
0
368386
},
369387
{ "WiOn", // Indoor Tap https://www.amazon.com/gp/product/B00ZYLUBJU/ref=s9_acsd_al_bw_c_x_3_w (ESP8266)
388+
0, // esp8266
370389
GPIO_USER, // GPIO00 Optional sensor (pm clock)
371390
0,
372391
GPIO_LED1, // GPIO02 Green Led (1 = On, 0 = Off)
@@ -379,6 +398,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
379398
0, 0
380399
},
381400
{ "WeMos D1 mini", // WeMos and NodeMCU hardware (ESP8266)
401+
0, // esp8266
382402
GPIO_USER, // GPIO00 D3 Wemos Button Shield
383403
GPIO_USER, // GPIO01 TX Serial RXD
384404
GPIO_USER, // GPIO02 D4 Wemos DHT Shield
@@ -394,6 +414,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
394414
GPIO_ADC0 // ADC0 A0 Analog input
395415
},
396416
{ "Sonoff Dev", // Sonoff Dev (ESP8266)
417+
0, // esp8266
397418
GPIO_KEY1, // GPIO00 E-FW Button
398419
GPIO_USER, // GPIO01 TX Serial RXD and Optional sensor
399420
0, // GPIO02
@@ -409,6 +430,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
409430
GPIO_ADC0 // ADC0 A0 Analog input
410431
},
411432
{ "H801", // Lixada H801 Wifi (ESP8266)
433+
0, // esp8266
412434
GPIO_KEY1, // GPIO00 E-FW Button
413435
GPIO_LED1, // GPIO01 Green LED
414436
GPIO_TXD, // GPIO02 RX - Pin next to TX on the PCB
@@ -423,6 +445,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
423445
0, 0
424446
},
425447
{ "Sonoff SC", // Sonoff SC (ESP8266)
448+
0, // esp8266
426449
GPIO_KEY1, // GPIO00 Button
427450
GPIO_TXD, // GPIO01 RXD to ATMEGA328P
428451
GPIO_USER, // GPIO02 Optional sensor
@@ -432,6 +455,16 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
432455
0,
433456
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
434457
0, 0, 0, 0
458+
},
459+
{ "Sonoff BN-SZ", // Sonoff BN-SZ01 LED (ESP8285)
460+
1, // esp8285
461+
0, 0, 0, 0, 0, 0,
462+
0, 0, 0, // Flash connection
463+
0, 0, 0,
464+
GPIO_PWM1, // GPIO12 Light
465+
GPIO_LED1_INV, // GPIO13 Red Led (0 = On, 1 = Off)
466+
0, 0,
467+
0, 0
435468
}
436469
};
437470

0 commit comments

Comments
 (0)