Merge branch 'arendst/development' into development

This commit is contained in:
reloxx13 2018-05-02 23:06:39 +02:00
commit b8cba8e82b
22 changed files with 262 additions and 168 deletions

View File

@ -10,10 +10,10 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute!
[![GitHub stars](https://img.shields.io/github/stars/arendst/Sonoff-Tasmota.svg?style=social&label=Star)](https://github.com/arendst/Sonoff-Tasmota/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/arendst/Sonoff-Tasmota.svg?style=social&label=Fork)](https://github.com/arendst/Sonoff-Tasmota/network)
### Development:
### Development
[![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota)
Current version is **5.12.0m** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
Current version is **5.13.1a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
### Quick install
Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki.
@ -133,7 +133,7 @@ Different firmware images are released based on Features and Sensors selection g
|--------------------------------|--------|---------|---------|------|------------|
| ESP/Arduino lib v2.3.0 | 526k | 488k | 427k | 535k | 549k |
| ESP/Arduino lib v2.4.0 | 531k | 496k | 435k | 540k | 552k |
| ESP/Arduino lib v2.4.1 | 533k | 498k | 436k | 542k | 554k |
| ESP/Arduino lib v2.4.1 | 534k | 499k | 437k | 543k | 555k |
### Contribute
You can contribute to Sonoff-Tasmota by

View File

@ -62,15 +62,15 @@ monitor_baud = 115200
;upload_speed = 115200
upload_speed = 512000
upload_resetmethod = nodemcu
;upload_port = COM5
upload_port = COM5
; *** Upload file to OTA server using SCP
;upload_port = user@host:/path
;extra_scripts = pio/strip-floats.py, pio/sftp-uploader.py
; *** Upload file to OTA server using HTTP
upload_port = domus1:80/api/upload-arduino.php
extra_scripts = pio/strip-floats.py, pio/http-uploader.py
;upload_port = domus1:80/api/upload-arduino.php
;extra_scripts = pio/strip-floats.py, pio/http-uploader.py
; *********************************************************************

View File

@ -1,106 +1,57 @@
/* 5.12.0m
* Reinit timers to accomodate random window (#2447)
* Remove sonoff-xxl
* Add sonoff-classic, sonoff-allsensors and sonoff-knx
* Add some coloring to important web buttons
* Add define MQTT_TELE_RETAIN compile option default set to 0 (#1071)
* Add user selectable defines for Sunrise/set Dawn option (#2378)
* Add random window to timers (#2447)
* Add optional KNX IP Protocol Support (#2402)
* Add Greek language file (#2491)
* Add Bulgarian language file
* Add support for sensor HC-SR04 ultrasonic (#113, #1964, #2444)
* Add support for Sonoff Pow R2 (#2340)
* Add GPIO_User to GPIO02 for all Sonoff T1 (#2524)
* Fix compile error when using ESP/Arduino library v2.3.0 by reverting KNX async UDP library to default UDP library (#2488, #2492, #2493)
* Fix configuration filename truncation when it contains spaces (#2484, #2490)
/* 5.13.1a
* Change user_config.h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602)
*
* 5.12.0l
* Release rules up to 511 characters
* Prepare for feature release - call on translators to update their language files
* Add timer sunrise and sunset offset (#2378)
* Fix negative Latitude and Longitude value entry (#2461)
* Fix sunrise and sunset calculation (#2461)
* 5.13.1 20180501
* Fix JSON buffers size too small for execution in some situations (#2580)
* Add define MODULE for user selecting default model although it preferably should not be changed (#569, #2589)
* Fix configuration restore (#2591)
*
* 5.12.0k
* Prepare for simple rules of up to 255 characters by enlarging Settings area to now 2048 bytes
* Change Timer parameter name from Power to Action
* Add commands Publish, Rule, RuleTimer and Event. See Wiki about Rule restriction, usage and examples
* Fix freeing more code space when emulation is disabled (#1592)
* Fix update temperature on DS18x20 drivers (#2328)
* Fix compile error when not defined USE_TIMERS (#2400)
*
* 5.12.0j
* Add optional Sunrise and Sunset timers with commands Latitide and Longitude to be enabled with define USE_SUNRISE in user_config.h (#2317)
*
* 5.12.0i
* Add 16 timers using commands Timer and Timers (#1091)
* Add commands Timer 0 to clear timer and Timer 1..16 to copy timer
* Add optional Timer configuration webpage to be enabled in user_config.h with define USE_TIMERS_WEB
* Add hexadecimal Data entry to command IrSend using 0x notation (#1290, #2314)
* Add Domoticz Battery and RSSI Quality (#1604)
* Add Home Assistant MQTT Discovery for Buttons and change SetOption19 response (#2277)
* Add support for SGP30 gas and air quality sensor (#2307)
* Add multiple color entry support for command Led like Led2 120000 001200 000012 setting led2 as Red, Led3 as Green and Led4 as Blue (#2303)
* Add hexadecimal RGB color entry on RGBCW leds (#2304)
* 5.13.0 20180430
* Change platformio option sonoff-ds18x20 to sonoff-allsensors enabling ds18x20 and all other sensors in one image
* Change status display of Ssid and SetOption
* Change default option SetOption15 from 0 to 1 providing better initial PWM experience
* Change webpage parameter communication
* Change Timer parameter Device to more obvious Output
* Change max number of commands in Backlog from 15 to 30 and ignore commands overflowing
* Change TSL2561 driver to joba library and delete Adafruit library (#1644)
* Change default parameters in user_config.h to undefined for easy installation (#1851)
* Change max user configurable hold time from 10 to 25 seconds (#1851)
* Change Sonoff SC JSON format (#1939)
* Change Polish language to using Diacritics (#2005)
* Change user_config_override usage by providing user_config_override_sample.h (#2228)
* Change MQTT response topic for Energy changes from ENERGY to SENSOR (#2229, #2251)
* Change default Reset configuration time from 4 seconds to 40 seconds on Button hold (#2268)
*
* 5.12.0h
* Add optional Arduino OTA support to be enabled in user_config.h (#1998)
* Add support for Software Serial bridge using commands SerialDelimiter, SBaudrate and SSerialSend. Supports 8N1 and text only (#2190)
* Add support for Hardware Serial bridge using commands SerialDelimiter, Baudrate and SerialSend. Supports 8N1 and text only (#2182)
* Add support for Zengge WF017 PWM Led strip controller (#2202)
* Add PWM status to command State if PWM enabled (#2203)
* Add command HSBColor Hue,Sat,Bri (#1642, #2203)
* Add command Channel 0..100 to control dimmer value for individual color channels (#2111, #2203)
* Add Channel status information (#2211)
* Add all FriendlyNames to Status information (#2208)
* Change status display of Ssid and SetOption
* Change default option SetOption15 from 0 to 1 providing better initial PWM experience
*
* 5.12.0f
* Add compile time support for WS2812 BRG and RBG led configurations to be defined in user_config.h (#1690)
*
* 5.12.0e
* Add Domoticz dust (custom) sensors to PMS5003 and NovaFitness SDS drivers as PM1, PM2.5 and PM10
* Add a second TLS fingerprint to allow switching keys in TLS mode (#2033, #2102)
* Add display of remaining pulse time to command PulseTime (#2085)
* Add additional time offset to Wifi Retry based on device mac address (#2089)
* Add command Color6 RRGGBB for Clock hour marker color and command Rotation pixels for Clock rotation (#2092)
* Add HTML language header in local language (#2123)
* Add command PowerDelta 0..100 (percentage) to Energy monitoring devices to report on active power load change (#2157)
* Add Restart Reason to Status 1 report (#2161)
* Fix MAX31850 higher temperatures (#1269)
*
* 5.12.0d
* Add support for optional MQTT drivers to be selected in user_config.h (#1992)
* Add Portuguese language file
* Add compiler check for stable lwIP version v1.4 (#1940)
* Add always suffix with device number in Mqtt discovery topic (#1962)
* Add diacritics to Polish language file (#2005)
* Add Hungarian language file (#2024)
* Add Czech language file
* Add Chinese (Traditional) in Taiwan language file (#2108)
* Add support for Nova Fitness SDS011 and possibly SDS021 particle concentration sensor (#2070)
* Add single decimal precision to Nova Fitness SDS0x1 sensor values (#2093)
* Add support for multiple SHT3X sensors (#1949, #2110)
* Add Sonoff SC domoticz support for Sound level as Counter and Air quality (#2118)
* Fix MQTT TLS fingerprint validation (#2033)
*
* 5.12.0c
* Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560)
* Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules
* Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}}
* Fix intermittent exception when dns lookup is used while sleep is enabled
* Fix 5.4.0 regression turning off single press after button hold during 4x hold time
* Fix possible wifi connection problem by erasing sdk configuration parameters
* Change Polish language to using Diacritics (#2005)
*
* 5.12.0b
* Fix NTP sync to Thu Jan 01 08:00:10 1970 results in uptime 17651+ days (core2.4.1/sdk2.2.1)
* Fix MAX31850 higher temperatures (#1269)
* Fix freeing more code space when emulation is disabled (#1592)
* Fix providing web page configuratin option for Friendly Name when no device (relay or light) is configured (#1850)
* Fix compile error when define HOME_ASSISTANT_DISCOVERY_ENABLE is not set (#1937)
* Fix MQTT TLS fingerprint validation (#2033)
* Fix update temperature on DS18x20 drivers (#2328)
* Fix compile error when not defined USE_TIMERS (#2400)
* Fix configuration filename truncation when it contains spaces (#2484, #2490)
* Fix Energy Today and Yesterday overflow (#2543)
* Add serial debug info
* Add Portuguese language file
* Add Czech language file
* Add Bulgarian language file
* Add Domoticz dust (custom) sensors to PMS5003 and NovaFitness SDS drivers as PM1, PM2.5 and PM10
* Add commands Publish, Rule, RuleTimer and Event. See Wiki about Rule restriction, usage and examples
* Add sonoff-classic, sonoff-allsensors and sonoff-knx
* Add some coloring to important web buttons
* Add support for sensor HC-SR04 ultrasonic (#113, #1964, #2444)
* Add define MQTT_TELE_RETAIN compile option default set to 0 (#1071)
* Add 16 timers using commands Timer and Timers (#1091)
* Add optional Timer configuration webpage to be enabled in user_config.h with define USE_TIMERS_WEB
* Add Multichannel Gas sensor using MultiChannel_Gas_Sensor library (#1245)
* Add Domoticz Battery and RSSI Quality (#1604)
* Add command HSBColor Hue,Sat,Bri (#1642, #2203)
* Add compile time support for WS2812 BRG and RBG led configurations to be defined in user_config.h (#1690)
* Add optional usage of %d or %X suffices in MQTT client to append chipid (#1871)
* Add optional usage of %d or %X suffices in MQTT topic to append chipid (#1871)
* Add optional usage of %d or %04d in ota url to be replaced with chipid (#1871)
@ -110,17 +61,46 @@
* Add Webserver upload preflight request support (#1927)
* Add Home Assistant clear other device (#1931)
* Add Restart time to Status 1 (#1938)
* Change TSL2561 driver to joba library and delete Adafruit library (#1644)
* Change Sonoff SC JSON format (#1939)
* Fix compile error when define HOME_ASSISTANT_DISCOVERY_ENABLE is not set (#1937)
* Add optional TSL2561 driver using library Joba_Tsl2561 to be enabled in user_config.h with define USE_TSL2561_JOBA (#1951)
* Add support for sensor SHTC3 (#1967)
*
* 5.12.0a
* Change platformio option sonoff-ds18x20 to sonoff-allsensors enabling ds18x20 and all other sensors in one image
* Fix providing web page configuratin option for Friendly Name when no device (relay or light) is configured (#1850)
* Change default parameters in user_config.h to undefined for easy installation (#1851)
* Change max user configurable hold time from 10 to 25 seconds (#1851)
* Add compiler check for stable lwIP version v1.4 (#1940)
* Add support for multiple SHT3X sensors (#1949, #2110)
* Add always suffix with device number in Mqtt discovery topic (#1962)
* Add support for optional MQTT drivers to be selected in user_config.h (#1992)
* Add optional Arduino OTA support to be enabled in user_config.h (#1998)
* Add diacritics to Polish language file (#2005)
* Add Hungarian language file (#2024)
* Add support for Nova Fitness SDS011 and possibly SDS021 particle concentration sensor (#2070)
* Add single decimal precision to Nova Fitness SDS0x1 sensor values (#2093)
* Add Chinese (Traditional) in Taiwan language file (#2108)
* Add Sonoff SC domoticz support for Sound level as Counter and Air quality (#2118)
* Add a second TLS fingerprint to allow switching keys in TLS mode (#2033, #2102)
* Add display of remaining pulse time to command PulseTime (#2085)
* Add additional time offset to Wifi Retry based on device mac address (#2089)
* Add command Color6 RRGGBB for Clock hour marker color and command Rotation pixels for Clock rotation (#2092)
* Add HTML language header in local language (#2123)
* Add command PowerDelta 0..100 (percentage) to Energy monitoring devices to report on active power load change (#2157)
* Add Restart Reason to Status 1 report (#2161)
* Add command Channel 0..100 to control dimmer value for individual color channels (#2111, #2203)
* Add support for Hardware Serial bridge using commands SerialDelimiter, Baudrate and SerialSend. Supports 8N1 and text only (#2182)
* Add support for Software Serial bridge using commands SerialDelimiter, SBaudrate and SSerialSend. Supports 8N1 and text only (#2190)
* Add support for Zengge WF017 PWM Led strip controller (#2202)
* Add PWM status to command State if PWM enabled (#2203)
* Add all FriendlyNames to Status information (#2208)
* Add Channel status information (#2211)
* Add hexadecimal Data entry to command IrSend using 0x notation (#1290, #2314)
* Add Home Assistant MQTT Discovery for Buttons and change SetOption19 response (#2277)
* Add multiple color entry support for command Led like Led2 120000 001200 000012 setting led2 as Red, Led3 as Green and Led4 as Blue (#2303)
* Add hexadecimal RGB color entry on RGBCW leds (#2304)
* Add support for SGP30 gas and air quality sensor (#2307)
* Add optional Sunrise and Sunset timers with commands Latitide and Longitude to be enabled with define USE_SUNRISE in user_config.h (#2317)
* Add timer sunrise and sunset offset (#2378)
* Add user selectable defines for Sunrise/set Dawn option (#2378)
* Add optional KNX IP Protocol Support (#2402)
* Add random window to timers (#2447)
* Add Greek language file (#2491)
* Add support for Sonoff Pow R2 (#2340)
* Add GPIO_User to GPIO02 for all Sonoff T1 (#2524)
*
* 5.12.0 20180209
* Change library PubSubClient.h define MQTT_MAX_PACKET_SIZE from 512 to 1000 for Home Assistant support

View File

@ -28,7 +28,7 @@
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
* Use online command Prefix to translate cmnd, stat and tele.
*
* Updated until v5.12.0m
* Updated until v5.12.0n
\*********************************************************************/
//#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English)
@ -43,7 +43,7 @@
#define D_HOUR_MINUTE_SEPARATOR ":"
#define D_MINUTE_SECOND_SEPARATOR ":"
#define D_DAY3LIST "Po Út St Čt Pá So Ne "
#define D_DAY3LIST "Ne Po Út St Čt Pá So "
#define D_MONTH3LIST "LedÚnoBřeDubKvěČvnČvcSrpZářŘíjLisPro"
// Non JSON decimal separator

View File

@ -1,7 +1,7 @@
/*
el-GR.h - localization for Greek - Greece for Sonoff-Tasmota
Copyright (C) 2018 Harry Kandiloros
Copyright (C) 2018 Kan3Nas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -28,7 +28,7 @@
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
* Use online command Prefix to translate cmnd, stat and tele.
*
* Updated until v5.12.0m
* Updated until v5.12.0n
\*********************************************************************/
//#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English)

View File

@ -28,7 +28,7 @@
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
* Use online command Prefix to translate cmnd, stat and tele.
*
* Updated until v5.12.0l
* Updated until v5.12.0n
\*********************************************************************/
//#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English)

View File

@ -851,7 +851,11 @@ void SettingsDelta()
Settings.knx_CB_registered = 0;
memset(&Settings.knx_physsical_addr, 0x00, 0x800 - 0x6b8); // Reset until 0x800 for future use
}
if (Settings.version < 0x050C000F) {
Settings.energy_kWhtoday /= 1000;
Settings.energy_kWhyesterday /= 1000;
RtcSettings.energy_kWhtoday /= 1000;
}
Settings.version = VERSION;
SettingsSave(1);
}

View File

@ -52,8 +52,6 @@ typedef unsigned long power_t; // Power (Relay) type
#define MAX_KNX_CB 10 // Max number of KNX Group Addresses to write that can be set
#define MAX_RULE_SIZE 512 // Max number of characters in rules
#define MODULE SONOFF_BASIC // [Module] Select default model
#define MQTT_TOKEN_PREFIX "%prefix%" // To be substituted by mqtt_prefix[x]
#define MQTT_TOKEN_TOPIC "%topic%" // To be substituted by mqtt_topic, mqtt_grptopic, mqtt_buttontopic, mqtt_switchtopic

View File

@ -25,7 +25,7 @@
- Select IDE Tools - Flash Size: "1M (no SPIFFS)"
====================================================*/
#define VERSION 0x050C000D // 5.12.0m
#define VERSION 0x050D0101 // 5.13.1a
// Location specific includes
#include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
@ -1462,7 +1462,12 @@ void PerformEverySecond()
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
mqtt_data[0] = '\0';
if (MqttShowSensor()) { MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); }
if (MqttShowSensor()) {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
#ifdef USE_RULES
RulesTeleperiod(); // Allow rule based HA messages
#endif // USE_RULES
}
}
}

