diff --git a/README.md b/README.md index 7773a5c9b..7607d23af 100644 --- a/README.md +++ b/README.md @@ -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.8.0a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.8.0b** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### ATTENTION All versions diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 8e54a7f4f..9163b9267 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,8 +1,14 @@ -/* 5.8.0a +/* 5.8.0b + * Fix command FullTopic entry when using serial or console interface + * Fix possible UDP syslog blocking + * Add debug information to MQTT subscribe + * Add Domoticz sensors for Voltage and Current (#903) + * + * 5.8.0a * Add translations to I2Cscan * Add translation to BH1750 unit lx * Set default WS2812 pixel count to WS2812_LEDS - * Fix GPIOx JSON response (#897) + * Fix command GPIOx JSON response (#897) * * 5.8.0 20170918 * Remove the need for NeoPixelBus library for Hue support diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index 9663b3cc9..d67a6e346 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -163,6 +163,7 @@ #define D_STOP "Stop" #define D_SUBNET_MASK "Subnet Mask" #define D_SUBNETMASK "Subnetmask" +#define D_SUBSCRIBE_TO "Subscribe to" #define D_SUCCESSFUL "Successful" #define D_SWITCH "Switch" #define D_SYNC "Sync" @@ -373,6 +374,8 @@ #define D_DOMOTICZ_POWER_ENERGY "Power,Energy" #define D_DOMOTICZ_ILLUMINANCE "Illuminance" #define D_DOMOTICZ_COUNT "Count" + #define D_DOMOTICZ_VOLTAGE "Voltage" + #define D_DOMOTICZ_CURRENT "Current" #define D_DOMOTICZ_UPDATE_TIMER "Update timer" #define D_CONFIGURE_DOMOTICZ "Configure Domoticz" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index 8e66c1eb4..3c7ef9d92 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -163,6 +163,7 @@ #define D_STOP "Stop" #define D_SUBNET_MASK "Subnet Masker" #define D_SUBNETMASK "Subnetmasker" +#define D_SUBSCRIBE_TO "Abonneer op" #define D_SUCCESSFUL "Gelukt" #define D_SWITCH "Schakelaar" #define D_SYNC "Sync" @@ -373,6 +374,8 @@ #define D_DOMOTICZ_POWER_ENERGY "Power,Energy" #define D_DOMOTICZ_ILLUMINANCE "Illuminance" #define D_DOMOTICZ_COUNT "Count" + #define D_DOMOTICZ_VOLTAGE "Spanning" + #define D_DOMOTICZ_CURRENT "Stroom" #define D_DOMOTICZ_UPDATE_TIMER "Bijwerk timer" #define D_CONFIGURE_DOMOTICZ "Configureer Domoticz" diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 66a516547..9d9d9666d 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,16 +25,16 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x05080001 // 5.8.0a +#define VERSION 0x05080002 // 5.8.0b -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}; enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat}; enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}; -enum wifi_t {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION}; -enum swtch_t {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, MAX_SWITCH_OPTION}; -enum led_t {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION}; -enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX}; +enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; // SerialLog, Syslog, Weblog +enum wifi_t {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION}; // WifiConfig +enum swtch_t {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, MAX_SWITCH_OPTION}; // SwitchMode +enum led_t {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION}; // LedState +enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX}; // Emulation #include "user_config.h" #include "user_config_override.h" @@ -73,7 +73,10 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX}; #undef USE_DS18x20 // Disable DS18x20 sensor #endif #ifdef USE_I2C -#undef USE_I2C // Disable all I2C sensors +#undef USE_I2C // Disable all I2C sensors and devices +#endif +#ifdef USE_SPI +#undef USE_SPI // Disable all SPI devices #endif #ifdef USE_WS2812 #undef USE_WS2812 // Disable WS2812 Led string @@ -445,6 +448,14 @@ void setLed(uint8_t state) /********************************************************************************************/ +void mqtt_subscribe(char *topic) +{ + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MQTT D_SUBSCRIBE_TO " %s"), topic); + addLog(LOG_LEVEL_DEBUG); + mqttClient.subscribe(topic); + mqttClient.loop(); // Solve LmacRxBlk:1 messages +} + void mqtt_publish_sec(const char* topic, boolean retained) { if (sysCfg.flag.mqtt_enabled) { @@ -550,17 +561,14 @@ void mqtt_connected() mqtt_publish_topic_P(0, S_RSLT_POWER); getTopic_P(stopic, 0, sysCfg.mqtt_topic, PSTR("#")); - mqttClient.subscribe(stopic); - mqttClient.loop(); // Solve LmacRxBlk:1 messages + mqtt_subscribe(stopic); if (strstr(sysCfg.mqtt_fulltopic, MQTT_TOKEN_TOPIC) != NULL) { getTopic_P(stopic, 0, sysCfg.mqtt_grptopic, PSTR("#")); - mqttClient.subscribe(stopic); - mqttClient.loop(); // Solve LmacRxBlk:1 messages + mqtt_subscribe(stopic); fallbacktopic = 1; getTopic_P(stopic, 0, MQTTClient, PSTR("#")); fallbacktopic = 0; - mqttClient.subscribe(stopic); - mqttClient.loop(); // Solve LmacRxBlk:1 messages + mqtt_subscribe(stopic); } #ifdef USE_DOMOTICZ domoticz_mqttSubscribe(); @@ -1450,7 +1458,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len) } #ifdef USE_EMULATION else if (!strcasecmp_P(type, PSTR(D_CMND_EMULATION))) { - if ((payload >= 0) && (payload <= 2)) { + if ((payload >= EMUL_NONE) && (payload < EMUL_MAX)) { sysCfg.flag.emulation = payload; restartflag = 2; } @@ -1732,7 +1740,8 @@ void do_cmnd(char *cmnd) } snprintf_P(stopic, sizeof(stopic), PSTR("/%s"), (token == NULL) ? "" : token); token = strtok(NULL, ""); - snprintf_P(svalue, sizeof(svalue), (token == NULL) ? "" : token); +// snprintf_P(svalue, sizeof(svalue), (token == NULL) ? "" : token); // Fails with command FullTopic home/%prefix%/%topic% as it processes %p of %prefix% + strlcpy(svalue, (token == NULL) ? "" : token, sizeof(svalue)); // Fixed 5.8.0b mqttDataCb(stopic, (byte*)svalue, strlen(svalue)); } diff --git a/sonoff/support.ino b/sonoff/support.ino index 4e13a20c8..f9269de89 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1153,6 +1153,7 @@ void syslog() // Destroys log_data char syslog_preamble[64]; // Hostname + Id + yield(); // Fix possible UDP syslog blocking if (portUDP.beginPacket(sysCfg.syslog_host, sysCfg.syslog_port)) { snprintf_P(syslog_preamble, sizeof(syslog_preamble), PSTR("%s ESP-"), Hostname); memmove(log_data + strlen(syslog_preamble), log_data, sizeof(log_data) - strlen(syslog_preamble)); diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index 1873cd6bc..630513dd6 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -1349,7 +1349,8 @@ void handleCmnd() if (valid) { byte curridx = logidx; if (strlen(webServer->arg("cmnd").c_str())) { - snprintf_P(svalue, sizeof(svalue), webServer->arg("cmnd").c_str()); +// snprintf_P(svalue, sizeof(svalue), webServer->arg("cmnd").c_str()); // Processes FullTopic %p + strlcpy(svalue, webServer->arg("cmnd").c_str(), sizeof(svalue)); // Fixed 5.8.0b // byte syslog_now = syslog_level; // syslog_level = 0; // Disable UDP syslog to not trigger hardware WDT - Seems to work fine since 5.7.1d (global logging) do_cmnd(svalue); @@ -1413,7 +1414,8 @@ void handleAjax() byte counter = 99; if (strlen(webServer->arg("c1").c_str())) { - snprintf_P(svalue, sizeof(svalue), webServer->arg("c1").c_str()); +// snprintf_P(svalue, sizeof(svalue), webServer->arg("c1").c_str()); // Processes FullTopic %p + strlcpy(svalue, webServer->arg("c1").c_str(), sizeof(svalue)); // Fixed 5.8.0b snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), svalue); addLog(LOG_LEVEL_INFO); // byte syslog_now = syslog_level; diff --git a/sonoff/xdrv_domoticz.ino b/sonoff/xdrv_domoticz.ino index ffc1d5a2e..fcd514673 100644 --- a/sonoff/xdrv_domoticz.ino +++ b/sonoff/xdrv_domoticz.ino @@ -19,7 +19,7 @@ #ifdef USE_DOMOTICZ -#define DOMOTICZ_MAX_SENSORS 6 +#define DOMOTICZ_MAX_SENSORS 8 #ifdef USE_WEBSERVER const char HTTP_FORM_DOMOTICZ[] PROGMEM = @@ -38,7 +38,7 @@ const char HTTP_FORM_DOMOTICZ_TIMER[] PROGMEM = #endif // USE_WEBSERVER const char domoticz_sensors[DOMOTICZ_MAX_SENSORS][DOMOTICZ_SENSORS_MAX_STRING_LENGTH] PROGMEM = - { D_DOMOTICZ_TEMP, D_DOMOTICZ_TEMP_HUM, D_DOMOTICZ_TEMP_HUM_BARO, D_DOMOTICZ_POWER_ENERGY, D_DOMOTICZ_ILLUMINANCE, D_DOMOTICZ_COUNT }; + { D_DOMOTICZ_TEMP, D_DOMOTICZ_TEMP_HUM, D_DOMOTICZ_TEMP_HUM_BARO, D_DOMOTICZ_POWER_ENERGY, D_DOMOTICZ_ILLUMINANCE, D_DOMOTICZ_COUNT, D_DOMOTICZ_VOLTAGE, D_DOMOTICZ_CURRENT }; char domoticz_in_topic[] = DOMOTICZ_IN_TOPIC; char domoticz_out_topic[] = DOMOTICZ_OUT_TOPIC; @@ -100,8 +100,7 @@ void domoticz_mqttSubscribe() if (domoticz_subscribe) { char stopic[TOPSZ]; snprintf_P(stopic, sizeof(stopic), PSTR("%s/#"), domoticz_out_topic); // domoticz topic - mqttClient.subscribe(stopic); - mqttClient.loop(); // Solve LmacRxBlk:1 messages + mqtt_subscribe(stopic); } } @@ -259,7 +258,7 @@ uint8_t dom_hum_stat(char *hum) return (!h) ? 0 : (h < 40) ? 2 : (h > 70) ? 3 : 1; } -void dom_sensor(byte idx, char *data) +void domoticz_sensor(byte idx, char *data) { if (sysCfg.domoticz_sensor_idx[idx]) { char dmess[64]; @@ -272,46 +271,46 @@ void dom_sensor(byte idx, char *data) } } -void domoticz_sensor1(char *temp) -{ - dom_sensor(0, temp); -} +// domoticz_sensor(0, temp); void domoticz_sensor2(char *temp, char *hum) { char data[16]; snprintf_P(data, sizeof(data), PSTR("%s;%s;%d"), temp, hum, dom_hum_stat(hum)); - dom_sensor(1, data); + domoticz_sensor(1, data); } void domoticz_sensor3(char *temp, char *hum, char *baro) { char data[32]; snprintf_P(data, sizeof(data), PSTR("%s;%s;%d;%s;5"), temp, hum, dom_hum_stat(hum), baro); - dom_sensor(2, data); + domoticz_sensor(2, data); } void domoticz_sensor4(uint16_t power, char *energy) { char data[16]; snprintf_P(data, sizeof(data), PSTR("%d;%s"), power, energy); - dom_sensor(3, data); + domoticz_sensor(3, data); } void domoticz_sensor5(uint16_t lux) { char data[8]; snprintf_P(data, sizeof(data), PSTR("%d"), lux); - dom_sensor(4, data); + domoticz_sensor(4, data); } void domoticz_sensor6(uint32_t count) { char data[16]; snprintf_P(data, sizeof(data), PSTR("%d"), count); - dom_sensor(5, data); + domoticz_sensor(5, data); } +// domoticz_sensor(6, voltage); +// domoticz_sensor(7, current); + /*********************************************************************************************\ * Presentation \*********************************************************************************************/ @@ -380,11 +379,11 @@ void domoticz_saveSettings() sysCfg.domoticz_relay_idx[0], sysCfg.domoticz_relay_idx[1], sysCfg.domoticz_relay_idx[2], sysCfg.domoticz_relay_idx[3], sysCfg.domoticz_update_timer); addLog(LOG_LEVEL_INFO); - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_CMND_KEYIDX " %d, %d, %d, %d, " D_CMND_SWITCHIDX " %d, %d, %d, %d, " D_CMND_SENSORIDX " %d, %d, %d, %d, %d, %d"), + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_CMND_KEYIDX " %d, %d, %d, %d, " D_CMND_SWITCHIDX " %d, %d, %d, %d, " D_CMND_SENSORIDX " %d, %d, %d, %d, %d, %d, %d, %d"), sysCfg.domoticz_key_idx[0], sysCfg.domoticz_key_idx[1], sysCfg.domoticz_key_idx[2], sysCfg.domoticz_key_idx[3], sysCfg.domoticz_switch_idx[0], sysCfg.domoticz_switch_idx[1], sysCfg.domoticz_switch_idx[2], sysCfg.domoticz_switch_idx[3], 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], sysCfg.domoticz_sensor_idx[5]); + sysCfg.domoticz_sensor_idx[4], sysCfg.domoticz_sensor_idx[5], sysCfg.domoticz_sensor_idx[6], sysCfg.domoticz_sensor_idx[7]); addLog(LOG_LEVEL_INFO); } #endif // USE_WEBSERVER diff --git a/sonoff/xdrv_wemohue.ino b/sonoff/xdrv_wemohue.ino index 8500f28dc..140303c5e 100755 --- a/sonoff/xdrv_wemohue.ino +++ b/sonoff/xdrv_wemohue.ino @@ -475,7 +475,7 @@ void hue_global_cfg(String *path) { String response; - path->remove(0,1); // cut leading / to get + path->remove(0,1); // cut leading / to get response = F("{\"lights\":{\""); for (uint8_t i = 1; i <= Maxdevice; i++) { response += i; @@ -521,8 +521,8 @@ void hue_lights(String *path) bool change = false; char id[4]; - path->remove(0,path->indexOf("/lights")); // Remove until /lights - if (path->endsWith("/lights")) { // Got /lights + path->remove(0,path->indexOf("/lights")); // Remove until /lights + if (path->endsWith("/lights")) { // Got /lights response = "{\""; for (uint8_t i = 1; i <= Maxdevice; i++) { response += i; @@ -539,9 +539,9 @@ void hue_lights(String *path) response += "}"; webServer->send(200, FPSTR(HDR_CTYPE_JSON), response); } - else if (path->endsWith("/state")) { // Got ID/state - path->remove(0,8); // Remove /lights/ - path->remove(path->indexOf("/state")); // Remove /state + else if (path->endsWith("/state")) { // Got ID/state + path->remove(0,8); // Remove /lights/ + path->remove(path->indexOf("/state")); // Remove /state device = atoi(path->c_str()); if ((device < 1) || (device > Maxdevice)) { device = 1; @@ -614,7 +614,7 @@ void hue_lights(String *path) response.replace("{res}", String(tmp)); change = true; } - if (hue_json.containsKey("ct")) { // Color temperature 153 (Cold) to 500 (Warm) + if (hue_json.containsKey("ct")) { // Color temperature 153 (Cold) to 500 (Warm) ct = hue_json["ct"]; if (resp) { response += ","; @@ -642,8 +642,8 @@ void hue_lights(String *path) webServer->send(200, FPSTR(HDR_CTYPE_JSON), response); } - else if(path->indexOf("/lights/") >= 0) { // Got /lights/ID - path->remove(0,8); // Remove /lights/ + else if(path->indexOf("/lights/") >= 0) { // Got /lights/ID + path->remove(0,8); // Remove /lights/ device = atoi(path->c_str()); if ((device < 1) || (device > Maxdevice)) { device = 1; @@ -696,16 +696,16 @@ void handle_hue_api(String *path) path->remove(0, 4); // remove /api uint16_t apilen = path->length(); snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_HUE_API " (%s)"), path->c_str()); - addLog(LOG_LEVEL_DEBUG_MORE); + addLog(LOG_LEVEL_DEBUG_MORE); // HTP: Hue API (//lights/1/state) for (args = 0; args < webServer->args(); args++) { String json = webServer->arg(args); snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_HUE_POST_ARGS " (%s)"), json.c_str()); - addLog(LOG_LEVEL_DEBUG_MORE); + addLog(LOG_LEVEL_DEBUG_MORE); // HTP: Hue POST args ({"on":false}) } - if (path->endsWith("/invalid/")) {} // Just ignore - else if (!apilen) hue_auth(path); // New HUE App setup - else if (path->endsWith("/")) hue_auth(path); // New HUE App setup + if (path->endsWith("/invalid/")) {} // Just ignore + else if (!apilen) hue_auth(path); // New HUE App setup + else if (path->endsWith("/")) hue_auth(path); // New HUE App setup else if (path->endsWith("/config")) hue_config(path); else if (path->indexOf("/lights") >= 0) hue_lights(path); else if (path->indexOf("/groups") >= 0) hue_groups(path); diff --git a/sonoff/xsns_ds18b20.ino b/sonoff/xsns_ds18b20.ino index 5940dfdbd..d8f41b205 100644 --- a/sonoff/xsns_ds18b20.ino +++ b/sonoff/xsns_ds18b20.ino @@ -195,7 +195,7 @@ void dsb_mqttPresent(uint8_t* djson) snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"DS18B20\":{\"" D_TEMPERATURE "\":%s}"), mqtt_data, stemp1); *djson = 1; #ifdef USE_DOMOTICZ - domoticz_sensor1(stemp1); + domoticz_sensor(0, stemp1); #endif // USE_DOMOTICZ } } diff --git a/sonoff/xsns_ds18x20.ino b/sonoff/xsns_ds18x20.ino index 3e20ecef3..4c50359e7 100644 --- a/sonoff/xsns_ds18x20.ino +++ b/sonoff/xsns_ds18x20.ino @@ -201,7 +201,9 @@ void ds18x20_mqttPresent(uint8_t* djson) mqtt_data, stemp1, i +1, dsbstype, ds18x20_address(i).c_str(), stemp2); strcpy(stemp1, ", "); #ifdef USE_DOMOTICZ - if (1 == dsxflg) domoticz_sensor1(stemp2); + if (1 == dsxflg) { + domoticz_sensor(0, stemp2); + } #endif // USE_DOMOTICZ } } diff --git a/sonoff/xsns_hlw8012.ino b/sonoff/xsns_hlw8012.ino index cf3f494e6..604dcf483 100644 --- a/sonoff/xsns_hlw8012.ino +++ b/sonoff/xsns_hlw8012.ino @@ -653,7 +653,9 @@ void hlw_mqttStat(byte option) #ifdef USE_DOMOTICZ if (option) { // Only send if telemetry dtostrfd(pet * 1000, 1, spet); - domoticz_sensor4((uint16_t)pw, spet); + domoticz_sensor4((uint16_t)pw, spet); // PowerUsage, EnergyToday + domoticz_sensor(6, spu); // Voltage + domoticz_sensor(7, spi); // Current } #endif // USE_DOMOTICZ }