Skip to content

Commit 70ccdfe

Browse files
committed
v5.1.3
5.1.3 20170520 * Add Domoticz Counter
1 parent 26d3a8c commit 70ccdfe

File tree

11 files changed

+167
-107
lines changed

11 files changed

+167
-107
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.2** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
4+
Current version is **5.1.3** - 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

224 Bytes
Binary file not shown.

sonoff/_releasenotes.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* 5.1.2 20170519
1+
/* 5.1.3 20170520
2+
* Add Domoticz Counter
3+
*
4+
* 5.1.2 20170519
25
* Fix Counter/Timer JSON message and update Counter/Timer on webpage
36
* Fix WS2812 Domoticz related regression issues
47
*

sonoff/settings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ struct SYSCFG {
197197
char mqtt_fulltopic[101];
198198

199199
// 5.1.1
200-
unsigned long pCounter[4];
200+
unsigned long pCounter[MAX_COUNTERS];
201201
uint16_t pCounterType;
202202
uint16_t pCounterDebounce;
203203

@@ -209,7 +209,7 @@ struct RTCMEM {
209209
uint8_t power;
210210
unsigned long hlw_kWhtoday;
211211
unsigned long hlw_kWhtotal;
212-
unsigned long pCounter[4];
212+
unsigned long pCounter[MAX_COUNTERS];
213213
} rtcMem;
214214

215215
// See issue https://github.com/esp8266/Arduino/issues/2913

sonoff/settings.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ void CFG_Delta()
642642
if (sysCfg.version < 0x05010100) {
643643
sysCfg.pCounterType = 0;
644644
sysCfg.pCounterDebounce = 0;
645-
for (byte i = 0; i < 4; i++) {
645+
for (byte i = 0; i < MAX_COUNTERS; i++) {
646646
sysCfg.pCounter[i] = 0;
647647
rtcMem.pCounter[i] = 0;
648648
}

sonoff/sonoff.ino

Lines changed: 6 additions & 19 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 0x05010200 // 5.1.2
27+
#define VERSION 0x05010300 // 5.1.3
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};
@@ -116,7 +116,7 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};
116116

117117
#define MQTT_RETRY_SECS 10 // Minimum seconds to retry MQTT connection
118118
#define APP_POWER 0 // Default saved power state Off
119-
#define MAX_DEVICE 1 // Max number of devices
119+
#define MAX_COUNTERS 4 // Max number of counter sensors
120120
#define MAX_PULSETIMERS 4 // Max number of supported pulse timers
121121
#define WS2812_MAX_LEDS 256 // Max number of LEDs
122122

@@ -240,7 +240,7 @@ int tele_period = 0; // Tele period timer
240240
String Log[MAX_LOG_LINES]; // Web log buffer
241241
byte logidx = 0; // Index in Web log buffer
242242
byte logajaxflg = 0; // Reset web console log
243-
byte Maxdevice = MAX_DEVICE; // Max number of devices supported
243+
byte Maxdevice = 0; // Max number of devices supported
244244
int status_update_timer = 0; // Refresh initial status
245245
uint16_t pulse_timer[MAX_PULSETIMERS] = { 0 }; // Power off timer
246246
uint16_t blink_timer = 0; // Power cycle timer
@@ -251,7 +251,6 @@ uint8_t blink_powersave; // Blink start power save state
251251
uint16_t mqtt_cmnd_publish = 0; // ignore flag for publish command
252252
uint8_t latching_power = 0; // Power state at latching start
253253
uint8_t latching_relay_pulse = 0; // Latching relay pulse timer
254-
unsigned long pTimeLast[4]; // Last counter time in milli seconds
255254

256255
#ifdef USE_MQTT_TLS
257256
WiFiClientSecure espClient; // Wifi Secure Client
@@ -1211,14 +1210,14 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
12111210
}
12121211
snprintf_P(svalue, sizeof(svalue), PSTR("%s}}"),svalue);
12131212
}
1214-
else if (!strcmp_P(type,PSTR("COUNTER")) && (index > 0) && (index <= 4)) {
1213+
else if (!strcmp_P(type,PSTR("COUNTER")) && (index > 0) && (index <= MAX_COUNTERS)) {
12151214
if ((data_len > 0) && (pin[GPIO_CNTR1 + index -1] < 99)) {
12161215
rtcMem.pCounter[index -1] = payload16;
12171216
sysCfg.pCounter[index -1] = payload16;
12181217
}
12191218
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Counter%d\":%d}"), index, rtcMem.pCounter[index -1]);
12201219
}
1221-
else if (!strcmp_P(type,PSTR("COUNTERTYPE")) && (index > 0) && (index <= 4)) {
1220+
else if (!strcmp_P(type,PSTR("COUNTERTYPE")) && (index > 0) && (index <= MAX_COUNTERS)) {
12221221
if ((data_len > 0) && (payload >= 0) && (payload <= 1) && (pin[GPIO_CNTR1 + index -1] < 99)) {
12231222
bitWrite(sysCfg.pCounterType, index -1, payload &1);
12241223
rtcMem.pCounter[index -1] = 0;
@@ -1799,8 +1798,6 @@ void state_mqttPresent(char* svalue, uint16_t ssvalue)
17991798

18001799
void sensors_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
18011800
{
1802-
char stemp[16];
1803-
18041801
snprintf_P(svalue, ssvalue, PSTR("%s{\"Time\":\"%s\""), svalue, getDateTime().c_str());
18051802
for (byte i = 0; i < 4; i++) {
18061803
if (pin[GPIO_SWT1 +i] < 99) {
@@ -1809,17 +1806,7 @@ void sensors_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
18091806
*djson = 1;
18101807
}
18111808
}
1812-
for (byte i = 0; i < 4; i++) {
1813-
if (pin[GPIO_CNTR1 +i] < 99) {
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);
1820-
*djson = 1;
1821-
}
1822-
}
1809+
counter_mqttPresent(svalue, ssvalue, djson);
18231810
#ifndef USE_ADC_VCC
18241811
if (pin[GPIO_ADC0] < 99) {
18251812
snprintf_P(svalue, ssvalue, PSTR("%s, \"AnalogInput0\":%d"), svalue, analogRead(A0));

sonoff/support.ino

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -947,70 +947,6 @@ void rtc_init()
947947
tickerRTC.attach(1, rtc_second);
948948
}
949949

950-
/*********************************************************************************************\
951-
* Counter sensors (water meters, electricity meters etc.)
952-
\*********************************************************************************************/
953-
954-
void counter_update(byte index)
955-
{
956-
// char log[LOGSZ];
957-
958-
unsigned long pTime = millis() - pTimeLast[index -1];
959-
if (pTime > sysCfg.pCounterDebounce) {
960-
pTimeLast[index -1] = millis();
961-
if (bitRead(sysCfg.pCounterType, index -1)) {
962-
rtcMem.pCounter[index -1] = pTime;
963-
} else {
964-
rtcMem.pCounter[index -1]++;
965-
}
966-
967-
// snprintf_P(log, sizeof(log), PSTR("CNTR: Interrupt %d"), index);
968-
// addLog(LOG_LEVEL_DEBUG, log);
969-
}
970-
}
971-
972-
void counter_update1()
973-
{
974-
counter_update(1);
975-
}
976-
977-
void counter_update2()
978-
{
979-
counter_update(2);
980-
}
981-
982-
void counter_update3()
983-
{
984-
counter_update(3);
985-
}
986-
987-
void counter_update4()
988-
{
989-
counter_update(4);
990-
}
991-
992-
void counter_savestate()
993-
{
994-
for (byte i = 0; i < 4; i++) {
995-
if (pin[GPIO_CNTR1 +i] < 99) {
996-
sysCfg.pCounter[i] = rtcMem.pCounter[i];
997-
}
998-
}
999-
}
1000-
1001-
void counter_init()
1002-
{
1003-
typedef void (*function) () ;
1004-
function counter_callbacks[] = { counter_update1, counter_update2, counter_update3, counter_update4 };
1005-
1006-
for (byte i = 0; i < 4; i++) {
1007-
if (pin[GPIO_CNTR1 +i] < 99) {
1008-
pinMode(pin[GPIO_CNTR1 +i], INPUT_PULLUP);
1009-
attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], FALLING);
1010-
}
1011-
}
1012-
}
1013-
1014950
/*********************************************************************************************\
1015951
* Miscellaneous
1016952
\*********************************************************************************************/

