Skip to content

Commit

Permalink
v4.0.1
Browse files Browse the repository at this point in the history
4.0.1 20170305
* Fix char default sizes and set MESSZ to 360 (#143)
* Fix SerialLog setting status
* Disable syslog when emulation is active
* Add DS18B20 web page display refresh
  • Loading branch information
arendst committed Mar 5, 2017
1 parent acb5252 commit 47d711b
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 52 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.0** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
Current version is **4.0.1** - 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 added api/arduino/sonoff-minimal.ino.bin
Binary file not shown.
Binary file modified api/arduino/sonoff.ino.bin
Binary file not shown.
8 changes: 7 additions & 1 deletion sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/* 4.0.0 20170303
/* 4.0.1 20170305
* Fix char default sizes and set MESSZ to 360 (#143)
* Fix SerialLog setting status
* Disable syslog when emulation is active
* Add DS18B20 web page display refresh
*
* 4.0.0 20170303
* Add define to remove config migration code for versions below 3.0 (See Wiki-Upgrade-Migration path)
* Free memory by switching from String to char[]
* Raised Sonoff Led PWM frequency from 200Hz to 432Hz in search of stability (hardware watchdog timeouts) (#122)
Expand Down
51 changes: 24 additions & 27 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 0x03091700 // 3.9.23
#define VERSION 0x03091800 // 3.9.24
#else
#define VERSION 0x04000000 // 4.0.0
#define VERSION 0x04000100 // 4.0.1
#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 All @@ -36,8 +36,6 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};
\*********************************************************************************************/

//#define USE_SPIFFS // Switch persistent configuration from flash to spiffs (+24k code, +0.6k mem)
//#define BE_MINIMAL // Compile a minimal version if upgrade memory gets tight (-45k code, -2k mem)
// To be used as step 1. Next step is compile and use desired version

/*********************************************************************************************\
* No user configurable items below
Expand All @@ -52,9 +50,9 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};
//#define DEBUG_THEO // Add debug code

#ifdef BE_MINIMAL
//#ifdef USE_MQTT_TLS
//#undef USE_MQTT_TLS // Disable TLS support won't work as the MQTTHost is not set
//#endif
#ifdef USE_MQTT_TLS
#undef USE_MQTT_TLS // Disable TLS support won't work as the MQTTHost is not set
#endif
#ifdef USE_DISCOVERY
#undef USE_DISCOVERY // Disable Discovery services for both MQTT and web server
#endif
Expand Down Expand Up @@ -145,10 +143,10 @@ enum butt_t {PRESSED, NOT_PRESSED};
#include "support.h" // Global support
#include <PubSubClient.h> // MQTT

#define MESSZ 352 // Max number of characters in JSON message string
#if (MQTT_MAX_PACKET_SIZE -TOPSZ -60 -40) < MESSZ // If the max message size is too small, throw an error at compile time
// 60 bytes for the IPv4 TCP header, 40 bytes to keep the original 400/240 headroom
#error "MQTT_MAX_PACKET_SIZE is too small in libraries/PubSubClient/src/PubSubClient.h, increase it to at least 512"
#define MESSZ 360 // Max number of characters in JSON message string (4 x DS18x20 sensors)
#if (MQTT_MAX_PACKET_SIZE -TOPSZ -7) < MESSZ // If the max message size is too small, throw an error at compile time
// See pubsubclient.c line 359
#error "MQTT_MAX_PACKET_SIZE is too small in libraries/PubSubClient/src/PubSubClient.h, increase it to at least 427"
#endif

#include <Ticker.h> // RTC
Expand Down Expand Up @@ -415,7 +413,7 @@ void json2legacy(char* stopic, char* svalue)

void mqtt_publish_sec(const char* topic, const char* data, boolean retained)
{
char log[TOPSZ+MESSZ];
char log[TOPSZ + MESSZ];

if (sysCfg.mqtt_enabled) {
if (mqttClient.publish(topic, data, retained)) {
Expand Down Expand Up @@ -459,7 +457,7 @@ void mqtt_publish_topic_P(uint8_t prefix, const char* subtopic, const char* data

void mqtt_publishPowerState(byte device)
{
char stopic[TOPSZ], svalue[MESSZ], sdevice[10];
char stopic[TOPSZ], sdevice[10], svalue[64]; // was MESSZ

if ((device < 1) || (device > Maxdevice)) device = 1;
snprintf_P(sdevice, sizeof(sdevice), PSTR("%d"), device);
Expand All @@ -473,7 +471,7 @@ void mqtt_publishPowerState(byte device)

void mqtt_publishPowerBlinkState(byte device)
{
char svalue[MESSZ], sdevice[10];
char sdevice[10], svalue[64]; // was MESSZ

if ((device < 1) || (device > Maxdevice)) device = 1;
snprintf_P(sdevice, sizeof(sdevice), PSTR("%d"), device);
Expand All @@ -484,7 +482,7 @@ void mqtt_publishPowerBlinkState(byte device)

void mqtt_connected()
{
char stopic[TOPSZ], svalue[MESSZ];
char stopic[TOPSZ], svalue[128]; // was MESSZ

if (sysCfg.mqtt_enabled) {

Expand Down Expand Up @@ -596,7 +594,6 @@ void mqtt_reconnect()
void mqttDataCb(char* topic, byte* data, unsigned int data_len)
{
char *str;
char svalue[MESSZ];

if (!strcmp(SUB_PREFIX,PUB_PREFIX)) {
str = strstr(topic,SUB_PREFIX);
Expand All @@ -606,10 +603,10 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
}
}

uint16_t i = 0, grpflg = 0, index;
char topicBuf[TOPSZ], dataBuf[data_len+1], dataBufUc[MESSZ];
char topicBuf[TOPSZ], dataBuf[data_len+1], dataBufUc[128], svalue[MESSZ];
char *p, *mtopic = NULL, *type = NULL;
char stemp1[TOPSZ], stemp2[10];
uint16_t i = 0, grpflg = 0, index;

strncpy(topicBuf, topic, sizeof(topicBuf));
memcpy(dataBuf, data, sizeof(dataBuf));
Expand Down Expand Up @@ -823,19 +820,16 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
sysCfg.seriallog_level = payload;
seriallog_level = payload;
seriallog_timer = 0;
snprintf_P(svalue, sizeof(svalue), PSTR("{\"SerialLog\":%d}"), sysCfg.syslog_level);
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"SerialLog\":\"%d (Setting %d)\"}"), seriallog_level, sysCfg.seriallog_level);
snprintf_P(svalue, sizeof(svalue), PSTR("{\"SerialLog\":\"%d (Active %d)\"}"), sysCfg.seriallog_level, seriallog_level);
}
else if (!strcmp(type,"SYSLOG")) {
if ((data_len > 0) && (payload >= LOG_LEVEL_NONE) && (payload <= LOG_LEVEL_ALL)) {
sysCfg.syslog_level = payload;
syslog_level = payload;
syslog_level = (sysCfg.emulation) ? 0 : payload;
syslog_timer = 0;
snprintf_P(svalue, sizeof(svalue), PSTR("{\"SysLog\":%d}"), sysCfg.syslog_level);
} else {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"SysLog\":\"%d (Setting %d)\"}"), syslog_level, sysCfg.syslog_level);
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"SysLog\":\"%d (Active %d)\"}"), sysCfg.syslog_level, syslog_level);
}
else if (!strcmp(type,"LOGHOST")) {
if ((data_len > 0) && (data_len < sizeof(sysCfg.syslog_host))) {
Expand Down Expand Up @@ -1507,7 +1501,7 @@ void every_second()
if (syslog_timer) { // Restore syslog level
syslog_timer--;
if (!syslog_timer) {
syslog_level = sysCfg.syslog_level;
syslog_level = (sysCfg.emulation) ? 0 : sysCfg.syslog_level;
if (sysCfg.syslog_level) {
addLog_P(LOG_LEVEL_INFO, PSTR("SYSL: Syslog logging re-enabled")); // Might trigger disable again (on purpose)
}
Expand Down Expand Up @@ -1591,7 +1585,7 @@ void every_second()
void stateloop()
{
uint8_t button = NOT_PRESSED, flag, switchflag, power_now;
char scmnd[20], log[LOGSZ], svalue[MESSZ];
char scmnd[20], log[LOGSZ], svalue[80]; // was MESSZ

timerxs = millis() + (1000 / STATES);
state++;
Expand Down Expand Up @@ -2038,7 +2032,10 @@ void setup()
savedatacounter = sysCfg.savedata;
seriallog_timer = SERIALLOG_TIMER;
seriallog_level = sysCfg.seriallog_level;
syslog_level = sysCfg.syslog_level;
#ifndef USE_EMULATION
sysCfg.emulation = 0;
#endif // USE_EMULATION
syslog_level = (sysCfg.emulation) ? 0 : sysCfg.syslog_level;
sleep = sysCfg.sleep;

GPIO_init();
Expand Down
5 changes: 3 additions & 2 deletions sonoff/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ void rtc_init(rtcCallback cb)

void syslog(const char *message)
{
char str[TOPSZ+MESSZ];
char str[TOPSZ + MESSZ];

if (portUDP.beginPacket(sysCfg.syslog_host, sysCfg.syslog_port)) {
snprintf_P(str, sizeof(str), PSTR("%s ESP-%s"), Hostname, message);
Expand Down Expand Up @@ -835,12 +835,13 @@ void addLog(byte loglevel, const char *line)
if (logidx > MAX_LOG_LINES -1) logidx = 0;
}
#endif // USE_WEBSERVER
// if (sysCfg.emulation) return; // Disable syslog (UDP) when emulation using UDP is selected
if ((WiFi.status() == WL_CONNECTED) && (loglevel <= syslog_level)) syslog(line);
}

void addLog_P(byte loglevel, const char *formatP)
{
char mess[MESSZ];
char mess[LOGSZ]; // was MESSZ

snprintf_P(mess, sizeof(mess), formatP);
addLog(loglevel, mess);
Expand Down
11 changes: 10 additions & 1 deletion sonoff/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
#define ENERGY_RESOLUTION 3 // Maximum number of decimals (0 - 5) showing energy usage in kWh

// -- Sensor code selection -----------------------
//#define USE_DS18x20 // Optional using OneWire library for multiple DS18B20 and/or DS18S20
//#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 //
#define USE_BH1750 // Add I2C code for BH1750 sensor
Expand All @@ -140,6 +140,15 @@
// #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial TXD) (+1k mem)
// When USE_WS2812_DMA is enabled expect Exceptions on Pow

/*********************************************************************************************\
* Compile a minimal version if upgrade memory gets tight.
* To be used as step 1 during upgrade.
* Step 2 is re-compile with option BE_MINIMAL commented out.
* !!! Needed for next release of Arduino/ESP8266 (+22k code, +2k mem) !!!
\*********************************************************************************************/

//#define BE_MINIMAL // Minimal version if upgrade memory gets tight (-45k code, -2k mem)

/*********************************************************************************************\
* No user configurable items below
\*********************************************************************************************/
Expand Down
14 changes: 5 additions & 9 deletions sonoff/webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,7 @@ void handleAjax2()
if (pin[GPIO_DSB] < 99) tpage += dsb_webPresent();
#endif // USE_DS18B20
#ifdef USE_DS18x20
if (pin[GPIO_DSB] < 99) {
tpage += ds18x20_webPresent();
ds18x20_search(); // Check for changes in sensors number
ds18x20_convert(); // Start Conversion, takes up to one second
}
if (pin[GPIO_DSB] < 99) tpage += ds18x20_webPresent();
#endif // USE_DS18x20
#ifdef USE_DHT
if (dht_type) tpage += dht_webPresent();
Expand Down Expand Up @@ -874,7 +870,7 @@ void handleReset()
{
if (httpUser()) return;

char svalue[MESSZ];
char svalue[16]; // was MESSZ

addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Reset parameters"));

Expand Down Expand Up @@ -923,7 +919,7 @@ void handleUpgrade()
void handleUpgradeStart()
{
if (httpUser()) return;
char svalue[MESSZ];
char svalue[16]; // was MESSZ

addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Firmware upgrade start"));
WIFI_configCounter();
Expand Down Expand Up @@ -1097,7 +1093,7 @@ void handleUploadLoop()
void handleCmnd()
{
if (httpUser()) return;
char svalue[MESSZ];
char svalue[128]; // was MESSZ

addLog_P(LOG_LEVEL_DEBUG, PSTR("HTTP: Handle cmnd"));

Expand Down Expand Up @@ -1166,7 +1162,7 @@ void handleConsole()
void handleAjax()
{
if (httpUser()) return;
char svalue[MESSZ], log[LOGSZ];
char log[LOGSZ], svalue[128]; // was MESSZ
byte cflg = 1, counter = 99;

if (strlen(webServer->arg("c1").c_str())) {
Expand Down
4 changes: 2 additions & 2 deletions sonoff/xdrv_domoticz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ byte domoticz_update_flag = 1;

void mqtt_publishDomoticzPowerState(byte device)
{
char svalue[MESSZ];
char svalue[64]; // was MESSZ

if (sysCfg.domoticz_relay_idx[device -1] && (strlen(sysCfg.domoticz_in_topic) != 0)) {
if ((device < 1) || (device > Maxdevice)) device = 1;
Expand Down Expand Up @@ -236,7 +236,7 @@ void domoticz_commands(char *svalue, uint16_t ssvalue)
boolean domoticz_button(byte key, byte device, byte state, byte svalflg)
{
if ((sysCfg.domoticz_key_idx[device -1] || sysCfg.domoticz_switch_idx[device -1]) && (svalflg)) {
char svalue[MESSZ];
char svalue[80]; // was MESSZ

snprintf_P(svalue, sizeof(svalue), PSTR("{\"command\":\"switchlight\",\"idx\":%d,\"switchcmd\":\"%s\"}"),
(key) ? sysCfg.domoticz_switch_idx[device -1] : sysCfg.domoticz_key_idx[device -1], (state) ? (state == 2) ? "Toggle" : "On" : "Off");
Expand Down
3 changes: 2 additions & 1 deletion sonoff/xdrv_snfled.ino
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ void sl_setPower(uint8_t power)

void sl_animate()
{
char svalue[MESSZ];
// {"Wakeup":"Done"}
char svalue[32]; // was MESSZ
uint8_t fadeValue;

if ((sl_power == 0) || sl_blankv) { // Power Off
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_dht.ino
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ String dht_webPresent()
float t, h;

if (dht_readTempHum(TEMP_CONVERSION, t, h)) { // Read temperature as Celsius (the default)
char stemp[10], sensor[128];
char stemp[10], sensor[80];
dtostrf(t, 1, TEMP_RESOLUTION &3, stemp);
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, dhtstype, stemp, (TEMP_CONVERSION) ? 'F' : 'C');
page += sensor;
Expand Down
16 changes: 12 additions & 4 deletions sonoff/xsns_ds18b20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ POSSIBILITY OF SUCH DAMAGE.
* Source: Marinus vd Broek https://github.com/ESP8266nu/ESPEasy and AlexTransit (CRC)
\*********************************************************************************************/

float dsb_mt = 0;

uint8_t dsb_reset()
{
uint8_t r;
Expand Down Expand Up @@ -131,11 +133,15 @@ boolean dsb_readTemp(bool S, float &t)
int16_t DSTemp;
byte msb, lsb, crc;

t = NAN;
if (!dsb_mt) {
t = NAN;
} else {
t = dsb_mt;
}

if (!dsb_read_bit()) { //check measurement end
addLog_P(LOG_LEVEL_DEBUG, PSTR("DSB: Sensor busy"));
return false;
return !isnan(t);
}
/*
dsb_reset();
Expand Down Expand Up @@ -165,6 +171,7 @@ boolean dsb_readTemp(bool S, float &t)
t = (float(DSTemp) * 0.0625);
if(S) t = dsb_convertCtoF(t);
}
if (!isnan(t)) dsb_mt = t;
return !isnan(t);
}

Expand All @@ -177,7 +184,7 @@ void dsb_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
char stemp1[10];
float t;

if (dsb_readTemp(TEMP_CONVERSION, t)) { // Check if read failed
if (dsb_readTemp(TEMP_CONVERSION, t)) { // Check if read failed
dtostrf(t, 1, TEMP_RESOLUTION &3, stemp1);
snprintf_P(svalue, ssvalue, PSTR("%s, \"DS18B20\":{\"Temperature\":%s}"), svalue, stemp1);
*djson = 1;
Expand All @@ -194,12 +201,13 @@ String dsb_webPresent()
String page = "";
float st;

if (dsb_readTemp(TEMP_CONVERSION, st)) { // Check if read failed
if (dsb_readTemp(TEMP_CONVERSION, st)) { // Check if read failed
char stemp[10], sensor[80];
dtostrf(st, 1, TEMP_RESOLUTION &3, stemp);
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, "DS18B20", stemp, (TEMP_CONVERSION) ? 'F' : 'C');
page += sensor;
}
dsb_readTempPrep();
return page;
}
#endif // USE_WEBSERVER
Expand Down
2 changes: 2 additions & 0 deletions sonoff/xsns_ds18x20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ String ds18x20_webPresent()
page += sensor;
}
}
ds18x20_search(); // Check for changes in sensors number
ds18x20_convert(); // Start Conversion, takes up to one second
return page;
}
#endif // USE_WEBSERVER
Expand Down
Loading

0 comments on commit 47d711b

Please sign in to comment.