Skip to content

Commit

Permalink
v5.8.0b - Add Domoticz Voltage and Current
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
arendst committed Sep 26, 2017
1 parent 5d9dab9 commit e974dcb
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 53 deletions.
2 changes: 1 addition & 1 deletion 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

Expand Down
10 changes: 8 additions & 2 deletions 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
Expand Down
3 changes: 3 additions & 0 deletions sonoff/language/en-GB.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions sonoff/language/nl-NL.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down
39 changes: 24 additions & 15 deletions sonoff/sonoff.ino
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
}

Expand Down
1 change: 1 addition & 0 deletions sonoff/support.ino
Expand Up @@ -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));
Expand Down
6 changes: 4 additions & 2 deletions sonoff/webserver.ino
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 15 additions & 16 deletions sonoff/xdrv_domoticz.ino
Expand Up @@ -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 =
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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];
Expand All @@ -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
\*********************************************************************************************/
Expand Down Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions sonoff/xdrv_wemohue.ino
Expand Up @@ -475,7 +475,7 @@ void hue_global_cfg(String *path)
{
String response;

path->remove(0,1); // cut leading / to get <id>
path->remove(0,1); // cut leading / to get <id>
response = F("{\"lights\":{\"");
for (uint8_t i = 1; i <= Maxdevice; i++) {
response += i;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 += ",";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_ds18b20.ino
Expand Up @@ -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
}
}
Expand Down
4 changes: 3 additions & 1 deletion sonoff/xsns_ds18x20.ino
Expand Up @@ -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
}
}
Expand Down
4 changes: 3 additions & 1 deletion sonoff/xsns_hlw8012.ino
Expand Up @@ -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
}
Expand Down

0 comments on commit e974dcb

Please sign in to comment.