sonoff/webserver.ino

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ const char HTTP_TABLE100[] PROGMEM =
250250
"<table style='width:100%'>";
251251
const char HTTP_COUNTER[] PROGMEM =
252252
"<br/><div id='t' name='t' style='text-align:center;'></div>";
253-
const char HTTP_SNS_COUNTER[] PROGMEM =
254-
"<tr><th>Counter%d</th><td>%s%s</td></tr>";
255253
const char HTTP_SNS_TEMP[] PROGMEM =
256254
"<tr><th>%s Temperature</th><td>%s&deg;%c</td></tr>";
257255
const char HTTP_SNS_HUM[] PROGMEM =
@@ -450,7 +448,6 @@ void handleRoot()
450448
void handleAjax2()
451449
{
452450
char svalue[16];
453-
char sensor[80];
454451

455452
if (strlen(webServer->arg("o").c_str())) {
456453
do_cmnd_power(atoi(webServer->arg("o").c_str()), 2);
@@ -461,17 +458,7 @@ void handleAjax2()
461458
}
462459

463460
String tpage = "";
464-
for (byte i = 0; i < 4; i++) {
465-
if (pin[GPIO_CNTR1 +i] < 99) {
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;
473-
}
474-
}
461+
tpage += counter_webPresent();
475462
if (hlw_flg) {
476463
tpage += hlw_webPresent();
477464
}

sonoff/xdrv_domoticz.ino

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#ifdef USE_DOMOTICZ
2121

22-
#define DOMOTICZ_MAX_SENSORS 5
22+
#define DOMOTICZ_MAX_SENSORS 6
2323

2424
#ifdef USE_WEBSERVER
2525
const char HTTP_FORM_DOMOTICZ[] PROGMEM =
@@ -40,7 +40,7 @@ const char HTTP_FORM_DOMOTICZ_TIMER[] PROGMEM =
4040
#endif // USE_WEBSERVER
4141

4242
const char domoticz_sensors[DOMOTICZ_MAX_SENSORS][14] PROGMEM =
43-
{ "Temp", "Temp,Hum", "Temp,Hum,Baro", "Power,Energy", "Illuminance" };
43+
{ "Temp", "Temp,Hum", "Temp,Hum,Baro", "Power,Energy", "Illuminance", "Count" };
4444

4545
boolean domoticz_subscribe = false;
4646
int domoticz_update_timer = 0;
@@ -329,6 +329,13 @@ void domoticz_sensor5(uint16_t lux)
329329
dom_sensor(4, data);
330330
}
331331