View File

@ -46,6 +46,10 @@ void KNX_CB_Action(message_t const &msg, void *arg);
* Default global defines
\*********************************************************************************************/
#ifndef MODULE
#define MODULE SONOFF_BASIC // [Module] Select default model
#endif
#define USE_DHT // Default DHT11 sensor needs no external library
/*********************************************************************************************\

View File

@ -615,7 +615,9 @@ void WifiBegin(uint8_t flag)
delay(200);
WiFi.mode(WIFI_STA); // Disable AP mode
if (Settings.sleep) {
#ifndef ARDUINO_ESP8266_RELEASE_2_4_1 // See https://github.com/arendst/Sonoff-Tasmota/issues/2559
WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times
#endif
}
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) {
// WiFi.setPhyMode(WIFI_PHY_MODE_11N);
@ -1312,7 +1314,7 @@ void RtcSecond()
uint8_t offset = (uptime < 30) ? RtcTime.second : (((ESP.getChipId() & 0xF) * 3) + 3) ; // First try ASAP to sync. If fails try once every 60 seconds based on chip id
if ((WL_CONNECTED == WiFi.status()) && (offset == RtcTime.second) && ((RtcTime.year < 2016) || (ntp_sync_minute == RtcTime.minute))) {
ntp_time = sntp_get_current_timestamp();
if (ntp_time) {
if (ntp_time > 1451602800) { // Fix NTP bug in core 2.4.1/SDK 2.2.1 (returns Thu Jan 01 08:00:10 1970 after power on)
utc_time = ntp_time;
ntp_sync_minute = 60; // Sync so block further requests
if (restart_time == 0) {
@ -1384,7 +1386,10 @@ void RtcInit()
* ADC support
\*********************************************************************************************/
void AdcShow(boolean json)
uint8_t adc_counter = 0;
uint16_t adc_last_value = 0;
uint16_t AdcRead()
{
uint16_t analog = 0;
for (byte i = 0; i < 32; i++) {
@ -1392,9 +1397,29 @@ void AdcShow(boolean json)
delay(1);
}
analog >>= 5;
return analog;
}
void AdcEvery50ms()
{
adc_counter++;
if (!(adc_counter % 4)) {
uint16_t new_value = AdcRead();
if ((new_value < adc_last_value -10) || (new_value > adc_last_value +10)) {
adc_last_value = new_value;
uint16_t value = adc_last_value / 10;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"ANALOG\":{\"A0div10\":%d}}"), (value > 99) ? 100 : value);
RulesProcess();
}
}
}
void AdcShow(boolean json)
{
uint16_t analog = AdcRead();
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_ANALOG_INPUT "0\":%d"), mqtt_data, analog);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"ANALOG\":{\"A0\":%d}"), mqtt_data, analog);
#ifdef USE_WEBSERVER
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ANALOG, mqtt_data, "", 0, analog);
@ -1414,6 +1439,9 @@ boolean Xsns02(byte function)
if (pin[GPIO_ADC0] < 99) {
switch (function) {
case FUNC_EVERY_50_MSECOND:
AdcEvery50ms();
break;
case FUNC_JSON_APPEND:
AdcShow(1);
break;

View File

@ -48,6 +48,7 @@
// -- Project -------------------------------------
#define PROJECT "sonoff" // PROJECT is used as the default topic delimiter
#define MODULE SONOFF_BASIC // [Module] Select default model from sonoff_template.h (Should not be changed)
#define SAVE_DATA 1 // [SaveData] Save changed parameters to Flash (0 = disable, 1 - 3600 seconds)
#define SAVE_STATE 1 // [SetOption0] Save changed power state to Flash (0 = disable, 1 = enable)
@ -73,7 +74,7 @@
#define WEB_LOG_LEVEL LOG_LEVEL_INFO // [WebLog] (LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE)
// -- Ota -----------------------------------------
#define OTA_URL "http://sonoff.maddox.co.uk/tasmota/sonoff.ino.bin" // [OtaUrl]
#define OTA_URL "http://sonoff.maddox.co.uk/tasmota/sonoff.bin" // [OtaUrl]
// -- MQTT ----------------------------------------
#define MQTT_USE 1 // [SetOption3] Select default MQTT use (0 = Off, 1 = On)

View File

@ -328,6 +328,8 @@ uint8_t webserver_state = HTTP_OFF;
uint8_t upload_error = 0;
uint8_t upload_file_type;
uint8_t upload_progress_dot_count;
uint8_t config_block_count = 0;
uint8_t config_xor_on = 0;
// Helper function to avoid code duplication (saves 4k Flash)
static void WebGetArg(const char* arg, char* out, size_t max)
@ -1317,17 +1319,14 @@ void HandleUploadLoop()
}
upload_progress_dot_count = 0;
} else if (!upload_error && (UPLOAD_FILE_WRITE == upload.status)) {
if (0 == upload.totalSize)
{
if (0 == upload.totalSize) {
if (upload_file_type) {
if (upload.buf[0] != CONFIG_FILE_SIGN) {
upload_error = 8;
return;
}
if (upload.currentSize > sizeof(Settings)) {
upload_error = 9;
return;
}
config_xor_on = upload.buf[1];
config_block_count = 0;
} else {
if (upload.buf[0] != 0xE9) {
upload_error = 3;
@ -1343,14 +1342,24 @@ void HandleUploadLoop()
}
if (upload_file_type) { // config
if (!upload_error) {
if (upload.buf[1]) {
if (upload.currentSize > (sizeof(Settings) - (config_block_count * HTTP_UPLOAD_BUFLEN))) {
if (config_block_count) { SettingsDefault(); }
upload_error = 9;
return;
}
if (config_xor_on) {
for (uint16_t i = 2; i < upload.currentSize; i++) {
upload.buf[i] ^= (CONFIG_FILE_XOR +i);
}
}
SettingsDefaultSet2();
memcpy((char*)&Settings +16, upload.buf +16, upload.currentSize -16);
memcpy((char*)&Settings +8, upload.buf +8, 4); // Restore version and auto upgrade
if (0 == config_block_count) {
SettingsDefaultSet2();
memcpy((char*)&Settings +16, upload.buf +16, upload.currentSize -16);
memcpy((char*)&Settings +8, upload.buf +8, 4); // Restore version and auto upgrade
} else {
memcpy((char*)&Settings +(config_block_count * HTTP_UPLOAD_BUFLEN), upload.buf, upload.currentSize);
}
config_block_count++;
}
} else { // firmware
if (!upload_error && (Update.write(upload.buf, upload.currentSize) != upload.currentSize)) {

View File

@ -648,7 +648,8 @@ bool MqttCommand()
mqtt_data[0] = '\0';
}
MqttPublishDirect(stemp1, false);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_DONE);
// snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_DONE);
mqtt_data[0] = '\0';
}
}
}

View File

@ -47,11 +47,12 @@ float energy_voltage = 0; // 123.1 V
float energy_current = 0; // 123.123 A
float energy_power = 0; // 123.1 W
float energy_power_factor = 0; // 0.12
float energy_daily = 0; // 12.123 kWh
float energy_daily = 0; // 123.123 kWh
float energy_total = 0; // 12345.12345 kWh
float energy_start = 0; // 12345.12345 kWh total previous
unsigned long energy_kWhtoday; // 1212312345 Wh * 10^-5 (deca micro Watt hours) - 5763924 = 0.05763924 kWh = 0.058 kWh = energy_daily
unsigned long energy_period = 0; // 1212312345 Wh * 10^-5 (deca micro Watt hours) - 5763924 = 0.05763924 kWh = 0.058 kWh = energy_daily
unsigned long energy_kWhtoday_delta = 0; // 1212312345 Wh 10^-5 (deca micro Watt hours) - Overflows to energy_kWhtoday (HLW and CSE only)
unsigned long energy_kWhtoday; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = energy_daily
unsigned long energy_period = 0; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = energy_daily
float energy_power_last[3] = { 0 };
uint8_t energy_power_delta = 0;
@ -81,9 +82,14 @@ Ticker ticker_energy;
void EnergyUpdateToday()
{
if (energy_kWhtoday_delta > 1000) {
unsigned long delta = energy_kWhtoday_delta / 1000;
energy_kWhtoday_delta -= (delta * 1000);
energy_kWhtoday += delta;
}
RtcSettings.energy_kWhtoday = energy_kWhtoday;
energy_daily = (float)energy_kWhtoday / 100000000;
energy_total = (float)(RtcSettings.energy_kWhtotal + (energy_kWhtoday / 1000)) / 100000;
energy_daily = (float)energy_kWhtoday / 100000;
energy_total = (float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000;
}
/*********************************************************************************************\
@ -156,7 +162,7 @@ void HlwEverySecond()
hlw_len = 10000 / hlw_energy_period_counter;
hlw_energy_period_counter = 0;
if (hlw_len) {
energy_kWhtoday += ((HLW_PREF * Settings.energy_power_calibration) / hlw_len) / 36;
energy_kWhtoday_delta += ((HLW_PREF * Settings.energy_power_calibration) / hlw_len) / 36;
EnergyUpdateToday();
}
}
@ -390,7 +396,7 @@ void CseEverySecond()
}
if (cf_frequency && energy_power) {
cf_pulses_last_time = cf_pulses;
energy_kWhtoday += (cf_frequency * Settings.energy_power_calibration) / 36;
energy_kWhtoday_delta += (cf_frequency * Settings.energy_power_calibration) / 36;
EnergyUpdateToday();
}
}
@ -539,7 +545,7 @@ void PzemEvery200ms()
break;
case 4: // Total energy as 99999Wh
if (!energy_start || (value < energy_start)) energy_start = value; // Init after restart and hanlde roll-over if any
energy_kWhtoday += (value - energy_start) * 100000;
energy_kWhtoday += (value - energy_start) * 100;
energy_start = value;
EnergyUpdateToday();
break;
@ -579,9 +585,10 @@ void Energy200ms()
if (RtcTime.valid) {
if (LocalTime() == Midnight()) {
Settings.energy_kWhyesterday = energy_kWhtoday;
Settings.energy_kWhtotal += (energy_kWhtoday / 1000);
Settings.energy_kWhtotal += energy_kWhtoday;
RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal;
energy_kWhtoday = 0;
energy_kWhtoday_delta = 0;
energy_period = energy_kWhtoday;
EnergyUpdateToday();
energy_max_energy_state = 3;
@ -851,14 +858,15 @@ boolean EnergyCommand()
if (p != XdrvMailbox.data) {
switch (XdrvMailbox.index) {
case 1:
energy_kWhtoday = lnum *100000;
energy_kWhtoday = lnum *100;
energy_kWhtoday_delta = 0;
energy_period = energy_kWhtoday;
Settings.energy_kWhtoday = energy_kWhtoday;
RtcSettings.energy_kWhtoday = energy_kWhtoday;
energy_daily = (float)energy_kWhtoday / 100000000;
energy_daily = (float)energy_kWhtoday / 100000;
break;
case 2:
Settings.energy_kWhyesterday = lnum *100000;
Settings.energy_kWhyesterday = lnum *100;
break;
case 3:
RtcSettings.energy_kWhtotal = lnum *100;
@ -869,9 +877,9 @@ boolean EnergyCommand()
char energy_yesterday_chr[10];
char stoday_energy[10];
char energy_total_chr[10];
dtostrfd((float)Settings.energy_kWhyesterday / 100000000, Settings.flag2.energy_resolution, energy_yesterday_chr);
dtostrfd((float)RtcSettings.energy_kWhtoday / 100000000, Settings.flag2.energy_resolution, stoday_energy);
dtostrfd((float)(RtcSettings.energy_kWhtotal + (energy_kWhtoday / 1000)) / 100000, Settings.flag2.energy_resolution, energy_total_chr);
dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr);
dtostrfd((float)RtcSettings.energy_kWhtoday / 100000, Settings.flag2.energy_resolution, stoday_energy);
dtostrfd((float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000, Settings.flag2.energy_resolution, energy_total_chr);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s}}"),
command, energy_total_chr, energy_yesterday_chr, stoday_energy);
status_flag = 1;
@ -1040,6 +1048,7 @@ void EnergySnsInit()
if (energy_flg) {
energy_kWhtoday = (RtcSettingsValid()) ? RtcSettings.energy_kWhtoday : (RtcTime.day_of_year == Settings.energy_kWhdoy) ? Settings.energy_kWhtoday : 0;
energy_kWhtoday_delta = 0;
energy_period = energy_kWhtoday;
EnergyUpdateToday();
ticker_energy.attach_ms(200, Energy200ms);
@ -1073,7 +1082,7 @@ void EnergyShow(boolean json)
float energy = 0;
if (show_energy_period) {
if (energy_period) energy = (float)(energy_kWhtoday - energy_period) / 100000;
if (energy_period) energy = (float)(energy_kWhtoday - energy_period) / 100;
energy_period = energy_kWhtoday;
}
@ -1084,7 +1093,7 @@ void EnergyShow(boolean json)
dtostrfd(energy_voltage, Settings.flag2.voltage_resolution, energy_voltage_chr);
dtostrfd(energy_current, Settings.flag2.current_resolution, energy_current_chr);
dtostrfd(energy_power_factor, 2, energy_power_factor_chr);
dtostrfd((float)Settings.energy_kWhyesterday / 100000000, Settings.flag2.energy_resolution, energy_yesterday_chr);
dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr);
if (json) {
snprintf_P(speriod, sizeof(speriod), PSTR(",\"" D_JSON_PERIOD "\":%s"), energy_period_chr);

View File

@ -201,7 +201,7 @@ void ApplyTimerOffsets(Timer *duskdawn)
if (timeBuffer > (uint16_t)duskdawn->time) {
timeBuffer = 1440 - (timeBuffer - (uint16_t)duskdawn->time);
duskdawn->days = duskdawn->days >> 1;
duskdawn->days = duskdawn->days |= (stored.days << 6);
duskdawn->days |= (stored.days << 6);
} else {
timeBuffer = (uint16_t)duskdawn->time - timeBuffer;
}
@ -212,7 +212,7 @@ void ApplyTimerOffsets(Timer *duskdawn)
if (timeBuffer > 1440) {
timeBuffer -= 1440;
duskdawn->days = duskdawn->days << 1;
duskdawn->days = duskdawn->days |= (stored.days >> 6);
duskdawn->days |= (stored.days >> 6);
}
}
duskdawn->time = timeBuffer;
@ -279,8 +279,8 @@ void TimerEverySecond()
#endif
if (xtimer.arm) {
set_time += timer_window[i]; // Add random time offset
if (set_time < 0) { set_time == 0; } // Stay today;
if (set_time > 1439) { set_time == 1439; }
if (set_time < 0) { set_time = 0; } // Stay today;
if (set_time > 1439) { set_time = 1439; }
if (time == set_time) {
if (xtimer.days & days) {
Settings.timer[i].arm = xtimer.repeat;
@ -354,7 +354,7 @@ boolean TimerCommand()
#ifndef USE_RULES
if (devices_present) {
#endif
StaticJsonBuffer<200> jsonBuffer;
StaticJsonBuffer<256> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(dataBufUc);
if (!root.success()) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_TIMER "%d\":\"" D_JSON_INVALID_JSON "\"}"), index); // JSON decode failed

View File

@ -62,6 +62,7 @@
\*********************************************************************************************/
#define MAX_RULE_TIMERS 8
#define RULES_MAX_VARS 5
#ifndef ULONG_MAX
#define ULONG_MAX 0xffffffffUL
@ -83,6 +84,7 @@ long rules_power = -1;
uint32_t rules_triggers = 0;
uint8_t rules_trigger_count = 0;
uint8_t rules_teleperiod = 0;
/*******************************************************************************************/
@ -146,6 +148,12 @@ bool RulesRuleMatch(String &event, String &rule)
if (pos == -1) { return false; } // No # sign in rule
String rule_task = rule.substring(0, pos); // "INA219" or "SYSTEM"
if (rules_teleperiod) {
int ppos = rule_task.indexOf("TELE-"); // "TELE-INA219" or "INA219"
if (ppos == -1) { return false; } // No pre-amble in rule
rule_task = rule.substring(5, pos); // "INA219" or "SYSTEM"
}
String rule_name = rule.substring(pos +1); // "CURRENT>0.100" or "BOOT"
char compare = ' ';
@ -173,7 +181,7 @@ bool RulesRuleMatch(String &event, String &rule)
}
// Step2: Search rule_task and rule_name
StaticJsonBuffer<400> jsonBuf;
StaticJsonBuffer<1024> jsonBuf;
JsonObject &root = jsonBuf.parseObject(event);
if (!root.success()) { return false; } // No valid JSON data
@ -228,6 +236,8 @@ bool RulesRuleMatch(String &event, String &rule)
bool RulesProcess()
{
bool serviced = false;
char vars[RULES_MAX_VARS][10] = { 0 };
char stemp[10];
if (!Settings.flag.rules_enabled) { return serviced; } // Not enabled
if (!strlen(Settings.rules)) { return serviced; } // No rules
@ -262,17 +272,32 @@ bool RulesProcess()
rules_event_value = "";
String event = event_saved;
if (RulesRuleMatch(event, event_trigger)) {
commands.replace(F("%value%"), rules_event_value);
char command[commands.length() +1];
snprintf(command, sizeof(command), commands.c_str());
commands.trim();
String ucommand = commands;
ucommand.toUpperCase();
if (ucommand.startsWith("VAR")) {
uint8_t idx = ucommand.charAt(3) - '1';
// idx -= '1';
if ((idx >= 0) && (idx < RULES_MAX_VARS)) { snprintf(vars[idx], sizeof(vars[idx]), rules_event_value.c_str()); }
} else {
commands.replace(F("%value%"), rules_event_value);
for (byte i = 0; i < RULES_MAX_VARS; i++) {
if (strlen(vars[i])) {
snprintf_P(stemp, sizeof(stemp), PSTR("%%var%d%%"), i +1);
commands.replace(stemp, vars[i]);
}
}
char command[commands.length() +1];
snprintf(command, sizeof(command), commands.c_str());
snprintf_P(log_data, sizeof(log_data), PSTR("RUL: %s performs \"%s\""), event_trigger.c_str(), command);
AddLog(LOG_LEVEL_INFO);
snprintf_P(log_data, sizeof(log_data), PSTR("RUL: %s performs \"%s\""), event_trigger.c_str(), command);
AddLog(LOG_LEVEL_INFO);
// snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, D_CMND_RULE, D_JSON_INITIATED);
// MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_RULE));
// snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, D_CMND_RULE, D_JSON_INITIATED);
// MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_RULE));
ExecuteCommand(command);
ExecuteCommand(command);
}
serviced = true;
}
rules_trigger_count++;
@ -288,6 +313,7 @@ void RulesInit()
Settings.flag.rules_enabled = 0;
Settings.flag.rules_once = 0;
}
rules_teleperiod = 0;
}
void RulesSetPower()
@ -344,6 +370,13 @@ void RulesEverySecond()
}
}
void RulesTeleperiod()
{
rules_teleperiod = 1;
RulesProcess();
rules_teleperiod = 0;
}
boolean RulesCommand()
{
char command[CMDSZ];

View File

@ -548,7 +548,7 @@ void KnxSensor(byte sensor_type, float value)
knx.write_2byte_float(KNX_addr, value);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX "%s " D_SENT_TO " %d.%d.%d "),
device_param_ga[sensor_type],
device_param_ga[sensor_type -1],
KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member);
AddLog(LOG_LEVEL_INFO);
@ -741,9 +741,13 @@ void HandleKNXConfiguration()
page.replace(F("GAarea"), F("CB_AREA"));
page.replace(F("GAfdef"), F("CB_FDEF"));
page += FPSTR(HTTP_FORM_KNX4);
byte j;
for (byte i = 0; i < KNX_MAX_device_param ; i++)
{
if ( device_param[i].show )
// Check How many Relays are available and add: RelayX and TogleRelayX
if ( (i > 8) && (i < 16) ) { j=i-8; } else { j=i; }
if ( i == 8 ) { j = 0; }
if ( device_param[j].show )
{
page += FPSTR(HTTP_FORM_KNX_OPT);
page.replace(F("{vop}"), String(device_param[i].type));

View File

@ -90,9 +90,11 @@ const char HTTP_SNS_COUNTER[] PROGMEM =
void CounterShow(boolean json)
{
char stemp[10];
char counter[16];
byte dsxflg = 0;
byte header = 0;
for (byte i = 0; i < MAX_COUNTERS; i++) {
if (pin[GPIO_CNTR1 +i] < 99) {
if (bitRead(Settings.pulse_counter_type, i)) {
@ -103,7 +105,13 @@ void CounterShow(boolean json)
}
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_COUNTER "%d\":%s"), mqtt_data, i +1, counter);
if (!header) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"COUNTER\":{"), mqtt_data);
stemp[0] = '\0';
}
header++;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"C%d\":%s"), mqtt_data, stemp, i +1, counter);
strcpy(stemp, ",");
#ifdef USE_DOMOTICZ
if ((0 == tele_period) && (1 == dsxflg)) {
DomoticzSensor(DZ_COUNT, RtcSettings.pulse_counter[i]);
@ -117,6 +125,11 @@ void CounterShow(boolean json)
}
}
}
if (json) {
if (header) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
}
}
}
/*********************************************************************************************\

View File

@ -465,7 +465,12 @@ void BmpShow(boolean json)
mqtt_data, bmp_name, temperature, (bmp_model >= 2) ? json_humidity : "", pressure, (Settings.altitude != 0) ? json_sealevel : "");
#endif // USE_BME680
#ifdef USE_DOMOTICZ
if (0 == tele_period) DomoticzTempHumPressureSensor(temperature, humidity, pressure);
if (0 == tele_period) {
DomoticzTempHumPressureSensor(temperature, humidity, pressure);
#ifdef USE_BME680
if (bmp_model >= 3) { DomoticzSensor(DZ_AIRQUALITY, (uint32_t)g); }
#endif // USE_BME680
}
#endif // USE_DOMOTICZ
#ifdef USE_KNX

View File

@ -190,7 +190,7 @@ void Ads1115Show(boolean json)
stemp[0] = '\0';
}
dsxflg++;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_JSON_ANALOG_INPUT "%d\":%d"), mqtt_data, stemp, i, adc_value);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"A%d\":%d"), mqtt_data, stemp, i, adc_value);
strcpy(stemp, ",");
#ifdef USE_WEBSERVER
} else {

View File

@ -110,7 +110,7 @@ void Ads1115Show(boolean json)
stemp[0] = '\0';
}
dsxflg++;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_JSON_ANALOG_INPUT "%d\":%d"), mqtt_data, stemp, i, adc_value);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"A%d\":%d"), mqtt_data, stemp, i, adc_value);
strcpy(stemp, ",");
#ifdef USE_WEBSERVER
} else {