Skip to content

Commit

Permalink
v3.9.11
Browse files Browse the repository at this point in the history
3.9.11 20170204
* Fix command I2Cscan
* Fix not allowed spaces in Topic, ButtonTopic and SwitchTopic
* Make all TELEMETRY, STATUS and COMMAND message topics unique (arendst#4)
* Advertise command topic to be used by iobroker (arendst#299)
* Fix butten (non)detection if no GPIO_KEY1 is defined (arendst#13)
* Change WeMo serialnumber from 7 decimal chars to 8 hexadecimal chars
(arendst#18)
* Update web page with Build Date/Time, Emulation and mDNS Discovery and
Advertise information (arendst#21)
  • Loading branch information
arendst committed Feb 4, 2017
1 parent e3b40ee commit 4ac7488
Show file tree
Hide file tree
Showing 18 changed files with 417 additions and 206 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 **3.9.7** - See ```sonoff/_releasenotes.ino``` for change information.
Current version is **3.9.11** - See ```sonoff/_releasenotes.ino``` for change information.

- This version provides all (Sonoff) modules in one file and starts up with Sonoff Basic.
- Once uploaded select module using the configuration webpage or the commands ```Modules``` and ```Module```.
Expand All @@ -11,7 +11,7 @@ Current version is **3.9.7** - See ```sonoff/_releasenotes.ino``` for change inf
See [Wiki](https://github.com/arendst/Sonoff-Tasmota/wiki) for more information.<br />
See [Community](https://groups.google.com/d/forum/sonoffusers) for forum and more user experience.

Starting with version 2.0.0 the following devices are supported:
The following devices are supported:
- [iTead Sonoff Basic](http://sonoff.itead.cc/en/products/sonoff/sonoff-basic)
- [iTead Sonoff RF](http://sonoff.itead.cc/en/products/sonoff/sonoff-rf)
- [iTead Sonoff SV](https://www.itead.cc/sonoff-sv.html)
Expand Down
Binary file modified api/arduino/sonoff.ino.bin
Binary file not shown.
22 changes: 21 additions & 1 deletion sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
/* 3.9.7 20170129
/* 3.9.11 20170204
* Fix command I2Cscan
* Fix not allowed spaces in Topic, ButtonTopic and SwitchTopic
* Make all TELEMETRY, STATUS and COMMAND message topics unique (#4)
* Advertise command topic to be used by iobroker (#299)
* Fix butten (non)detection if no GPIO_KEY1 is defined (#13)
* Change WeMo serialnumber from 7 decimal chars to 8 hexadecimal chars (#18)
* Update web page with Build Date/Time, Emulation and mDNS Discovery and Advertise information (#21)
*
* 3.9.10 20170130
* Add WS2812 Color Type selection (RGB or GRB) to user_config.h (#7)
* Hue api changes to support HUE App(s) (#8)
*
* 3.9.9 20170130
* Add command status 10 showing sensor data
* Fix hlw status messages if hlw is disabled
*
* 3.9.8 20170130
* Remove GPIO07 and GPIO08 from user selectable (#5)
*
* 3.9.7 20170129
* Fix possible WS2812 exceptions when using emulation
* Add command Emulation to dynamic configure Belkin WeMo and Hue Bridge for Alexa
*
Expand Down
223 changes: 121 additions & 102 deletions sonoff/sonoff.ino

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions sonoff/sonoff_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,10 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_KEY1, // GPIO00 Button 1
0,
GPIO_USER, // GPIO02 Optional sensor
0,
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
GPIO_REL3, // GPIO04 Sonoff 4CH Red Led and Relay 3 (0 = Off, 1 = On)
GPIO_REL2, // GPIO05 Sonoff 4CH Red Led and Relay 2 (0 = Off, 1 = On)
0,
GPIO_USER, // GPIO07 Optional sensor
GPIO_USER, // GPIO08 Optional sensor
0, 0, 0,
GPIO_KEY2, // GPIO09 Button 2
GPIO_KEY3, // GPIO10 Button 3
0,
Expand Down Expand Up @@ -235,7 +233,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
},
{ "User Test", // Sonoff Basic User Test
GPIO_KEY1, // GPIO00 Button
0, 0,
0,
GPIO_USER, // GPIO02 Optional sensor
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
GPIO_USER, // GPIO04 Optional sensor
0, 0, 0, 0, 0, 0, 0,
Expand Down
1 change: 1 addition & 0 deletions sonoff/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
#define USE_HTU // Add I2C code for HTU21 sensor

#define USE_WS2812 // WS2812 Led string support (+8k code, +1k mem)
#define USE_WS2812_CTYPE 1 // WS2812 Color type (0 - RGB, 1 - GRB)
// #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial TXD) (+1k mem)
// When USE_WS2812_DMA is enabled expect Exceptions on Pow

Expand Down
254 changes: 196 additions & 58 deletions sonoff/webserver.ino

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sonoff/xdrv_domoticz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ boolean domoticz_command(char *type, uint16_t index, char *dataBuf, uint16_t dat

void domoticz_commands(char *svalue, uint16_t ssvalue)
{
snprintf_P(svalue, ssvalue, PSTR("{\"Commands\":\"DomoticzInTopic, DomoticzOutTopic, DomoticzIdx, DomoticzKeyIdx, DomoticzSwitchIdx, DomoticzSensorIdx, DomoticzUpdateTimer\"}"));
snprintf_P(svalue, ssvalue, PSTR("{\"Commands4\":\"DomoticzInTopic, DomoticzOutTopic, DomoticzIdx, DomoticzKeyIdx, DomoticzSwitchIdx, DomoticzSensorIdx, DomoticzUpdateTimer\"}"));
}

boolean domoticz_button(byte key, byte device, byte state, byte svalflg)
Expand Down
11 changes: 5 additions & 6 deletions sonoff/xdrv_wemohue.ino
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ const char WEMO_MSEARCH[] PROGMEM =

String wemo_serial()
{
char serial[15];
snprintf_P(serial, sizeof(serial), PSTR("201612K%07d"), ESP.getChipId());
char serial[16];
snprintf_P(serial, sizeof(serial), PSTR("201612K%08X"), ESP.getChipId());
return String(serial);
}

String wemo_UUID()
{
char uuid[26];
char uuid[27];
snprintf_P(uuid, sizeof(uuid), PSTR("Socket-1_0-%s"), wemo_serial().c_str());
return String(uuid);
}
Expand Down Expand Up @@ -138,7 +138,6 @@ void hue_respondToMSearch()
response.replace("{r3}", hue_UUID());
portUDP.write(response.c_str());
portUDP.endPacket();
snprintf_P(message, sizeof(message), PSTR("Response1 sent"));
// addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());

response = FPSTR(HUE_RESPONSE);
Expand All @@ -150,7 +149,6 @@ void hue_respondToMSearch()
response.replace("{r3}", hue_UUID());
portUDP.write(response.c_str());
portUDP.endPacket();
snprintf_P(message, sizeof(message), PSTR("Response2 sent"));
// addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());

response = FPSTR(HUE_RESPONSE);
Expand All @@ -161,7 +159,8 @@ void hue_respondToMSearch()
response.replace("{r3}", hue_UUID());
portUDP.write(response.c_str());
portUDP.endPacket();
snprintf_P(message, sizeof(message), PSTR("Response3 sent"));

snprintf_P(message, sizeof(message), PSTR("3 response packets sent"));
// addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());

} else {
Expand Down
20 changes: 18 additions & 2 deletions sonoff/xdrv_ws2812.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ POSSIBILITY OF SUCH DAMAGE.
#include <NeoPixelBus.h>

#ifdef USE_WS2812_DMA
#if (USE_WS2812_CTYPE == 1)
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> *strip = NULL;
#else
#else // USE_WS2812_CTYPE
NeoPixelBus<NeoRgbFeature, Neo800KbpsMethod> *strip = NULL;
#endif // USE_WS2812_CTYPE
#else // USE_WS2812_DMA
#if (USE_WS2812_CTYPE == 1)
NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> *strip = NULL;
#else // USE_WS2812_CTYPE
NeoPixelBus<NeoRgbFeature, NeoEsp8266BitBang800KbpsMethod> *strip = NULL;
#endif // USE_WS2812_CTYPE
#endif // USE_WS2812_DMA

#define COLOR_SATURATION 254.0f
Expand Down Expand Up @@ -457,9 +465,17 @@ void ws2812_pixels()
void ws2812_init()
{
#ifdef USE_WS2812_DMA
#if (USE_WS2812_CTYPE == 1)
strip = new NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>(WS2812_MAX_LEDS); // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
#else
#else // USE_WS2812_CTYPE
strip = new NeoPixelBus<NeoRgbFeature, Neo800KbpsMethod>(WS2812_MAX_LEDS); // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
#endif // USE_WS2812_CTYPE
#else // USE_WS2812_DMA
#if (USE_WS2812_CTYPE == 1)
strip = new NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod>(WS2812_MAX_LEDS, pin[GPIO_WS2812]);
#else // USE_WS2812_CTYPE
strip = new NeoPixelBus<NeoRgbFeature, NeoEsp8266BitBang800KbpsMethod>(WS2812_MAX_LEDS, pin[GPIO_WS2812]);
#endif // USE_WS2812_CTYPE
#endif // USE_WS2812_DMA
strip->Begin();
ws2812_pixels();
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_bh1750.ino
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ boolean bh1750_detect()
* Presentation
\*********************************************************************************************/

void bh1750_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx)
void bh1750_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
{
if (!bh1750type) return;

Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_bmp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ boolean bmp_detect()
* Presentation
\*********************************************************************************************/

void bmp_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx)
void bmp_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
{
if (!bmptype) return;

Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_dht.ino
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void dht_init()
* Presentation
\*********************************************************************************************/

void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx)
void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
{
char stemp1[10], stemp2[10];
float t, h;
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_dht2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void dht_init()
* Presentation
\*********************************************************************************************/

void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx)
void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
{
char stemp1[10], stemp2[10];
float t, h;
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_ds18b20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ boolean dsb_readTemp(bool S, float &t)
* Presentation
\*********************************************************************************************/

void dsb_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx)
void dsb_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
{
char stemp1[10];
float t;
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_ds18x20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ boolean ds18x20_read(uint8_t sensor, bool S, float &t)
* Presentation
\*********************************************************************************************/

void ds18x20_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx)
void ds18x20_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
{
char stemp1[10], stemp2[10];
float t;
Expand Down
63 changes: 41 additions & 22 deletions sonoff/xsns_hlw8012.ino
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void hlw_setPowerSteadyCounter(byte value)

void hlw_margin_chk()
{
char log[LOGSZ], stopic[TOPSZ], svalue[MESSZ];
char log[LOGSZ], svalue[MESSZ];
float ped, pi, pc;
uint16_t uped, piv, pe, pw, pu;
byte flag, jsonflg;
Expand All @@ -296,7 +296,6 @@ void hlw_margin_chk()
// snprintf_P(log, sizeof(log), PSTR("HLW: W %d, U %d, I %d"), pw, pu, piv);
// addLog(LOG_LEVEL_DEBUG, log);

snprintf_P(stopic, sizeof(stopic), PSTR("%s/%s/TELEMETRY"), PUB_PREFIX2, sysCfg.mqtt_topic);
snprintf_P(svalue, sizeof(svalue), PSTR("{"));
jsonflg = 0;
if (hlw_margin(0, sysCfg.hlw_pmin, pw, flag, hlw_pminflg)) {
Expand Down Expand Up @@ -325,12 +324,11 @@ void hlw_margin_chk()
}
if (jsonflg) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s}"), svalue);
mqtt_publish(stopic, svalue);
mqtt_publish_topic_P(1, PSTR("MARGINS"), svalue);
}
}

#if FEATURE_POWER_LIMIT
snprintf_P(stopic, sizeof(stopic), PSTR("%s/%s/RESULT"), PUB_PREFIX, sysCfg.mqtt_topic);
// Max Power
if (sysCfg.hlw_mpl) {
if (pw > sysCfg.hlw_mpl) {
Expand All @@ -340,7 +338,7 @@ void hlw_margin_chk()
hlw_mplh_counter--;
if (!hlw_mplh_counter) {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"MaxPowerReached\":\"%d%s\"}"), pw, (sysCfg.value_units) ? " W" : "");
mqtt_publish(stopic, svalue);
mqtt_publish_topic_P(0, PSTR("WARNING"), svalue);
do_cmnd_power(1, 0);
if (!hlw_mplr_counter) hlw_mplr_counter = MAX_POWER_RETRY +1;
hlw_mplw_counter = sysCfg.hlw_mplw;
Expand All @@ -359,12 +357,12 @@ void hlw_margin_chk()
if (hlw_mplr_counter) {
hlw_mplr_counter--;
if (hlw_mplr_counter) {
snprintf_P(svalue, sizeof(stopic), PSTR("{\"PowerMonitor\":\"%s\"}"), MQTT_STATUS_ON);
mqtt_publish(stopic, svalue);
snprintf_P(svalue, sizeof(svalue), PSTR("{\"PowerMonitor\":\"%s\"}"), MQTT_STATUS_ON);
mqtt_publish_topic_P(0, PSTR("RESULT"), svalue);
do_cmnd_power(1, 1);
} else {
snprintf_P(svalue, sizeof(stopic), PSTR("{\"MaxPowerReachedRetry\":\"%s\"}"), MQTT_STATUS_OFF);
mqtt_publish(stopic, svalue);
snprintf_P(svalue, sizeof(svalue), PSTR("{\"MaxPowerReachedRetry\":\"%s\"}"), MQTT_STATUS_OFF);
mqtt_publish_topic_P(0, PSTR("WARNING"), svalue);
}
}
}
Expand All @@ -376,15 +374,15 @@ void hlw_margin_chk()
uped = (uint16_t)(ped * 1000);
if (!hlw_mkwh_state && (rtcTime.Hour == sysCfg.hlw_mkwhs)) {
hlw_mkwh_state = 1;
snprintf_P(svalue, sizeof(stopic), PSTR("{\"EnergyMonitor\":\"%s\"}"), MQTT_STATUS_ON);
mqtt_publish(stopic, svalue);
snprintf_P(svalue, sizeof(svalue), PSTR("{\"EnergyMonitor\":\"%s\"}"), MQTT_STATUS_ON);
mqtt_publish_topic_P(0, PSTR("RESULT"), svalue);
do_cmnd_power(1, 1);
}
else if ((hlw_mkwh_state == 1) && (uped >= sysCfg.hlw_mkwh)) {
hlw_mkwh_state = 2;
dtostrf(ped, 1, 3, svalue);
snprintf_P(svalue, sizeof(svalue), PSTR("{\"MaxEnergyReached\":\"%s%s\"}"), svalue, (sysCfg.value_units) ? " kWh" : "");
mqtt_publish(stopic, svalue);
mqtt_publish_topic_P(0, PSTR("WARNING"), svalue);
do_cmnd_power(1, 0);
}
}
Expand Down Expand Up @@ -512,37 +510,58 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len

void hlw_commands(char *svalue, uint16_t ssvalue)
{
snprintf_P(svalue, ssvalue, PSTR("{\"Commands\":\"PowerLow, PowerHigh, VoltageLow, VoltageHigh, CurrentLow, CurrentHigh, HlwPcal, HlwUcal, HlwIcal%s\"}"),
snprintf_P(svalue, ssvalue, PSTR("{\"Commands5\":\"PowerLow, PowerHigh, VoltageLow, VoltageHigh, CurrentLow, CurrentHigh, HlwPcal, HlwUcal, HlwIcal%s\"}"),
(FEATURE_POWER_LIMIT)?", SafePower, SafePowerHold, SafePowerWindow, MaxPower, MaxPowerHold, MaxPowerWindow, MaxEnergy, MaxEnergyStart":"");
}

/*********************************************************************************************\
* Presentation
\*********************************************************************************************/

void hlw_mqttPresent(uint8_t domidx)
void hlw_mqttStat(byte option, char* svalue, uint16_t ssvalue)
{
char stopic[TOPSZ], svalue[MESSZ], stime[21], stemp0[10], stemp1[10], stemp2[10], stemp3[10];
char stemp0[10], stemp1[10], stemp2[10], stemp3[10], speriod[20];
float ped, pi, pc;
uint16_t pe, pw, pu;

snprintf_P(stime, sizeof(stime), PSTR("%04d-%02d-%02dT%02d:%02d:%02d"),
rtcTime.Year, rtcTime.Month, rtcTime.Day, rtcTime.Hour, rtcTime.Minute, rtcTime.Second);
hlw_readEnergy(1, ped, pe, pw, pu, pi, pc);
hlw_readEnergy(option, ped, pe, pw, pu, pi, pc);
dtostrf((float)sysCfg.hlw_kWhyesterday / 100000000, 1, 3, stemp0);
dtostrf(ped, 1, 3, stemp1);
dtostrf(pc, 1, 2, stemp2);
dtostrf(pi, 1, 3, stemp3);
snprintf_P(stopic, sizeof(stopic), PSTR("%s/%s/TELEMETRY"), PUB_PREFIX2, sysCfg.mqtt_topic);
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Time\":\"%s\", \"Energy\":{\"Yesterday\":\"%s\", \"Today\":\"%s\", \"Period\":%d, \"Power\":%d, \"Factor\":\"%s\", \"Voltage\":%d, \"Current\":\"%s\"}}"),
stime, stemp0, stemp1, pe, pw, stemp2, pu, stemp3);
mqtt_publish(stopic, svalue);
snprintf_P(speriod, sizeof(speriod), PSTR(", \"Period\":%d"), pe);
snprintf_P(svalue, ssvalue, PSTR("%s\"Yesterday\":\"%s\", \"Today\":\"%s\"%s, \"Power\":%d, \"Factor\":\"%s\", \"Voltage\":%d, \"Current\":\"%s\"}"),
svalue, stemp0, stemp1, (option) ? speriod : "", pw, stemp2, pu, stemp3);
#ifdef USE_DOMOTICZ
dtostrf(ped * 1000, 1, 1, stemp1);
domoticz_sensor4(pw, stemp1);
#endif // USE_DOMOTICZ
}

void hlw_mqttPresent()
{
// char stopic[TOPSZ], svalue[MESSZ], stime[21];
char svalue[MESSZ], stime[21];

snprintf_P(stime, sizeof(stime), PSTR("%04d-%02d-%02dT%02d:%02d:%02d"),
rtcTime.Year, rtcTime.Month, rtcTime.Day, rtcTime.Hour, rtcTime.Minute, rtcTime.Second);
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Time\":\"%s\", "), stime);
hlw_mqttStat(1, svalue, sizeof(svalue));

// snprintf_P(stopic, sizeof(stopic), PSTR("%s/%s/ENERGY"), PUB_PREFIX2, sysCfg.mqtt_topic);
// mqtt_publish(stopic, svalue);

mqtt_publish_topic_P(1, PSTR("ENERGY"), svalue);

}

void hlw_mqttStatus(char* svalue, uint16_t ssvalue)
{
snprintf_P(svalue, ssvalue, PSTR("{\"StatusPWR\":{"));
hlw_mqttStat(0, svalue, ssvalue);
snprintf_P(svalue, ssvalue, PSTR("%s}"), svalue);
}

#ifdef USE_WEBSERVER
String hlw_webPresent()
{
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_htu21.ino
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ uint8_t htu_detect()
* Presentation
\*********************************************************************************************/

void htu_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx)
void htu_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
{
if (!htutype) return;

Expand Down

0 comments on commit 4ac7488

Please sign in to comment.