From ad40589a7f20201273be61b05dfba2a0bab0f065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Iv=C3=A1n=20=20Conde=20Mart=C3=ADn?= Date: Wed, 5 Dec 2018 10:57:40 +0100 Subject: [PATCH 1/5] Improvement on ANALOG_SENSOR (#1326) * Testing branch * Added ability (by define) to scale analog sensor, also with number of decimals (it was formerly zero) Useful when running on batteries to check the battery voltage just adding the appropriate resistor * Reverting DHTSensor.h file * Trying again to revert DHTSensor.h * Using macro DEBUG_MSG * fix method types --- code/espurna/config/sensors.h | 19 +++++++++++++ code/espurna/sensor.ino | 4 +++ code/espurna/sensors/AnalogSensor.h | 43 ++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index b0ea4dcc..ae1b4a3a 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -99,6 +99,25 @@ #define ANALOG_DELAY 0 // Delay between samples in micros #endif +//Use the following to perform scaling of raw analog values +// scaledRead = ( factor * rawRead ) + offset +// +//Please take note that the offset is not affected by the scaling factor + +#ifndef ANALOG_FACTOR +#define ANALOG_FACTOR 1.0 // Multiply raw reading by this factor +#endif + +#ifndef ANALOG_OFFSET +#define ANALOG_OFFSET 0.0 // Add this offset to *scaled* value +#endif + +// Round to this number of decimals +#ifndef ANALOG_DECIMALS +#define ANALOG_DECIMALS 2 +#endif + + //------------------------------------------------------------------------------ // BH1750 // Enable support by passing BH1750_SUPPORT=1 build flag diff --git a/code/espurna/sensor.ino b/code/espurna/sensor.ino index 48fef408..dc9476b3 100644 --- a/code/espurna/sensor.ino +++ b/code/espurna/sensor.ino @@ -52,6 +52,7 @@ unsigned char _magnitudeDecimals(unsigned char type) { // Hardcoded decimals (these should be linked to the unit, instead of the magnitude) + if (type == MAGNITUDE_ANALOG) return ANALOG_DECIMALS; if (type == MAGNITUDE_ENERGY || type == MAGNITUDE_ENERGY_DELTA) { if (_sensor_energy_units == ENERGY_KWH) return 3; @@ -347,6 +348,9 @@ void _sensorLoad() { AnalogSensor * sensor = new AnalogSensor(); sensor->setSamples(ANALOG_SAMPLES); sensor->setDelay(ANALOG_DELAY); + //CICM For analog scaling + sensor->setFactor(ANALOG_FACTOR); + sensor->setOffset(ANALOG_OFFSET); _sensors.push_back(sensor); } #endif diff --git a/code/espurna/sensors/AnalogSensor.h b/code/espurna/sensors/AnalogSensor.h index e13d2cee..f5e0a2df 100644 --- a/code/espurna/sensors/AnalogSensor.h +++ b/code/espurna/sensors/AnalogSensor.h @@ -35,6 +35,16 @@ class AnalogSensor : public BaseSensor { _micros = micros; } + void setFactor(double factor) { + //DEBUG_MSG(("[ANALOG_SENSOR] Factor set to: %s \n"), String(factor,6).c_str()); + _factor = factor; + } + + void setOffset(double offset) { + //DEBUG_MSG(("[ANALOG_SENSOR] Factor set to: %s \n"), String(offset,6).c_str()); + _offset = offset; + } + // --------------------------------------------------------------------- unsigned int getSamples() { @@ -45,6 +55,14 @@ class AnalogSensor : public BaseSensor { return _micros; } + double getFactor() { + return _factor; + } + + double getOffset() { + return _offset; + } + // --------------------------------------------------------------------- // Sensor API // --------------------------------------------------------------------- @@ -77,6 +95,7 @@ class AnalogSensor : public BaseSensor { } // Current value for slot # index + // Changed return type as moving to scaled value double value(unsigned char index) { if (index == 0) return _read(); return 0; @@ -84,7 +103,9 @@ class AnalogSensor : public BaseSensor { protected: - unsigned int _read() { + //CICM: this should be for raw values + // renaming protected function "_read" to "_rawRead" + unsigned int _rawRead() { if (1 == _samples) return analogRead(0); unsigned long sum = 0; for (unsigned int i=0; i<_samples; i++) { @@ -94,8 +115,28 @@ class AnalogSensor : public BaseSensor { return sum / _samples; } + //CICM: and proper read should be scalable and thus needs sign + //and decimal part + double _read() { + //Raw measure could also be a class variable with getter so that can + //be reported through MQTT, ... + unsigned int rawValue; + double scaledValue; + // Debugging doubles to string + //DEBUG_MSG(("[ANALOG_SENSOR] Started standard read, factor: %s , offset: %s, decimals: %d \n"), String(_factor).c_str(), String(_offset).c_str(), ANALOG_DECIMALS); + rawValue = _rawRead(); + //DEBUG_MSG(("[ANALOG_SENSOR] Raw read received: %d \n"), rawValue); + scaledValue = _factor*rawValue + _offset; + //DEBUG_MSG(("[ANALOG_SENSOR] Scaled value result: %s \n"), String(scaledValue).c_str()); + return scaledValue; + } + + unsigned int _samples = 1; unsigned long _micros = 0; + //CICM: for scaling and offset, also with getters and setters + double _factor = 1.0; + double _offset = 0.0; }; From 64b5155aa7d4f28f6b4f6dc57d6cc6b560edd5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Fri, 22 Feb 2019 09:50:44 +0100 Subject: [PATCH 2/5] Change naming for BlitzWolf SHP2 and SHP6 (now SHPX) boards --- code/espurna/migrate.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/espurna/migrate.ino b/code/espurna/migrate.ino index bb7c5599..9da0b10e 100644 --- a/code/espurna/migrate.ino +++ b/code/espurna/migrate.ino @@ -1027,7 +1027,7 @@ void migrate() { setSetting("relayType", 0, RELAY_TYPE_NORMAL); setSetting("relayType", 1, RELAY_TYPE_NORMAL); - #elif defined(BLITZWOLF_BWSHP2) + #elif defined(BLITZWOLF_BWSHPX) setSetting("board", 79); setSetting("ledGPIO", 0, 2); From 31195ba3b62ff886313d0369baf4b6ab1a07187b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Fri, 22 Feb 2019 09:57:30 +0100 Subject: [PATCH 3/5] Removing loop delay if WIFI is not set to sleep, reducing it to 1ms otherwise (#1541) --- code/espurna/config/general.h | 2 +- code/espurna/system.ino | 16 ++++++++++++---- code/espurna/utils.ino | 4 +++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 9c1ef409..8c74394c 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -21,7 +21,7 @@ #endif #ifndef LOOP_DELAY_TIME -#define LOOP_DELAY_TIME 10 // Delay for this millis in the main loop [0-250] +#define LOOP_DELAY_TIME 1 // Delay for this millis in the main loop [0-250] (see https://github.com/xoseperez/espurna/issues/1541) #endif //------------------------------------------------------------------------------ diff --git a/code/espurna/system.ino b/code/espurna/system.ino index 791ba99c..33bbf267 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -10,7 +10,10 @@ Copyright (C) 2018 by Xose PĂ©rez // ----------------------------------------------------------------------------- +#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP unsigned long _loop_delay = 0; +#endif + bool _system_send_heartbeat = false; unsigned char _heartbeat_mode = HEARTBEAT_MODE; unsigned long _heartbeat_interval = HEARTBEAT_INTERVAL; @@ -72,10 +75,11 @@ bool systemGetHeartbeat() { return _system_send_heartbeat; } +#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP unsigned long systemLoopDelay() { return _loop_delay; } - +#endif unsigned long systemLoadAverage() { return _load_average; @@ -157,7 +161,9 @@ void systemLoop() { // Power saving delay // ------------------------------------------------------------------------- - delay(_loop_delay); + #if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP + delay(_loop_delay); + #endif } @@ -196,8 +202,10 @@ void systemSetup() { _systemSetupSpecificHardware(); // Cache loop delay value to speed things (recommended max 250ms) - _loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str()); - _loop_delay = constrain(_loop_delay, 0, 300); + #if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP + _loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str()); + _loop_delay = constrain(_loop_delay, 0, 300); + #endif // Register Loop espurnaRegisterLoop(systemLoop); diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 23c6ea03..888f3963 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -469,7 +469,9 @@ void info() { #if ADC_MODE_VALUE == ADC_VCC DEBUG_MSG_P(PSTR("[MAIN] Power: %u mV\n"), ESP.getVcc()); #endif - DEBUG_MSG_P(PSTR("[MAIN] Power saving delay value: %lu ms\n"), systemLoopDelay()); + #if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP + DEBUG_MSG_P(PSTR("[MAIN] Power saving delay value: %lu ms\n"), systemLoopDelay()); + #endif // ------------------------------------------------------------------------- From 47305984340fa64209861c2eb4f39c239427f85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sat, 23 Feb 2019 00:19:20 +0100 Subject: [PATCH 4/5] Version 1.13.4 --- CHANGELOG.md | 115 ++++++++++++++++++++++++++++++++++ README.md | 2 +- code/espurna/config/version.h | 2 +- 3 files changed, 117 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3f69788..26ca0554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,121 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.13.4] 2019-02-21 +### Fixed +- Travis fixes +- IR results on raw mode (thanks to @vtochq) +- Missing configuration in HTTP API (#1288) +- NTP sync changes (#1342) +- Proper buffer size to fit two digit rfbOFF key (#1348) +- Use correct arguments for stat on macOS (#1355, thanks to @jackwilson) +- Enable `reload` command when no web support (#1383) +- Wrong GPIO value for dummy relay (#1386) +- Wait until mqtt client has finished trying to connect +- Disable EEPROM Rotate before NoFUSS update (#1398, thanks to @arihantdaga) +- Only check domoticz state in broker callback (#1562) +- Fix upload_port and upload_args +- Fix heartbeat dropdown size +- Setup settings before using them in system module (#1542) +- Fix HEARTBEAT_REPORT_DESCRIPTION typo (#1539) +- Fix wsDebugSend prototype +- Fix pulse for dummy relays (#1496, thanks to @Niek) +- Fix RFBridge websocket data +- Only process Domoticz RGB MQTT Messages for the current idx (#1489, thanks to @soif) +- Fix pulse for dummy relays +- Fix compile error when both RF_SUPPORT and API_SUPPORT are enabled (#1479, thanks to @Niek) +- Fix compile error when TERMINAL_SUPPORT is disabled (#1426) +- Fix compile error when RF_SUPPORT is enabled (#1475) +- Fix CodingStyle link (#1473) +- Fix: Add Debug flag for compilation of wifiDebug() function (#1454) +- Fix bug in RFM69 that counted packets twice +- Escape hyphens in img.shields.io urls +- Fix travis builds based on latest core +- Increase buffer size to fit B0 code (#1423) +- Fix function call typo in RF code (#1421) +- Fix RF code conversion to long (#1410) + +### Added +- Support for MAXCIO W-DE003 device (thanks to @kerk1v) +- Support for Tonbux XS-SSA01 device (thanks to @StevenWolfe) +- Support for Blitzwolf BW-SHP2 v2.3 (#1351) +- Support for Tecking SP22 v1.4+ +- Support for Lombez Lux Nova 2 smart bulbs (thanks to @kcghost) +- Support for Orvibo B25 (#1402, thanks to @plutec) +- Support for GBLife RGBW Socket (#1305) +- Support for Generic Relay ESP01 V4.0 in inverse relay version (#1504, #1554) +- Support for Gosund WS1 aka KS-602S (#1551, thanks to @nsvrana) +- Support for Oukitel P1 smart switch (#1553, thanks to @quinnsam) +- Support for Lyasi light bulb (#1533, thanks to Eichhoernchen) +- Support for RGB(WW) controlled using Domoticz MQTT messages (#1459, thanks to @sq5gvm) +- Support for newer AL-LC02 boards with different pinout (#1469, thanks to @sq5gvm) +- Support for SmartLife Mini Smart Socket RGB (thanks to @kuppe234, #1411) +- Support for Gosund SP1 v2.3 (#1448) +- Support for OBI Wifi Schuko Plug V2 (#1408, thanks to @arthurf1969) +- Support for pulse meter power sensor for new-generation smart-meters +- Support for VL53L1X ToF sensor (thanks to @ruimarinho) +- Support for VEML6075 UV sensor (thanks to @ruimarinho) +- Support for EZO pH Circuit sensor (thanks to @ruimarinho) +- Support for MAX6675 temperature sensor (#1375, thanks to @lucciano) +- Support for MagicHome ZJ WFMN A/B v1.1 (#1339) +- Support for multiple PZEM004T sensors (thanks to @0x3333) +- Support for Support PMS5003S (#1511, thanks to @Yonsm) +- Support for pulse meter power sensor for new-generation smart-meters (including debouncing and energy ratio support by @jackwilson) +- Support for BMP085 and BMP180 sensors (#1082) +- Add dim up and down actions to button handler (#1250) +- Compact WS data (#1387) +- Improved analog sensor (#1326, thanks to @cconde) +- Report SSID in heartbeat messages +- Option to send full data to thinkgspeak on every message (#1369) +- Added RSSI to InfluxDB heartbeat (#1400, tahnks to @BuildTheRobots) +- Option to report time even if no NTP sync (#1310) +- Support for mixed combination of real and dummy relays (#1305) +- Report target color values on MQTT and API +- Note on WiFi tab about hostname (#1555) +- Allow saving heartbeat settings from web (#1538) +- Build images for Sonoff Basic R2 with DHT and DALLAS support +- Add warning about TELNET_PASSWORD +- Domoticz: track last relay state (#1536) +- Adding description field to web UI, reporting it via MQTT (#1523) +- ESP-01 + 2ch 5v relay LC tech Exclusive relay on (#1519, thanks to @clabnet) +- Add OTA support over MQTT (#1424, thanks to @Niek) +- Configure Heartbeat from WebUI & option HEARTBEAT_REPEAT_STATUS (#1474, thanks to martiera) +- Delay light comms (mqtt, ws, broker) to avoid jamming +- Added message type to broker +- Yield() after handling OTA request +- Disconnect websocket when auth fails +- Manage relay changes in third party modules via broker +- Added API entry points for RFBridge module (#1407) +- Domoticz over MQTT to Espurna RGB/RGBW/RGBWW +- Debug check position to make sure definition is not nullified to avoid putting checks in all places +- MQTT reconnect delay based on last disconnection +- Add terminal support for wifiDebug +- Created contribute.md and support.md files +- Created issue templates +- Runtime heartbeat configuration (#1406) +- APP_VERSION suffix (#1418) +- Allow {hostname} and {mac} placeholder for mqtt user and client_id fields (#1338) +- Split ws messages for relays and rf codes (#262) +- Added learn and forget terminal commands to RFBridge and RF modules (#1253) +- Change light transition time via MQTT or API (#1412) + +### Changed +- Telnet password requirements (#1382) +- Separate tab for NoFUSS options (#1404) +- Updated to use gulp4 (#1403) +- Updated to EEPROM_Rotate 0.9.2 +- Show proper switches names in web UI +- Removing loop delay if WIFI is not set to sleep, reducing it to 1ms otherwise (#1541) +- Change naming for BlitzWolf SHP2 and SHP6 (now SHPX) boards +- Print each HA config entry separately (#1535) +- Updated DebounceEvent to 2.0.5 (#1527, #1254) +- Python cleanup (@1526, thanks to Cabalist) +- Normalize naming for Arilux AL LC02 v14 +- Increase version field size in OTA manager +- Merge RF and RFBridge code (#1435, thanks to @Niek) +- Update to fauxmoESP 3.1.0 +- Move crash code to it's own module + ## [1.13.3] 2018-10-08 ### Fixed - Honour build time settings for MQTT on fresh install (#719) diff --git a/README.md b/README.md index 2ead2bf0..ca73c982 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smart switches, lights and sensors. It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. -[![version](https://img.shields.io/badge/version-1.13.4--dev-brightgreen.svg)](CHANGELOG.md) +[![version](https://img.shields.io/badge/version-1.13.4-brightgreen.svg)](CHANGELOG.md) [![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna/tree/dev/) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE) [![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) diff --git a/code/espurna/config/version.h b/code/espurna/config/version.h index f9697a4d..7f3c064f 100644 --- a/code/espurna/config/version.h +++ b/code/espurna/config/version.h @@ -1,5 +1,5 @@ #define APP_NAME "ESPURNA" -#define APP_VERSION "1.13.4-dev" +#define APP_VERSION "1.13.4" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" #define CFG_VERSION 3 From 2aa5c590666b5cf550d03cd832da4d5c36e83de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sat, 23 Feb 2019 00:20:35 +0100 Subject: [PATCH 5/5] Update version in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ca73c982..c30534c4 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. [![version](https://img.shields.io/badge/version-1.13.4-brightgreen.svg)](CHANGELOG.md) -[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna/tree/dev/) +[![branch](https://img.shields.io/badge/branch-master-orange.svg)](https://github.com/xoseperez/espurna/tree/master/) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE) -[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) +[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=master)](https://travis-ci.org/xoseperez/espurna) [![codacy](https://api.codacy.com/project/badge/Grade/c9496e25cf07434cba786b462cb15f49)](https://www.codacy.com/app/xoseperez/espurna/dashboard) [![downloads](https://img.shields.io/github/downloads/xoseperez/espurna/total.svg)](https://github.com/xoseperez/espurna/releases)