Skip to content

Commit

Permalink
v4.0.5
Browse files Browse the repository at this point in the history
4.0.5 20170314
* Add command Status 11 to show power status with Vcc if define
USE_ADC_VCC is enabled (default)
* Add ADC input to Sonoff SV and Wemos D1 mini - Needs recompile with
define USE_ADC_VCC disabled (#137)
* Add MQTT host:port to timeout message (#199)
  • Loading branch information
arendst committed Mar 14, 2017
1 parent 5e4157e commit 67fe118
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 39 deletions.
2 changes: 1 addition & 1 deletion 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 **4.0.4** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
Current version is **4.0.5** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/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 Down
Binary file modified api/arduino/sonoff.ino.bin
Binary file not shown.
7 changes: 6 additions & 1 deletion sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/* 4.0.4 20170312
/* 4.0.5 20170314
* Add command Status 11 to show power status with Vcc if define USE_ADC_VCC is enabled (default)
* Add ADC input to Sonoff SV and Wemos D1 mini - Needs recompile with define USE_ADC_VCC disabled (#137)
* Add MQTT host:port to timeout message (#199)
*
* 4.0.4 20170312
* Add pulse timers for up to 4 relays (#106)
* Fix Sonoff Led power state when dimmer or color is 0 (#176)
* Add command NtpServer<x> to configure up to three NTP servers (#177)
Expand Down
5 changes: 5 additions & 0 deletions sonoff/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,8 @@ struct RTCMEM {
unsigned long hlw_kWhtoday;
} rtcMem;

// See issue https://github.com/esp8266/Arduino/issues/2913
#ifdef USE_ADC_VCC
ADC_MODE(ADC_VCC); // Set ADC input for Power Supply Voltage usage
#endif

4 changes: 4 additions & 0 deletions sonoff/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@ void CFG_Delta()
if (sysCfg.version < 0x04000400) {
CFG_DefaultSet_4_0_4();
}
if (sysCfg.version < 0x04000500) {
memmove(sysCfg.my_module.gp.io, sysCfg.my_module.gp.io +1, MAX_GPIO_PIN -1); // move myio 1 byte to front
sysCfg.my_module.gp.io[MAX_GPIO_PIN -1] = 0; // Clear ADC0
}
sysCfg.version = VERSION;
}
}
Expand Down
61 changes: 44 additions & 17 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

//#define ALLOW_MIGRATE_TO_V3
#ifdef ALLOW_MIGRATE_TO_V3
#define VERSION 0x03091B00 // 3.9.27
#define VERSION 0x03091C00 // 3.9.28
#else
#define VERSION 0x04000400 // 4.0.4
#define VERSION 0x04000500 // 4.0.5
#endif // ALLOW_MIGRATE_TO_V3

enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
Expand Down Expand Up @@ -136,7 +136,7 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};
#endif

#define APP_BAUDRATE 115200 // Default serial baudrate
#define MAX_STATUS 10 // Max number of status lines
#define MAX_STATUS 11 // Max number of status lines

enum butt_t {PRESSED, NOT_PRESSED};

Expand Down Expand Up @@ -584,8 +584,9 @@ void mqtt_reconnect()
mqtt_publish(stopic, svalue, true);
mqtt_connected();
} else {
snprintf_P(log, sizeof(log), PSTR("MQTT: CONNECT FAILED, rc %d. Retry in %d seconds"), mqttClient.state(), mqttcounter);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log, sizeof(log), PSTR("MQTT: Connect FAILED to %s:%d, rc %d. Retry in %d seconds"),
sysCfg.mqtt_host, sysCfg.mqtt_port, mqttClient.state(), mqttcounter); //status codes are documented here http://pubsubclient.knolleary.net/api.html#state
addLog(LOG_LEVEL_INFO, log);
}
}

Expand Down Expand Up @@ -1473,12 +1474,47 @@ void publish_status(uint8_t payload)
snprintf_P(svalue, sizeof(svalue), PSTR("%s}"), svalue);
mqtt_publish_topic_P(option, PSTR("STATUS10"), svalue);
}

if ((payload == 0) || (payload == 11)) {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"StatusPWR\":"));
state_mqttPresent(svalue, sizeof(svalue));
snprintf_P(svalue, sizeof(svalue), PSTR("%s}"), svalue);
mqtt_publish_topic_P(option, PSTR("STATUS11"), svalue);
}

}

void state_mqttPresent(char* svalue, uint16_t ssvalue)
{
char stemp1[8];

snprintf_P(svalue, ssvalue, PSTR("%s{\"Time\":\"%s\", \"Uptime\":%d"), svalue, getDateTime().c_str(), uptime);
#ifdef USE_ADC_VCC
dtostrf((double)ESP.getVcc()/1000, 1, 3, stemp1);
snprintf_P(svalue, ssvalue, PSTR("%s, \"Vcc\":%s"), svalue, stemp1);
#endif
for (byte i = 0; i < Maxdevice; i++) {
if (Maxdevice == 1) { // Legacy
snprintf_P(svalue, ssvalue, PSTR("%s, \"%s\":"), svalue, sysCfg.mqtt_subtopic);
} else {
snprintf_P(svalue, ssvalue, PSTR("%s, \"%s%d\":"), svalue, sysCfg.mqtt_subtopic, i +1);
}
snprintf_P(svalue, ssvalue, PSTR("%s\"%s\""), svalue, (power & (0x01 << i)) ? MQTT_STATUS_ON : MQTT_STATUS_OFF);
}
snprintf_P(svalue, ssvalue, PSTR("%s, \"Wifi\":{\"AP\":%d, \"SSID\":\"%s\", \"RSSI\":%d}}"),
svalue, sysCfg.sta_active +1, sysCfg.sta_ssid[sysCfg.sta_active], WIFI_getRSSIasQuality(WiFi.RSSI()));
}

void sensors_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
{
snprintf_P(svalue, ssvalue, PSTR("%s{\"Time\":\"%s\""), svalue, getDateTime().c_str());


#ifndef USE_ADC_VCC
if (pin[GPIO_ADC0] < 99) {
snprintf_P(svalue, ssvalue, PSTR("%s, \"AnalogInput0\":%d"), svalue, analogRead(A0));
*djson = 1;
}
#endif
if (pin[GPIO_DSB] < 99) {
#ifdef USE_DS18B20
dsb_mqttPresent(svalue, ssvalue, djson);
Expand Down Expand Up @@ -1584,17 +1620,8 @@ void every_second()
if (tele_period >= sysCfg.tele_period) {
tele_period = 0;

snprintf_P(svalue, sizeof(svalue), PSTR("{\"Time\":\"%s\", \"Uptime\":%d"), getDateTime().c_str(), uptime);
for (byte i = 0; i < Maxdevice; i++) {
if (Maxdevice == 1) { // Legacy
snprintf_P(svalue, sizeof(svalue), PSTR("%s, \"%s\":"), svalue, sysCfg.mqtt_subtopic);
} else {
snprintf_P(svalue, sizeof(svalue), PSTR("%s, \"%s%d\":"), svalue, sysCfg.mqtt_subtopic, i +1);
}
snprintf_P(svalue, sizeof(svalue), PSTR("%s\"%s\""), svalue, (power & (0x01 << i)) ? MQTT_STATUS_ON : MQTT_STATUS_OFF);
}
snprintf_P(svalue, sizeof(svalue), PSTR("%s, \"Wifi\":{\"AP\":%d, \"SSID\":\"%s\", \"RSSI\":%d}}"),
svalue, sysCfg.sta_active +1, sysCfg.sta_ssid[sysCfg.sta_active], WIFI_getRSSIasQuality(WiFi.RSSI()));
svalue[0] = '\0';
state_mqttPresent(svalue, sizeof(svalue));
mqtt_publish_topic_P(1, PSTR("STATE"), svalue);

uint8_t djson = 0;
Expand Down
46 changes: 26 additions & 20 deletions sonoff/sonoff_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ enum fpins_t {
GPIO_HLW_SEL, // HLW8012 Sel output (Sonoff Pow)
GPIO_HLW_CF1, // HLW8012 CF1 voltage / current (Sonoff Pow)
GPIO_HLW_CF, // HLW8012 CF power (Sonoff Pow)
GPIO_ADC0, // ADC
GPIO_USER, // User configurable
GPIO_MAX };

Expand Down Expand Up @@ -117,14 +118,14 @@ enum module_t {

/********************************************************************************************/

#define MAX_GPIO_PIN 17 // Number of supported GPIO
#define MAX_GPIO_PIN 18 // Number of supported GPIO

typedef struct MYIO {
uint8_t io[MAX_GPIO_PIN];
} myio;

typedef struct MYTMPLT {
char name[16];
char name[15];
myio gp;
} mytmplt;

Expand All @@ -147,7 +148,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
GPIO_USER, // GPIO14 Optional sensor
0, // GPIO15
0 // GPIO16
0, // GPIO16
0 // ADC0 Analog input
},
{ "Sonoff RF", // Sonoff RF (ESP8266)
GPIO_KEY1, // GPIO00 Button
Expand All @@ -160,7 +162,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
GPIO_USER, // GPIO14 Optional sensor
0, 0
0, 0, 0
},
{ "Sonoff SV", // Sonoff SV (ESP8266)
GPIO_KEY1, // GPIO00 Button
Expand All @@ -173,7 +175,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
GPIO_USER, // GPIO14 Optional sensor
0, 0
0, 0,
GPIO_ADC0 // ADC0 Analog input
},
{ "Sonoff TH", // Sonoff TH10/16 (ESP8266)
GPIO_KEY1, // GPIO00 Button
Expand All @@ -186,7 +189,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
GPIO_USER, // GPIO14 Optional sensor
0, 0
0, 0, 0
},
{ "Sonoff Dual", // Sonoff Dual (ESP8266)
0,
Expand All @@ -198,7 +201,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0, 0, 0, 0, // Flash connection
0,
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
0, 0, 0
0, 0, 0, 0
},
{ "Sonoff Pow", // Sonoff Pow (ESP8266)
GPIO_KEY1, // GPIO00 Button
Expand All @@ -209,7 +212,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_HLW_CF1, // GPIO13 HLW8012 CF1 voltage / current
GPIO_HLW_CF, // GPIO14 HLW8012 CF power
GPIO_LED1, // GPIO15 Green Led (0 = On, 1 = Off)
0
0, 0
},
{ "Sonoff 4CH", // Sonoff 4CH (ESP8285)
GPIO_KEY1, // GPIO00 Button 1
Expand All @@ -226,23 +229,23 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
GPIO_KEY4, // GPIO14 Button 4
GPIO_REL4, // GPIO15 Red Led and Relay 4 (0 = Off, 1 = On)
0
0, 0
},
{ "S20 Socket", // S20 Smart Socket (ESP8266)
GPIO_KEY1, // GPIO00 Button
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, // Flash connection
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
0, 0, 0
0, 0, 0, 0
},
{ "Slampher", // Slampher (ESP8266)
GPIO_KEY1, // GPIO00 Button
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, // Flash connection
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
0, 0, 0
0, 0, 0, 0
},
{ "Sonoff Touch", // Sonoff Touch (ESP8285)
GPIO_KEY1, // GPIO00 Button
Expand All @@ -251,7 +254,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0,
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
0, 0, 0
0, 0, 0, 0
},
{ "Sonoff LED", // Sonoff LED (ESP8266)
GPIO_KEY1, // GPIO00 Button
Expand All @@ -263,15 +266,15 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
GPIO_PWM1, // GPIO14 Warm light
GPIO_USER, // GPIO15 Optional sensor (PWM4 Blue)
0
0, 0
},
{ "1 Channel", // 1 Channel Inching/Latching Relay using (PSA-B01 - ESP8266)
GPIO_KEY1, // GPIO00 Button
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, // Flash connection
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
0, 0, 0
0, 0, 0, 0
},
{ "4 Channel", // 4 Channel Inching/Latching Relays
0,
Expand All @@ -282,15 +285,15 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
0, 0, 0, 0, 0, 0, // Flash connection
0,
GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off)
0, 0, 0
0, 0, 0, 0
},
{ "Motor C/AC", // Motor Clockwise / Anti clockwise (PSA-B01 - ESP8266)
GPIO_KEY1, // GPIO00 Button
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, // Flash connection
GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On)
GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off)
0, 0, 0
0, 0, 0, 0
},
{ "ElectroDragon", // ElectroDragon IoT Relay Board (ESP8266)
GPIO_KEY2, // GPIO00 Button 2
Expand All @@ -304,7 +307,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_REL1, // GPIO13 Red Led and Relay 1 (0 = Off, 1 = On)
GPIO_USER, // GPIO14 Optional sensor
GPIO_USER, // GPIO15 Optional sensor
GPIO_LED1 // GPIO16 Green/Blue Led (1 = On, 0 = Off)
GPIO_LED1, // GPIO16 Green/Blue Led (1 = On, 0 = Off)
0
},
{ "EXS Relay", // Latching relay https://ex-store.de/ESP8266-WiFi-Relay-V31 (ESP8266)
// Module Pin 1 VCC 3V3, Module Pin 6 GND
Expand All @@ -319,7 +323,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_REL2, // GPIO13 Relay1 ( 1 = On)
GPIO_USER, // GPIO14 Module Pin 5
0,
GPIO_USER // GPIO16 Module Pin 4
GPIO_USER, // GPIO16 Module Pin 4
0
},
{ "WiOn", // Indoor Tap https://www.amazon.com/gp/product/B00ZYLUBJU/ref=s9_acsd_al_bw_c_x_3_w (ESP8266)
GPIO_USER, // GPIO00 Optional sensor (pm clock)
Expand All @@ -331,7 +336,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_KEY1, // GPIO13 Button
0,
GPIO_REL1, // GPIO15 Relay (0 = Off, 1 = On)
0
0, 0
},
{ "WeMos D1 mini", // WeMos and NodeMCU hardware (ESP8266)
GPIO_USER, // GPIO00 D3 Wemos Button Shield
Expand All @@ -345,7 +350,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_USER, // GPIO13 D7
GPIO_USER, // GPIO14 D5
GPIO_USER, // GPIO15 D8
GPIO_USER // GPIO16 D0 Wemos Wake
GPIO_USER, // GPIO16 D0 Wemos Wake
GPIO_ADC0 // ADC0 A0 Analog input
}
};

2 changes: 2 additions & 0 deletions sonoff/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
#define ENERGY_RESOLUTION 3 // Maximum number of decimals (0 - 5) showing energy usage in kWh

// -- Sensor code selection -----------------------
#define USE_ADC_VCC // Display Vcc in Power status. Disable for use as Analog input on selected devices

//#define USE_DS18x20 // Optional using OneWire library for multiple DS18B20 and/or DS18S20 (+2k code)

#define USE_I2C // I2C using library wire (+10k code, 0.2k mem) - Disable by //
Expand Down

0 comments on commit 67fe118

Please sign in to comment.