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)
This commit is contained in:
arendst 2017-03-14 12:36:06 +01:00
parent b85fef0479
commit 18a1f5e5df
7 changed files with 96 additions and 38 deletions

View File

@ -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```.

Binary file not shown.

View File

@ -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)

View File

@ -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

View File

@ -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};
@ -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};
@ -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);
}
}
@ -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]) {
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);
@ -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;

View File

@ -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 };
@ -117,7 +118,7 @@ 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];
@ -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 // ADC or Vcc
},
{ "Sonoff RF", // Sonoff RF (ESP8266)
GPIO_KEY1, // GPIO00 Button
@ -160,7 +162,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,
0 // ADC or Vcc
},
{ "Sonoff SV", // Sonoff SV (ESP8266)
GPIO_KEY1, // GPIO00 Button
@ -173,7 +176,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 // ADC or Vcc
},
{ "Sonoff TH", // Sonoff TH10/16 (ESP8266)
GPIO_KEY1, // GPIO00 Button
@ -186,7 +190,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,
0 // ADC or Vcc
},
{ "Sonoff Dual", // Sonoff Dual (ESP8266)
0,
@ -198,7 +203,8 @@ 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 // ADC or Vcc
},
{ "Sonoff Pow", // Sonoff Pow (ESP8266)
GPIO_KEY1, // GPIO00 Button
@ -209,7 +215,8 @@ 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 // ADC or Vcc
},
{ "Sonoff 4CH", // Sonoff 4CH (ESP8285)
GPIO_KEY1, // GPIO00 Button 1
@ -226,7 +233,8 @@ 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 // ADC or Vcc
},
{ "S20 Socket", // S20 Smart Socket (ESP8266)
GPIO_KEY1, // GPIO00 Button
@ -234,7 +242,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
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 // ADC or Vcc
},
{ "Slampher", // Slampher (ESP8266)
GPIO_KEY1, // GPIO00 Button
@ -242,7 +251,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
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 // ADC or Vcc
},
{ "Sonoff Touch", // Sonoff Touch (ESP8285)
GPIO_KEY1, // GPIO00 Button
@ -251,7 +261,8 @@ 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 // ADC or Vcc
},
{ "Sonoff LED", // Sonoff LED (ESP8266)
GPIO_KEY1, // GPIO00 Button
@ -263,7 +274,8 @@ 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 // ADC or Vcc
},
{ "1 Channel", // 1 Channel Inching/Latching Relay using (PSA-B01 - ESP8266)
GPIO_KEY1, // GPIO00 Button
@ -271,7 +283,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
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 // ADC or Vcc
},
{ "4 Channel", // 4 Channel Inching/Latching Relays
0,
@ -282,7 +295,8 @@ 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 // ADC or Vcc
},
{ "Motor C/AC", // Motor Clockwise / Anti clockwise (PSA-B01 - ESP8266)
GPIO_KEY1, // GPIO00 Button
@ -290,7 +304,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
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 // ADC or Vcc
},
{ "ElectroDragon", // ElectroDragon IoT Relay Board (ESP8266)
GPIO_KEY2, // GPIO00 Button 2
@ -304,7 +319,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 // ADC or Vcc
},
{ "EXS Relay", // Latching relay https://ex-store.de/ESP8266-WiFi-Relay-V31 (ESP8266)
// Module Pin 1 VCC 3V3, Module Pin 6 GND
@ -319,7 +335,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 // ADC or Vcc
},
{ "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)
@ -331,7 +348,8 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_KEY1, // GPIO13 Button
0,
GPIO_REL1, // GPIO15 Relay (0 = Off, 1 = On)
0
0,
0 // ADC or Vcc
},
{ "WeMos D1 mini", // WeMos and NodeMCU hardware (ESP8266)
GPIO_USER, // GPIO00 D3 Wemos Button Shield
@ -345,7 +363,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 // ADC or Vcc
}
};

View File

@ -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 ADC input use 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 //