Skip to content

Commit 26d3a8c

Browse files
committed
v5.1.2
5.1.2 20170519 * Fix Counter/Timer JSON message and update Counter/Timer on webpage * Fix WS2812 Domoticz related regression issues
1 parent 88648a8 commit 26d3a8c

File tree

7 files changed

+65
-45
lines changed

7 files changed

+65
-45
lines changed

README.md

Lines changed: 1 addition & 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.1.1** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
4+
Current version is **5.1.2** - 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

api/arduino/sonoff.ino.bin

160 Bytes
Binary file not shown.

sonoff/_releasenotes.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
/* 5.1.1 20170517
1+
/* 5.1.2 20170519
2+
* Fix Counter/Timer JSON message and update Counter/Timer on webpage
3+
* Fix WS2812 Domoticz related regression issues
4+
*
5+
* 5.1.1 20170517
26
* Allow command FullTopic in group mode
37
* Prepare for more use of RTC memory
48
* Add independant WS2812 led string power control (#386, #390)

sonoff/sonoff.ino

Lines changed: 24 additions & 16 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 0x05010100 // 5.1.1
27+
#define VERSION 0x05010200 // 5.1.2
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};
@@ -1799,6 +1799,8 @@ void state_mqttPresent(char* svalue, uint16_t ssvalue)
17991799

18001800
void sensors_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
18011801
{
1802+
char stemp[16];
1803+
18021804
snprintf_P(svalue, ssvalue, PSTR("%s{\"Time\":\"%s\""), svalue, getDateTime().c_str());
18031805
for (byte i = 0; i < 4; i++) {
18041806
if (pin[GPIO_SWT1 +i] < 99) {
@@ -1809,7 +1811,12 @@ void sensors_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
18091811
}
18101812
for (byte i = 0; i < 4; i++) {
18111813
if (pin[GPIO_CNTR1 +i] < 99) {
1812-
snprintf_P(svalue, ssvalue, PSTR("%s, {\"Counter%d\":%d}"), svalue, i +1, rtcMem.pCounter[i]);
1814+
if (bitRead(sysCfg.pCounterType, i)) {
1815+
dtostrf((double)rtcMem.pCounter[i] / 1000, 1, 3, stemp);
1816+
} else {
1817+
dtostrf(rtcMem.pCounter[i], 1, 0, stemp);
1818+
}
1819+
snprintf_P(svalue, ssvalue, PSTR("%s, \"Counter%d\":%s"), svalue, i +1, stemp);
18131820
*djson = 1;
18141821
}
18151822
}
@@ -2467,14 +2474,28 @@ void GPIO_init()
24672474
analogWrite(pin[GPIO_PWM1 +i], sysCfg.pwmvalue[i]);
24682475
}
24692476
}
2470-
counter_init();
24712477

24722478
if (EXS_RELAY == sysCfg.module) {
24732479
setLatchingRelay(0,2);
24742480
setLatchingRelay(1,2);
24752481
}
24762482
setLed(sysCfg.ledstate &8);
24772483

2484+
#ifdef USE_WS2812
2485+
if (pin[GPIO_WS2812] < 99) {
2486+
Maxdevice++;
2487+
ws2812_init(Maxdevice);
2488+
}
2489+
#endif // USE_WS2812
2490+
2491+
#ifdef USE_IR_REMOTE
2492+
if (pin[GPIO_IRSEND] < 99) {
2493+
ir_send_init();
2494+
}
2495+
#endif // USE_IR_REMOTE
2496+
2497+
counter_init();
2498+
24782499
hlw_flg = ((pin[GPIO_HLW_SEL] < 99) && (pin[GPIO_HLW_CF1] < 99) && (pin[GPIO_HLW_CF] < 99));
24792500
if (hlw_flg) {
24802501
hlw_init();
@@ -2498,19 +2519,6 @@ void GPIO_init()
24982519
Wire.begin(pin[GPIO_I2C_SDA], pin[GPIO_I2C_SCL]);
24992520
}
25002521
#endif // USE_I2C
2501-
2502-
#ifdef USE_WS2812
2503-
if (pin[GPIO_WS2812] < 99) {
2504-
Maxdevice++;
2505-
ws2812_init(Maxdevice);
2506-
}
2507-
#endif // USE_WS2812
2508-
2509-
#ifdef USE_IR_REMOTE
2510-
if (pin[GPIO_IRSEND] < 99) {
2511-
ir_send_init();
2512-
}
2513-
#endif // USE_IR_REMOTE
25142522
}
25152523

25162524
extern "C" {

sonoff/webserver.ino

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const char HTTP_TABLE100[] PROGMEM =
251251
const char HTTP_COUNTER[] PROGMEM =
252252
"<br/><div id='t' name='t' style='text-align:center;'></div>";
253253
const char HTTP_SNS_COUNTER[] PROGMEM =
254-
"<tr><th>Counter%d</th><td>%d</td></tr>";
254+
"<tr><th>Counter%d</th><td>%s%s</td></tr>";
255255
const char HTTP_SNS_TEMP[] PROGMEM =
256256
"<tr><th>%s Temperature</th><td>%s&deg;%c</td></tr>";
257257
const char HTTP_SNS_HUM[] PROGMEM =
@@ -449,7 +449,8 @@ void handleRoot()
449449

450450
void handleAjax2()
451451
{
452-
char svalue[80];
452+
char svalue[16];
453+
char sensor[80];
453454

454455
if (strlen(webServer->arg("o").c_str())) {
455456
do_cmnd_power(atoi(webServer->arg("o").c_str()), 2);
@@ -462,8 +463,13 @@ void handleAjax2()
462463
String tpage = "";
463464
for (byte i = 0; i < 4; i++) {
464465
if (pin[GPIO_CNTR1 +i] < 99) {
465-
snprintf_P(svalue, sizeof(svalue), HTTP_SNS_COUNTER, i+1, rtcMem.pCounter[i]);
466-
tpage += svalue;
466+
if (bitRead(sysCfg.pCounterType, i)) {
467+
dtostrf((double)rtcMem.pCounter[i] / 1000, 1, 3, svalue);
468+
} else {
469+
dtostrf(rtcMem.pCounter[i], 1, 0, svalue);
470+
}
471+
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_COUNTER, i+1, svalue, (bitRead(sysCfg.pCounterType, i)) ? " Sec" : "");
472+
tpage += sensor;
467473
}
468474
}
469475
if (hlw_flg) {

sonoff/xdrv_domoticz.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const char HTTP_FORM_DOMOTICZ_TIMER[] PROGMEM =
4242
const char domoticz_sensors[DOMOTICZ_MAX_SENSORS][14] PROGMEM =
4343
{ "Temp", "Temp,Hum", "Temp,Hum,Baro", "Power,Energy", "Illuminance" };
4444

45+
boolean domoticz_subscribe = false;
4546
int domoticz_update_timer = 0;
4647
byte domoticz_update_flag = 1;
4748

@@ -59,7 +60,7 @@ void mqtt_publishDomoticzPowerState(byte device)
5960
sysCfg.domoticz_relay_idx[device -1], sysCfg.led_dimmer[device -1]);
6061
mqtt_publish(sysCfg.domoticz_in_topic, svalue);
6162
}
62-
else if ((1 == device) && (pin[GPIO_WS2812] < 99)) {
63+
else if ((Maxdevice == device) && (pin[GPIO_WS2812] < 99)) {
6364
snprintf_P(svalue, sizeof(svalue), PSTR("{\"idx\":%d,\"nvalue\":2,\"svalue\":\"%d\"}"),
6465
sysCfg.domoticz_relay_idx[device -1], sysCfg.ws_dimmer);
6566
mqtt_publish(sysCfg.domoticz_in_topic, svalue);
@@ -80,7 +81,7 @@ void domoticz_updatePowerState(byte device)
8081

8182
void domoticz_mqttUpdate()
8283
{
83-
if ((sysCfg.domoticz_update_timer || domoticz_update_timer) && sysCfg.domoticz_relay_idx[0]) {
84+
if (domoticz_subscribe && (sysCfg.domoticz_update_timer || domoticz_update_timer)) {
8485
domoticz_update_timer--;
8586
if (domoticz_update_timer <= 0) {
8687
domoticz_update_timer = sysCfg.domoticz_update_timer;
@@ -98,7 +99,12 @@ void domoticz_setUpdateTimer(uint16_t value)
9899

99100
void domoticz_mqttSubscribe()
100101
{
101-
if (sysCfg.domoticz_relay_idx[0] && (strlen(sysCfg.domoticz_out_topic) != 0)) {
102+
for (byte i = 0; i < Maxdevice; i++) {
103+
if (sysCfg.domoticz_relay_idx[i]) {
104+
domoticz_subscribe = true;
105+
}
106+
}
107+
if (domoticz_subscribe && (strlen(sysCfg.domoticz_out_topic) != 0)) {
102108
char stopic[TOPSZ];
103109
snprintf_P(stopic, sizeof(stopic), PSTR("%s/#"), sysCfg.domoticz_out_topic); // domoticz topic
104110
mqttClient.subscribe(stopic);

sonoff/xdrv_ws2812.ino

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,12 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
537537
}
538538
else if (!strcmp_P(type,PSTR("LED")) && (index > 0) && (index <= sysCfg.ws_pixels)) {
539539
if (6 == data_len) {
540-
// ws2812_setColor(index, dataBufUc);
541540
ws2812_setColor(index, dataBuf);
542541
}
543542
ws2812_getColor(index, svalue, ssvalue);
544543
}
545544
else if (!strcmp_P(type,PSTR("COLOR"))) {
546545
if (6 == data_len) {
547-
// ws2812_setColor(0, dataBufUc);
548546
ws2812_setColor(0, dataBuf);
549547
bitSet(power, ws_bit);
550548
}
@@ -555,7 +553,8 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
555553
sysCfg.ws_dimmer = payload;
556554
bitSet(power, ws_bit);
557555
#ifdef USE_DOMOTICZ
558-
mqtt_publishDomoticzPowerState(index);
556+
// mqtt_publishDomoticzPowerState(index);
557+
mqtt_publishDomoticzPowerState(ws_bit +1);
559558
#endif // USE_DOMOTICZ
560559
}
561560
snprintf_P(svalue, ssvalue, PSTR("{\"Dimmer\":%d}"), sysCfg.ws_dimmer);
@@ -601,23 +600,6 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
601600
}
602601
snprintf_P(svalue, ssvalue, PSTR("{\"Width\":%d}"), sysCfg.ws_width);
603602
}
604-
else if (!strcmp_P(type,PSTR("UNDOCA"))) { // Theos WS2812 legacy status
605-
RgbColor mcolor;
606-
char mtopic[TOPSZ];
607-
getTopic_P(mtopic, 1, sysCfg.mqtt_topic, type);
608-
ws2812_setDim(sysCfg.ws_dimmer);
609-
mcolor = dcolor;
610-
uint32_t color = (uint32_t)mcolor.R << 16;
611-
color += (uint32_t)mcolor.G << 8;
612-
color += (uint32_t)mcolor.B;
613-
snprintf_P(svalue, ssvalue, PSTR("%s, %s, %d, %d, %d, %06X, %d, 0, %d, %d, %d, %d, %d, %d"),
614-
Version, sysCfg.mqtt_topic, bitRead(power, ws_bit), sysCfg.ws_fade, sysCfg.ws_dimmer, color,
615-
sysCfg.ws_pixels, sysCfg.ws_wakeup,
616-
sysCfg.ws_scheme, sysCfg.ws_speed, sysCfg.ws_width, sysCfg.timezone, sysCfg.ws_ledtable);
617-
mqtt_publish(mtopic, svalue);
618-
// snprintf_P(svalue, ssvalue, PSTR("{\"UndocA\":\"Done\"}"));
619-
svalue[0] = '\0';
620-
}
621603
else if (!strcmp_P(type,PSTR("WAKEUP"))) {
622604
if ((data_len > 0) && (payload > 0) && (payload < 3601)) {
623605
sysCfg.ws_wakeup = payload;
@@ -638,6 +620,20 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
638620
}
639621
snprintf_P(svalue, ssvalue, PSTR("{\"Scheme\":%d}"), sysCfg.ws_scheme);
640622
}
623+
else if (!strcmp_P(type,PSTR("UNDOCA"))) { // Theos WS2812 legacy status
624+
RgbColor mcolor;
625+
char mtopic[TOPSZ];
626+
getTopic_P(mtopic, 1, sysCfg.mqtt_topic, type);
627+
ws2812_setDim(sysCfg.ws_dimmer);
628+
mcolor = dcolor;
629+
uint32_t color = (uint32_t)mcolor.R << 16;
630+
color += (uint32_t)mcolor.G << 8;
631+
color += (uint32_t)mcolor.B;
632+
snprintf_P(svalue, ssvalue, PSTR("%06X, %d, %d, %d, %d, %d"),
633+
color, sysCfg.ws_fade, sysCfg.ws_ledtable, sysCfg.ws_scheme, sysCfg.ws_speed, sysCfg.ws_width);
634+
mqtt_publish(mtopic, svalue);
635+
svalue[0] = '\0';
636+
}
641637
else {
642638
serviced = false; // Unknown command
643639
}

0 commit comments

Comments
 (0)