332+
void domoticz_sensor6(uint32_t count)
333+
{
334+
char data[16];
335+
snprintf_P(data, sizeof(data), PSTR("%d"), count);
336+
dom_sensor(5, data);
337+
}
338+
332339
/*********************************************************************************************\
333340
* Presentation
334341
\*********************************************************************************************/
@@ -400,10 +407,11 @@ void domoticz_saveSettings()
400407
sysCfg.domoticz_relay_idx[0], sysCfg.domoticz_relay_idx[1], sysCfg.domoticz_relay_idx[2], sysCfg.domoticz_relay_idx[3],
401408
sysCfg.domoticz_update_timer);
402409
addLog(LOG_LEVEL_INFO, log);
403-
snprintf_P(log, sizeof(log), PSTR("HTTP: key %d, %d, %d, %d, switch %d, %d, %d, %d, sensor %d, %d, %d, %d, %d"),
410+
snprintf_P(log, sizeof(log), PSTR("HTTP: key %d, %d, %d, %d, switch %d, %d, %d, %d, sensor %d, %d, %d, %d, %d, %d"),
404411
sysCfg.domoticz_key_idx[0], sysCfg.domoticz_key_idx[1], sysCfg.domoticz_key_idx[2], sysCfg.domoticz_key_idx[3],
405412
sysCfg.domoticz_switch_idx[0], sysCfg.domoticz_switch_idx[1], sysCfg.domoticz_switch_idx[2], sysCfg.domoticz_switch_idx[3],
406-
sysCfg.domoticz_sensor_idx[0], sysCfg.domoticz_sensor_idx[1], sysCfg.domoticz_sensor_idx[2], sysCfg.domoticz_sensor_idx[3], sysCfg.domoticz_sensor_idx[4]);
413+
sysCfg.domoticz_sensor_idx[0], sysCfg.domoticz_sensor_idx[1], sysCfg.domoticz_sensor_idx[2], sysCfg.domoticz_sensor_idx[3],
414+
sysCfg.domoticz_sensor_idx[4], sysCfg.domoticz_sensor_idx[5]);
407415
addLog(LOG_LEVEL_INFO, log);
408416
}
409417
#endif // USE_WEBSERVER

0 commit comments

Comments
 (0)