diff --git a/README.md b/README.md index 9fef62adb..b0a864cb5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **6.0.0c** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **6.1.1b** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for release information and [sonoff/_changelog.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_changelog.ino) for change information. ### Disclaimer :warning: **DANGER OF ELECTROCUTION** :warning: @@ -39,7 +39,7 @@ If you want to compile Sonoff-Tasmota yourself keep in mind the following: - Once uploaded select module using the configuration webpage or the commands ```Modules``` and ```Module```. - After reboot select config menu again or use commands ```GPIOs``` and ```GPIO``` to change GPIO with desired sensor. -### Migration Instructions +### Migration Information See [wiki migration path](https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade#migration-path) for instructions how to migrate to a major version. Pay attention to the following version breaks due to dynamic settings updates: 1. Migrate to **Sonoff-Tasmota 3.9.x** @@ -134,34 +134,34 @@ Different firmware images are released based on Features and Sensors selection g | USE_ADS1115 | - | - | - | - | x | | USE_ADS1115_I2CDEV | - | - | - | - | - | | USE_INA219 | - | - | - | - | x | -| USE_APDS9960 | - | - | - | - | - | | USE_MGS | - | - | - | - | x | | USE_SPI | - | - | - | - | - | | USE_MHZ19 | x | x | - | x | x | -| USE_SENSEAIR | x | x | - | x | x | -| USE_PMS5003 | x | x | - | x | x | +| USE_SENSEAIR | x | - | - | x | x | +| USE_PMS5003 | x | - | - | x | x | | USE_NOVA_SDS | x | - | - | x | x | -| USE_PZEM004T | x | x | - | x | x | +| USE_PZEM004T | x | - | - | x | x | | USE_SERIAL_BRIDGE | x | - | - | x | x | -| USE_SDM120 | x | - | - | - | x | -| USE_SDM630 | x | - | - | - | x | +| USE_SDM120 | - | - | - | - | x | +| USE_SDM630 | - | - | - | - | x | | USE_IR_REMOTE | x | x | - | x | x | | USE_IR_HVAC | - | - | - | - | x | | USE_IR_RECEIVE | x | - | - | x | x | | USE_WS2812 | x | x | - | x | x | | USE_WS2812_DMA | - | - | - | - | - | -| USE_ARILUX_RF | x | x | - | x | x | +| USE_ARILUX_RF | x | - | - | x | x | | USE_SR04 | x | - | - | x | x | -| USE_TM1638 | - | - | - | - | - | | USE_RF_FLASH | x | - | - | x | x | -#### Typical File Size +#### Typical file size | ESP/Arduino library version | sonoff | classic | minimal | knx | allsensors | |-----------------------------|--------|---------|---------|------|------------| -| ESP/Arduino lib v2.3.0 | 529k | 490k | 429k | 538k | 554k | -| ESP/Arduino lib v2.4.0 | 534k | 498k | 436k | 542k | 558k | -| ESP/Arduino lib v2.4.1 | 536k | 501k | 439k | 545k | 560k | +| ESP/Arduino lib v2.3.0 | 538k | 490k | 407k | 548k | 562k | +| ESP/Arduino lib v2.4.0 | 543k | 498k | 414k | 553k | 565k | +| ESP/Arduino lib v2.4.1 | 544k | 500k | 416k | 555k | 567k | + +See [Tasmota ESP/Arduino library version related issues](https://github.com/arendst/Sonoff-Tasmota/wiki/Theo's-Tasmota-Tips#20180523---relation-tasmota-and-esp8266arduino-core-version) for more information. ### Contribute You can contribute to Sonoff-Tasmota by @@ -176,13 +176,14 @@ You can contribute to Sonoff-Tasmota by #### Libraries Used Libraries used with Sonoff-Tasmota are: - [ESP8266 core for Arduino](https://github.com/esp8266/Arduino) -- [Adafruit BME680](https://github.com/adafruit/Adafruit_BME680) -- [Adafruit Sensor](https://github.com/adafruit/Adafruit_Sensor) - [Adafruit SGP30](https://github.com/adafruit/Adafruit_SGP30) - [ArduinoJson](https://arduinojson.org/) +- [Bosch BME680](https://github.com/BoschSensortec/BME680_driver) +- [C2 Programmer](http://app.cear.ufpb.br/~lucas.hartmann/tag/efm8bb1/) - [Esp8266MqttClient](https://github.com/tuanpmt/ESP8266MQTTClient) - [esp-knx-ip](https://github.com/envy/esp-knx-ip) - [esp-mqtt-arduino](https://github.com/i-n-g-o/esp-mqtt-arduino) +- [ESPAsyncUDP](https://github.com/me-no-dev/ESPAsyncUDP) - [I2Cdevlib](https://github.com/jrowberg/i2cdevlib) - [IRremoteEsp8266](https://github.com/markszabo/IRremoteESP8266) - [JobaTsl2561](https://github.com/joba-1/Joba_Tsl2561) diff --git a/lib/Joba_Tsl2561/COPYING b/lib/Joba_Tsl2561-2.0.7/COPYING similarity index 100% rename from lib/Joba_Tsl2561/COPYING rename to lib/Joba_Tsl2561-2.0.7/COPYING diff --git a/lib/Joba_Tsl2561/COPYING.LESSER b/lib/Joba_Tsl2561-2.0.7/COPYING.LESSER similarity index 100% rename from lib/Joba_Tsl2561/COPYING.LESSER rename to lib/Joba_Tsl2561-2.0.7/COPYING.LESSER diff --git a/lib/Joba_Tsl2561/README b/lib/Joba_Tsl2561-2.0.7/README similarity index 100% rename from lib/Joba_Tsl2561/README rename to lib/Joba_Tsl2561-2.0.7/README diff --git a/lib/Joba_Tsl2561/examples/Autogain/Autogain.ino b/lib/Joba_Tsl2561-2.0.7/examples/Autogain/Autogain.ino similarity index 54% rename from lib/Joba_Tsl2561/examples/Autogain/Autogain.ino rename to lib/Joba_Tsl2561-2.0.7/examples/Autogain/Autogain.ino index 03da78d46..169d2b6e3 100644 --- a/lib/Joba_Tsl2561/examples/Autogain/Autogain.ino +++ b/lib/Joba_Tsl2561-2.0.7/examples/Autogain/Autogain.ino @@ -21,6 +21,17 @@ This file is part of the Joba_Tsl2561 Library. #include +// to mimic Serial.printf() of esp8266 core for other platforms +char *format( const char *fmt, ... ) { + static char buf[128]; + va_list arg; + va_start(arg, fmt); + vsnprintf(buf, sizeof(buf), fmt, arg); + buf[sizeof(buf)-1] = '\0'; + va_end(arg); + return buf; +} + Tsl2561 Tsl(Wire); uint8_t id; @@ -35,31 +46,30 @@ void setup() { } void loop() { - uint16_t scaledFull = ~0, scaledIr = ~0; - uint32_t full = ~0, ir = ~0, milliLux = ~0; + uint16_t scaledFull = 0xffff, scaledIr = 0xffff; + uint32_t full = 0xffffffff, ir = 0xffffffff, milliLux = 0xffffffff; bool gain = false; Tsl2561::exposure_t exposure = Tsl2561::EXP_OFF; if( Tsl2561Util::autoGain(Tsl, gain, exposure, scaledFull, scaledIr) ) { if( Tsl2561Util::normalizedLuminosity(gain, exposure, full = scaledFull, ir = scaledIr) ) { - if( Tsl2561Util::milliLux(full, ir, milliLux, Tsl2561::packageCS(id)) ) { - Serial.printf("Tsl2561 addr: 0x%02x, id: 0x%02x, sfull: %5u, sir: %5u, full: %5u, ir: %5u, gain: %d, exp: %d, lux: %5u.%03u\n", - Tsl.address(), id, scaledFull, scaledIr, full, ir, gain, exposure, milliLux/1000, milliLux%1000); + if( Tsl2561Util::milliLux(full, ir, milliLux, Tsl2561::packageCS(id), 5) ) { + Serial.print(format("Tsl2561 addr: 0x%02x, id: 0x%02x, sfull: %5u, sir: %5u, full: %7lu, ir: %7lu, gain: %d, exp: %d, lux: %5lu.%03lu\n", + Tsl.address(), id, scaledFull, scaledIr, (unsigned long)full, (unsigned long)ir, gain, exposure, (unsigned long)milliLux/1000, (unsigned long)milliLux%1000)); } else { - Serial.printf("Tsl2561Util::milliLux(full=%u, ir=%u) error\n", full, ir); + Serial.print(format("Tsl2561Util::milliLux(full=%lu, ir=%lu) error\n", (unsigned long)full, (unsigned long)ir)); } } else { - Serial.printf("Tsl2561Util::normalizedLuminosity(gain=%u, exposure=%u, sfull=%u, sir=%u, full=%u, ir=%u) error\n", - gain, exposure, scaledFull, scaledIr, full, ir); + Serial.print(format("Tsl2561Util::normalizedLuminosity(gain=%u, exposure=%u, sfull=%u, sir=%u, full=%lu, ir=%lu) error\n", + gain, exposure, scaledFull, scaledIr, (unsigned long)full, (unsigned long)ir)); } } else { - Serial.printf("Tsl2561Util::autoGain(gain=%u, exposure=%u, sfull=%u, sir=%u) error\n", - gain, exposure, scaledFull, scaledIr); + Serial.print(format("Tsl2561Util::autoGain(gain=%u, exposure=%u, sfull=%u, sir=%u) error\n", + gain, exposure, scaledFull, scaledIr)); } delay(1000); } - diff --git a/lib/Joba_Tsl2561/examples/Simple/Simple.ino b/lib/Joba_Tsl2561-2.0.7/examples/Simple/Simple.ino similarity index 76% rename from lib/Joba_Tsl2561/examples/Simple/Simple.ino rename to lib/Joba_Tsl2561-2.0.7/examples/Simple/Simple.ino index f1c2d88d9..5bebb7e50 100644 --- a/lib/Joba_Tsl2561/examples/Simple/Simple.ino +++ b/lib/Joba_Tsl2561-2.0.7/examples/Simple/Simple.ino @@ -21,6 +21,17 @@ This file is part of the Joba_Tsl2561 Library. #include +// to mimic Serial.printf() of esp8266 core for other platforms +char *format( const char *fmt, ... ) { + static char buf[128]; + va_list arg; + va_start(arg, fmt); + vsnprintf(buf, sizeof(buf), fmt, arg); + buf[sizeof(buf)-1] = '\0'; + va_end(arg); + return buf; +} + Tsl2561 Tsl(Wire); void setup() { @@ -44,7 +55,7 @@ void loop() { Tsl.fullLuminosity(full); Tsl.irLuminosity(ir); - Serial.printf("Tsl2561 at 0x%02x(id=0x%02x) luminosity is %5u (full) and %5u (ir)\n", Tsl.address(), id, full, ir); + Serial.print(format("Tsl2561 at 0x%02x(id=0x%02x) luminosity is %5u (full) and %5u (ir)\n", Tsl.address(), id, full, ir)); Tsl.off(); } diff --git a/lib/Joba_Tsl2561/examples/Testing/Testing.ino b/lib/Joba_Tsl2561-2.0.7/examples/Testing/Testing.ino similarity index 82% rename from lib/Joba_Tsl2561/examples/Testing/Testing.ino rename to lib/Joba_Tsl2561-2.0.7/examples/Testing/Testing.ino index 8fc6d121a..0dbeb09be 100644 --- a/lib/Joba_Tsl2561/examples/Testing/Testing.ino +++ b/lib/Joba_Tsl2561-2.0.7/examples/Testing/Testing.ino @@ -22,11 +22,22 @@ This file is part of the Joba_Tsl2561 Library. #include +// to mimic Serial.printf() of esp8266 core for other platforms +char *format( const char *fmt, ... ) { + static char buf[128]; + va_list arg; + va_start(arg, fmt); + vsnprintf(buf, sizeof(buf), fmt, arg); + buf[sizeof(buf)-1] = '\0'; + va_end(arg); + return buf; +} + Tsl2561 Tsl(Wire); void showError( Tsl2561 &tsl ) { Tsl2561::status_t status = tsl.status(); - Serial.printf("Error was %u: ", status); + Serial.print(format("Error was %u: ", status)); switch( status ) { case Tsl2561::ERR_OK: Serial.println("None"); break; case Tsl2561::ERR_RW: Serial.println("Read/Write"); break; @@ -40,7 +51,7 @@ void showError( Tsl2561 &tsl ) { void testSensitivity( Tsl2561 &tsl, bool newGain, Tsl2561::exposure_t newExp ) { if( tsl.on() ) { uint32_t start = millis(); - Serial.printf("Chip powered on at %u\n", start); + Serial.print(format("Chip powered on at %lu\n", (unsigned long)start)); bool chipGain; Tsl2561::exposure_t chipExp; @@ -58,7 +69,7 @@ void testSensitivity( Tsl2561 &tsl, bool newGain, Tsl2561::exposure_t newExp ) { bool check = true; if( change ) { if( tsl.setSensitivity(newGain, newExp) ) { - Serial.printf("New gain = %d, exposure = 0x%02x\n", newGain, newExp); + Serial.print(format("New gain = %d, exposure = 0x%02x\n", newGain, newExp)); } else { check = false; @@ -69,6 +80,7 @@ void testSensitivity( Tsl2561 &tsl, bool newGain, Tsl2561::exposure_t newExp ) { if( check ) { uint16_t ir, full = 0; + while( !full && millis() - start < 1000 ) { if( !tsl.fullLuminosity(full) ) { Serial.print("Check full luminosity failed. "); @@ -89,7 +101,7 @@ void testSensitivity( Tsl2561 &tsl, bool newGain, Tsl2561::exposure_t newExp ) { Serial.println("No luminosity reading after 1s. Too dark?"); } else { - Serial.printf("Got luminosity after %d ms. Full spectrum is %d and IR only is %d\n", millis() - start, full, ir); + Serial.print(format("Got luminosity after %lu ms. Full spectrum is %u and IR only is %u\n", (unsigned long)millis() - start, full, ir)); } } @@ -107,7 +119,7 @@ void testSensitivity( Tsl2561 &tsl, bool newGain, Tsl2561::exposure_t newExp ) { bool testPackage( Tsl2561 &tsl ) { uint8_t id; if( tsl.id(id) ) { - Serial.printf("Chip has type %02x and revision %x\n", Tsl2561::type(id), Tsl2561::revision(id) ); + Serial.print(format("Chip has type %02x and revision %x\n", Tsl2561::type(id), Tsl2561::revision(id))); if( Tsl2561::packageT_FN_CL(id) ) { Serial.println("Chip is a T, FN or CL type package"); } @@ -128,7 +140,7 @@ bool testPackage( Tsl2561 &tsl ) { void test( Tsl2561 &tsl ) { bool ok = tsl.available(); - Serial.printf("\nTesting Tsl2561 at address %02x: %sfound\n", tsl.address(), ok ? "" : "NOT "); + Serial.print(format("\nTesting Tsl2561 at address %02x: %sfound\n", tsl.address(), ok ? "" : "NOT ")); if( ok ) { if( testPackage(tsl) ) { testSensitivity(tsl, Tsl2561::GAIN_OFF, Tsl2561::EXP_402); @@ -160,4 +172,3 @@ void loop() { Serial.println("\nNext test in 5s\n"); delay(5000); } - diff --git a/lib/Joba_Tsl2561/examples/Utility/Utility.ino b/lib/Joba_Tsl2561-2.0.7/examples/Utility/Utility.ino similarity index 70% rename from lib/Joba_Tsl2561/examples/Utility/Utility.ino rename to lib/Joba_Tsl2561-2.0.7/examples/Utility/Utility.ino index 58e03ca14..d05549616 100644 --- a/lib/Joba_Tsl2561/examples/Utility/Utility.ino +++ b/lib/Joba_Tsl2561-2.0.7/examples/Utility/Utility.ino @@ -21,6 +21,17 @@ This file is part of the Joba_Tsl2561 Library. #include +// to mimic Serial.printf() of esp8266 core for other platforms +char *format( const char *fmt, ... ) { + static char buf[128]; + va_list arg; + va_start(arg, fmt); + vsnprintf(buf, sizeof(buf), fmt, arg); + buf[sizeof(buf)-1] = '\0'; + va_end(arg); + return buf; +} + Tsl2561::address_t addr[] = { Tsl2561::ADDR_GND, Tsl2561::ADDR_FLOAT, Tsl2561::ADDR_VDD }; Tsl2561 Tsl(Wire); @@ -58,18 +69,19 @@ void loop() { Tsl.fullLuminosity(scaledFull); Tsl.irLuminosity(scaledIr); - Serial.printf("Tsl2561 addr: 0x%02x, id: 0x%02x, sfull: %5u, sir: %5u, gain: %d, exp: %d", addr[i], id, scaledFull, scaledIr, gain, exposure); + Serial.print(format("Tsl2561 addr: 0x%02x, id: 0x%02x, sfull: %5u, sir: %5u, gain: %d, exp: %d", + addr[i], id, scaledFull, scaledIr, gain, exposure)); if( Tsl2561Util::normalizedLuminosity(gain, exposure, full = scaledFull, ir = scaledIr) ) { if( Tsl2561Util::milliLux(full, ir, milliLux, Tsl2561::packageCS(id)) ) { - Serial.printf(", full: %5u, ir: %5u, lux: %5u.%03u\n", full, ir, milliLux/1000, milliLux%1000); + Serial.print(format(", full: %5lu, ir: %5lu, lux: %5lu.%03lu\n", (unsigned long)full, (unsigned long)ir, (unsigned long)milliLux/1000, (unsigned long)milliLux%1000)); } else { - Serial.printf(", full: %5u, ir: %5u: Tsl2561Util::milliLux() error\n", full, ir); + Serial.print(format(", full: %5lu, ir: %5lu: Tsl2561Util::milliLux() error\n", (unsigned long)full, (unsigned long)ir)); } } else { - Serial.printf(", full: %5u, ir: %5u: Tsl2561Util::normalizedLuminosity() error\n", full, ir); + Serial.print(format(", full: %5lu, ir: %5lu: Tsl2561Util::normalizedLuminosity() error\n", (unsigned long)full, (unsigned long)ir)); } Tsl.off(); @@ -84,4 +96,3 @@ void loop() { delay(5000); } - diff --git a/lib/Joba_Tsl2561-2.0.7/examples/platformio.ini b/lib/Joba_Tsl2561-2.0.7/examples/platformio.ini new file mode 100644 index 000000000..ef71e03ae --- /dev/null +++ b/lib/Joba_Tsl2561-2.0.7/examples/platformio.ini @@ -0,0 +1,61 @@ +; PlatformIO Project Configuration File +; +; Example config for flashing nodemcuv2 boards via linux serial port +; +; Adapt (e.g. platform, board, port) to your environment as needed. +; Then call platformio.sh to copy the file to all examples. +; Now cd to the example directory (e.g. Autogain/) and do "pio run" +; to build it or directly upload with "pio run --target upload". +; Watch the serial output of your sketch with "pio device monitor". +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + + +[platformio] +src_dir = . +lib_dir = ../.. + +; uncomment one, if you want to build only one +; env_default = nodemcuv2 +; env_default = nano328 + +[env:nodemcuv2] +; TSL <-> ESP8266 +; ------------ +; GND <-> GND +; VCC <-> 3V +; SCL <-> D1 +; SDA <-> D2 +platform = espressif8266 +board = nodemcuv2 +framework = arduino +build_flags = -Wall + +monitor_speed = 115200 + +upload_speed = 230400 +upload_resetmethod = nodemcu +;usually upload port is autodetected +;upload_port = /dev/ttyUSB[1-9] + + +[env:nano328] +; TSL <-> NANO +; ------------ +; GND <-> GND +; VCC <-> 3V3 +; SCL <-> A5 +; SDA <-> A4 +platform = atmelavr +board = nanoatmega328 +framework = arduino +build_flags = -Wall + +monitor_speed = 115200 +;upload_port = /dev/ttyUSB[1-9] diff --git a/lib/Joba_Tsl2561-2.0.7/examples/platformio.sh b/lib/Joba_Tsl2561-2.0.7/examples/platformio.sh new file mode 100644 index 000000000..e5f0d3f76 --- /dev/null +++ b/lib/Joba_Tsl2561-2.0.7/examples/platformio.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# Create platformio.ini templates for all examples, if missing. +# Start this script from within the examples directory. + +for d in *; do + if [ -d "$d" -a -f "$d/$d.ino" -a ! -e "$d/platformio.ini" ] + then + cp -av platformio.ini "$d/" + fi +done + diff --git a/lib/Joba_Tsl2561-2.0.7/lib/readme.txt b/lib/Joba_Tsl2561-2.0.7/lib/readme.txt new file mode 100644 index 000000000..dbadc3d63 --- /dev/null +++ b/lib/Joba_Tsl2561-2.0.7/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/page/librarymanager/ldf.html diff --git a/lib/Joba_Tsl2561/library.json b/lib/Joba_Tsl2561-2.0.7/library.json similarity index 93% rename from lib/Joba_Tsl2561/library.json rename to lib/Joba_Tsl2561-2.0.7/library.json index cacc33d5a..94585c488 100644 --- a/lib/Joba_Tsl2561/library.json +++ b/lib/Joba_Tsl2561-2.0.7/library.json @@ -1,6 +1,6 @@ { "name": "Joba_Tsl2561", - "version": "2.0.1", + "version": "2.0.7", "keywords": "twowire, i2c, bus, sensor, luminosity, illuminance, lux", "description": "Arduino Library for ams (taos) luminance chip Tsl2561 with autogain", "repository": diff --git a/lib/Joba_Tsl2561/library.properties b/lib/Joba_Tsl2561-2.0.7/library.properties similarity index 95% rename from lib/Joba_Tsl2561/library.properties rename to lib/Joba_Tsl2561-2.0.7/library.properties index 148736de6..ba1840764 100644 --- a/lib/Joba_Tsl2561/library.properties +++ b/lib/Joba_Tsl2561-2.0.7/library.properties @@ -1,5 +1,5 @@ name=Joba Tsl2561 Library -version=2.0.1 +version=2.0.7 author=joba-1 maintainer=joba-1 sentence=IoT library for using the Tsl2561 luminosity sensor diff --git a/lib/Joba_Tsl2561-2.0.7/platformio.ini b/lib/Joba_Tsl2561-2.0.7/platformio.ini new file mode 100644 index 000000000..ea6847aaa --- /dev/null +++ b/lib/Joba_Tsl2561-2.0.7/platformio.ini @@ -0,0 +1,58 @@ +; PlatformIO Project Configuration File +; +; Example config for flashing nodemcuv2 boards via linux serial port +; +; Adapt (e.g. platform, board, port) to your environment as needed. +; Then call platformio.sh to copy the file to all examples. +; Now cd to the example directory (e.g. Autogain/) and do "pio run" +; to build it or directly upload with "pio run --target upload". +; Watch the serial output of your sketch with "pio device monitor". +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + + +[platformio] +; uncomment one, if you want to build only one +; env_default = nodemcuv2 +; env_default = nano328 + + +[env:nodemcuv2] +; TSL <-> ESP8266 +; ------------ +; GND <-> GND +; VCC <-> 3V +; SCL <-> D1 +; SDA <-> D2 +platform = espressif8266 +board = nodemcuv2 +framework = arduino +build_flags = -Wall + +monitor_speed = 115200 + +upload_speed = 230400 +upload_resetmethod = nodemcu +;usually upload port is autodetected +;upload_port = /dev/ttyUSB[1-9] + + +[env:nano328] +; TSL <-> NANO +; ------------ +; GND <-> GND +; VCC <-> 3V3 +; SCL <-> A5 +; SDA <-> A4 +platform = atmelavr +board = nanoatmega328 +framework = arduino +build_flags = -Wall + +monitor_speed = 115200 diff --git a/lib/Joba_Tsl2561/src/Tsl2561.cpp b/lib/Joba_Tsl2561-2.0.7/src/Tsl2561.cpp similarity index 85% rename from lib/Joba_Tsl2561/src/Tsl2561.cpp rename to lib/Joba_Tsl2561-2.0.7/src/Tsl2561.cpp index ad347f071..f0e324eb8 100644 --- a/lib/Joba_Tsl2561/src/Tsl2561.cpp +++ b/lib/Joba_Tsl2561-2.0.7/src/Tsl2561.cpp @@ -29,7 +29,7 @@ bool Tsl2561::available() { bool Tsl2561::begin( address_t addr ) { _addr = addr; - return available(); + return available(); } bool Tsl2561::begin() { @@ -48,24 +48,30 @@ bool Tsl2561::begin() { bool Tsl2561::readByte( register_t reg, uint8_t &val ) { _wire.beginTransmission(_addr); _wire.write(reg | CONTROL_CMD); - if( _wire.endTransmission(false) == ERR_OK ) { - if( _wire.requestFrom(_addr, 1) ) { + if( (_status = static_cast(_wire.endTransmission(false))) == ERR_OK ) { + if( _wire.requestFrom(_addr, 1) == 1 ) { val = static_cast(_wire.read()); } + else { + _status = ERR_RW; + } } - return (_status = static_cast(_wire.endTransmission())) == ERR_OK; + return _status == ERR_OK; } bool Tsl2561::readWord( register_t reg, uint16_t &val ) { _wire.beginTransmission(_addr); _wire.write(reg | CONTROL_CMD); - if( _wire.endTransmission(false) == ERR_OK ) { - if( _wire.requestFrom(_addr, 2) ) { - val = (uint16_t)_wire.read() & 0xff; - val |= ((uint16_t)_wire.read() & 0xff) << 8; + if( (_status = static_cast(_wire.endTransmission(false))) == ERR_OK ) { + if( _wire.requestFrom(_addr, 2) == 2 ) { + val = static_cast(_wire.read()) & 0xff; + val |= (static_cast(_wire.read()) & 0xff) << 8; + } + else { + _status = ERR_RW; } } - return (_status = static_cast(_wire.endTransmission())) == ERR_OK; + return _status == ERR_OK; } bool Tsl2561::writeByte( register_t reg, uint8_t val ) { diff --git a/lib/Joba_Tsl2561/src/Tsl2561.h b/lib/Joba_Tsl2561-2.0.7/src/Tsl2561.h similarity index 100% rename from lib/Joba_Tsl2561/src/Tsl2561.h rename to lib/Joba_Tsl2561-2.0.7/src/Tsl2561.h diff --git a/lib/Joba_Tsl2561/src/Tsl2561Util.cpp b/lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.cpp similarity index 78% rename from lib/Joba_Tsl2561/src/Tsl2561Util.cpp rename to lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.cpp index 92997b60b..ae811f743 100644 --- a/lib/Joba_Tsl2561/src/Tsl2561Util.cpp +++ b/lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.cpp @@ -39,22 +39,22 @@ bool normalizedLuminosity( bool gain, Tsl2561::exposure_t exposure, uint32_t &fu switch( exposure ) { case Tsl2561::EXP_14: - full = (scaledFull >= 5047/4*3) ? ~0 : ((full + 5) * 322) / 11; - ir = (scaledIr >= 5047/4*3) ? ~0 : ((ir + 5) * 322) / 11; + full = (scaledFull >= 5047/4*3) ? 0xffffffff : ((full + 5) * 322) / 11; + ir = (scaledIr >= 5047/4*3) ? 0xffffffff : ((ir + 5) * 322) / 11; break; case Tsl2561::EXP_101: - full = (scaledFull >= 37177/4*3) ? ~0 : ((full + 40) * 322) / 81; - ir = (scaledIr >= 37177/4*3) ? ~0 : ((ir + 40) * 322) / 81; + full = (scaledFull >= 37177/4*3) ? 0xffffffff : ((full + 40) * 322) / 81; + ir = (scaledIr >= 37177/4*3) ? 0xffffffff : ((ir + 40) * 322) / 81; break; case Tsl2561::EXP_402: - if( scaledFull >= 65535/4*3 ) full = ~0; - if( scaledIr >= 65535/4*3 ) ir = ~0; + if( scaledFull >= 65535/4*3 ) full = 0xffffffff; + if( scaledIr >= 65535/4*3 ) ir = 0xffffffff; break; default: return false; } - return full != ~0U && ir != ~0U; + return full != 0xffffffff && ir != 0xffffffff; } return false; @@ -72,9 +72,9 @@ uint16_t getLimit( Tsl2561::exposure_t exposure ) { // Wait for one measurement interval plus some empirically tested extra millis void waitNext( Tsl2561::exposure_t exposure ) { switch( exposure ) { - case Tsl2561::EXP_14: delay(16); break; - case Tsl2561::EXP_101: delay(103); break; - default: delay(408); break; + case Tsl2561::EXP_14: delay(Tsl2561Util::DELAY_EXP_14); break; + case Tsl2561::EXP_101: delay(Tsl2561Util::DELAY_EXP_101); break; + default: delay(Tsl2561Util::DELAY_EXP_402); break; } } @@ -95,7 +95,7 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t // get current sensitivity if( !tsl.getSensitivity(gain, exposure) ) { - return false; + return false; // I2C error } // find index of current sensitivity @@ -111,11 +111,13 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t } // in a loop wait for next sample, get values and adjust sensitivity if needed + uint8_t retryOnSaturated = 10; + while( true ) { waitNext(exposure); if( !tsl.fullLuminosity(full) || !tsl.irLuminosity(ir) ) { - return false; + return false; // I2C error } uint16_t limit = getLimit(exposure); @@ -126,13 +128,15 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t if( (full < 1000 && ++curr < sizeof(sensitivity)/sizeof(sensitivity[0])) || (full > limit && curr-- > 0) ) { if( !tsl.setSensitivity(sensitivity[curr].gain, sensitivity[curr].exposure) ) { - return false; + return false; // I2C error } gain = sensitivity[curr].gain; exposure = sensitivity[curr].exposure; } else { - return true; // saturated, but best we can do + if( ++curr > 0 && retryOnSaturated-- == 0 ) { + return true; // saturated, but best we can do + } } } } @@ -141,16 +145,32 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t bool compensateTemperature( int16_t centiCelsius, uint32_t &full, uint32_t &ir ) { // assume linear gradient 0% at 25°C to +20% at 70°C if( centiCelsius >= -3000 && centiCelsius <= 7000 ) { - full -= (full * (centiCelsius - 2500) * 20) / (100 * (7000 - 2500)); - ir -= (ir * (centiCelsius - 2500) * 20) / (100 * (7000 - 2500)); + full -= (full * (centiCelsius - 2500)) / (5 * (7000 - 2500)); + ir -= (ir * (centiCelsius - 2500)) / (5 * (7000 - 2500)); return true; } return false; } +// Round num after valid digits +uint32_t significance( uint32_t num, uint8_t digits ) { + uint8_t len = 1; + uint32_t n = num; + while( n /= 10 ) { + len++; + } + + uint32_t e10 = 1; + while( len-- > digits ) { + e10 *= 10; + } + + return ((num + e10 / 2) / e10) * e10; +} + // Calculate lux from raw luminosity values -bool milliLux( uint32_t full, uint32_t ir, uint32_t &mLux, bool csType ) { +bool milliLux( uint32_t full, uint32_t ir, uint32_t &mLux, bool csType, uint8_t digits ) { if( !full ) { mLux = 0; return true; @@ -187,6 +207,8 @@ bool milliLux( uint32_t full, uint32_t ir, uint32_t &mLux, bool csType ) { mLux /= 400 * 16 / 193; // 33 = counts/lux (cpl) } + mLux = significance(mLux, digits); // only the first 4 digits seem to make sense. + return true; } diff --git a/lib/Joba_Tsl2561/src/Tsl2561Util.h b/lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.h similarity index 79% rename from lib/Joba_Tsl2561/src/Tsl2561Util.h rename to lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.h index 58c5d4bbf..5b831183d 100644 --- a/lib/Joba_Tsl2561/src/Tsl2561Util.h +++ b/lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.h @@ -24,6 +24,14 @@ This file is part of the Joba_Tsl2561 Library. namespace Tsl2561Util { + // Some chips may need higher values. + // Tweak here if autogain does not return valid results. + typedef enum { + DELAY_EXP_14 = 20, // Max. delay in ms after + DELAY_EXP_101 = 110, // starting a measurement until + DELAY_EXP_402 = 430 // the first values arrive. + } delay_t; + // delay until next sample is available void waitNext( Tsl2561::exposure_t exposure ); @@ -40,9 +48,11 @@ namespace Tsl2561Util { // adjust luminosity according to sensor temperature (max +/-20% from 25°C) bool compensateTemperature( int16_t centiCelsius, uint32_t &full, uint32_t &ir ); - // calculate lux from normalized (and optionally temperature adjusted) luminosity - bool milliLux( uint32_t full, uint32_t ir, uint32_t &milliLux, bool csType = false ); + // helper function to round after significant digits (~4 digits for Tsl2561) + uint32_t significance( uint32_t value, uint8_t digits ); + // calculate lux from normalized (and optionally temperature adjusted) luminosity + bool milliLux( uint32_t full, uint32_t ir, uint32_t &milliLux, bool csType = false, uint8_t digits = 4 ); }; #endif diff --git a/platformio.ini b/platformio.ini index cb5da39a9..4e1e4be7b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -39,7 +39,7 @@ platform = espressif8266@1.5.0 ; *** Esp8266 core for Arduino version 2.4.0 ;platform = espressif8266@1.6.0 ; *** Esp8266 core for Arduino version 2.4.1 -;platform = espressif8266@1.7.0 +;platform = espressif8266@1.7.3 ; *** Esp8266 core for Arduino version latest beta ;platform = https://github.com/platformio/platform-espressif8266.git#feature/stage ; *** Esp8266 core for Arduino current version @@ -62,8 +62,7 @@ build_flags = monitor_speed = 115200 ; *** Upload Serial reset method for Wemos and NodeMCU -;upload_speed = 115200 -upload_speed = 512000 +upload_speed = 115200 upload_resetmethod = nodemcu upload_port = COM5 ; *** Fix Esp/Arduino core 2.4.x induced Tasmota unused floating point includes diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino new file mode 100644 index 000000000..c603f826f --- /dev/null +++ b/sonoff/_changelog.ino @@ -0,0 +1,1391 @@ +/* 6.1.1b + * Add support for MCP230xx for general purpose input expansion and command Sensor29 (#3188) + * Fix command Scale buffer overflow (#3236) + * Fix rules once regression from v6.1.0 (#3198, #3226) + * Add default Wifi Configuration tool as define WIFI_CONFIG_NO_SSID in user_config.h if no SSID is configured (#3224) + * Add user selection of Wifi Smartconfig as define USE_SMARTCONFIG in user_config.h + * Add user selection of WPS as define USE_WPS in user_config.h in preparation for core v2.4.2 (#3221) + * Change default Wifi config option from WPS to Wifi Manager if WPS is disabled + * or Wifi Smartconfig if webserver is disabled + * or Wifi Serial input if Smartconfig is disabled + * Remove WPS and SmartConfig from sonoff-minimal saving 56k code space + * + * 6.1.1a + * Fix TM1638 compile error (#3212) + * Add TM1638 switch support (#2226) + * Fix invalid response using more than 4 switches and domoticz + * Update sensor drivers to provide instant results + * Add read sensor retry to DS18B20, DS18x20, DHT, SHT1X and HTU21 + * Change SHT1x driver to provide better instant results + * Fix DHT driver mixing values for different sensors (#1797) + * Change DHT driver to provide better instant results and add decimals to DHT11 (#3164) + * Change DS18x20 driver to provide better instant results (#3169) + * Change DS18B20 driver to provide better instant results + * Remove TSL2561 debug message and update library (#2415) + * Change SHT1x sensor initialization from pre-teleperiod to once during restart to fix I2C interference + * Add wifi and mqtt status led blinkyblinky to be disabled by SetOption31 1. Does not work when LedPower is On (deliberate) (#871, #2230, #3114, #3155) + * Add experimental (untested) TM1638 switch support (#2226) + * Add support for APDS9960 proximity sensor (#3051) + * Add heap and stack debug information + * Add debug facilities using optional xdrv_99_debug.ino to enable in user_config.h + * Remove not needed functionality from Sonoff-minimal to save space + * + * 6.1.1 20180714 + * Revert wifi changes (#3177) + * Revert sonoff-minimal removals causing failure of wifi connection (#3177) + * + * 6.1.0 20180706 + * Remove version 3, 4 and pre 5.2 settings auto-upgrade. See https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade#migration-path + * Change default CFG_HOLDER from 0x20161209 to 4617 (=0x1209) - no impact on default upgrades + * Change number of supported switches from 4 to 8 (#2885, #3086) + * Change BME680 driver from Adafruit to Bosch BME680 library (#2969) + * Fix Pzem004T checksum error + * Fix KNX bug when doing reply of sensors values + * Fix rules induced LWT message + * Fix possible wifi connection problem (#1366) + * Fix some Pow R2 and S31 checksum errors (#1907) + * Fix display selection of un-available GPIO options in Module Configuration webpage (#2718) + * Fix timer re-trigger within one minute after restart (#2744) + * Fix IRSend not accepting data value of 0 by David Conran (#2751) + * Fix vars on rules by Adrian Scillato (#2769) + * Fix bug in KNX menu by Adrian Scillato (#2770) + * Fix anomalies in rules (#2778) + * Fix HUE bridge V1 software version by Heiko Krupp (#2788) + * Fix Hardware Watchdog restart when using event command (#2853) + * Add Ukrainian language file + * Add KNX support for DS18S20 Temperature sensor + * Add CRC to Settings making future upgrades more fail-safe + * Add feature information to Status 4 + * Add tools folder with python script decode-status.py for decoding some status fields like SetOption and Features + * Add Slots on the KNX Web Menu to select Group Addess to receive data to trigger rules + * Add two rule sets of 511 characters using commands rule1, rule2 and rule3 + * Add Console Commands to send KNX Commands and KNX Values + * Add Slots on the KNX Web Menu to select Group Addess to send data from console commands + * Add Events to trigger rules when a command or read requests is received from KNX + * Add command SetOption30 to enforce Hass discovery as light group (#1784) + * Add support for BlitzWolf BW-SHP2 (and Homecube, Gosund SP1) Energy Monitoring Smart Socket (#2223) + * Add time in minutes to rule Time#Initialized, Time#set and Time#Minute (#2669) + * Add Eastron SDM630 energy meter by Gennaro Tortone (#2735) + * Add KNX communication enhancement by Adrian Scillato (#2742) + * Add KNX energy data by Adrian Scillato (#2750) + * Add rule support for IrReceive and RfReceive (#2758) + * Add python script fw-server.py in tools folder to create a simple OTA server by Gennaro Tortone (#2759) + * Add rule variables %time% for minutes since midnight, %uptime%, %sunrise% and %sunset% giving time in minutes (#2669) + * Add rules %mem1% to %mem5% variable names storing data in flash (#2780) + * Add rules test on %varx% or %memx% (#2780) + * Add optional token %id% substituting the unique MAC address to fulltopic by Michael Graf (#2794) + * Add support for Sonoff S26 Smart Socket (#2808) + * Add command WebSend [(:,:)] (#2821) + * Add increment and decrement value to command Counter (#2838) + * Add support for Sonoff iFan02 as module 44 introducing command FanSpeed 0..3 (#2839) + * Add source information to command execution to be shown with logging option 3 (#2843) + * Add support for uploading Sonoff Bridge firmware found in tools/fw_efm8bb1 folder build by Portisch using Web Gui File Upload (#2886) + * Add command RfRaw to control Portisch firmware features + * Add support for I2C temperature sensor LM75AD (#2909) + * Add option 0 to command Timers disarming all timers (#2962) + * Add performance improvement when updating multiple individual WS2812 pixels (#3007) + * Add command SetOption28 to switch between hex or decimal Sonoff Bridge RF received data format (#3008) + * Add command SetOption29 to switch between hex or decimal IR received data format + * Add decimal values support for commands ADD, SUB, MULT and SCALE (#3083, #3089) + * Add support for bitflags SetOption50 .. SetOption81 (#3118) + * + * 5.14.0 20180515 + * Update language files + * Update TasmotaSerial to 2.0.0 allowing Hardware Serial Fallback when correct connections are configured + * Change command handling + * Change user_config(_override).h defines TIME_STD and TIME_DST + * Change user_config(_override).h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602) + * Fix configuration restore regression from 5.13.1 + * Fix compile error when ADC is enabled and Rules are disabled (#2608) + * Fix rule power trigger when no backlog command is used (#2613) + * Fix several timer data input and output errors (#2597, #2620) + * Fix KNX config error (#2628) + * Fix sensor MHZ-19 vanishing data over time (#2659) + * Fix KNX reconnection issue (#2679) + * Fix DST and STD time for Southern Hemisphere by Adrian Scillato (#2684, #2714) + * Add Portuguese in Brazil language file + * Add SetOption26 to enforce use of indexes even when only one relay is present (#1055) + * Add support for sensor SI1145 UV Index / IR / Visible light (#2496) + * Add rule state test for On/Off in addition to 0/1 (#2613) + * Add hardware serial option to MHZ-19 sensor (#2659) + * Add Eastron SDM120 energy meter by Gennaro Tortone (#2694) + * Add user entry DST/STD using commands TimeStd and TimeDst (See wiki for parameter syntax) (#2721) + * + * 5.13.1 20180501 + * Fix JSON buffers size too small for execution in some situations (#2580) + * Fix configuration restore (#2591) + * Add define MODULE for user selecting default model although it preferably should not be changed (#569, #2589) + * + * 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 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) + * 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 + * 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) + * Add Sonoff Bridge command RfKey 5 to show current RF key values either default or learned (#1884) + * Add user configurable serial GPIOs to MagicHome and Arilux modules (#1887) + * Add Russian language file (#1909) + * Add Webserver upload preflight request support (#1927) + * Add Home Assistant clear other device (#1931) + * Add Restart time to Status 1 (#1938) + * 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) + * 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 + * Change relation of define MESSZ being dependent on PubSubClient.h define MQTT_MAX_PACKET_SIZE + * Change command color parameter input checks to less strict for Home Assistant support + * Change command Ina219Mode into command Sensor13 + * Change commands HlwPCal, HlwUCal and HlwICal to PowerCal, VoltageCal and CurrentCal to be used for both Pow and S31 calibration + * Change commands HlwPSet, HlwUSet and HlwISet to PowerSet, VoltageSet and CurrentSet to be used for both Pow and S31 calibration + * Change uptime from hour to second resulting in a display of 123T13:45:21 where 123 is days + * Change module name Wemos D1 mini into Generic (#1220) + * Change HTML from width=100% to style=width:100% supporting HTML5 (#1358) + * Change OSWATCH_RESET_TIME (Blocked loop) from 30 to 120 seconds to allow slow networks (#1556) + * Change WIFI_MANAGER_SEC into WIFI_CONFIG_SEC (#1616) + * Change function pointers code to save code space and memory (#1683) + * Change webserver argument processing gaining 5k code space (#1705) + * Change weblog memory usage (#1730, #1793, #1819) + * Update TasmotaSerial library to 1.1.0 + * Update language files Italian (#1594), Dutch (#1723) and Spanish (#1722) + * Fix Non-English JSON temperature unit attachement + * Fix Arilux RF induced exception by moving interrupt handler to iram on non ESP8266/Arduino lib v2.3.0 + * Fix truncated command names and wrong response for DomoticzSwitchIdx (#1571) + * Fix %-sign issue as printf escape character in Humidity and Sonoff SC (#1579) + * Fix DS18B20 temperature JSON decimal dot (#1561) + * Fix Energy JSON message (#1621) + * Fix IRSend parameter translation (#1636) + * Fix TSL2561 device detection (#1644, #1825) + * Fix BME680 teleperiod resistance measuring (#1647) + * Fix Energy Monitoring Energy Today and Energy Total reading after restart (#1648) + * Fix IRReceive Data value (#1663) + * Fix Energy Monitoring Energy Period roll-over (#1688) + * Fix compiler warnings (#1774) + * Fix command PWM response if no PWM channel is configured (#1783) + * Add locale Decimal Separator to Web sensor page + * Add ColorTemperature to light status message + * Add command PowerOnState option 5 which inverts PulseTime and allows for delayed always on after power on + * Add OtaMagic two step Web server OTA upgrade using filename-minimal image if OTA free space is too small + * Add support for PMS5003 and PMS7003 particle concentration sensor + * Add command SetOption21 1 to allow Energy Monitoring when power is off on Sonoff Pow and Sonoff S31 (#1420) + * Add Chinese language file (#1551) + * Add French language file (#1561) + * Add Spanish language file (#1589) + * Add HTTP Allow Cross Origin removed from ESP8266/Arduino lib v2.4.0 (#1572) + * Add Home Assistant MQTT Discovery for switch and light to be enabled by command SetOption19 1 (#1534) or define HOME_ASSISTANT_DISCOVERY_ENABLE in user_config.h (#1685) + * Add command State to retrieve device state information (same data as teleperiod state and status 11 in slightly different JSON format) + * Add optional login to Webserver AP mode (#1587, #1635) + * Add command Sensor15 2 to start MHZ19(B) Zero Point Calibration (#1643) + * Add support for Sonoff S31 Smart Socket with Power Consumption Detection (#1626) + * Add command SetOption20 to allow update of Dimmer/Color/Ct without turning power on (#1719, #1741) + * Add NTP sync time slot based on chip id (#1773) + * Add cursor pointer to web button (#1836) + * + * 5.11.1 20180107 + * Fix Sonoff Pow command handling (#1542) + * + * 5.11.0 20180107 + * Minor webpage HTML optimizations (#1358) + * Updated German translation (#1438) + * Change Sonoff Pow Energy MQTT data message and consolidate Status 8 into Status 10 + * Change ADS1115 default voltage range from +/-2V to +/-6V (#1289) + * Change text to Active for 3 minutes (#1364) + * Change Wemo SetBinaryState to distinguish from GetBinaryState (#1357) + * Change output of HTTP command to valid JSON and Array only (#1363) + * Removed all MQTT, JSON and Command language defines from locale files and set fixed to English (#1473) + * Renamed commands Color2,3,4 to Color3,4,5 + * Fix BME280 calculation (#1051) + * Fix Sonoff Bridge missed learned key if learned data contains 0x55 (End of Transmission) flag (#1095, #1294) + * Fix PWM initialization in Dimmer/Color mode (#1321) + * Fix Wemo Emulation (#1357) + * Fix display of build date and time in non-english locale (#1465) + * Fix Wemo and Hue emulation by adding M-Search response delay (#1486) + * Add libraries Adafruit_BME680-1.0.5, Adafruit_Sensor-1.0.2.02, TasmotaSerial-1.0.0 and TSL2561-Arduino-Library + * Add command Color2 to set color while keeping same dimmer value + * Add device function pointers + * Add support for SenseAir S8 CO2 sensor + * Add color led signal to Carbon Dioxide (CO2) sensors using defines CO2_LOW and CO2_HIGH in user_config.h + * Add support for Domoticz Air Quality sensor to be used by MH-Z19(B) and SenseAir sensors + * Add support for PZEM004T energy sensor + * Add support for iTead SI7021 temperature and humidity sensor by consolidating DHT22 into AM2301 and using former DHT22 as SI7021 (#735) + * Add support for BME680 using adafruit libraries (#1212) + * Add support for MH-Z19(B) CO2 sensor (#561, #1248) + * Add multipress support and more user configurable GPIO to Sonoff Dual R2 (#1291) + * Add support for TSL2561 using adafruit library (#661, #1311) + * Add support for SHT3x (#1314) + * Add support for Arilux LC06 (#1414) + * Add Italian language file (#1449) + * Add 2nd Gen Alexa support to Wemo emulation discovery (#1357, #1450) + * Add define for additional number of WS2812 schemes (#1463) + * + * 5.10.0 20171201 + * Upgrade library ArduinoJson to 5.11.2 + * Upgrade library IRRemoteEsp8266 to 2.2.1 + 2 commits but disabled some protocols (code size reduction) + * Upgrade library NeoPixelBus to 2.2.9 + * Upgrade library OneWire to 2.3.3 + 6 commits and disabled CRC lookup-table (#define ONEWIRE_CRC8_TABLE 0) (code size reduction) + * Update library PubSubClient to 2.6 + 9 commits and additional delay (#790) + * Update core_esp8266_wiring_digital.c to latest (staged) level + * Patch library I2Cdevlib-Core for esp8266-core 2.4.0-rc2 compatibility + * Remove command EnergyReset 1..3 now replaced by EnergyReset1 to EnergyReset3 + * Remove spaces in JSON messages (code size reduction) + * Renamed xsns_05_ds18x20.ino to xsns_05_ds18x20_legacy.ino still using library OneWire and providing dynamic sensor scan + * Fix possible iram1_0_seg compile error by shrinking ICACHE_RAM_ATTR code usage + * Fix PWM watchdog timeout if Dimmer is set to 100 or Color set to 0xFF (#1146) + * Fix Sonoff Bridge Learn Mode hang caused by unrecognised RF code (#1181) + * Fix blank console log window by using XML character encoding (#1187) + * Fix wrong response name for command HlwISet (#1214) + * Fix DHT type sensor timeout recognition by distinguish "signal already there" from "timeout" (#1233) + * Add fixed color options 1..12 to command Color + * Add + (plus) and - (minus) to commands Dimmer (+10/-10), Speed and Scheme + * Add + (plus) and - (minus) to command Color to select 1 out of 12 preset colors + * Add + (plus) and - (minus) to command Ct to control ColdWarm led ColorTemperature (+34/-34) + * Add commands EnergyReset1 0..42500, EnergyReset2 0..42500 and EnergyReset3 0..42500000 + * to (Re)set Energy Today, Yesterday or Total respectively in Wh (#406, #685, #1202) + * Add optional ADS1115 driver as alternative for unsupported I2Cdevlib in esp8266-core 2.4.0-rc2 + * Add support for INA219 Voltage and Current sensor to be enabled in user_config.h with define USE_INA219 + * Add support for Arilux LC11 (Clearing RF home code when selecting no Arilux module) + * Add support for WS2812 RGBW ledstrips to be enabled in user_config.h with define USE_WS2812_CTYPE (#1156) + * Add SettingsSaveAll routine to command SaveData to be used before controlled power down (#1202) + * Add option PUSHBUTTON_TOGGLE (SwitchMode 7) to allow toggling on any switch change (#1221) + * Add new xdrv_05_ds18x20.ino free from library OneWire and add the following features: + * Add support for DS1822 + * Add forced setting of 12-bit resolution for selected device types (#1222) + * Add read temperature retry counter (#1215) + * Fix lost sensors by performing sensor probe at restart only thereby removing dynamic sensor probe (#1215) + * Fix sensor address sorting using ascending sort on sensor type followed by sensor address + * Rewrite JSON resulting in shorter message allowing more sensors in default firmware image: + * "DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6} + * Add additional define in user_config.h to select either single sensor (defines disabled), new multi sensor (USE_DS18X20) or legacy multi sensor (USE_DS18X20_LEGACY) + * Add clock support for more different pixel counts (#1226) + * Add support for Sonoff Dual R2 (#1249) + * Add FriendlyName to web page tab and add program information to web page footer (#1275) + * + * 5.9.1 20171107 + * Add external sensor function pointer interface to enable easy sensor addition + * Add support for ADS1115 to be enabled in user_config.h and needs libraries i2cdevlib-Core and i2cdevlib-ADS1115 (#338, #660) + * Fix Backup Configuration file download failure by defining proper file size (#1115) + * Fix Exception 26 and empty console screen after usage of command WakeupDuration (#1133) + * Fix some changed iTead web links in README.md (#1137) + * + * 5.9.0 20171030 + * Rewrite code (partly) using Google C++ Style Guide (https://google.github.io/styleguide/cppguide.html) + * Rewrite code by using command lookup tables and javascript (client side) web page expansions + * Change HTML/CSS to enable nicer form field entry + * Change default PWM assignments for H801 RGB(CW) led controller to support optional Color/Dimmer control + * GPIO04 (W2) from GPIO_PWM2 to GPIO_USER to be user configurable for GPIO_PWM5 (second White - Warm if W1 is Cold) + * GPIO12 (Blue) GPIO_PWM3 no change + * GPIO13 (Green) from GPIO_PWM4 to GPIO_PWM2 + * GPIO14 (W1) from GPIO_PWM1 to GPIO_USER to be user configurable for GPIO_PWM4 (first White - Cold or Warm) + * GPIO15 (Red) from GPIO_PWM5 to GPIO_PWM1 + * Change default PWM assignments for MagicHome RGB(W) led controller to support optional Color/Dimmer control + * GPIO05 (Green) from GPIO_PWM4 to GPIO_PWM2 + * GPIO12 (Blue) from GPIO_PWM5 to GPIO_PWM3 + * GPIO13 (White) GPIO_USER to be user configurable for GPIO_PWM4 (White - Cold or Warm) + * GPIO14 (Red) from GPIO_PWM3 to GPIO_PWM1 + * Change default PWM assignment for Witty Cloud to support optional Color/Dimmer control (#976) + * GPIO12 (Green) from GPIO_PWM4 to GPIO_PWM2 + * GPIO13 (Blue) from GPIO_PWM5 to GPIO_PWM3 + * GPIO15 (Red) from GPIO_PWM3 to GPIO_PWM1 + * Change when another module is selected now all GPIO user configuration is removed + * Change command name IRRemote to IRSend (#956) + * Remove Arduino IDE version too low warning as it interferes with platformio.ini platform = espressif8266_stage + * Fix command FullTopic entry when using serial or console interface + * Fix possible UDP syslog blocking + * Fix minimum TelePeriod of 10 seconds set by web page + * Fix command GPIOx JSON response (#897) + * Fix inverted relay power on state (#909) + * Fix compile error when DOMOTICZ_UPDATE_TIMER is not defined (#930) + * Fix alignment of web page items in some browsers (#935) + * Fix setting all saved power settings to Off when SetOption0 (SaveState) = 0 (#955) + * Fix timezone range from -12/12 to -13/13 (#968) + * Fix Southern Hemisphere TIME_STD/TIME_DST (#968) + * Fix TLS MQTT SSL fingerprint test (#970, #808) + * Fix virtual relay status message used with Color/Dimmer control (#989) + * Fix command IRSend and IRHvac case sensitive parameter regression introduced with version 5.8.0 (#993) + * Fix pressure calculation for some BMP versions regression introduced with version 5.8.0i (#974) + * Fix Domoticz Dimmer set to same level not powering on (#945) + * Fix Blocked Loop when erasing large flash using command reset 2 (#1002) + * Fix relay power control when light power control is also configured as regression from 5.8.0 (#1016) + * Fix Mqtt server mDNS lookup only when MqttHost name is empty (#1026) + * Add debug information to MQTT subscribe + * Add translations to I2Cscan + * Add translation to BH1750 unit lx + * Add light scheme options (Color cycle Up, Down, Random) and moving WS2812 schemes up by 3 + * Add Domoticz counter sensor to IrReceive representing Received IR Protocol and Data + * Add option 0 to MqttHost to allow empty Mqtt host name + * Add support for Arilux AL-LC01 RGB Led controller (#370) + * Add esp8266 de-blocking to PubSubClient library (#790) + * Add Domoticz sensors for Voltage and Current (#903) + * Add platformio OTA upload support (#928, #934) + * Add warning to webpage when USE_MINIMAL is selected (#929) + * Add smoother movement of hour hand in WS2812 led clock (#936) + * Add support for Magic Home RGBW and some Arilux Led controllers (#940) + * Add command SetOption15 0 (default) for command PWM control or SetOption15 1 for commands Color/Dimmer control to PWM RGB(CW) leds (#941) + * Add Domoticz counter sensor to Sonoff Bridge representing Received RF code (#943) + * Add support for Luani HVIO board (https://luani.de/projekte/esp8266-hvio/) (#953) + * Add PWM initialization after restart (#955) + * Add IR Receiver support. Disable in user_config.h (#956) + * Add support for inverted PWM (#960) + * Add Sea level pressure calculation and Provide command Altitude (#974) + * Add support for up to 8 relays (#995) + * Add commands RfSync, RfLow, RfHigh, RfHost and RfCode to allow sending custom RF codes (#1001) + * Add retain to ENERGY messages controlled by command SensorRetain (#1013) + * Add commands Color2, Color3, Color4, Width2, Width3, Width4 and SetOption16 to set Ws2812 Clock parameters (#1019) + * Add German language file (#1022) + * Add support for connecting to MQTT brokers without userid and/or password (#1023) + * Add support for esp8266 core v2.4.0-rc2 (#1024) + * Add commands PwmRange 1,255..1023 and PwmFrequency 1,100..4000 (#1025) + * Add Polish language file (#1044, #1047) + * Add support for KMC 70011 Power Monitoring Smart Plug (#1045) + * Add support for VEML6070 I2C Ultra Violet level sensor (#1053) + * Add light turn Off Fade (#925) + * Add IrSend command option Panasonic as IrSend {"Protocol":"Panasonic", "Bits":16388, "Data":} + * where 16388 is 0x4004 hexadecimal (#1014) + * Add retry counter to DHT11/21/22 sensors (#1082) + * + * 5.8.0 20170918 + * Remove the need for NeoPixelBus library for Hue support + * Consolidate WS2812 into Sonoff Led for flexible future led strip library changes + * Invert WS2812 fade speed to align with Sonoff led (Speed 1 = fast, Speed 8 = slow) + * Remove upper case MQTT receive buffer + * Reduce code and string length for output of commands Modules and GPIOs + * Add Sonoff SC debug information + * Change syslog service + * Removed webserver syslog disable as now no longer needed + * Increased default MQTT message size from 368 to 405 bytes while keeping MQTT_MAX_PACKET_SIZE = 512 (because we can) + * Fix MQTT Offline or Remove MQTT retained topic code + * Fix Domoticz loop when Emulation is selected + * Add blink to WS2812 and Sonoff Led (#643) + * Add option WIFI_WAIT (5) to command WifiConfig to allow connection retry to same AP without restart or update flash (#772, #869) + * Add support for Witty Cloud (#794) + * Add GPIO14 to Sonoff Dual (#797, #839) + * Add support for Yunshan Wifi Relay (#802) + * Add GPIO16 input pulldown (#827) + * Add timeout to DHT and DS18B20 sensors (#852) + * Fix watchdog timeout caused by lack of stack space by moving to heap (#853) + * Allow LogPort and MqttPort up to 65535 and add LogPort tot Status 3 (#859) + * Allow command SwitchTopic in group mode (#861) + * Allow command SwitchMode if no switches are defined (#861) + * Add optional dimmer parameter to command Wakeup for WS2812, AiLight, Sonoff B1, Led and BN-SZ01 (#867) + * Fix basic On, Off, Toggle, Blink and BlinkOff commands when other language is selected (#874) + * + * 5.7.1 20170909 + * Remove leading spaces from MQTT data + * Fix webconsole special character entry + * Allow # as prefix for color value + * Fix Alexa detection and Hue App Update Request (#698, #854) + * + * 5.7.0 20170907 + * Shrink module configuration webpage + * Fix settings order during startup to allow for displaying debug messages + * Fix some string length issues + * Add more string length tests by using strncpy + * Add Ai-Thinker RGBW led (AiLight) + * Add Power check and add PulseTime to power check at startup (#526) + * Add Supla Espablo support (#755) + * Add more precision to Sonoff Pow period and power results using command WattRes 0|1 (#759) + * Add basic internationalization and localization (#763) + * Add more Sonoff Pow range checking (#772) + * Fix invalid JSON (#786, #822) + * Add duplicate check to received RF signal within 2 seconds for Sonoff Bridge (#810) + * + * 5.6.1 20170818 + * Change module list order in webpage + * Fix Sonoff T1 1CH and 2CH configuration (#751) + * + * 5.6.0 20170818 + * Fix Sonoff Pow intermittent exception 0 + * Change Sonoff Pow sending Domoticz telemetry data only + * Add Ai-Thinker RGBW led (AiLight) (experimental) + * Add NeoPixelBus library to Sonoff Led for Hue support + * Add user configurable GPIO4 and GPIO5 to module Sonoff Bridge + * Add Sonoff B1 RGBCW led support with command Color RRGGBBCCWW (#676) + * Add command CT 152..500 to Sonoff Led and Sonoff B1 to control Color Temperature + * Add Cold-Warm slider to web page for Sonoff Led and Sonoff B1 + * Add CT parameter to Hue + * Add Sonoff T1 support (#582) + * Add AnalogInput0 if configured as Analog Input to webpage (#697, #746) + * Add command SetOption14 0|1 to enable interlock mode (#719, #721) + * Fix Mitsubishi HVAC IR power controll (#740) + * + * 5.5.2 20170808 + * Extent max number of WS2812 pixels from 256 to 512 (#667) + * Add OTA handling if server responds with no update available (#695) + * Removed undocumented command FlashMode (#696) + * Fix compile time error message due to increased message buffer size (#703) + * + * 5.5.1 20170805 + * Fix Sonoff Rf Bridge issues + * Add Sonoff RF Bridge MQTT messages on received and learned RF signal + * Add command VoltRes 0|1 to select voltage resolution to 0.1 V (#654) + * Add averaging to Analog input (#686) + * Add Energy tele data on Sonoff Pow Threshold change (#688) + * Fix inconsistent property names in Messages (#690) + * + * 5.5.0 20170730 + * Reduce code space by removing the following commands as they are replaced by SetOption alternatives: + * SaveState = SetOption0 + * ButtonRestrict = SetOption1 + * Units = SetOption2 + * MQTT = SetOption3 + * MQTTResponse = SetOption4 + * TempUnit = SetOption8 + * Smoothing WS2812 animation poll, invert fade speed and max allowed wakeup time down to 3000 seconds + * Fix initial button press detection + * Add support for Sonoff RF Bridge 433 using command RfKey + * Fix regression from 5.0.7 by increasing message buffer size from 360 to 368 to accomodate 4 x DS18x20 sensors (#637) + * Add GroupTopic to Topic test when using ButtonTopic/SwitchTopic to send either ON/OFF or TOGGLE (#642) + * Adjust HLW calibration limits to accomodate HuaFan device and add commands HlwPSet, HlwUSet and HlwISet (#654) + * + * 5.4.0 20170725 + * Fix command reset regression introduced in 5.2.0 + * Increase polling from 0.1 second to 0.05 second + * Add multipress to all buttons + * Fix button 1 double press behaviour on multi relay devices + * Add support for Hua Fan Smart Socket (#479) + * Add support for Sonoff 4ch Pro (#565) + * Add command SetOption13 1 to allow immediate action on single button press + * (disables multipress, hold and unrestricted commands) (#587) + * + * 5.3.0 20170715 + * Major Hue rewrite which might introduce Alexa problems. If so, initiate an issue + * Add support for Sonoff Led and BN-SZ01 Ceiling Led brightness control to Hue + * Fix Sonoff Led Power, Dimmer and Color MQTT response (#176) + * Add commands Delay and Backlog to allow multiple commands at once separated by ";" (#593) + * Use default flashmode DOUT to solve restart hangs on esp8285 chips (#453, #598) + * Change Web console column width from 99 to 300 (#599) + * + * 5.2.4 20170703 + * Removed flash mode update after selecting different module solving esp8285 related problems + * Add device type flag to sonoff_template.ino + * Change Sonoff Led Wakeup and add support for Sonoff BN-SZ01 Led (#567) + * + * 5.2.3 20170630 + * Change Sonoff Led color conversion code + * Fix SetOption12 handling + * Simplify auto configuration upgrade + * Add option Upgrade to only upgrade to any higher version (Old PR #213) + * Change FallbackTopic to cmnd// bypassing FullTopic and Prefix (#538) + * + * 5.2.2 20170625 + * Add configuration SaveAddress to Status 1 and Information Page + * Change Sonoff Led Color conversion from AtoH to strtol + * Fix possible wrong uploads due to configuration overwrites (#542) + * Fix payload negative numbers (#547) + * + * 5.2.1 20170622 + * Fix Restore Configuration in case of lower version + * Revert auto configuration upgrade allowing easy upgrade which was removed in version 5.2.0 + * Fix config auto upgrade from versions below version 4.1.1 (#530) + * + * 5.2.0 20170619 + * Add command SetOption12 1 to disable newly released configuration flash rotate to reduce flash wear + * Fix command CounterDebounce by removing test for active GPIO (#524) + * Add command SetOption33 1..250 to allow user configure POW Max_Power_Retry count (#525) + * + * 5.1.7 20170616 + * Prep removal of SetOptions alternatives + * Restore webpage upgrade error messages removed in 5.1.5 + * Add hold button functionality to buttons 2 to 4 + * Add command SetOption32 1..100 to set Key Hold Time from 0.1 seconds to 10 seconds (#200) + * Allow slashes in Topic, GroupTopic, ButtonTopic and SwitchTopic (#507) + * Changed webpage form actions from post to get and use relative path url (#434, #522) + * + * 5.1.6 20170606 + * Shrink code + * Removed online configuration of Domoticz In and Domoticz Out MQTT strings + * Removed commands DomoticzInTopic and DomoticzOutTopic + * Add define KEY_HOLD_TIME to configure button hold threshold before sending MQTT Hold message + * Add command StateText4 to configure button MQTT Hold text (= MQTT_CMND_HOLD) + * Add command SetOption11 0|1 to swap pushbutton single and double press functionality (#200) + * Add command SwitchMode 5 (PUSHBUTTONHOLD) and 6 (PUSHBUTTONHOLD_INV) (#489) + * + * 5.1.5 20170604 + * Shrink code in preparation to ESP8266-Arduino 2.4.0-rc1 + * Add effect parameter to HUE Device (#464) + * + * 5.1.4 20170601 + * Removed pre-compiled versions from repository as they are available within the release + * Changed HUE Device type to color supporting version (#464) + * Fix compile error when BE_MINIMAL is selected (#467, #476) + * Add multiple compiled versions to release using updated Travis script and platformio.ini (#467) + * + * 5.1.3 20170520 + * Add Domoticz Counter + * + * 5.1.2 20170519 + * Fix Counter/Timer JSON message and update Counter/Timer on webpage + * Fix WS2812 Domoticz related regression issues + * + * 5.1.1 20170517 + * Allow command FullTopic in group mode + * Prepare for more use of RTC memory + * Add independant WS2812 led string power control (#386, #390) + * Add command Counter to control up to four GPIO falling edge interrupt counters or timers (#459) + * Add command CounterType to select between pulse counting or pulse timing + * Add command CounterDebounce to select global counter debounce time in mSec + * + * 5.1.0 20170513 + * Fix Offline/Removal of retained topic when FullTopic is changed + * Add FullTopic to MQTT Configuration and Information web pages + * Add license model GPLv3 (#188) + * + * 5.0.7 20170511 + * Fix possible exception 28 on empty command + * Add command SetOption0 as replacement for SaveState + * Add command SetOption1 as replacement for ButtonRestrict + * Add command SetOption2 as replacement for Units + * Add command SetOption4 as replacement for MqttResponse + * Add command SetOption8 as replacement for TempUnit + * Add command SetOption10 On|Off to select between Offline or Removing previous retained topic (#417, #436) + * + * 5.0.6 20170510 + * Remove hyphen in case of a single DHT sensor connected (#427) + * Add command MqttRetry to change default MQTT reconnect retry timer from minimal 10 seconds (#429) + * + * 5.0.5 20170508 + * Add command FullTopic with tokens %topic% (replaced by command Topic value) and + * %prefix% (replaced by command Prefix values) for more flexible topic definitions (#244) + * See wiki > MQTT Features https://github.com/arendst/Sonoff-Tasmota/wiki/MQTT-Features for more information + * + * 5.0.4 20170505 + * Add Sonoff Pow Energy Total up to 40 MWh + * Add command EnergyReset 1|2|3 to reset Energy counters (#406) + * Fix Domoticz Energy logging (#411) + * Add command PowerOnState 4 to keep relay always on and disabling all power control (#418) + * + * 5.0.3 20170504 + * Add command SensorRetain on|off to enable retaining of mqtt message tele/sonoff/SENSOR (#74) + * Change WifiConfig timeout from 60 seconds to 180 seconds (#212) + * Change Sonoff Touch command Ledstate functionality by turning led on if power is off (#214) + * Add 4 seconds delay after power on before enabling button to workaround Wemos D1 mini RTS circuit (#380) + * + * 5.0.2 20170503 + * Reset SaveData, SaveState and MqttResponse to default values due to rearranging settings + * Moved some settings to flag area + * Add command TempUnit Celsius|Fahrenheit for selecting Celsius or Fahrenheit (#347) + * Add command TempRes 0..3 for selecting Temperature Resolution (#347) + * Add command HumRes 0..3 for selecting Humidity Resolution (#347) + * Add command PressRes 0..3 for selecting Pressure Resolution (#347) + * Add command EnergyRes 0..5 for selecting Energy Resolution (#347) + * Add "TempUnit":"C|F" to sensor JSON output (#347) + * Add support for up to three DHT type sensors each using a different GPIO (#339, #404) + * + * 5.0.1 20170429 + * Adjust Sonoff SC messages to prepare for display feature + * Move static data from RAM to Flash + * Fix PowerOnState for some devices not reporting "Power on" state (#284, #380, #383) + * + * 5.0.0 20170425 + * Memory status message update + * Fix setting migration to better preserve settings during move (#382) + * Best practice is first doing a Backup Configuration before installing version 5.0.0 + * Reset save count after setting move + * Start using new linker script without SPIFFS + * + * 4.2.0 20170424 + * Prepare for SPIFFS removal by moving settings to EEPROM area + * Fix compilation error when webserver is disabled (#378) + * + * 4.1.3 20170410 + * Add user configuarble GPIO to module S20 Socket and Slampher + * Add support for Sonoff SC (#112) + * Set PWM frequency from 1000Hz to 910Hz as used on iTead Sonoff Led firmware (#122) + * Set Sonoff Led unconfigured floating outputs to 0 to reduce exceptions due to power supply instabilities (#122) + * Add Access Point Mac Address to Status 11 and Telemetry (#329) + * Fix DS18B20 negative temperature readings (#334) + * + * 4.1.2 20170403 + * Rename Unrecognised command to Unknown command + * Remove all command lists + * Remove command SmartConfig (superseded by WifiConfig) + * Fix boot loop when selecting module Sonoff 4CH or Sonoff Touch on non ESP8285 hardware + * Add optional support for Toshiba and Mitsubishi HVAC IR control (needs updated IRremote8266 library) (#83, #257) + * Add all configured switches to Domoticz Configuration web page (#305) + * Fix compile error when selecting WS2812 DMA (#313) + * + * 4.1.1 20170329 + * Fix default Telemetry for command Prefix3 + * Fix webserver Module parameters for disabled select + * Fix sensor status for enabled switches + * Remove Light as alternative for Power (save code space) + * Remove migration option from pre V3 (code cleanup) + * Remove unofficial SPIFFS support (code cleanup) + * Remove command list when unknown command is entered (save code space) + * Rename Status11 json from StatusPWR to unique StatusSTS + * Rename command Gateway to IPAddres2, Subnetmask to IPAddress3 and DnsServer to IPAddress4 (save code space) + * Add Command MqttResponse to select either command or RESULT topic as response (#258) + * Add command StateText1 to StateText3 to assign MQTT_STATUS_OFF, MQTT_STATUS_ON and MQTT_CMND_TOGGLE respectively (#286) + * Remove restart after IPAddress changes (#292) + * Add support for MAX31850 in xsns_ds18x20.ino (#295) + * Fix possible uptime update misses (#302) + * + * 4.1.0 20170325 + * Change static IP addresses in user_config.h from list (using commas) to string (using dots) + * Unify display result of commands Modules, Module and Gpios + * Rewrite Module selection web page to bring size down from 18651 to 4319 bytes (!) (#234, #240) + * Add basic support for (Lixada) H801 RGBWW controller (#252) + * Add command Prefix1 to Prefix3 to assign SUB_PREFIX, PUB_PREFIX and PUB_PREFIX2 respectively (#255) + * Add static ip addresses to flash (#262) + * Add commands IpAddress, Gateway, Subnetmask and DnsServer to select static ip addresses (#273) + * + * 4.0.8 20170321 + * Fix entering non-numeric webpassword + * Force selection between TLS or Webserver due to memory restraint (#240) + * Allow entering empty string using "0" for selected commands (#242) + * Fix exception when posting commands to web console containing % (#250) + * + * 4.0.7 20170319 + * Increased Sonoff Led PWM frequency from 432 to 1000 + * Fix possible watch dog reboot after changing module type on web page + * Fix reporting of GPIO usage from web page + * Fix Sonoff Led blank during firmware upgrade + * Fix Sonoff Led flicker and possible flash corruption by using latest Arduino-esp8266 versions + * of pwm core files included in sonoff library (#211) + * Add PWM output control with commands PWM1 to PWM5 using user selectable GPIOs (#211) + * Fix exceptions due to low values of commands HlwPCal (10000), HlwUCal (1000) and HlwICal (2500) (#223) + * Add Switch state to sensor status (#227, #233) + * Add user configuarble GPIO to module Sonoff Touch (#228) + * Add define WEB_PORT to user_config.h to change default web server port from 80 (#232) + * Fix failed Ota Firmware upgrade started from Web page (#235) + * + * 4.0.6 20170316 + * Fix to better find device by Wifi hostname + * Fix compile error when some I2C devices are disabled + * Add (experimental) support for SHT1X emulating I2C (#97) + * Add ADC to ElectroDragon (#203) + * Add support for Sonoff Dev (#206) + * + * 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 to configure up to three NTP servers (#177) + * Delete module User Test as module Wemos D1 mini has same/more user configurable GPIO (#178) + * Add more user configurable GPIO to module ElectroDragon (#183) + * + * 4.0.3 20170309 + * Renamed Module NodeMCU to WeMos D1 mini + * Add GPIO1 as user option to some modules + * Add Buttons, Relays and Leds to user configurable options (#159) + * Add description on Module parameters web page to some well known GPIOs (#107, #171) + * + * 4.0.2 20170308 + * Restore correct seriallog level after Serial logging was disabled + * Add simple dimmer slider to Sonoff Led web page + * Reduced root webpage size by 31% + * Expand Status 2 with Build date/time and core version + * Fix webserver redirection when not in WifiManager mode (#156) + * Add command ButtonRestrict On/Off to restrict access to button hold and button multi press options above 2 (#161) + * Fix DS18S20 negative temperature readings (#165) + * Fix crlf compilation error due to bad syntax (#144, #167) + * + * 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) + * Increase message size and suggested minimum MQTT_MAX_PACKET_SIZE to 512 (#114, #124) + * Remove runtime warning message regarding MQTT_MAX_PACKET_SIZE too small as it is now moved to compile time (#124) + * Fix possible panics with web console and http commands while UDP syslog is active (#127) + * Add optional static IP address (#129) + * Add define ENERGY_RESOLUTION in user_config.h to allow user control over precision (#136) + * + * 3.9.22 20170228 + * Update web console + * Fix Status 4 JSON message + * Add Exception info during restart if available + * Add osWatch service to detect loop hangs that might happen during (OTA) upgrades + * Add WiOn support for relay and switch only (#82, #102) + * Allow for user specified relay count up to four in sonoff_template.h (#109) + * Add support for HTU21 compatible I2C sensors SI7013, SI7020 and SI7021 (#118) + * Add NodeMCU or Wemos configuration option (#119) + * + * 3.9.21 20170224 + * Add ajax to web root page and web console (#79) + * Add commands SwitchMode1..4 and enable user switches 2, 3 and 4 (#84, #88) + * Fix MQTT upgrade when webserver is active + * + * 3.9.20 20170221 + * Add minimal basic authentication to Web Admin mode (#87) + * Fix Hue and add HSB support (#89) + * + * 3.9.19 20170219 + * Sonoff Led: Made GPIO04, 05 and 15 available for user + * Sonoff Led: Add commands Fade, Speed, WakupDuration, Wakeup and LedTable + * + * 3.9.18 20170218 + * Fix ledstate 0 to turn off led + * Fix Sonoff Led dimmer range (#16) + * Change Sonoff Led command Dimmer to act on both cold and warm color + * Add Sonoff Led command Color CCWW where CCWW are hexadecimal values fro 00 - FF + * Reduce Sonoff Led flickering by disabling interrupts during flash save and disabling + * Led during OTA upgrade and Web upload (#16) + * + * 3.9.17 20170217 + * Fix possible ArduinoJSON related memory fragmentation + * Changed console logging using less memory + * Add GPIO04 as user selectable for Sonoff Dual (#75) + * + * 3.9.16 20170214 + * Update latching relay handler + * Add support for IR led using IRremoteESP8266 library (#59) + * Add Hue argument passing using ArduinoJSON library (#59) + * + * 3.9.15 20170213 + * Change JSON float values from string to number according to http://json.org (#56) + * Add support for exs latched relay module https://ex-store.de/ESP8266-WiFi-Relay-V31 (#58) + * Add support for inverted relays + * Changed MAX_LOG_LINES from 70 to 60 to preserve memory + * + * 3.9.14 20170211 + * Add False and True as alternatives for 0/Off and 1/On (#49) + * Fix Status10 JSON format (#52) + * Fix DS18x20 using OneWire library (#53) + * + * 3.9.13 20170210 + * Add FlashChipMode to Status 4 + * Removed redundant DHT2 option and code + * Add Sonoff SV GPIO pin 05 configuration (#40) + * Add configuration file backup and restore via web page + * Fix latency due to light_sleep mode even if sleep was set to zero (#50) + * + * 3.9.12 20170208 + * Fix compile error when webserver is disabled (#30) + * Fix possible ESP8285 flash problem by updating Flash Chip Mode to DOUT during OTA upload + * Fix hostname issues by not allowing user entry of string formatting and removing from user_config.h (#36) + * + * 3.9.11 20170204 + * Fix command I2Cscan + * Fix not allowed spaces in Topic, ButtonTopic and SwitchTopic + * Make all TELEMETRY, STATUS and COMMAND message topics unique (#4) + * Advertise command topic to be used by iobroker (#299) + * Fix butten (non)detection if no GPIO_KEY1 is defined (#13) + * Change WeMo serialnumber from 7 decimal chars to 8 hexadecimal chars (#18) + * Update web page with Build Date/Time, Emulation and mDNS Discovery and Advertise information (#21) + * + * 3.9.10 20170130 + * Add WS2812 Color Type selection (RGB or GRB) to user_config.h (#7) + * Hue api changes to support HUE App(s) (#8) + * + * 3.9.9 20170130 + * Add command status 10 showing sensor data + * Fix hlw status messages if hlw is disabled + * + * 3.9.8 20170130 + * Remove GPIO07 and GPIO08 from user selectable (#5) + * + * 3.9.7 20170129 + * Fix possible WS2812 exceptions when using emulation + * Add command Emulation to dynamic configure Belkin WeMo and Hue Bridge for Alexa + * + * 3.9.6 20170129 + * Add dynamic sleep for WS2812 animation (#1) + * + * 3.9.5 20170128 + * Fix error message in case of wrong Domoticz command + * + * 3.9.4 20170127 + * Fix Sonoff Dual Relay switching (#287) + * + * 3.9.3 20170127 + * Add confirmation before Restart via webpage + * Expand Domoticz Configuration webpage with Key, Switch and Sensor Index and + * add commands DomoticzSwitchIdx and DomoticzSensorIdx (#86) (#174) (#219) + * Fix default DHT11 sensor driver selection + * Fix LedPower status after button press (#279) + * Add command Sleep 0 - 250 mSec for optional light sleep mode to lower energy consumption (#272) + * (Expect overall button/key/switch misses and wrong values on Sonoff Pow) + * Add Hue brightness extension (#281) + * Fix Hue brightness and change to call by reference (#283) + * + * 3.9.2 20170124 + * Add confirmation before Reset Configuration via webpage (#244) + * Add WS2812 features (see Wiki commands) + * + * 3.9.1 20170124 + * Change PowerOnState function to only trigger when Power On (and not just restart) (#238) + * Move HLW interrupts back to RAM and make WS2812_DMA optional as it generates Exception on Pow (#264) + * Add charset=utf-8 to webpages (#266) + * Update Hue emulation (#268) + * Fix status module number + * Add support for domoticz Dimmer on Sonoff_Led and WS2812 + * Fix possible ESP8285 flash problem by updating Flash Chip Mode to DOUT during web upload + * + * 3.2.6a 20170120 + * Fix Sonoff Pow compile error (#255) + * Move HLW interrupts back to ROM (Needed for WS2812 DMA interrupts) + * Removed all IO config from user_config.h as this will be done by commands or webpage + * Removed MessageFormat and supports JSON only except POWER/LIGHT status + * Add command LedPower to control main led (#247) + * Add more FriendlyNames for Hue (#254) + * Add DMA support for WS2812 when using pin 3 while other pins work just as well in my case... + * Add HUE emulation for Alexa (#229) + * Add basic WS2812 support (#229) + * Fix Wemo when MQTT is disabled (#245) + * Revert ButtonTopic and change SwitchTopic1 - 4 to one SwitchTopic + * Rename MqttUnits to Units + * Add Mqtt command to enable/disable MQTT + * + * 3.2.2a 20170115 + * Add dynamic (Sonoff) Module, user GPIO and sensor selection (one size fits (almost) all) + * Add support for Sonoff LED + * Add Seriallog disable after 600 seconds for Sonoff Dual and 4 Channel + * Add ButtonTopic2 - 4, SwitchTopic1 - 4 and SwitchRetain + * + * 3.2.2 20170113 + * Fix PowerOnState 2 functionality after re-applying power (#230) + * + * 3.2.1 20170113 + * Fix some failed command decoding (#228) + * Removed passwords from status messages (#216) + * + * 3.2.0 20170111 + * Add I2C BH1750 sensor (#222) + * Sensor rewrite preparing for online selection + * + * 3.1.16 20170109 + * Fix Domoticz possible error condition + * Remove Wifi password from connection message (#216) + * Add Configure Other menu item to web page (#209) + * Add command FriendlyName, field Friendly Name and define FRIENDLY_NAME to be used by Alexa + * eliminating current use of MQTT_CLIENT_ID (#209) + * Add friendlyname to webpage replacing former hostname + * + * 3.1.15 20170108 + * Fix Domoticz send key regression with Toggle command + * + * 3.1.14 20170107 + * Add support for command TOGGLE (define MQTT_CMND_TOGGLE) when ButtonTopic is in use and not equal to Topic (#207) + * + * 3.1.13 20170107 + * Fix web console command input when SUB_PREFIX contains '/' (#152) + * Add command response to web command (#200) + * Add option to disable MQTT as define USE_MQTT in user_config.h (#200) + * + * 3.1.12 20170106 + * Add OTA retry to solve possible HTTP transient errors (#204) + * Fix MQTT host discovery + * + * 3.1.11 20170105 + * Add mDNS to advertise webserver as .local/ + * + * 3.1.10 20170105 + * Fix ButtonTopic when SUB_PREFIX = PUB_PREFIX + * Add workaround for possible MQTT queueing when SUB_PREFIX = PUB_PREFIX + * Add optional MQTT host discovery using define USE_DISCOVERY in user_config.h (#115) + * + * 3.1.9 20170104 + * Fix Power Blink start position (toggled) + * Change PulseTime increments: 1 .. 111 in 0.1 sec (max 11 seconds) and 112 .. 64900 in seconds (= 12 seconds until 18 hours) (#188) + * Add support for SUB_PREFIX = PUB_PREFIX (#190) + * + * 3.1.8 20170103 + * Add retain flag to LWT offline and only send "tele/sonoff/LWT Offline" (#179) + * Change retained LWT Online message to only send "tele/sonoff/LWT Online" + * + * 3.1.7 20161231 + * Add retained message LWT Online when sonoff makes MQTT connection (#179) + * + * 3.1.6 20161230 + * Add blinking using commands BlinkTime, BlinkCount and Power Blink|3|BlinkOff|4 (#165) + * + * 3.1.5 20161228 + * Fix serial space command exception (28) + * + * 3.1.4 20161227 + * Fix MQTT subscribe regression exception (3) (#162) + * Fix serial empty command exception (28) + * + * 3.1.3 20161225 + * Extent Domoticz configuration webpage with optional indices (#153) + * Fix multi relay legacy tele message from tele/sonoff/2/POWER to tele/sonoff/POWER2 + * Add support for iTead Motor Clockwise/Anticlockwise + * + * 3.1.2 20161224 + * Extent command PowerOnState with toggle at power on (option 2 is now option 3!) (#156) + * + * 3.1.1 20161223 + * Add support for Sonoff Touch and Sonoff 4CH (#40) + * Update DomoticzIdx and DomoticzKeyIdx with relay/key index (DomoticzIdx1/DomoticzKeyIdx1) + * Add command PowerOnState to control relay(s) at power on (#154) + * + * 3.1.0 20161221 + * Add Sonoff Pow measurement smoothing + * Fix serial command topic preamble error (#151) + * Fix 2.x to 3.x migration inconsistencies (#146) + * + * 3.0.9 20161218 + * Add Sonoff Pow voltage reading when relay is on but no load present (#123) + * + * 3.0.8 20161218 + * Add temperature conversion to Fahrenheit as option in user_config.h (TEMP_CONVERSION) (#145) + * + * 3.0.7 20161217 + * Add user_config_override.h to be used by user to override some defaults in user_config.h (#58) + * Fix Sonoff Pow low power (down to 4W) intermittent measurements (#123) + * + * 3.0.6 20161217 + * Fix MQTT_CLIENT_ID starting with % sign as in "%06X" (#142) + * Add auto power off after PulseTime * 0.1 Sec to relay 1 (#134) + * + * 3.0.5 20161215 + * Add more control over LED with command LedState options (#136, #143) + * LED_OFF (0), LED_POWER (1), LED_MQTTSUB (2), LED_POWER_MQTTSUB (3), LED_MQTTPUB (4), LED_POWER_MQTTPUB (5), LED_MQTT (6), LED_POWER_MQTT (7) + * Add option WIFI_RETRY (4) to command WifiConfig to allow connection retry to other AP without restart (#73) + * + * 3.0.4 20161211 + * Fix intermittent Domoticz update misses (#133) + * + * 3.0.3 20161210 + * Fix compiler warnings (#132) + * Remove redundant code + * Fix Domoticz pushbutton support + * + * 3.0.2 20161209 + * Add pushbutton to SwitchMode (#130) + * + * 3.0.1 20161209 + * Fix initial config + * + * 3.0.0 20161208 + * Migrate and clean-up flash layout + * Settings from version 2.x are saved but settings from version 3.x can not be used with version 2.x + * Change SEND_TELEMETRY_RSSI to SEND_TELEMETRY_WIFI and add AP and SSID to telemetry + * Split long JSON messages + * Fix inconsistent status messages + * Fix all status messages to return JSON if enabled + * Remove relay index in cmnd/sonoff//POWER now changed + * to cmnd/sonoff/POWER for single relay units + * and cmnd/sonoff/POWER for multi relay units like Sonoff dual + * Add retain option to Power/Light status controlled by command PowerRetain On|Off (#126) + * + * 2.1.2 20161204 + * Add support for second wifi AP (#73) + * Update command WifiConfig + * Fix possible WifiManager hang + * + * 2.1.1a 20161203 + * Fix scan for wifi networks if WeMo is enabled + * Fix syslog setting using web page + * + * 2.1.1 20161202 + * Add support for ElectroDragon second relay and button (only toggle with optional ButtonTopic) (#110) + * + * 2.1.0 20161202 + * Add optional EXPERIMENTAL TLS to MQTT (#49) + * Fix MQTT payload handling (#111) + * Optimzed WeMo code + * + * 2.0.21a 20161201 + * Fix WeMo PowerPlug emulation + * + * 2.0.21 20161130 + * Add Belkin WeMo PowerPlug emulation enabled with USE_WEMO_EMULATION in user_config.h (Heiko Krupp) (#105, #109) + * + * 2.0.20 20161130 + * Relax MQTTClient naming but only allows hexadecimal uppercase numbers (#107) + * Add I2C support with command I2CScan + * Add I2C sensor driver for HTU21 as alternate sensor using TH10/16 connectors (Heiko Krupp) (#105) + * Add I2C sensor driver for BMP085/BMP180/BMP280/BME280 as alternate sensor using TH10/16 connectors + * + * 2.0.19a 20161127 + * Add support for ButtonTopic and ButtonRetain to wall switch function + * Add pullup to SWITCH_PIN and command SwitchMode to syntax + * + * 2.0.18 20161126 + * Add SUB_PREFIX multi level support allowing 'cmnd' or 'cmnd/level2/level3' + * Add wall switch function to GPIO14 and command SwitchMode (Alex Scott) (#103) + * + * 2.0.17 20161123 + * Calibrate HLWPCAL from 12345 to 12530 + * Add alternative sensor driver DHT2 using Adafruit DHT library + * Add define MESSAGE_FORMAT to user_config.h + * Throttle console messages + * Shorten JSON messages + * Fix possible Panic + * Fix User mode webserver security + * + * 2.0.16 20161118 + * Add alternative sensor driver DS18x20 using OneWire library (#95) + * Change sensor MQTT message from tele/sonoff/TEMPERATURE to tele/sonoff/DHT/TEMPERATURE or + * tele/sonoff/DS18B20/TEMPERATURE or tele/sonoff/DS18x20/1/TEMPERATURE + * Add sensors to root webpage and auto refresh every 4 seconds (#92) + * Add optional JSON messageformat to all telemetry data + * Enforce minimum TelePeriod to be 10 seconds + * Fix Energy Yesterday reset after restart + * Add Energy Today restore after controlled restart + * + * 2.0.15 20161116 + * Change TODAY_POWER and PERIOD_POWER to TODAY_ENERGY and PERIOD_ENERGY + * Fix serial regression + * Fix syslog hangs when loghost is unavailable + * + * 2.0.14 20161115 + * Add HLW threshold delay + * Fix HLW intermittent current deviation + * Fix button functionality during wificonfig + * Add CRC check to DS18B20 sensor (#88) + * + * 2.0.13 20161113 + * Add additional upload error code descriptions + * Add PlatformIO support (#80) + * + * 2.0.12 20161113 + * Fix Serial and Web response regression when no MQTT connection available + * Fix Sonoff Dual power telemetric data for second relay + * Removed MQTT password from Information web page + * Hide MQTT password from Configure MQTT web page + * + * 2.0.11 20161111 + * Rewrite button and web toggle code + * Fix NTP sync + * Add HLW calibration commands HLWPCAL, HLWUCAL and HLWICAL (need define USE_POWERCALIBRATION) + * Fix power threshold tests + * + * 2.0.10 20161109 + * Add additional Domoticz define (#63) + * Add defines MQTT_STATUS_ON and MQTT_STATUS_OFF in user_config.h to select status On/Off string + * Fix status response differences (#65) + * Fix divide by zero exception (#70) + * Fix syslog loop exception + * + * 2.0.9 20161108 + * clarify MODULE in user_config.h + * Fix hlw false values + * + * 2.0.8 20161108 + * Add initial status after power on + * Seperate driver files + * Fix hlw code and calibrate Pow + * Move user config defines to user_config.h (#61) + * + * 2.0.7 20161030 + * Make Ticker mandatory + * Add Domoticz support (Increase MQTT_MAX_PACKET_SIZE to 400) (#54) + * Add command MessageFormat 0|1 to select either legacy or JSON output + * + * 2.0.6 20161024 + * Add Sonoff Pow power factor + * Initial support for up to four relays using iTEAD PSB (4Channel) + * - Currently only supports one button (All buttons behave the same) + * - Use command MODEL 4 to select four relay option + * (After first power on it will support 2 relays like Sonoff Dual) + * Fix ledstate + * Add command Status 9 to display Sonoff Pow thresholds + * Add commands PowerLow, PowerHigh, VoltageLow, VoltageHigh, CurrentLow and CurrentHigh for use + * with Sonoff Pow thresholds + * + * 2.0.5 20161018 + * Add updates to user_config.h - moved SEND_TELEMETRY_DS18B20 and SEND_TELEMETRY_DHT to module area. + * As Sonoff TH10/16 does not have the logic installed for GPIO04 You'll have to select ONE of both + * Add Sonoff Pow support (experimental until Pow tested) + * Add command Status 8 to display Sonoff Pow energy values + * Add command MqttUnits On|Off to add units to values + * Change web main page header character size + * Change On/Off to ON/OFF status messages to satisfy openHAB + * Change TEMP to TEMPERATURE and HUM to HUMIDITY + * + * 2.0.4 20161009 + * Add MQTT_BUTTON_RETAIN, SAVE_DATA and SAVE_STATE defines to user_config.h (#35) + * Update ButtonRetain to remove retained message(s) from broker when turned off + * Add Retain for second relay on Sonoff Dual + * Provide power status messages with device topic index if requested + * + * 2.0.3 20161008 + * Update wifi initialization + * Add command BUTTONRETAIN for optional MQTT retain on button press (#35) + * Add command SAVESTATE to disable power state save. May be used with MQTT retain + * + * 2.0.2 20161006 + * Fix wifi issue 2186 + * + * 2.0.1 20161002 + * Fix button press + * + * 2.0.0 20161002 + * Update Sonoff TH10/16 sensor pins (My TH10 only has GPIO14 connected) + * Add full support for Sonoff dual + * + * 1.0.35 20160929 + * Add more lines to console + * Add timeout and disable MQTT on web upload + * Add command SAVEDATA to control parameter save (for flash wear afficionados) (#30) + * + * 1.0.34 20160926 + * Fix button press six and seven + * Add more information to webserver + * + * 1.0.33 20160915 + * Better WPS error message + * Separate webserver code from support.ino into webserver.ino + * Fix webserver User by removing unwanted restart option + * + * 1.0.32 20160913 + * Add Wifi Protected Setup (WPS) as third option for initial config + * Add command WIFICONFIG replacing deprecated command SMARTCONFIG + * Add option WIFICONFIG 3 to start WPSconfig + * Add option WIFICONFIG 0 to start saved Wifi config tool (WPSconfig, Smartconfig or Wifimanager) + * Change button behaviour - See Wiki + * + * 1.0.31 20160907 + * Fix DS18B20 misread if teleperiod = 2 + * Tuned sensor code + * Updated prefered ElectroDragon connection to Relay 1 and Button 1 + * Moved SONOFF and ELECTRO_DRAGON port config to user_config.h + * + * 1.0.30 20160902 + * Fix command TELEPERIOD 0 + * Add ESP- tag to UDP log message for easy rsyslogd filtering + * Add ElectroDragon (Relay 2 only) functionality. Select with #define MODULE ELECTRO_DRAGON + * Add ? as null message alternative + * Add DHT temperature and humidity telemetry support. Enable with #define SEND_TELEMETRY_DHT + * Add DS18B20 temperature telemetry support. Enable with #define SEND_TELEMETRY_DS18B20 + * Restrict HOSTNAME, MQTTCLIENT, TOPIC and BUTTONTOPIC in topic mode only + * + * 1.0.29 20160831 + * Allow UPGRADE, OTAURL, RESTART, RESET, MQTTHOST, MQTTPORT, MQTTUSER, MQTTPASSWORD and WEBSERVER also in group mode + * + * 1.0.28 20160831 + * Add webserver state to status 5 + * Add optional PUB_PREFIX2 (tele) for telemetry usage + * Add command TELEPERIOD + * Fix syntax message + * Change memory status display + * + * 1.0.27 20160831 + * Add sketch flash size + * Add console to webserver + * Add command weblog + * Change WifiManager web pages to minimal + * Change display default hostname and MQTT client id in webserver + * Change HTTP command interface to http://sonoff-1234/cm?cmnd=light 2 + * Change HEARTBEAT to UPTIME + * + * 1.0.26 20160829 + * Add define USE_WEBSERVER to disable web server code in source + * Add file upload as alternative for ota upload to webserver + * Add information to webserver + * Add command hostname + * Add command logport + * Change HTTP command interface to http://sonoff-1234/cmd?cmnd=light 2 + * Change button behaviour with regards to Smartconfig and OTA upload. See README.md + * Enforce default hostname to either "%s-%04d" or user defined without any % + * Enforce default mqtt client id to either "DVES_%06X" or user defined without any % + * + * 1.0.25 20160822 + * Remove config system halts to keep ota available + * + * 1.0.24 20160821 + * Add test for MQTT_SUBTOPIC + * Change log range to LOG_LEVEL_ALL + * Change MQTT introduction messages + * Moved MQTT_MAX_PACKET_SIZE warning message to introduction messages + * + * 1.0.23 20160821 + * Add option USE_SPIFFS to move config from flash to spiffs + * Add webserver with options 0 (off), 1 (user) and 2 (admin) + * Add HTTP command interface (http://sonoff-1234/c?cmnd=light 2) + * Add wifimanager countdown counter + * Add command line webpage + * Add relay control to wifimanager + * Add restart option 99 to force restart + * Fix wifi hostname + * Fix NETBIOS hostname problem by reducing default hostname length + * Fix possible exception if WIFI_HOSTNAME is changed + * Fix upgrade messages + * Reduce memory use by redesigning config routines + * Split syntax message + * Rename define SERIAL_IO to USE_SERIAL + * + * 1.0.22 20160814 + * Add all MQTT parameters for configuration + * Add wifimanager to configure Wifi and MQTT via web server + * Change NTP time handling + * Fix Smartconfig parameter buffer overflow + * Fix PlatformIO warnings + * + * 1.0.21 20160808 + * Remove semaphore as subscription flooding (more than 15 subscriptions per second) is managed by SDK (LmacRxBlk:1) + * Add optional RTC interrupt (define USE_TICKER) to keep RTC synced during subscription flooding + * Remove heartbeatflag + * + * 1.0.20 20160805 + * Add semaphore to handle out of memory when too many subscriptions requested + * Use Daylight Saving (DST) parameters from user_config.h when timezone = 99 + * Add status 7 option displaying RTC information + * Add ledstate to status 0 + * + * 1.0.19 20160803 + * Fix possible MQTT_CLIENT_ID induced Exception(28) + * + * 1.0.18 20160803 + * Moved Cfg_Default + * Fix negative data handling + * Remove MQTT information from status 1 and add labels to status 1 + * Add mac address to status 5 + * Add MQTT ClientId, UserId and Password to status 6 + * + * 1.0.17 20160731 + * Better variable range checking + * Change ambiguous connection messages + * Add timestamp to serial message + * + * 1.0.16 20160729 + * Moved wifi, rtc, syslog and config to support.ino + * Fixed button action when buttontopic is used. Introduced with 1.0.15 + * Better buffer overflow checks (strlcpy) + * + * 1.0.15 20160728 + * Removed pubsubclient config changes from sonoff.ino as it doesn't work + * reapply MQTT_MAX_PACKET_SIZE 256 and MQTT_KEEPALIVE 120 to PubSubClient.h + * Add status 0 option displaying all status messages + * Change MQTT_MAX_PACKET_SIZE from 1024 to 256 + * Add buffer overflow checks (snprintf and strncpy) + * Implemented common string sizes + * + * 1.0.14 20160722 + * Seperate user config from sonoff.ino to user_config.h (pucebaboon) + * Change defaults from sidnas2 to domus1 + * Add MQTT status message as status 6 (pucebaboon) + * Add status type to message (pucebaboon) + * Add pubsubclient config changes to sonoff.ino (pucebaboon) + * + * 1.0.13 20160702 + * Add Ledstate 1 option to show power state on led + * + * 1.0.12 20160529 + * Allow disable of button topic using "0" + * + * 1.0.11 20160524 + * Provide button response if MQTT connection lost + * + * 1.0.10 20160520 + * Add optional button topic to assist external MQTT clients + * Change version notation + * Reset default values + * + * 1.0.9 20160503 + * Add more blinks + * Add reset 2 option erasing flash + * Add status 5 option displaying network info + * Add syslog check for Wifi connection + * Resize MqttPublish log array + * Change Wifi smartconfig active from 100 to 60 seconds + * Update Wifi initialization + * + * 1.0.8 20160430 + * Remove use of Wifi config data from SDK + * Add status 3 (syslog info) and status 4 (flash info) + * Add restart option to button (5 quick presses) + * + * 1.0.7 20160420 + * Add UDP syslog support + * Change HOST command to MQTTHOST command + * Add commands SYSLOG, SERIALLOG and LOGHOST + * Change hostname to lower case to distinguise between open-sdk version + * Add support for ESP-12F used in my modified wkaku power socket switch + * Fix timezone command + * Add RTC month names for future use + * Modify button code + * Remove initialization errors by better use of MQTT loop + * + * 1.0.6 20160406 + * Removed Wifi AP mode (#1) + * Add test for Arduino IDE version >= 1.6.8 + * Fix RTC time sync code + * + * 1.0.5 20160310 + * Initial public release + * Show debug info by selecting option from IDE Tools Debug port: Serial + */ diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 25d26f547..f17feb45c 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,1382 +1,16 @@ -/* 6.0.0c - * Rewrite BME680 driver now using latest Bosch BME680 library (#2969) - * Add support for bitflags SetOption50 .. SetOption81 (#3118) - * - * 6.0.0b - * Add support for BlitzWolf BW-SHP2 (and Homecube, Gosund SP1) Energy Monitoring Smart Socket (#2223) - * Add support for Sonoff iFan02 as module 44 introducing command FanSpeed 0..3 (#2839) - * Add support for Sonoff S26 Smart Socket (#2808) - * Add command SetOption30 to enforce Hass discovery as light group (#1784) - * Add decimal values support for commands ADD, SUB, MULT and SCALE (#3083, #3089) - * Add experimental (untested) TM1638 switch support (#2226) - * Change number of switches from 4 to 8 (#2885, #3086) - * - * 6.0.0a - * Add support for APDS9960 proximity sensor (#3051) - * Add increment and decrement value to command Counter (#2838) - * Add option 0 to command Timers disarming all timers (#2962) - * Add time in minutes to rule Time#Initialized, Time#set and Time#Minute (#2669) - * Add rule variables %time% for minutes since midnight, %uptime%, %sunrise% and %sunset% giving time in minutes (#2669) - * Add heap and stack debug information - * Add command SetOption28 to switch between hex or decimal Sonoff Bridge RF received data format (#3008) - * Add command SetOption29 to switch between hex or decimal IR received data format - * Add performance improvement when updating multiple individual WS2812 pixels (#3007) - * Add debug facilities using optional xdrv_99_debug.ino to enable in user_config.h - * Add KNX support for DS18S20 Temperature sensor - * Add CRC to Settings making future upgrades more fail-safe - * Add support for uploading Sonoff Bridge firmware found in tools/fw_efm8bb1 folder build by Portisch using Web Gui File Upload (#2886) - * Add support for I2C temperature sensor LM75AD (#2909) - * Add command RfRaw to control Portisch firmware features - * Remove version 3, 4 and pre 5.2 settings auto-upgrade. See https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade#migration-path - * Change default CFG_HOLDER from 0x20161209 to 4617 (=0x1209) - no impact on default upgrades - * Fix Pzem004T checksum error - * Fix KNX bug when doing reply of sensors values - * Fix rules induced LWT message - * Fix possible wifi connection problem (#1366) - * - * 5.14.0b - * Add Console Commands to send KNX Commands - usage: KnxTx_Cmnd[slot] command - where [slot] is any of the 5 slots on the KNX Menu and command is 0 or 1 - example: KnxTx_Cmnd1 0 - * Add Console Commands to send KNX Values - usage: KnxTx_Val[slot] value - where [slot] is any of the 5 slots on the KNX Menu and value is a number - example: KnxTx_Val1 35 - * Add Slots on the KNX Web Menu to select Group Addess to send data from console commands - * Add Events to trigger rules when a command is received from KNX - usage on rules as: event#KnxRx_Cmnd[slot] - where [slot] is any of the 5 slots on the KNX Menu - example: rule on event#KnxRx_Cmnd1 do VAR1 %value% endon - (where %value% can be 0 or 1) - * Add Events to trigger rules when received read requests from KNX - usage on rules as: event#KnxRx_Req[slot] - where [slot] is any of the 5 slots on the KNX Menu - example: rule on event#KnxRx_Req1 do KnxTx_Val1 35 endon - * Add Slots on the KNX Web Menu to select Group Addess to receive data to trigger rules - * Add two rule sets of 511 characters using commands rule1, rule2 and rule3 - * Add Ukranian language file - * Add rule support for IrReceive and RfReceive (#2758) - * Add command WebSend [(:,:)] (#2821) - * Add source information to command execution to be shown with logging option 3 (#2843) - * Fix some Pow R2 and S31 checksum errors (#1907) - * Fix Hardware Watchdog restart when using event command (#2853) - * - * 5.14.0a - * Add feature information to Status 4 - * Add tools folder with python script decode-status.py for decoding some status fields like SetOption and Features - * Add Eastron SDM630 energy meter by Gennaro Tortone (#2735) - * Add KNX communication enhancement by Adrian Scillato (#2742) - * Add KNX energy data by Adrian Scillato (#2750) - * Add python script fw-server.py in tools folder to create a simple OTA server by Gennaro Tortone (#2759) - * Add rules %mem1% to %mem5% variable names storing data in flash (#2780) - * Add rules test on %varx% or %memx% (#2780) - * Add optional token %id% substituting the unique MAC address to fulltopic by Michael Graf (#2794) - * Fix display selection of un-available GPIO options in Module Configuration webpage (#2718) - * Fix timer re-trigger within one minute after restart (#2744) - * Fix IRSend not accepting data value of 0 by David Conran (#2751) - * Fix vars on rules by Adrian Scillato (#2769) - * Fix bug in KNX menu by Adrian Scillato (#2770) - * Fix anomalies in rules (#2778) - * Fix HUE bridge V1 software version by Heiko Krupp (#2788) - * - * 5.14.0 20180515 - * Update language files - * Update TasmotaSerial to 2.0.0 allowing Hardware Serial Fallback when correct connections are configured - * Change command handling - * Change user_config(_override).h defines TIME_STD and TIME_DST - * Change user_config(_override).h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602) - * Fix configuration restore regression from 5.13.1 - * Fix compile error when ADC is enabled and Rules are disabled (#2608) - * Fix rule power trigger when no backlog command is used (#2613) - * Fix several timer data input and output errors (#2597, #2620) - * Fix KNX config error (#2628) - * Fix sensor MHZ-19 vanishing data over time (#2659) - * Fix KNX reconnection issue (#2679) - * Fix DST and STD time for Southern Hemisphere by Adrian Scillato (#2684, #2714) - * Add Portuguese in Brazil language file - * Add SetOption26 to enforce use of indexes even when only one relay is present (#1055) - * Add support for sensor SI1145 UV Index / IR / Visible light (#2496) - * Add rule state test for On/Off in addition to 0/1 (#2613) - * Add hardware serial option to MHZ-19 sensor (#2659) - * Add Eastron SDM120 energy meter by Gennaro Tortone (#2694) - * Add user entry DST/STD using commands TimeStd and TimeDst (See wiki for parameter syntax) (#2721) - * - * 5.13.1 20180501 - * Fix JSON buffers size too small for execution in some situations (#2580) - * Fix configuration restore (#2591) - * Add define MODULE for user selecting default model although it preferably should not be changed (#569, #2589) - * - * 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 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) - * 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 - * 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) - * Add Sonoff Bridge command RfKey 5 to show current RF key values either default or learned (#1884) - * Add user configurable serial GPIOs to MagicHome and Arilux modules (#1887) - * Add Russian language file (#1909) - * Add Webserver upload preflight request support (#1927) - * Add Home Assistant clear other device (#1931) - * Add Restart time to Status 1 (#1938) - * 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) - * 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 - * Change relation of define MESSZ being dependent on PubSubClient.h define MQTT_MAX_PACKET_SIZE - * Change command color parameter input checks to less strict for Home Assistant support - * Change command Ina219Mode into command Sensor13 - * Change commands HlwPCal, HlwUCal and HlwICal to PowerCal, VoltageCal and CurrentCal to be used for both Pow and S31 calibration - * Change commands HlwPSet, HlwUSet and HlwISet to PowerSet, VoltageSet and CurrentSet to be used for both Pow and S31 calibration - * Change uptime from hour to second resulting in a display of 123T13:45:21 where 123 is days - * Change module name Wemos D1 mini into Generic (#1220) - * Change HTML from width=100% to style=width:100% supporting HTML5 (#1358) - * Change OSWATCH_RESET_TIME (Blocked loop) from 30 to 120 seconds to allow slow networks (#1556) - * Change WIFI_MANAGER_SEC into WIFI_CONFIG_SEC (#1616) - * Change function pointers code to save code space and memory (#1683) - * Change webserver argument processing gaining 5k code space (#1705) - * Change weblog memory usage (#1730, #1793, #1819) - * Update TasmotaSerial library to 1.1.0 - * Update language files Italian (#1594), Dutch (#1723) and Spanish (#1722) - * Fix Non-English JSON temperature unit attachement - * Fix Arilux RF induced exception by moving interrupt handler to iram on non ESP8266/Arduino lib v2.3.0 - * Fix truncated command names and wrong response for DomoticzSwitchIdx (#1571) - * Fix %-sign issue as printf escape character in Humidity and Sonoff SC (#1579) - * Fix DS18B20 temperature JSON decimal dot (#1561) - * Fix Energy JSON message (#1621) - * Fix IRSend parameter translation (#1636) - * Fix TSL2561 device detection (#1644, #1825) - * Fix BME680 teleperiod resistance measuring (#1647) - * Fix Energy Monitoring Energy Today and Energy Total reading after restart (#1648) - * Fix IRReceive Data value (#1663) - * Fix Energy Monitoring Energy Period roll-over (#1688) - * Fix compiler warnings (#1774) - * Fix command PWM response if no PWM channel is configured (#1783) - * Add locale Decimal Separator to Web sensor page - * Add ColorTemperature to light status message - * Add command PowerOnState option 5 which inverts PulseTime and allows for delayed always on after power on - * Add OtaMagic two step Web server OTA upgrade using filename-minimal image if OTA free space is too small - * Add support for PMS5003 and PMS7003 particle concentration sensor - * Add command SetOption21 1 to allow Energy Monitoring when power is off on Sonoff Pow and Sonoff S31 (#1420) - * Add Chinese language file (#1551) - * Add French language file (#1561) - * Add Spanish language file (#1589) - * Add HTTP Allow Cross Origin removed from ESP8266/Arduino lib v2.4.0 (#1572) - * Add Home Assistant MQTT Discovery for switch and light to be enabled by command SetOption19 1 (#1534) or define HOME_ASSISTANT_DISCOVERY_ENABLE in user_config.h (#1685) - * Add command State to retrieve device state information (same data as teleperiod state and status 11 in slightly different JSON format) - * Add optional login to Webserver AP mode (#1587, #1635) - * Add command Sensor15 2 to start MHZ19(B) Zero Point Calibration (#1643) - * Add support for Sonoff S31 Smart Socket with Power Consumption Detection (#1626) - * Add command SetOption20 to allow update of Dimmer/Color/Ct without turning power on (#1719, #1741) - * Add NTP sync time slot based on chip id (#1773) - * Add cursor pointer to web button (#1836) - * - * 5.11.1 20180107 - * Fix Sonoff Pow command handling (#1542) - * - * 5.11.0 20180107 - * Minor webpage HTML optimizations (#1358) - * Updated German translation (#1438) - * Change Sonoff Pow Energy MQTT data message and consolidate Status 8 into Status 10 - * Change ADS1115 default voltage range from +/-2V to +/-6V (#1289) - * Change text to Active for 3 minutes (#1364) - * Change Wemo SetBinaryState to distinguish from GetBinaryState (#1357) - * Change output of HTTP command to valid JSON and Array only (#1363) - * Removed all MQTT, JSON and Command language defines from locale files and set fixed to English (#1473) - * Renamed commands Color2,3,4 to Color3,4,5 - * Fix BME280 calculation (#1051) - * Fix Sonoff Bridge missed learned key if learned data contains 0x55 (End of Transmission) flag (#1095, #1294) - * Fix PWM initialization in Dimmer/Color mode (#1321) - * Fix Wemo Emulation (#1357) - * Fix display of build date and time in non-english locale (#1465) - * Fix Wemo and Hue emulation by adding M-Search response delay (#1486) - * Add libraries Adafruit_BME680-1.0.5, Adafruit_Sensor-1.0.2.02, TasmotaSerial-1.0.0 and TSL2561-Arduino-Library - * Add command Color2 to set color while keeping same dimmer value - * Add device function pointers - * Add support for SenseAir S8 CO2 sensor - * Add color led signal to Carbon Dioxide (CO2) sensors using defines CO2_LOW and CO2_HIGH in user_config.h - * Add support for Domoticz Air Quality sensor to be used by MH-Z19(B) and SenseAir sensors - * Add support for PZEM004T energy sensor - * Add support for iTead SI7021 temperature and humidity sensor by consolidating DHT22 into AM2301 and using former DHT22 as SI7021 (#735) - * Add support for BME680 using adafruit libraries (#1212) - * Add support for MH-Z19(B) CO2 sensor (#561, #1248) - * Add multipress support and more user configurable GPIO to Sonoff Dual R2 (#1291) - * Add support for TSL2561 using adafruit library (#661, #1311) - * Add support for SHT3x (#1314) - * Add support for Arilux LC06 (#1414) - * Add Italian language file (#1449) - * Add 2nd Gen Alexa support to Wemo emulation discovery (#1357, #1450) - * Add define for additional number of WS2812 schemes (#1463) - * - * 5.10.0 20171201 - * Upgrade library ArduinoJson to 5.11.2 - * Upgrade library IRRemoteEsp8266 to 2.2.1 + 2 commits but disabled some protocols (code size reduction) - * Upgrade library NeoPixelBus to 2.2.9 - * Upgrade library OneWire to 2.3.3 + 6 commits and disabled CRC lookup-table (#define ONEWIRE_CRC8_TABLE 0) (code size reduction) - * Update library PubSubClient to 2.6 + 9 commits and additional delay (#790) - * Update core_esp8266_wiring_digital.c to latest (staged) level - * Patch library I2Cdevlib-Core for esp8266-core 2.4.0-rc2 compatibility - * Remove command EnergyReset 1..3 now replaced by EnergyReset1 to EnergyReset3 - * Remove spaces in JSON messages (code size reduction) - * Renamed xsns_05_ds18x20.ino to xsns_05_ds18x20_legacy.ino still using library OneWire and providing dynamic sensor scan - * Fix possible iram1_0_seg compile error by shrinking ICACHE_RAM_ATTR code usage - * Fix PWM watchdog timeout if Dimmer is set to 100 or Color set to 0xFF (#1146) - * Fix Sonoff Bridge Learn Mode hang caused by unrecognised RF code (#1181) - * Fix blank console log window by using XML character encoding (#1187) - * Fix wrong response name for command HlwISet (#1214) - * Fix DHT type sensor timeout recognition by distinguish "signal already there" from "timeout" (#1233) - * Add fixed color options 1..12 to command Color - * Add + (plus) and - (minus) to commands Dimmer (+10/-10), Speed and Scheme - * Add + (plus) and - (minus) to command Color to select 1 out of 12 preset colors - * Add + (plus) and - (minus) to command Ct to control ColdWarm led ColorTemperature (+34/-34) - * Add commands EnergyReset1 0..42500, EnergyReset2 0..42500 and EnergyReset3 0..42500000 - * to (Re)set Energy Today, Yesterday or Total respectively in Wh (#406, #685, #1202) - * Add optional ADS1115 driver as alternative for unsupported I2Cdevlib in esp8266-core 2.4.0-rc2 - * Add support for INA219 Voltage and Current sensor to be enabled in user_config.h with define USE_INA219 - * Add support for Arilux LC11 (Clearing RF home code when selecting no Arilux module) - * Add support for WS2812 RGBW ledstrips to be enabled in user_config.h with define USE_WS2812_CTYPE (#1156) - * Add SettingsSaveAll routine to command SaveData to be used before controlled power down (#1202) - * Add option PUSHBUTTON_TOGGLE (SwitchMode 7) to allow toggling on any switch change (#1221) - * Add new xdrv_05_ds18x20.ino free from library OneWire and add the following features: - * Add support for DS1822 - * Add forced setting of 12-bit resolution for selected device types (#1222) - * Add read temperature retry counter (#1215) - * Fix lost sensors by performing sensor probe at restart only thereby removing dynamic sensor probe (#1215) - * Fix sensor address sorting using ascending sort on sensor type followed by sensor address - * Rewrite JSON resulting in shorter message allowing more sensors in default firmware image: - * "DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6} - * Add additional define in user_config.h to select either single sensor (defines disabled), new multi sensor (USE_DS18X20) or legacy multi sensor (USE_DS18X20_LEGACY) - * Add clock support for more different pixel counts (#1226) - * Add support for Sonoff Dual R2 (#1249) - * Add FriendlyName to web page tab and add program information to web page footer (#1275) - * - * 5.9.1 20171107 - * Add external sensor function pointer interface to enable easy sensor addition - * Add support for ADS1115 to be enabled in user_config.h and needs libraries i2cdevlib-Core and i2cdevlib-ADS1115 (#338, #660) - * Fix Backup Configuration file download failure by defining proper file size (#1115) - * Fix Exception 26 and empty console screen after usage of command WakeupDuration (#1133) - * Fix some changed iTead web links in README.md (#1137) - * - * 5.9.0 20171030 - * Rewrite code (partly) using Google C++ Style Guide (https://google.github.io/styleguide/cppguide.html) - * Rewrite code by using command lookup tables and javascript (client side) web page expansions - * Change HTML/CSS to enable nicer form field entry - * Change default PWM assignments for H801 RGB(CW) led controller to support optional Color/Dimmer control - * GPIO04 (W2) from GPIO_PWM2 to GPIO_USER to be user configurable for GPIO_PWM5 (second White - Warm if W1 is Cold) - * GPIO12 (Blue) GPIO_PWM3 no change - * GPIO13 (Green) from GPIO_PWM4 to GPIO_PWM2 - * GPIO14 (W1) from GPIO_PWM1 to GPIO_USER to be user configurable for GPIO_PWM4 (first White - Cold or Warm) - * GPIO15 (Red) from GPIO_PWM5 to GPIO_PWM1 - * Change default PWM assignments for MagicHome RGB(W) led controller to support optional Color/Dimmer control - * GPIO05 (Green) from GPIO_PWM4 to GPIO_PWM2 - * GPIO12 (Blue) from GPIO_PWM5 to GPIO_PWM3 - * GPIO13 (White) GPIO_USER to be user configurable for GPIO_PWM4 (White - Cold or Warm) - * GPIO14 (Red) from GPIO_PWM3 to GPIO_PWM1 - * Change default PWM assignment for Witty Cloud to support optional Color/Dimmer control (#976) - * GPIO12 (Green) from GPIO_PWM4 to GPIO_PWM2 - * GPIO13 (Blue) from GPIO_PWM5 to GPIO_PWM3 - * GPIO15 (Red) from GPIO_PWM3 to GPIO_PWM1 - * Change when another module is selected now all GPIO user configuration is removed - * Change command name IRRemote to IRSend (#956) - * Remove Arduino IDE version too low warning as it interferes with platformio.ini platform = espressif8266_stage - * Fix command FullTopic entry when using serial or console interface - * Fix possible UDP syslog blocking - * Fix minimum TelePeriod of 10 seconds set by web page - * Fix command GPIOx JSON response (#897) - * Fix inverted relay power on state (#909) - * Fix compile error when DOMOTICZ_UPDATE_TIMER is not defined (#930) - * Fix alignment of web page items in some browsers (#935) - * Fix setting all saved power settings to Off when SetOption0 (SaveState) = 0 (#955) - * Fix timezone range from -12/12 to -13/13 (#968) - * Fix Southern Hemisphere TIME_STD/TIME_DST (#968) - * Fix TLS MQTT SSL fingerprint test (#970, #808) - * Fix virtual relay status message used with Color/Dimmer control (#989) - * Fix command IRSend and IRHvac case sensitive parameter regression introduced with version 5.8.0 (#993) - * Fix pressure calculation for some BMP versions regression introduced with version 5.8.0i (#974) - * Fix Domoticz Dimmer set to same level not powering on (#945) - * Fix Blocked Loop when erasing large flash using command reset 2 (#1002) - * Fix relay power control when light power control is also configured as regression from 5.8.0 (#1016) - * Fix Mqtt server mDNS lookup only when MqttHost name is empty (#1026) - * Add debug information to MQTT subscribe - * Add translations to I2Cscan - * Add translation to BH1750 unit lx - * Add light scheme options (Color cycle Up, Down, Random) and moving WS2812 schemes up by 3 - * Add Domoticz counter sensor to IrReceive representing Received IR Protocol and Data - * Add option 0 to MqttHost to allow empty Mqtt host name - * Add support for Arilux AL-LC01 RGB Led controller (#370) - * Add esp8266 de-blocking to PubSubClient library (#790) - * Add Domoticz sensors for Voltage and Current (#903) - * Add platformio OTA upload support (#928, #934) - * Add warning to webpage when USE_MINIMAL is selected (#929) - * Add smoother movement of hour hand in WS2812 led clock (#936) - * Add support for Magic Home RGBW and some Arilux Led controllers (#940) - * Add command SetOption15 0 (default) for command PWM control or SetOption15 1 for commands Color/Dimmer control to PWM RGB(CW) leds (#941) - * Add Domoticz counter sensor to Sonoff Bridge representing Received RF code (#943) - * Add support for Luani HVIO board (https://luani.de/projekte/esp8266-hvio/) (#953) - * Add PWM initialization after restart (#955) - * Add IR Receiver support. Disable in user_config.h (#956) - * Add support for inverted PWM (#960) - * Add Sea level pressure calculation and Provide command Altitude (#974) - * Add support for up to 8 relays (#995) - * Add commands RfSync, RfLow, RfHigh, RfHost and RfCode to allow sending custom RF codes (#1001) - * Add retain to ENERGY messages controlled by command SensorRetain (#1013) - * Add commands Color2, Color3, Color4, Width2, Width3, Width4 and SetOption16 to set Ws2812 Clock parameters (#1019) - * Add German language file (#1022) - * Add support for connecting to MQTT brokers without userid and/or password (#1023) - * Add support for esp8266 core v2.4.0-rc2 (#1024) - * Add commands PwmRange 1,255..1023 and PwmFrequency 1,100..4000 (#1025) - * Add Polish language file (#1044, #1047) - * Add support for KMC 70011 Power Monitoring Smart Plug (#1045) - * Add support for VEML6070 I2C Ultra Violet level sensor (#1053) - * Add light turn Off Fade (#925) - * Add IrSend command option Panasonic as IrSend {"Protocol":"Panasonic", "Bits":16388, "Data":} - * where 16388 is 0x4004 hexadecimal (#1014) - * Add retry counter to DHT11/21/22 sensors (#1082) - * - * 5.8.0 20170918 - * Remove the need for NeoPixelBus library for Hue support - * Consolidate WS2812 into Sonoff Led for flexible future led strip library changes - * Invert WS2812 fade speed to align with Sonoff led (Speed 1 = fast, Speed 8 = slow) - * Remove upper case MQTT receive buffer - * Reduce code and string length for output of commands Modules and GPIOs - * Add Sonoff SC debug information - * Change syslog service - * Removed webserver syslog disable as now no longer needed - * Increased default MQTT message size from 368 to 405 bytes while keeping MQTT_MAX_PACKET_SIZE = 512 (because we can) - * Fix MQTT Offline or Remove MQTT retained topic code - * Fix Domoticz loop when Emulation is selected - * Add blink to WS2812 and Sonoff Led (#643) - * Add option WIFI_WAIT (5) to command WifiConfig to allow connection retry to same AP without restart or update flash (#772, #869) - * Add support for Witty Cloud (#794) - * Add GPIO14 to Sonoff Dual (#797, #839) - * Add support for Yunshan Wifi Relay (#802) - * Add GPIO16 input pulldown (#827) - * Add timeout to DHT and DS18B20 sensors (#852) - * Fix watchdog timeout caused by lack of stack space by moving to heap (#853) - * Allow LogPort and MqttPort up to 65535 and add LogPort tot Status 3 (#859) - * Allow command SwitchTopic in group mode (#861) - * Allow command SwitchMode if no switches are defined (#861) - * Add optional dimmer parameter to command Wakeup for WS2812, AiLight, Sonoff B1, Led and BN-SZ01 (#867) - * Fix basic On, Off, Toggle, Blink and BlinkOff commands when other language is selected (#874) - * - * 5.7.1 20170909 - * Remove leading spaces from MQTT data - * Fix webconsole special character entry - * Allow # as prefix for color value - * Fix Alexa detection and Hue App Update Request (#698, #854) - * - * 5.7.0 20170907 - * Shrink module configuration webpage - * Fix settings order during startup to allow for displaying debug messages - * Fix some string length issues - * Add more string length tests by using strncpy - * Add Ai-Thinker RGBW led (AiLight) - * Add Power check and add PulseTime to power check at startup (#526) - * Add Supla Espablo support (#755) - * Add more precision to Sonoff Pow period and power results using command WattRes 0|1 (#759) - * Add basic internationalization and localization (#763) - * Add more Sonoff Pow range checking (#772) - * Fix invalid JSON (#786, #822) - * Add duplicate check to received RF signal within 2 seconds for Sonoff Bridge (#810) - * - * 5.6.1 20170818 - * Change module list order in webpage - * Fix Sonoff T1 1CH and 2CH configuration (#751) - * - * 5.6.0 20170818 - * Fix Sonoff Pow intermittent exception 0 - * Change Sonoff Pow sending Domoticz telemetry data only - * Add Ai-Thinker RGBW led (AiLight) (experimental) - * Add NeoPixelBus library to Sonoff Led for Hue support - * Add user configurable GPIO4 and GPIO5 to module Sonoff Bridge - * Add Sonoff B1 RGBCW led support with command Color RRGGBBCCWW (#676) - * Add command CT 152..500 to Sonoff Led and Sonoff B1 to control Color Temperature - * Add Cold-Warm slider to web page for Sonoff Led and Sonoff B1 - * Add CT parameter to Hue - * Add Sonoff T1 support (#582) - * Add AnalogInput0 if configured as Analog Input to webpage (#697, #746) - * Add command SetOption14 0|1 to enable interlock mode (#719, #721) - * Fix Mitsubishi HVAC IR power controll (#740) - * - * 5.5.2 20170808 - * Extent max number of WS2812 pixels from 256 to 512 (#667) - * Add OTA handling if server responds with no update available (#695) - * Removed undocumented command FlashMode (#696) - * Fix compile time error message due to increased message buffer size (#703) - * - * 5.5.1 20170805 - * Fix Sonoff Rf Bridge issues - * Add Sonoff RF Bridge MQTT messages on received and learned RF signal - * Add command VoltRes 0|1 to select voltage resolution to 0.1 V (#654) - * Add averaging to Analog input (#686) - * Add Energy tele data on Sonoff Pow Threshold change (#688) - * Fix inconsistent property names in Messages (#690) - * - * 5.5.0 20170730 - * Reduce code space by removing the following commands as they are replaced by SetOption alternatives: - * SaveState = SetOption0 - * ButtonRestrict = SetOption1 - * Units = SetOption2 - * MQTT = SetOption3 - * MQTTResponse = SetOption4 - * TempUnit = SetOption8 - * Smoothing WS2812 animation poll, invert fade speed and max allowed wakeup time down to 3000 seconds - * Fix initial button press detection - * Add support for Sonoff RF Bridge 433 using command RfKey - * Fix regression from 5.0.7 by increasing message buffer size from 360 to 368 to accomodate 4 x DS18x20 sensors (#637) - * Add GroupTopic to Topic test when using ButtonTopic/SwitchTopic to send either ON/OFF or TOGGLE (#642) - * Adjust HLW calibration limits to accomodate HuaFan device and add commands HlwPSet, HlwUSet and HlwISet (#654) - * - * 5.4.0 20170725 - * Fix command reset regression introduced in 5.2.0 - * Increase polling from 0.1 second to 0.05 second - * Add multipress to all buttons - * Fix button 1 double press behaviour on multi relay devices - * Add support for Hua Fan Smart Socket (#479) - * Add support for Sonoff 4ch Pro (#565) - * Add command SetOption13 1 to allow immediate action on single button press - * (disables multipress, hold and unrestricted commands) (#587) - * - * 5.3.0 20170715 - * Major Hue rewrite which might introduce Alexa problems. If so, initiate an issue - * Add support for Sonoff Led and BN-SZ01 Ceiling Led brightness control to Hue - * Fix Sonoff Led Power, Dimmer and Color MQTT response (#176) - * Add commands Delay and Backlog to allow multiple commands at once separated by ";" (#593) - * Use default flashmode DOUT to solve restart hangs on esp8285 chips (#453, #598) - * Change Web console column width from 99 to 300 (#599) - * - * 5.2.4 20170703 - * Removed flash mode update after selecting different module solving esp8285 related problems - * Add device type flag to sonoff_template.ino - * Change Sonoff Led Wakeup and add support for Sonoff BN-SZ01 Led (#567) - * - * 5.2.3 20170630 - * Change Sonoff Led color conversion code - * Fix SetOption12 handling - * Simplify auto configuration upgrade - * Add option Upgrade to only upgrade to any higher version (Old PR #213) - * Change FallbackTopic to cmnd// bypassing FullTopic and Prefix (#538) - * - * 5.2.2 20170625 - * Add configuration SaveAddress to Status 1 and Information Page - * Change Sonoff Led Color conversion from AtoH to strtol - * Fix possible wrong uploads due to configuration overwrites (#542) - * Fix payload negative numbers (#547) - * - * 5.2.1 20170622 - * Fix Restore Configuration in case of lower version - * Revert auto configuration upgrade allowing easy upgrade which was removed in version 5.2.0 - * Fix config auto upgrade from versions below version 4.1.1 (#530) - * - * 5.2.0 20170619 - * Add command SetOption12 1 to disable newly released configuration flash rotate to reduce flash wear - * Fix command CounterDebounce by removing test for active GPIO (#524) - * Add command SetOption33 1..250 to allow user configure POW Max_Power_Retry count (#525) - * - * 5.1.7 20170616 - * Prep removal of SetOptions alternatives - * Restore webpage upgrade error messages removed in 5.1.5 - * Add hold button functionality to buttons 2 to 4 - * Add command SetOption32 1..100 to set Key Hold Time from 0.1 seconds to 10 seconds (#200) - * Allow slashes in Topic, GroupTopic, ButtonTopic and SwitchTopic (#507) - * Changed webpage form actions from post to get and use relative path url (#434, #522) - * - * 5.1.6 20170606 - * Shrink code - * Removed online configuration of Domoticz In and Domoticz Out MQTT strings - * Removed commands DomoticzInTopic and DomoticzOutTopic - * Add define KEY_HOLD_TIME to configure button hold threshold before sending MQTT Hold message - * Add command StateText4 to configure button MQTT Hold text (= MQTT_CMND_HOLD) - * Add command SetOption11 0|1 to swap pushbutton single and double press functionality (#200) - * Add command SwitchMode 5 (PUSHBUTTONHOLD) and 6 (PUSHBUTTONHOLD_INV) (#489) - * - * 5.1.5 20170604 - * Shrink code in preparation to ESP8266-Arduino 2.4.0-rc1 - * Add effect parameter to HUE Device (#464) - * - * 5.1.4 20170601 - * Removed pre-compiled versions from repository as they are available within the release - * Changed HUE Device type to color supporting version (#464) - * Fix compile error when BE_MINIMAL is selected (#467, #476) - * Add multiple compiled versions to release using updated Travis script and platformio.ini (#467) - * - * 5.1.3 20170520 - * Add Domoticz Counter - * - * 5.1.2 20170519 - * Fix Counter/Timer JSON message and update Counter/Timer on webpage - * Fix WS2812 Domoticz related regression issues - * - * 5.1.1 20170517 - * Allow command FullTopic in group mode - * Prepare for more use of RTC memory - * Add independant WS2812 led string power control (#386, #390) - * Add command Counter to control up to four GPIO falling edge interrupt counters or timers (#459) - * Add command CounterType to select between pulse counting or pulse timing - * Add command CounterDebounce to select global counter debounce time in mSec - * - * 5.1.0 20170513 - * Fix Offline/Removal of retained topic when FullTopic is changed - * Add FullTopic to MQTT Configuration and Information web pages - * Add license model GPLv3 (#188) - * - * 5.0.7 20170511 - * Fix possible exception 28 on empty command - * Add command SetOption0 as replacement for SaveState - * Add command SetOption1 as replacement for ButtonRestrict - * Add command SetOption2 as replacement for Units - * Add command SetOption4 as replacement for MqttResponse - * Add command SetOption8 as replacement for TempUnit - * Add command SetOption10 On|Off to select between Offline or Removing previous retained topic (#417, #436) - * - * 5.0.6 20170510 - * Remove hyphen in case of a single DHT sensor connected (#427) - * Add command MqttRetry to change default MQTT reconnect retry timer from minimal 10 seconds (#429) - * - * 5.0.5 20170508 - * Add command FullTopic with tokens %topic% (replaced by command Topic value) and - * %prefix% (replaced by command Prefix values) for more flexible topic definitions (#244) - * See wiki > MQTT Features https://github.com/arendst/Sonoff-Tasmota/wiki/MQTT-Features for more information - * - * 5.0.4 20170505 - * Add Sonoff Pow Energy Total up to 40 MWh - * Add command EnergyReset 1|2|3 to reset Energy counters (#406) - * Fix Domoticz Energy logging (#411) - * Add command PowerOnState 4 to keep relay always on and disabling all power control (#418) - * - * 5.0.3 20170504 - * Add command SensorRetain on|off to enable retaining of mqtt message tele/sonoff/SENSOR (#74) - * Change WifiConfig timeout from 60 seconds to 180 seconds (#212) - * Change Sonoff Touch command Ledstate functionality by turning led on if power is off (#214) - * Add 4 seconds delay after power on before enabling button to workaround Wemos D1 mini RTS circuit (#380) - * - * 5.0.2 20170503 - * Reset SaveData, SaveState and MqttResponse to default values due to rearranging settings - * Moved some settings to flag area - * Add command TempUnit Celsius|Fahrenheit for selecting Celsius or Fahrenheit (#347) - * Add command TempRes 0..3 for selecting Temperature Resolution (#347) - * Add command HumRes 0..3 for selecting Humidity Resolution (#347) - * Add command PressRes 0..3 for selecting Pressure Resolution (#347) - * Add command EnergyRes 0..5 for selecting Energy Resolution (#347) - * Add "TempUnit":"C|F" to sensor JSON output (#347) - * Add support for up to three DHT type sensors each using a different GPIO (#339, #404) - * - * 5.0.1 20170429 - * Adjust Sonoff SC messages to prepare for display feature - * Move static data from RAM to Flash - * Fix PowerOnState for some devices not reporting "Power on" state (#284, #380, #383) - * - * 5.0.0 20170425 - * Memory status message update - * Fix setting migration to better preserve settings during move (#382) - * Best practice is first doing a Backup Configuration before installing version 5.0.0 - * Reset save count after setting move - * Start using new linker script without SPIFFS - * - * 4.2.0 20170424 - * Prepare for SPIFFS removal by moving settings to EEPROM area - * Fix compilation error when webserver is disabled (#378) - * - * 4.1.3 20170410 - * Add user configuarble GPIO to module S20 Socket and Slampher - * Add support for Sonoff SC (#112) - * Set PWM frequency from 1000Hz to 910Hz as used on iTead Sonoff Led firmware (#122) - * Set Sonoff Led unconfigured floating outputs to 0 to reduce exceptions due to power supply instabilities (#122) - * Add Access Point Mac Address to Status 11 and Telemetry (#329) - * Fix DS18B20 negative temperature readings (#334) - * - * 4.1.2 20170403 - * Rename Unrecognised command to Unknown command - * Remove all command lists - * Remove command SmartConfig (superseded by WifiConfig) - * Fix boot loop when selecting module Sonoff 4CH or Sonoff Touch on non ESP8285 hardware - * Add optional support for Toshiba and Mitsubishi HVAC IR control (needs updated IRremote8266 library) (#83, #257) - * Add all configured switches to Domoticz Configuration web page (#305) - * Fix compile error when selecting WS2812 DMA (#313) - * - * 4.1.1 20170329 - * Fix default Telemetry for command Prefix3 - * Fix webserver Module parameters for disabled select - * Fix sensor status for enabled switches - * Remove Light as alternative for Power (save code space) - * Remove migration option from pre V3 (code cleanup) - * Remove unofficial SPIFFS support (code cleanup) - * Remove command list when unknown command is entered (save code space) - * Rename Status11 json from StatusPWR to unique StatusSTS - * Rename command Gateway to IPAddres2, Subnetmask to IPAddress3 and DnsServer to IPAddress4 (save code space) - * Add Command MqttResponse to select either command or RESULT topic as response (#258) - * Add command StateText1 to StateText3 to assign MQTT_STATUS_OFF, MQTT_STATUS_ON and MQTT_CMND_TOGGLE respectively (#286) - * Remove restart after IPAddress changes (#292) - * Add support for MAX31850 in xsns_ds18x20.ino (#295) - * Fix possible uptime update misses (#302) - * - * 4.1.0 20170325 - * Change static IP addresses in user_config.h from list (using commas) to string (using dots) - * Unify display result of commands Modules, Module and Gpios - * Rewrite Module selection web page to bring size down from 18651 to 4319 bytes (!) (#234, #240) - * Add basic support for (Lixada) H801 RGBWW controller (#252) - * Add command Prefix1 to Prefix3 to assign SUB_PREFIX, PUB_PREFIX and PUB_PREFIX2 respectively (#255) - * Add static ip addresses to flash (#262) - * Add commands IpAddress, Gateway, Subnetmask and DnsServer to select static ip addresses (#273) - * - * 4.0.8 20170321 - * Fix entering non-numeric webpassword - * Force selection between TLS or Webserver due to memory restraint (#240) - * Allow entering empty string using "0" for selected commands (#242) - * Fix exception when posting commands to web console containing % (#250) - * - * 4.0.7 20170319 - * Increased Sonoff Led PWM frequency from 432 to 1000 - * Fix possible watch dog reboot after changing module type on web page - * Fix reporting of GPIO usage from web page - * Fix Sonoff Led blank during firmware upgrade - * Fix Sonoff Led flicker and possible flash corruption by using latest Arduino-esp8266 versions - * of pwm core files included in sonoff library (#211) - * Add PWM output control with commands PWM1 to PWM5 using user selectable GPIOs (#211) - * Fix exceptions due to low values of commands HlwPCal (10000), HlwUCal (1000) and HlwICal (2500) (#223) - * Add Switch state to sensor status (#227, #233) - * Add user configuarble GPIO to module Sonoff Touch (#228) - * Add define WEB_PORT to user_config.h to change default web server port from 80 (#232) - * Fix failed Ota Firmware upgrade started from Web page (#235) - * - * 4.0.6 20170316 - * Fix to better find device by Wifi hostname - * Fix compile error when some I2C devices are disabled - * Add (experimental) support for SHT1X emulating I2C (#97) - * Add ADC to ElectroDragon (#203) - * Add support for Sonoff Dev (#206) - * - * 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 to configure up to three NTP servers (#177) - * Delete module User Test as module Wemos D1 mini has same/more user configurable GPIO (#178) - * Add more user configurable GPIO to module ElectroDragon (#183) - * - * 4.0.3 20170309 - * Renamed Module NodeMCU to WeMos D1 mini - * Add GPIO1 as user option to some modules - * Add Buttons, Relays and Leds to user configurable options (#159) - * Add description on Module parameters web page to some well known GPIOs (#107, #171) - * - * 4.0.2 20170308 - * Restore correct seriallog level after Serial logging was disabled - * Add simple dimmer slider to Sonoff Led web page - * Reduced root webpage size by 31% - * Expand Status 2 with Build date/time and core version - * Fix webserver redirection when not in WifiManager mode (#156) - * Add command ButtonRestrict On/Off to restrict access to button hold and button multi press options above 2 (#161) - * Fix DS18S20 negative temperature readings (#165) - * Fix crlf compilation error due to bad syntax (#144, #167) - * - * 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) - * Increase message size and suggested minimum MQTT_MAX_PACKET_SIZE to 512 (#114, #124) - * Remove runtime warning message regarding MQTT_MAX_PACKET_SIZE too small as it is now moved to compile time (#124) - * Fix possible panics with web console and http commands while UDP syslog is active (#127) - * Add optional static IP address (#129) - * Add define ENERGY_RESOLUTION in user_config.h to allow user control over precision (#136) - * - * 3.9.22 20170228 - * Update web console - * Fix Status 4 JSON message - * Add Exception info during restart if available - * Add osWatch service to detect loop hangs that might happen during (OTA) upgrades - * Add WiOn support for relay and switch only (#82, #102) - * Allow for user specified relay count up to four in sonoff_template.h (#109) - * Add support for HTU21 compatible I2C sensors SI7013, SI7020 and SI7021 (#118) - * Add NodeMCU or Wemos configuration option (#119) - * - * 3.9.21 20170224 - * Add ajax to web root page and web console (#79) - * Add commands SwitchMode1..4 and enable user switches 2, 3 and 4 (#84, #88) - * Fix MQTT upgrade when webserver is active - * - * 3.9.20 20170221 - * Add minimal basic authentication to Web Admin mode (#87) - * Fix Hue and add HSB support (#89) - * - * 3.9.19 20170219 - * Sonoff Led: Made GPIO04, 05 and 15 available for user - * Sonoff Led: Add commands Fade, Speed, WakupDuration, Wakeup and LedTable - * - * 3.9.18 20170218 - * Fix ledstate 0 to turn off led - * Fix Sonoff Led dimmer range (#16) - * Change Sonoff Led command Dimmer to act on both cold and warm color - * Add Sonoff Led command Color CCWW where CCWW are hexadecimal values fro 00 - FF - * Reduce Sonoff Led flickering by disabling interrupts during flash save and disabling - * Led during OTA upgrade and Web upload (#16) - * - * 3.9.17 20170217 - * Fix possible ArduinoJSON related memory fragmentation - * Changed console logging using less memory - * Add GPIO04 as user selectable for Sonoff Dual (#75) - * - * 3.9.16 20170214 - * Update latching relay handler - * Add support for IR led using IRremoteESP8266 library (#59) - * Add Hue argument passing using ArduinoJSON library (#59) - * - * 3.9.15 20170213 - * Change JSON float values from string to number according to http://json.org (#56) - * Add support for exs latched relay module https://ex-store.de/ESP8266-WiFi-Relay-V31 (#58) - * Add support for inverted relays - * Changed MAX_LOG_LINES from 70 to 60 to preserve memory - * - * 3.9.14 20170211 - * Add False and True as alternatives for 0/Off and 1/On (#49) - * Fix Status10 JSON format (#52) - * Fix DS18x20 using OneWire library (#53) - * - * 3.9.13 20170210 - * Add FlashChipMode to Status 4 - * Removed redundant DHT2 option and code - * Add Sonoff SV GPIO pin 05 configuration (#40) - * Add configuration file backup and restore via web page - * Fix latency due to light_sleep mode even if sleep was set to zero (#50) - * - * 3.9.12 20170208 - * Fix compile error when webserver is disabled (#30) - * Fix possible ESP8285 flash problem by updating Flash Chip Mode to DOUT during OTA upload - * Fix hostname issues by not allowing user entry of string formatting and removing from user_config.h (#36) - * - * 3.9.11 20170204 - * Fix command I2Cscan - * Fix not allowed spaces in Topic, ButtonTopic and SwitchTopic - * Make all TELEMETRY, STATUS and COMMAND message topics unique (#4) - * Advertise command topic to be used by iobroker (#299) - * Fix butten (non)detection if no GPIO_KEY1 is defined (#13) - * Change WeMo serialnumber from 7 decimal chars to 8 hexadecimal chars (#18) - * Update web page with Build Date/Time, Emulation and mDNS Discovery and Advertise information (#21) - * - * 3.9.10 20170130 - * Add WS2812 Color Type selection (RGB or GRB) to user_config.h (#7) - * Hue api changes to support HUE App(s) (#8) - * - * 3.9.9 20170130 - * Add command status 10 showing sensor data - * Fix hlw status messages if hlw is disabled - * - * 3.9.8 20170130 - * Remove GPIO07 and GPIO08 from user selectable (#5) - * - * 3.9.7 20170129 - * Fix possible WS2812 exceptions when using emulation - * Add command Emulation to dynamic configure Belkin WeMo and Hue Bridge for Alexa - * - * 3.9.6 20170129 - * Add dynamic sleep for WS2812 animation (#1) - * - * 3.9.5 20170128 - * Fix error message in case of wrong Domoticz command - * - * 3.9.4 20170127 - * Fix Sonoff Dual Relay switching (#287) - * - * 3.9.3 20170127 - * Add confirmation before Restart via webpage - * Expand Domoticz Configuration webpage with Key, Switch and Sensor Index and - * add commands DomoticzSwitchIdx and DomoticzSensorIdx (#86) (#174) (#219) - * Fix default DHT11 sensor driver selection - * Fix LedPower status after button press (#279) - * Add command Sleep 0 - 250 mSec for optional light sleep mode to lower energy consumption (#272) - * (Expect overall button/key/switch misses and wrong values on Sonoff Pow) - * Add Hue brightness extension (#281) - * Fix Hue brightness and change to call by reference (#283) - * - * 3.9.2 20170124 - * Add confirmation before Reset Configuration via webpage (#244) - * Add WS2812 features (see Wiki commands) - * - * 3.9.1 20170124 - * Change PowerOnState function to only trigger when Power On (and not just restart) (#238) - * Move HLW interrupts back to RAM and make WS2812_DMA optional as it generates Exception on Pow (#264) - * Add charset=utf-8 to webpages (#266) - * Update Hue emulation (#268) - * Fix status module number - * Add support for domoticz Dimmer on Sonoff_Led and WS2812 - * Fix possible ESP8285 flash problem by updating Flash Chip Mode to DOUT during web upload - * - * 3.2.6a 20170120 - * Fix Sonoff Pow compile error (#255) - * Move HLW interrupts back to ROM (Needed for WS2812 DMA interrupts) - * Removed all IO config from user_config.h as this will be done by commands or webpage - * Removed MessageFormat and supports JSON only except POWER/LIGHT status - * Add command LedPower to control main led (#247) - * Add more FriendlyNames for Hue (#254) - * Add DMA support for WS2812 when using pin 3 while other pins work just as well in my case... - * Add HUE emulation for Alexa (#229) - * Add basic WS2812 support (#229) - * Fix Wemo when MQTT is disabled (#245) - * Revert ButtonTopic and change SwitchTopic1 - 4 to one SwitchTopic - * Rename MqttUnits to Units - * Add Mqtt command to enable/disable MQTT - * - * 3.2.2a 20170115 - * Add dynamic (Sonoff) Module, user GPIO and sensor selection (one size fits (almost) all) - * Add support for Sonoff LED - * Add Seriallog disable after 600 seconds for Sonoff Dual and 4 Channel - * Add ButtonTopic2 - 4, SwitchTopic1 - 4 and SwitchRetain - * - * 3.2.2 20170113 - * Fix PowerOnState 2 functionality after re-applying power (#230) - * - * 3.2.1 20170113 - * Fix some failed command decoding (#228) - * Removed passwords from status messages (#216) - * - * 3.2.0 20170111 - * Add I2C BH1750 sensor (#222) - * Sensor rewrite preparing for online selection - * - * 3.1.16 20170109 - * Fix Domoticz possible error condition - * Remove Wifi password from connection message (#216) - * Add Configure Other menu item to web page (#209) - * Add command FriendlyName, field Friendly Name and define FRIENDLY_NAME to be used by Alexa - * eliminating current use of MQTT_CLIENT_ID (#209) - * Add friendlyname to webpage replacing former hostname - * - * 3.1.15 20170108 - * Fix Domoticz send key regression with Toggle command - * - * 3.1.14 20170107 - * Add support for command TOGGLE (define MQTT_CMND_TOGGLE) when ButtonTopic is in use and not equal to Topic (#207) - * - * 3.1.13 20170107 - * Fix web console command input when SUB_PREFIX contains '/' (#152) - * Add command response to web command (#200) - * Add option to disable MQTT as define USE_MQTT in user_config.h (#200) - * - * 3.1.12 20170106 - * Add OTA retry to solve possible HTTP transient errors (#204) - * Fix MQTT host discovery - * - * 3.1.11 20170105 - * Add mDNS to advertise webserver as .local/ - * - * 3.1.10 20170105 - * Fix ButtonTopic when SUB_PREFIX = PUB_PREFIX - * Add workaround for possible MQTT queueing when SUB_PREFIX = PUB_PREFIX - * Add optional MQTT host discovery using define USE_DISCOVERY in user_config.h (#115) - * - * 3.1.9 20170104 - * Fix Power Blink start position (toggled) - * Change PulseTime increments: 1 .. 111 in 0.1 sec (max 11 seconds) and 112 .. 64900 in seconds (= 12 seconds until 18 hours) (#188) - * Add support for SUB_PREFIX = PUB_PREFIX (#190) - * - * 3.1.8 20170103 - * Add retain flag to LWT offline and only send "tele/sonoff/LWT Offline" (#179) - * Change retained LWT Online message to only send "tele/sonoff/LWT Online" - * - * 3.1.7 20161231 - * Add retained message LWT Online when sonoff makes MQTT connection (#179) - * - * 3.1.6 20161230 - * Add blinking using commands BlinkTime, BlinkCount and Power Blink|3|BlinkOff|4 (#165) - * - * 3.1.5 20161228 - * Fix serial space command exception (28) - * - * 3.1.4 20161227 - * Fix MQTT subscribe regression exception (3) (#162) - * Fix serial empty command exception (28) - * - * 3.1.3 20161225 - * Extent Domoticz configuration webpage with optional indices (#153) - * Fix multi relay legacy tele message from tele/sonoff/2/POWER to tele/sonoff/POWER2 - * Add support for iTead Motor Clockwise/Anticlockwise - * - * 3.1.2 20161224 - * Extent command PowerOnState with toggle at power on (option 2 is now option 3!) (#156) - * - * 3.1.1 20161223 - * Add support for Sonoff Touch and Sonoff 4CH (#40) - * Update DomoticzIdx and DomoticzKeyIdx with relay/key index (DomoticzIdx1/DomoticzKeyIdx1) - * Add command PowerOnState to control relay(s) at power on (#154) - * - * 3.1.0 20161221 - * Add Sonoff Pow measurement smoothing - * Fix serial command topic preamble error (#151) - * Fix 2.x to 3.x migration inconsistencies (#146) - * - * 3.0.9 20161218 - * Add Sonoff Pow voltage reading when relay is on but no load present (#123) - * - * 3.0.8 20161218 - * Add temperature conversion to Fahrenheit as option in user_config.h (TEMP_CONVERSION) (#145) - * - * 3.0.7 20161217 - * Add user_config_override.h to be used by user to override some defaults in user_config.h (#58) - * Fix Sonoff Pow low power (down to 4W) intermittent measurements (#123) - * - * 3.0.6 20161217 - * Fix MQTT_CLIENT_ID starting with % sign as in "%06X" (#142) - * Add auto power off after PulseTime * 0.1 Sec to relay 1 (#134) - * - * 3.0.5 20161215 - * Add more control over LED with command LedState options (#136, #143) - * LED_OFF (0), LED_POWER (1), LED_MQTTSUB (2), LED_POWER_MQTTSUB (3), LED_MQTTPUB (4), LED_POWER_MQTTPUB (5), LED_MQTT (6), LED_POWER_MQTT (7) - * Add option WIFI_RETRY (4) to command WifiConfig to allow connection retry to other AP without restart (#73) - * - * 3.0.4 20161211 - * Fix intermittent Domoticz update misses (#133) - * - * 3.0.3 20161210 - * Fix compiler warnings (#132) - * Remove redundant code - * Fix Domoticz pushbutton support - * - * 3.0.2 20161209 - * Add pushbutton to SwitchMode (#130) - * - * 3.0.1 20161209 - * Fix initial config - * - * 3.0.0 20161208 - * Migrate and clean-up flash layout - * Settings from version 2.x are saved but settings from version 3.x can not be used with version 2.x - * Change SEND_TELEMETRY_RSSI to SEND_TELEMETRY_WIFI and add AP and SSID to telemetry - * Split long JSON messages - * Fix inconsistent status messages - * Fix all status messages to return JSON if enabled - * Remove relay index in cmnd/sonoff//POWER now changed - * to cmnd/sonoff/POWER for single relay units - * and cmnd/sonoff/POWER for multi relay units like Sonoff dual - * Add retain option to Power/Light status controlled by command PowerRetain On|Off (#126) - * - * 2.1.2 20161204 - * Add support for second wifi AP (#73) - * Update command WifiConfig - * Fix possible WifiManager hang - * - * 2.1.1a 20161203 - * Fix scan for wifi networks if WeMo is enabled - * Fix syslog setting using web page - * - * 2.1.1 20161202 - * Add support for ElectroDragon second relay and button (only toggle with optional ButtonTopic) (#110) - * - * 2.1.0 20161202 - * Add optional EXPERIMENTAL TLS to MQTT (#49) - * Fix MQTT payload handling (#111) - * Optimzed WeMo code - * - * 2.0.21a 20161201 - * Fix WeMo PowerPlug emulation - * - * 2.0.21 20161130 - * Add Belkin WeMo PowerPlug emulation enabled with USE_WEMO_EMULATION in user_config.h (Heiko Krupp) (#105, #109) - * - * 2.0.20 20161130 - * Relax MQTTClient naming but only allows hexadecimal uppercase numbers (#107) - * Add I2C support with command I2CScan - * Add I2C sensor driver for HTU21 as alternate sensor using TH10/16 connectors (Heiko Krupp) (#105) - * Add I2C sensor driver for BMP085/BMP180/BMP280/BME280 as alternate sensor using TH10/16 connectors - * - * 2.0.19a 20161127 - * Add support for ButtonTopic and ButtonRetain to wall switch function - * Add pullup to SWITCH_PIN and command SwitchMode to syntax - * - * 2.0.18 20161126 - * Add SUB_PREFIX multi level support allowing 'cmnd' or 'cmnd/level2/level3' - * Add wall switch function to GPIO14 and command SwitchMode (Alex Scott) (#103) - * - * 2.0.17 20161123 - * Calibrate HLWPCAL from 12345 to 12530 - * Add alternative sensor driver DHT2 using Adafruit DHT library - * Add define MESSAGE_FORMAT to user_config.h - * Throttle console messages - * Shorten JSON messages - * Fix possible Panic - * Fix User mode webserver security - * - * 2.0.16 20161118 - * Add alternative sensor driver DS18x20 using OneWire library (#95) - * Change sensor MQTT message from tele/sonoff/TEMPERATURE to tele/sonoff/DHT/TEMPERATURE or - * tele/sonoff/DS18B20/TEMPERATURE or tele/sonoff/DS18x20/1/TEMPERATURE - * Add sensors to root webpage and auto refresh every 4 seconds (#92) - * Add optional JSON messageformat to all telemetry data - * Enforce minimum TelePeriod to be 10 seconds - * Fix Energy Yesterday reset after restart - * Add Energy Today restore after controlled restart - * - * 2.0.15 20161116 - * Change TODAY_POWER and PERIOD_POWER to TODAY_ENERGY and PERIOD_ENERGY - * Fix serial regression - * Fix syslog hangs when loghost is unavailable - * - * 2.0.14 20161115 - * Add HLW threshold delay - * Fix HLW intermittent current deviation - * Fix button functionality during wificonfig - * Add CRC check to DS18B20 sensor (#88) - * - * 2.0.13 20161113 - * Add additional upload error code descriptions - * Add PlatformIO support (#80) - * - * 2.0.12 20161113 - * Fix Serial and Web response regression when no MQTT connection available - * Fix Sonoff Dual power telemetric data for second relay - * Removed MQTT password from Information web page - * Hide MQTT password from Configure MQTT web page - * - * 2.0.11 20161111 - * Rewrite button and web toggle code - * Fix NTP sync - * Add HLW calibration commands HLWPCAL, HLWUCAL and HLWICAL (need define USE_POWERCALIBRATION) - * Fix power threshold tests - * - * 2.0.10 20161109 - * Add additional Domoticz define (#63) - * Add defines MQTT_STATUS_ON and MQTT_STATUS_OFF in user_config.h to select status On/Off string - * Fix status response differences (#65) - * Fix divide by zero exception (#70) - * Fix syslog loop exception - * - * 2.0.9 20161108 - * clarify MODULE in user_config.h - * Fix hlw false values - * - * 2.0.8 20161108 - * Add initial status after power on - * Seperate driver files - * Fix hlw code and calibrate Pow - * Move user config defines to user_config.h (#61) - * - * 2.0.7 20161030 - * Make Ticker mandatory - * Add Domoticz support (Increase MQTT_MAX_PACKET_SIZE to 400) (#54) - * Add command MessageFormat 0|1 to select either legacy or JSON output - * - * 2.0.6 20161024 - * Add Sonoff Pow power factor - * Initial support for up to four relays using iTEAD PSB (4Channel) - * - Currently only supports one button (All buttons behave the same) - * - Use command MODEL 4 to select four relay option - * (After first power on it will support 2 relays like Sonoff Dual) - * Fix ledstate - * Add command Status 9 to display Sonoff Pow thresholds - * Add commands PowerLow, PowerHigh, VoltageLow, VoltageHigh, CurrentLow and CurrentHigh for use - * with Sonoff Pow thresholds - * - * 2.0.5 20161018 - * Add updates to user_config.h - moved SEND_TELEMETRY_DS18B20 and SEND_TELEMETRY_DHT to module area. - * As Sonoff TH10/16 does not have the logic installed for GPIO04 You'll have to select ONE of both - * Add Sonoff Pow support (experimental until Pow tested) - * Add command Status 8 to display Sonoff Pow energy values - * Add command MqttUnits On|Off to add units to values - * Change web main page header character size - * Change On/Off to ON/OFF status messages to satisfy openHAB - * Change TEMP to TEMPERATURE and HUM to HUMIDITY - * - * 2.0.4 20161009 - * Add MQTT_BUTTON_RETAIN, SAVE_DATA and SAVE_STATE defines to user_config.h (#35) - * Update ButtonRetain to remove retained message(s) from broker when turned off - * Add Retain for second relay on Sonoff Dual - * Provide power status messages with device topic index if requested - * - * 2.0.3 20161008 - * Update wifi initialization - * Add command BUTTONRETAIN for optional MQTT retain on button press (#35) - * Add command SAVESTATE to disable power state save. May be used with MQTT retain - * - * 2.0.2 20161006 - * Fix wifi issue 2186 - * - * 2.0.1 20161002 - * Fix button press - * - * 2.0.0 20161002 - * Update Sonoff TH10/16 sensor pins (My TH10 only has GPIO14 connected) - * Add full support for Sonoff dual - * - * 1.0.35 20160929 - * Add more lines to console - * Add timeout and disable MQTT on web upload - * Add command SAVEDATA to control parameter save (for flash wear afficionados) (#30) - * - * 1.0.34 20160926 - * Fix button press six and seven - * Add more information to webserver - * - * 1.0.33 20160915 - * Better WPS error message - * Separate webserver code from support.ino into webserver.ino - * Fix webserver User by removing unwanted restart option - * - * 1.0.32 20160913 - * Add Wifi Protected Setup (WPS) as third option for initial config - * Add command WIFICONFIG replacing deprecated command SMARTCONFIG - * Add option WIFICONFIG 3 to start WPSconfig - * Add option WIFICONFIG 0 to start saved Wifi config tool (WPSconfig, Smartconfig or Wifimanager) - * Change button behaviour - See Wiki - * - * 1.0.31 20160907 - * Fix DS18B20 misread if teleperiod = 2 - * Tuned sensor code - * Updated prefered ElectroDragon connection to Relay 1 and Button 1 - * Moved SONOFF and ELECTRO_DRAGON port config to user_config.h - * - * 1.0.30 20160902 - * Fix command TELEPERIOD 0 - * Add ESP- tag to UDP log message for easy rsyslogd filtering - * Add ElectroDragon (Relay 2 only) functionality. Select with #define MODULE ELECTRO_DRAGON - * Add ? as null message alternative - * Add DHT temperature and humidity telemetry support. Enable with #define SEND_TELEMETRY_DHT - * Add DS18B20 temperature telemetry support. Enable with #define SEND_TELEMETRY_DS18B20 - * Restrict HOSTNAME, MQTTCLIENT, TOPIC and BUTTONTOPIC in topic mode only - * - * 1.0.29 20160831 - * Allow UPGRADE, OTAURL, RESTART, RESET, MQTTHOST, MQTTPORT, MQTTUSER, MQTTPASSWORD and WEBSERVER also in group mode - * - * 1.0.28 20160831 - * Add webserver state to status 5 - * Add optional PUB_PREFIX2 (tele) for telemetry usage - * Add command TELEPERIOD - * Fix syntax message - * Change memory status display - * - * 1.0.27 20160831 - * Add sketch flash size - * Add console to webserver - * Add command weblog - * Change WifiManager web pages to minimal - * Change display default hostname and MQTT client id in webserver - * Change HTTP command interface to http://sonoff-1234/cm?cmnd=light 2 - * Change HEARTBEAT to UPTIME - * - * 1.0.26 20160829 - * Add define USE_WEBSERVER to disable web server code in source - * Add file upload as alternative for ota upload to webserver - * Add information to webserver - * Add command hostname - * Add command logport - * Change HTTP command interface to http://sonoff-1234/cmd?cmnd=light 2 - * Change button behaviour with regards to Smartconfig and OTA upload. See README.md - * Enforce default hostname to either "%s-%04d" or user defined without any % - * Enforce default mqtt client id to either "DVES_%06X" or user defined without any % - * - * 1.0.25 20160822 - * Remove config system halts to keep ota available - * - * 1.0.24 20160821 - * Add test for MQTT_SUBTOPIC - * Change log range to LOG_LEVEL_ALL - * Change MQTT introduction messages - * Moved MQTT_MAX_PACKET_SIZE warning message to introduction messages - * - * 1.0.23 20160821 - * Add option USE_SPIFFS to move config from flash to spiffs - * Add webserver with options 0 (off), 1 (user) and 2 (admin) - * Add HTTP command interface (http://sonoff-1234/c?cmnd=light 2) - * Add wifimanager countdown counter - * Add command line webpage - * Add relay control to wifimanager - * Add restart option 99 to force restart - * Fix wifi hostname - * Fix NETBIOS hostname problem by reducing default hostname length - * Fix possible exception if WIFI_HOSTNAME is changed - * Fix upgrade messages - * Reduce memory use by redesigning config routines - * Split syntax message - * Rename define SERIAL_IO to USE_SERIAL - * - * 1.0.22 20160814 - * Add all MQTT parameters for configuration - * Add wifimanager to configure Wifi and MQTT via web server - * Change NTP time handling - * Fix Smartconfig parameter buffer overflow - * Fix PlatformIO warnings - * - * 1.0.21 20160808 - * Remove semaphore as subscription flooding (more than 15 subscriptions per second) is managed by SDK (LmacRxBlk:1) - * Add optional RTC interrupt (define USE_TICKER) to keep RTC synced during subscription flooding - * Remove heartbeatflag - * - * 1.0.20 20160805 - * Add semaphore to handle out of memory when too many subscriptions requested - * Use Daylight Saving (DST) parameters from user_config.h when timezone = 99 - * Add status 7 option displaying RTC information - * Add ledstate to status 0 - * - * 1.0.19 20160803 - * Fix possible MQTT_CLIENT_ID induced Exception(28) - * - * 1.0.18 20160803 - * Moved Cfg_Default - * Fix negative data handling - * Remove MQTT information from status 1 and add labels to status 1 - * Add mac address to status 5 - * Add MQTT ClientId, UserId and Password to status 6 - * - * 1.0.17 20160731 - * Better variable range checking - * Change ambiguous connection messages - * Add timestamp to serial message - * - * 1.0.16 20160729 - * Moved wifi, rtc, syslog and config to support.ino - * Fixed button action when buttontopic is used. Introduced with 1.0.15 - * Better buffer overflow checks (strlcpy) - * - * 1.0.15 20160728 - * Removed pubsubclient config changes from sonoff.ino as it doesn't work - * reapply MQTT_MAX_PACKET_SIZE 256 and MQTT_KEEPALIVE 120 to PubSubClient.h - * Add status 0 option displaying all status messages - * Change MQTT_MAX_PACKET_SIZE from 1024 to 256 - * Add buffer overflow checks (snprintf and strncpy) - * Implemented common string sizes - * - * 1.0.14 20160722 - * Seperate user config from sonoff.ino to user_config.h (pucebaboon) - * Change defaults from sidnas2 to domus1 - * Add MQTT status message as status 6 (pucebaboon) - * Add status type to message (pucebaboon) - * Add pubsubclient config changes to sonoff.ino (pucebaboon) - * - * 1.0.13 20160702 - * Add Ledstate 1 option to show power state on led - * - * 1.0.12 20160529 - * Allow disable of button topic using "0" - * - * 1.0.11 20160524 - * Provide button response if MQTT connection lost - * - * 1.0.10 20160520 - * Add optional button topic to assist external MQTT clients - * Change version notation - * Reset default values - * - * 1.0.9 20160503 - * Add more blinks - * Add reset 2 option erasing flash - * Add status 5 option displaying network info - * Add syslog check for Wifi connection - * Resize MqttPublish log array - * Change Wifi smartconfig active from 100 to 60 seconds - * Update Wifi initialization - * - * 1.0.8 20160430 - * Remove use of Wifi config data from SDK - * Add status 3 (syslog info) and status 4 (flash info) - * Add restart option to button (5 quick presses) - * - * 1.0.7 20160420 - * Add UDP syslog support - * Change HOST command to MQTTHOST command - * Add commands SYSLOG, SERIALLOG and LOGHOST - * Change hostname to lower case to distinguise between open-sdk version - * Add support for ESP-12F used in my modified wkaku power socket switch - * Fix timezone command - * Add RTC month names for future use - * Modify button code - * Remove initialization errors by better use of MQTT loop - * - * 1.0.6 20160406 - * Removed Wifi AP mode (#1) - * Add test for Arduino IDE version >= 1.6.8 - * Fix RTC time sync code - * - * 1.0.5 20160310 - * Initial public release - * Show debug info by selecting option from IDE Tools Debug port: Serial - */ +/* +6.1.1b 20180715 +** Change default initial wifi config tool ** +Default initial wifi config tool has changed from WPS to Wifi Manager (local Access Point). +Both WPS and Wifi Smartconfig are now optional and are disabled in user_config.h saving a massive 66k of code space. +See _changelog.ino how to enable them again. +Define WIFI_CONFIG_TOOL now contains the default behaviour once a SSID has been configured. +If no SSID is configured making a wifi connection impossible the new define WIFI_CONFIG_NO_SSID will be used. +While define WIFI_CONFIG_NO_SSID is set to WIFI_WPSCONFIG in user_config.h the compiler will check for define USE_WPS and if not enabled + WIFI_CONFIG_NO_SSID will default to WIFI_MANAGER using the webserver. If define USE_WEBSERVER is also not enabled + WIFI_CONFIG_NO_SSID will default to WIFI_SMARTCONFIG. If define USE_SMARTCONFIG is also not enabled + WIFI_CONFIG_NO_SSID will default to a new option WIFI_SERIAL allowing to enter wifi parameters to serial which is always possible. + +** Introduction _changelog.ino ** +Finally the changes can be found in a changelog where they belong. Release info will now be in _releasenotes.ino +*/ \ No newline at end of file diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 08e909300..fc91c0d8e 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -215,6 +215,7 @@ #define D_WCFG_3_WPSCONFIG "WPSConfig" #define D_WCFG_4_RETRY "Retry" #define D_WCFG_5_WAIT "Wait" + #define D_WCFG_6_SERIAL "Serial" #define D_CMND_FRIENDLYNAME "FriendlyName" #define D_CMND_SWITCHMODE "SwitchMode" #define D_CMND_TELEPERIOD "TelePeriod" @@ -471,6 +472,7 @@ const char S_JSON_COMMAND_INDEX_NVALUE_ACTIVE_NVALUE[] PROGMEM = "{\"%s%d\":\"%d const char S_JSON_SENSOR_INDEX_NVALUE[] PROGMEM = "{\"" D_CMND_SENSOR "%d\":%d}"; const char S_JSON_SENSOR_INDEX_SVALUE[] PROGMEM = "{\"" D_CMND_SENSOR "%d\":\"%s\"}"; +const char JSON_SNS_TEMP[] PROGMEM = "%s,\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"; const char JSON_SNS_TEMPHUM[] PROGMEM = "%s,\"%s\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s}"; const char S_LOG_I2C_FOUND_AT[] PROGMEM = D_LOG_I2C "%s " D_FOUND_AT " 0x%x"; @@ -498,7 +500,8 @@ const char kWifiConfig[MAX_WIFI_OPTION][WCFG_MAX_STRING_LENGTH] PROGMEM = { D_WCFG_2_WIFIMANAGER, D_WCFG_3_WPSCONFIG, D_WCFG_4_RETRY, - D_WCFG_5_WAIT }; + D_WCFG_5_WAIT, + D_WCFG_6_SERIAL }; const char kPrefixes[3][PRFX_MAX_STRING_LENGTH] PROGMEM = { D_CMND, D_STAT, diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index 6d82a843c..6f03fcf55 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Подтвърдете рестартирането" #define D_CONFIGURE_MODULE "Конфигурация на модула" +#define D_CONFIGURE_MCP230XX "Конфигурация на MCP230xx" #define D_CONFIGURE_WIFI "Конфигурация на WiFi" #define D_CONFIGURE_MQTT "Конфигурация на MQTT" #define D_CONFIGURE_DOMOTICZ "Конфигурация на Domoticz" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index cb93ad553..03bc4b8cd 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Potvrzení restartu" #define D_CONFIGURE_MODULE "Nastavení modulu" +#define D_CONFIGURE_MCP230XX "Nastavení MCP230xx" #define D_CONFIGURE_WIFI "Nastavení WiFi" #define D_CONFIGURE_MQTT "Nastavení MQTT" #define D_CONFIGURE_DOMOTICZ "Nastavení Domoticz" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index 4c0fde470..71d9ae65e 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Wirklich neustarten?" #define D_CONFIGURE_MODULE "Gerät konfigurieren" +#define D_CONFIGURE_MCP230XX "MCP230xx konfigurieren" #define D_CONFIGURE_WIFI "WLAN konfigurieren" #define D_CONFIGURE_MQTT "MQTT konfigurieren" #define D_CONFIGURE_DOMOTICZ "Domoticz konfigurieren" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 702381ab1..e45efd5ba 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Επιβεβαίωση Επανεκκίνησης" #define D_CONFIGURE_MODULE "Ρύθμιση Module" +#define D_CONFIGURE_MCP230XX "Ρύθμιση MCP230xx" #define D_CONFIGURE_WIFI "Ρύθμιση WiFi" #define D_CONFIGURE_MQTT "Ρύθμιση MQTT" #define D_CONFIGURE_DOMOTICZ "Ρύθμιση Domoticz" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index 8858eea2f..5a85abba3 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Confirm Restart" #define D_CONFIGURE_MODULE "Configure Module" +#define D_CONFIGURE_MCP230XX "Configure MCP230xx" #define D_CONFIGURE_WIFI "Configure WiFi" #define D_CONFIGURE_MQTT "Configure MQTT" #define D_CONFIGURE_DOMOTICZ "Configure Domoticz" diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index cb50b7377..82451d205 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.h @@ -131,7 +131,7 @@ #define D_PROGRAM_SIZE "Tamaño Programa" #define D_PROJECT "Proyecto" #define D_RECEIVED "Recibido" -#define D_RESTART "Reinicio" +#define D_RESTART "Reiniciar" #define D_RESTARTING "Reiniciando" #define D_RESTART_REASON "Causa Reinicio" #define D_RESTORE "Restauración" @@ -168,7 +168,7 @@ #define D_WEB_SERVER "Servidor Web" // sonoff.ino -#define D_WARNING_MINIMAL_VERSION "Precaución, esta versión no salva los cambios" +#define D_WARNING_MINIMAL_VERSION "Cuidado, esta versión no guarda los cambios" #define D_LEVEL_10 "level 1-0" #define D_LEVEL_01 "level 0-1" #define D_SERIAL_LOGGING_DISABLED "Log serial deshabilitado" @@ -188,12 +188,12 @@ #define D_PATCH_ISSUE_2186 "Patch issue 2186" #define D_CONNECTING_TO_AP "Connectando a AP" #define D_IN_MODE "en modo" -#define D_CONNECT_FAILED_NO_IP_ADDRESS "Falló Conección, Dirección IP no recibida" -#define D_CONNECT_FAILED_AP_NOT_REACHED "Falló Conección, AP no pudo ser contactado" -#define D_CONNECT_FAILED_WRONG_PASSWORD "Falló Conección, clave de AP incorrecta" -#define D_CONNECT_FAILED_AP_TIMEOUT "Falló Conección, timeout de AP" +#define D_CONNECT_FAILED_NO_IP_ADDRESS "Falló Conexión, Dirección IP no recibida" +#define D_CONNECT_FAILED_AP_NOT_REACHED "Falló Conexión, AP no pudo ser contactado" +#define D_CONNECT_FAILED_WRONG_PASSWORD "Falló Conexión, clave de AP incorrecta" +#define D_CONNECT_FAILED_AP_TIMEOUT "Falló Conexión, timeout de AP" #define D_ATTEMPTING_CONNECTION "Intentando conectar..." -#define D_CHECKING_CONNECTION "Probando conección..." +#define D_CHECKING_CONNECTION "Probando conexión..." #define D_QUERY_DONE "Consulta lista. Servicio MQTT encontrado" #define D_MQTT_SERVICE_FOUND "Servicio MQTT encontrado en" #define D_FOUND_AT "encontrado en" @@ -211,22 +211,23 @@ #define D_WITH_IP_ADDRESS "con dirección IP" #define D_WEBSERVER_STOPPED "Servidor web detenido" #define D_FILE_NOT_FOUND "Archivo No Encontrado" -#define D_REDIRECTED "Redireccinado al portal captivo" +#define D_REDIRECTED "Redireccionado al portal captivo" #define D_WIFIMANAGER_SET_ACCESSPOINT_AND_STATION "Wifimanager como AccessPoint y Estación" #define D_WIFIMANAGER_SET_ACCESSPOINT "Wifimanager como AccessPoint" #define D_TRYING_TO_CONNECT "Intentado conectar dispositivo a la red" #define D_RESTART_IN "Reinicio en" #define D_SECONDS "segundos" -#define D_DEVICE_WILL_RESTART "El dispositivo se reiniciará en pocos segundos" +#define D_DEVICE_WILL_RESTART "El dispositivo se reiniciará en unos segundos" #define D_BUTTON_TOGGLE "Alternar ON/OFF" #define D_CONFIGURATION "Configuración" #define D_INFORMATION "Información" -#define D_FIRMWARE_UPGRADE "Actualización Firmware" +#define D_FIRMWARE_UPGRADE "Actualizar Firmware" #define D_CONSOLE "Consola" #define D_CONFIRM_RESTART "Confirmar Reinicio" #define D_CONFIGURE_MODULE "Configuración del Módulo" +#define D_CONFIGURE_MCP230XX "Configuración MCP230xx" #define D_CONFIGURE_WIFI "Configuración WiFi" #define D_CONFIGURE_MQTT "Configuración MQTT" #define D_CONFIGURE_DOMOTICZ "Configuración Domoticz" @@ -239,7 +240,7 @@ #define D_MAIN_MENU "Menú Principal" #define D_MODULE_PARAMETERS "Parámetros del módulo" -#define D_MODULE_TYPE "Tipo módulo" +#define D_MODULE_TYPE "Tipo de módulo" #define D_GPIO "GPIO" #define D_SERIAL_IN "Serial In" #define D_SERIAL_OUT "Serial Out" @@ -250,7 +251,7 @@ #define D_NO_NETWORKS_FOUND "Ninguna red encontrada" #define D_REFRESH_TO_SCAN_AGAIN "Recargar página para buscar nuevamente" #define D_DUPLICATE_ACCESSPOINT "AccessPoint duplicado" -#define D_SKIPPING_LOW_QUALITY "Ignorado debido a baja calidad" +#define D_SKIPPING_LOW_QUALITY "Ignorado por baja calidad" #define D_RSSI "RSSI" #define D_WEP "WEP" #define D_WPA_PSK "WPA PSK" @@ -268,7 +269,7 @@ #define D_SERIAL_LOG_LEVEL "Nivel de log Serial" #define D_WEB_LOG_LEVEL "Nivel de log Web" #define D_SYS_LOG_LEVEL "Nivel de Syslog" -#define D_MORE_DEBUG "Mas Debug" +#define D_MORE_DEBUG "Más Debug" #define D_SYSLOG_HOST "Host del Syslog" #define D_SYSLOG_PORT "Puerto del Syslog" #define D_TELEMETRY_PERIOD "Período de Telemetría" @@ -287,7 +288,7 @@ #define D_CONFIGURATION_RESET "Configuración restablecida" #define D_PROGRAM_VERSION "Versión del Programa" -#define D_BUILD_DATE_AND_TIME "Fecha y Hora de la Compilación" +#define D_BUILD_DATE_AND_TIME "Fecha y Hora de Compilación" #define D_CORE_AND_SDK_VERSION "Versión Core/SDK" #define D_FLASH_WRITE_COUNT "Contador de escritura en Flash" #define D_MAC_ADDRESS "Dirección MAC" @@ -333,16 +334,16 @@ // xdrv_01_mqtt.ino #define D_FINGERPRINT "Verificar TLS fingerprint..." -#define D_TLS_CONNECT_FAILED_TO "Falló Conección TLS a" +#define D_TLS_CONNECT_FAILED_TO "Falló Conexión TLS a" #define D_RETRY_IN "Reintentando" #define D_VERIFIED "Verificado Fingerprint" -#define D_INSECURE "Conección insegura por Fingerprint no válido" -#define D_CONNECT_FAILED_TO "Falló Conección a" +#define D_INSECURE "Conexión insegura por Fingerprint inválido" +#define D_CONNECT_FAILED_TO "Falló Conexión a" // xplg_wemohue.ino #define D_MULTICAST_DISABLED "Multicast deshabilitado" #define D_MULTICAST_REJOINED "Multicast (re)conectado" -#define D_MULTICAST_JOIN_FAILED "Conección Multicast fallida" +#define D_MULTICAST_JOIN_FAILED "Conexión Multicast fallida" #define D_FAILED_TO_SEND_RESPONSE "Falla al enviar respuesta" #define D_WEMO "WeMo" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index ce1485513..a5aed67c1 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Confirmer redémarrage" #define D_CONFIGURE_MODULE "Configuration du Module" +#define D_CONFIGURE_MCP230XX "Configuration MCP230xx" #define D_CONFIGURE_WIFI "Configuration WiFi" #define D_CONFIGURE_MQTT "Configuration MQTT" #define D_CONFIGURE_DOMOTICZ "Configuration Domoticz" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index 14fb2a08b..a4ac7cea2 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Újraindítás megerősítése" #define D_CONFIGURE_MODULE "Eszköz konfiguráció" +#define D_CONFIGURE_MCP230XX "MCP230xx konfiguráció" #define D_CONFIGURE_WIFI "WiFi konfiguráció" #define D_CONFIGURE_MQTT "MQTT konfiguráció" #define D_CONFIGURE_DOMOTICZ "Domoticz konfiguráció" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 6f1c4db0f..2a60abaf0 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Conferma Riavvio" #define D_CONFIGURE_MODULE "Configurazione Modulo" +#define D_CONFIGURE_MCP230XX "Configurazione MCP230xx" #define D_CONFIGURE_WIFI "Configurazione WiFi" #define D_CONFIGURE_MQTT "Configurazione MQTT" #define D_CONFIGURE_DOMOTICZ "Configurazione Domoticz" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index cf1c2b3b0..936d14861 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Bevestig herstart" #define D_CONFIGURE_MODULE "Configureer Module" +#define D_CONFIGURE_MCP230XX "Configureer MCP230xx" #define D_CONFIGURE_WIFI "Configureer WiFi" #define D_CONFIGURE_MQTT "Configureer MQTT" #define D_CONFIGURE_DOMOTICZ "Configureer Domoticz" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index e250e4c4d..ce29dde07 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Potwierdź restart" #define D_CONFIGURE_MODULE "Konfiguruj moduł" +#define D_CONFIGURE_MCP230XX "Konfiguruj MCP230xx" #define D_CONFIGURE_WIFI "Konfiguruj WiFi" #define D_CONFIGURE_MQTT "Konfiguruj MQTT" #define D_CONFIGURE_DOMOTICZ "Konfiguruj Domoticz" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index a32a7b5c3..0e6f82342 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Confirmar o reinicio" #define D_CONFIGURE_MODULE "Configurar Módulo" +#define D_CONFIGURE_MCP230XX "Configurar MCP230xx" #define D_CONFIGURE_WIFI "Configurar WiFi" #define D_CONFIGURE_MQTT "Configurar MQTT" #define D_CONFIGURE_DOMOTICZ "Configurar Domoticz" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index 393a74a87..e6d56ba1d 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Confirmar o reinicio" #define D_CONFIGURE_MODULE "Configurar Módulo" +#define D_CONFIGURE_MCP230XX "Configurar MCP230xx" #define D_CONFIGURE_WIFI "Configurar WiFi" #define D_CONFIGURE_MQTT "Configurar MQTT" #define D_CONFIGURE_DOMOTICZ "Configurar Domoticz" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index 79df5b2d4..e4bc30ea2 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Подтвердить перезагрузку" #define D_CONFIGURE_MODULE "Конфигурация Модуля" +#define D_CONFIGURE_MCP230XX "Конфигурация MCP230xx" #define D_CONFIGURE_WIFI "Конфигурация WiFi" #define D_CONFIGURE_MQTT "Конфигурация MQTT" #define D_CONFIGURE_DOMOTICZ "Конфигурация Domoticz" diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h index d925d13fb..fda5d2e46 100644 --- a/sonoff/language/uk-UK.h +++ b/sonoff/language/uk-UK.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "Підтвердити перезавантаження" #define D_CONFIGURE_MODULE "Конфігурація модуля" +#define D_CONFIGURE_MCP230XX "Конфігурація MCP230xx" #define D_CONFIGURE_WIFI "Конфігурація WiFi" #define D_CONFIGURE_MQTT "Конфігурація MQTT" #define D_CONFIGURE_DOMOTICZ "Конфігурація Domoticz" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index 9e5149125..203e5ac08 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "确认重启" #define D_CONFIGURE_MODULE "模块设置" +#define D_CONFIGURE_MCP230XX "MCP230xx设置" #define D_CONFIGURE_WIFI "WiFi设置" #define D_CONFIGURE_MQTT "MQTT设置" #define D_CONFIGURE_DOMOTICZ "Domoticz设置" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index 6d4154cdf..22f35f924 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -227,6 +227,7 @@ #define D_CONFIRM_RESTART "確認重啟" #define D_CONFIGURE_MODULE "模塊設置" +#define D_CONFIGURE_MCP230XX "MCP230xx設置" #define D_CONFIGURE_WIFI "WiFi設置" #define D_CONFIGURE_MQTT "MQTT設置" #define D_CONFIGURE_DOMOTICZ "Domoticz設置" diff --git a/sonoff/settings.h b/sonoff/settings.h index c4de3d659..4a3dc415c 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -56,7 +56,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t rf_receive_decimal : 1; // bit 28 (v6.0.0a) uint32_t ir_receive_decimal : 1; // bit 29 (v6.0.0a) uint32_t hass_light : 1; // bit 30 (v6.0.0b) - uint32_t spare31 : 1; + uint32_t global_state : 1; // bit 31 (v6.1.0) }; } SysBitfield; @@ -394,6 +394,20 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu }; } RulesBitfield; +typedef union { + uint8_t data; + struct { + uint8_t wifi_down : 1; + uint8_t mqtt_down : 1; + uint8_t spare02 : 1; + uint8_t spare03 : 1; + uint8_t spare04 : 1; + uint8_t spare05 : 1; + uint8_t spare06 : 1; + uint8_t spare07 : 1; + }; +} StateBitfield; + // 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 diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 1c1f24532..1a2e6f8af 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -95,6 +95,8 @@ typedef unsigned long power_t; // Power (Relay) type #define LOGSZ 512 // Max number of characters in log #define MIN_MESSZ 893 // Min number of characters in MQTT message +#define SENSOR_MAX_MISS 5 // Max number of missed sensor reads before deciding it's offline + #ifdef USE_MQTT_TLS #define WEB_LOG_SIZE 2000 // Max number of characters in weblog #else @@ -109,11 +111,15 @@ typedef unsigned long power_t; // Power (Relay) type #define SERIAL_POLLING 100 // Serial receive polling in ms #define MAX_STATUS 11 // Max number of status lines +#define NO_EXTRA_4K_HEAP // Allocate 4k heap for WPS in ESP8166/Arduino core v2.4.2 (was always allocated in previous versions) + /* // Removed from esp8266 core since 20171105 #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) */ +#define tmin(a,b) ((a)<(b)?(a):(b)) +#define tmax(a,b) ((a)>(b)?(a):(b)) #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) @@ -167,7 +173,7 @@ enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART, DT_UPTIME }; enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; -enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION}; +enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, MAX_WIFI_OPTION}; enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, MAX_SWITCH_OPTION}; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index e23627f26..3bb37c5e6 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x06000003 // 6.0.0c +#define VERSION 0x06010102 // 6.1.1b // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) @@ -161,6 +161,7 @@ uint8_t stop_flash_rotate = 0; // Allow flash configuration rotatio int blinks = 201; // Number of LED blinks uint8_t blinkstate = 0; // LED state +uint8_t blinkspeed = 1; // LED blink rate uint8_t blockgpio0 = 4; // Block GPIO0 for 4 seconds after poweron to workaround Wemos D1 RTS circuit uint8_t lastbutton[MAX_KEYS] = { NOT_PRESSED, NOT_PRESSED, NOT_PRESSED, NOT_PRESSED }; // Last button states @@ -169,7 +170,7 @@ uint8_t multiwindow[MAX_KEYS] = { 0 }; // Max time between button presses t uint8_t multipress[MAX_KEYS] = { 0 }; // Number of button presses within multiwindow uint8_t lastwallswitch[MAX_SWITCHES]; // Last wall switch states uint8_t holdwallswitch[MAX_SWITCHES] = { 0 }; // Timer for wallswitch push button hold -uint8_t virtualswitch[MAX_SWITCHES] = { 0 }; // Virtual switch states +uint8_t virtualswitch[MAX_SWITCHES]; // Virtual switch states mytmplt my_module; // Active copy of Module name and GPIOs uint8_t pin[GPIO_MAX]; // Possible pin configurations @@ -184,6 +185,7 @@ uint8_t light_type = 0; // Light types bool pwm_present = false; // Any PWM channel configured with SetOption15 0 boolean mdns_begun = false; uint8_t ntp_force_sync = 0; // Force NTP sync +StateBitfield global_state; RulesBitfield rules_flag; char my_version[33]; // Composed version string @@ -540,6 +542,53 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) mqtt_data[0] = '\0'; MqttShowState(); } + else if (CMND_SLEEP == command_code) { + if ((payload >= 0) && (payload < 251)) { + if ((!Settings.sleep && payload) || (Settings.sleep && !payload)) restart_flag = 2; + Settings.sleep = payload; + sleep = payload; + } + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_UNIT_NVALUE_UNIT, command, sleep, (Settings.flag.value_units) ? " " D_UNIT_MILLISECOND : "", Settings.sleep, (Settings.flag.value_units) ? " " D_UNIT_MILLISECOND : ""); + } + else if ((CMND_UPGRADE == command_code) || (CMND_UPLOAD == command_code)) { + // Check if the payload is numerically 1, and had no trailing chars. + // e.g. "1foo" or "1.2.3" could fool us. + // Check if the version we have been asked to upgrade to is higher than our current version. + // We also need at least 3 chars to make a valid version number string. + if (((1 == data_len) && (1 == payload)) || ((data_len >= 3) && NewerVersion(dataBuf))) { + ota_state_flag = 3; +// snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}", command, my_version, Settings.ota_url); + snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}", command, my_version, GetOtaUrl(stemp1, sizeof(stemp1))); + } else { + snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_ONE_OR_GT "\"}", command, my_version); + } + } + else if (CMND_OTAURL == command_code) { + if ((data_len > 0) && (data_len < sizeof(Settings.ota_url))) + strlcpy(Settings.ota_url, (1 == payload) ? OTA_URL : dataBuf, sizeof(Settings.ota_url)); + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, Settings.ota_url); + } + else if (CMND_SERIALLOG == command_code) { + if ((payload >= LOG_LEVEL_NONE) && (payload <= LOG_LEVEL_ALL)) { + Settings.flag.mqtt_serial = 0; + SetSeriallog(payload); + } + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, command, Settings.seriallog_level, seriallog_level); + } + else if (CMND_RESTART == command_code) { + switch (payload) { + case 1: + restart_flag = 2; + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_RESTARTING); + break; + case 99: + AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_RESTARTING)); + EspRestart(); + break; + default: + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_ONE_TO_RESTART); + } + } else if ((CMND_POWERONSTATE == command_code) && (Settings.module != MOTOR)) { /* 0 = Keep relays off after power on * 1 = Turn relays on after power on, if PulseTime set wait for PulseTime seconds, and turn relays off @@ -854,32 +903,6 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.pulse_counter_debounce); } - else if (CMND_SLEEP == command_code) { - if ((payload >= 0) && (payload < 251)) { - if ((!Settings.sleep && payload) || (Settings.sleep && !payload)) restart_flag = 2; - Settings.sleep = payload; - sleep = payload; - } - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_UNIT_NVALUE_UNIT, command, sleep, (Settings.flag.value_units) ? " " D_UNIT_MILLISECOND : "", Settings.sleep, (Settings.flag.value_units) ? " " D_UNIT_MILLISECOND : ""); - } - else if ((CMND_UPGRADE == command_code) || (CMND_UPLOAD == command_code)) { - // Check if the payload is numerically 1, and had no trailing chars. - // e.g. "1foo" or "1.2.3" could fool us. - // Check if the version we have been asked to upgrade to is higher than our current version. - // We also need at least 3 chars to make a valid version number string. - if (((1 == data_len) && (1 == payload)) || ((data_len >= 3) && NewerVersion(dataBuf))) { - ota_state_flag = 3; -// snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}", command, my_version, Settings.ota_url); - snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}", command, my_version, GetOtaUrl(stemp1, sizeof(stemp1))); - } else { - snprintf_P(mqtt_data, sizeof(mqtt_data), "{\"%s\":\"" D_JSON_ONE_OR_GT "\"}", command, my_version); - } - } - else if (CMND_OTAURL == command_code) { - if ((data_len > 0) && (data_len < sizeof(Settings.ota_url))) - strlcpy(Settings.ota_url, (1 == payload) ? OTA_URL : dataBuf, sizeof(Settings.ota_url)); - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, Settings.ota_url); - } else if (CMND_BAUDRATE == command_code) { if (payload32 > 0) { payload32 /= 1200; // Make it a valid baudrate @@ -917,13 +940,6 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.serial_delimiter); } - else if (CMND_SERIALLOG == command_code) { - if ((payload >= LOG_LEVEL_NONE) && (payload <= LOG_LEVEL_ALL)) { - Settings.flag.mqtt_serial = 0; - SetSeriallog(payload); - } - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, command, Settings.seriallog_level, seriallog_level); - } else if (CMND_SYSLOG == command_code) { if ((payload >= LOG_LEVEL_NONE) && (payload <= LOG_LEVEL_ALL)) { Settings.syslog_level = payload; @@ -976,7 +992,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } else if ((CMND_SSID == command_code) && (index > 0) && (index <= 2)) { if ((data_len > 0) && (data_len < sizeof(Settings.sta_ssid[0]))) { - strlcpy(Settings.sta_ssid[index -1], (1 == payload) ? (1 == index) ? STA_SSID1 : STA_SSID2 : dataBuf, sizeof(Settings.sta_ssid[0])); + strlcpy(Settings.sta_ssid[index -1], (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? (1 == index) ? STA_SSID1 : STA_SSID2 : dataBuf, sizeof(Settings.sta_ssid[0])); Settings.sta_active = index -1; restart_flag = 2; } @@ -984,7 +1000,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } else if ((CMND_PASSWORD == command_code) && (index > 0) && (index <= 2)) { if ((data_len > 0) && (data_len < sizeof(Settings.sta_pwd[0]))) { - strlcpy(Settings.sta_pwd[index -1], (1 == payload) ? (1 == index) ? STA_PASS1 : STA_PASS2 : dataBuf, sizeof(Settings.sta_pwd[0])); + strlcpy(Settings.sta_pwd[index -1], (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? (1 == index) ? STA_PASS1 : STA_PASS2 : dataBuf, sizeof(Settings.sta_pwd[0])); Settings.sta_active = index -1; restart_flag = 2; snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.sta_pwd[index -1]); @@ -1040,20 +1056,6 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_UNIT, command, Settings.tele_period, (Settings.flag.value_units) ? " " D_UNIT_SECOND : ""); } - else if (CMND_RESTART == command_code) { - switch (payload) { - case 1: - restart_flag = 2; - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_RESTARTING); - break; - case 99: - AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_RESTARTING)); - EspRestart(); - break; - default: - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_ONE_TO_RESTART); - } - } else if (CMND_RESET == command_code) { switch (payload) { case 1: @@ -1721,7 +1723,7 @@ void SwitchHandler(byte mode) uint8_t switchflag; for (byte i = 0; i < MAX_SWITCHES; i++) { - if (pin[GPIO_SWT1 +i] < 99) { + if ((pin[GPIO_SWT1 +i] < 99) || (mode)) { if (holdwallswitch[i]) { holdwallswitch[i]--; @@ -1802,6 +1804,7 @@ void SwitchHandler(byte mode) void StateLoop() { power_t power_now; + uint8_t blinkinterval = 1; state_loop_timer = millis() + (1000 / STATES); state++; @@ -1879,27 +1882,38 @@ void StateLoop() \*-------------------------------------------------------------------------------------------*/ if (!(state % ((STATES/10)*2))) { + if (!Settings.flag.global_state) { // Problem blinkyblinky enabled + if (global_state.data) { // Any problem + if (global_state.mqtt_down) { blinkinterval = 9; } // MQTT problem so blink every 2 seconds (slowest) + if (global_state.wifi_down) { blinkinterval = 4; } // Wifi problem so blink every second (slow) + blinks = 201; // Allow only a single blink in case the problem is solved + } + } if (blinks || restart_flag || ota_state_flag) { - if (restart_flag || ota_state_flag) { - blinkstate = 1; // Stay lit + if (restart_flag || ota_state_flag) { // Overrule blinks and keep led lit + blinkstate = 1; // Stay lit } else { - blinkstate ^= 1; // Blink + blinkspeed--; + if (!blinkspeed) { + blinkspeed = blinkinterval; // Set interval to 0.2 (default), 1 or 2 seconds + blinkstate ^= 1; // Blink + } } if ((!(Settings.ledstate &0x08)) && ((Settings.ledstate &0x06) || (blinks > 200) || (blinkstate))) { - SetLedPower(blinkstate); +// if ( (!Settings.flag.global_state && global_state.data) || ((!(Settings.ledstate &0x08)) && ((Settings.ledstate &0x06) || (blinks > 200) || (blinkstate))) ) { + SetLedPower(blinkstate); // Set led on or off } if (!blinkstate) { blinks--; - if (200 == blinks) blinks = 0; + if (200 == blinks) blinks = 0; // Disable blink } - } else { - if (Settings.ledstate &1) { - boolean tstate = power; - if ((SONOFF_TOUCH == Settings.module) || (SONOFF_T11 == Settings.module) || (SONOFF_T12 == Settings.module) || (SONOFF_T13 == Settings.module)) { - tstate = (!power) ? 1 : 0; - } - SetLedPower(tstate); + } + else if (Settings.ledstate &1) { + boolean tstate = power; + if ((SONOFF_TOUCH == Settings.module) || (SONOFF_T11 == Settings.module) || (SONOFF_T12 == Settings.module) || (SONOFF_T13 == Settings.module)) { + tstate = (!power) ? 1 : 0; // As requested invert signal for Touch devices to find them in the dark } + SetLedPower(tstate); } } @@ -2142,6 +2156,7 @@ void SerialInput() } } +#ifdef USE_ENERGY_SENSOR /*-------------------------------------------------------------------------------------------*\ * Sonoff S31 and Sonoff Pow R2 4800 baud serial interface \*-------------------------------------------------------------------------------------------*/ @@ -2152,7 +2167,7 @@ void SerialInput() return; } } - +#endif // USE_ENERGY_SENSOR /*-------------------------------------------------------------------------------------------*/ if (serial_in_byte > 127) { // binary data... @@ -2364,10 +2379,13 @@ void GpioInit() } } for (byte i = 0; i < MAX_SWITCHES; i++) { + lastwallswitch[i] = 1; // Init global to virtual switch state; if (pin[GPIO_SWT1 +i] < 99) { pinMode(pin[GPIO_SWT1 +i], (16 == pin[GPIO_SWT1 +i]) ? INPUT_PULLDOWN_16 :INPUT_PULLUP); - lastwallswitch[i] = digitalRead(pin[GPIO_SWT1 +i]); // set global now so doesn't change the saved power state on first switch check + lastwallswitch[i] = digitalRead(pin[GPIO_SWT1 +i]); // Set global now so doesn't change the saved power state on first switch check + } + virtualswitch[i] = lastwallswitch[i]; } #ifdef USE_WS2812 diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h index afdded74d..929d95558 100644 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -51,6 +51,7 @@ void KNX_CB_Action(message_t const &msg, void *arg); #endif #define USE_DHT // Default DHT11 sensor needs no external library +#define USE_ENERGY_SENSOR // Use energy sensors /*********************************************************************************************\ * [sonoff-allsensors.bin] @@ -58,6 +59,7 @@ void KNX_CB_Action(message_t const &msg, void *arg); \*********************************************************************************************/ #ifdef USE_ALL_SENSORS + #define USE_ADC_VCC // Display Vcc in Power status. Disable for use as Analog input on selected devices #define USE_DS18x20 // For more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code) //#define USE_DS18x20_LEGACY // For more than one DS18x20 sensors with dynamic scan using library OneWire (+1k5 code) @@ -65,16 +67,19 @@ void KNX_CB_Action(message_t const &msg, void *arg); #define USE_SHT // Add I2C emulating code for SHT1X sensor (+1k4 code) #define USE_SHT3X // Add I2C code for SHT3x sensor (+0k6 code) #define USE_HTU // Add I2C code for HTU21/SI7013/SI7020/SI7021 sensor (+1k5 code) +#define USE_LM75AD // Add I2C code for LM75AD sensor (+0k5 code) #define USE_BMP // Add I2C code for BMP085/BMP180/BMP280/BME280 sensor (+4k code) - #define USE_BME680 // Add additional support for BME680 sensor using Adafruit Sensor and BME680 libraries (+6k code) + #define USE_BME680 // Add additional support for BME680 sensor using Bosch BME680 library (+4k code) #define USE_SGP30 // Add I2C code for SGP30 sensor (+1k1 code) #define USE_BH1750 // Add I2C code for BH1750 sensor (+0k5 code) #define USE_VEML6070 // Add I2C code for VEML6070 sensor (+0k5 code) #define USE_TSL2561 // Add I2C code for TSL2561 sensor using library Adafruit TSL2561 Arduino (+1k2 code) +//#define USE_SI1145 // Add I2C code for SI1145/46/47 sensor (+1k code) #define USE_ADS1115 // Add I2C code for ADS1115 16 bit A/D converter based on Adafruit ADS1x15 library (no library needed) (+0k7 code) //#define USE_ADS1115_I2CDEV // Add I2C code for ADS1115 16 bit A/D converter using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code) #define USE_INA219 // Add I2C code for INA219 Low voltage and current sensor (+1k code) #define USE_MGS // Add I2C code for Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code) +//#define USE_APDS9960 // Add I2C code for APDS9960 Proximity Sensor. Disables SHT and VEML6070 (+4k7 code) #define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code) #define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code) #ifndef CO2_LOW @@ -87,6 +92,8 @@ void KNX_CB_Action(message_t const &msg, void *arg); #define USE_NOVA_SDS // Add support for SDS011 and SDS021 particle concentration sensor (+0k7 code) #define USE_PZEM004T // Add support for PZEM004T Energy monitor (+2k code) #define USE_SERIAL_BRIDGE // Add support for software Serial Bridge (+0k8 code) +#define USE_SDM120 // Add support for Eastron SDM120-Modbus energy meter (+1k7 code) +#define USE_SDM630 // Add support for Eastron SDM630-Modbus energy meter (+2k code) #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram) #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) #define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram) @@ -105,36 +112,28 @@ void KNX_CB_Action(message_t const &msg, void *arg); \*********************************************************************************************/ #ifdef USE_CLASSIC -#ifdef USE_KNX -#undef USE_KNX -#endif -#ifdef USE_TIMERS -#undef USE_TIMERS -#endif -#ifdef USE_TIMERS_WEB -#undef USE_TIMERS_WEB -#endif -#ifdef USE_SUNRISE -#undef USE_SUNRISE -#endif -#ifdef USE_RULES -#undef USE_RULES -#endif -#ifdef USE_SGP30 -#undef USE_SGP30 -#endif -#ifdef USE_NOVA_SDS -#undef USE_NOVA_SDS -#endif -#ifdef USE_IR_RECEIVE -#undef USE_IR_RECEIVE -#endif -#ifdef USE_SERIAL_BRIDGE -#undef USE_SERIAL_BRIDGE -#endif -#ifdef USE_SR04 -#undef USE_SR04 -#endif + +#undef USE_KNX // Disable KNX IP Protocol Support +#undef USE_TIMERS // Disable support for up to 16 timers +#undef USE_TIMERS_WEB // Disable support for timer webpage +#undef USE_SUNRISE // Disable support for Sunrise and sunset tools +#undef USE_RULES // Disable support for rules +#undef USE_LM75AD // Disable sensor +#undef USE_BME680 // Disable sensor +#undef USE_SGP30 // Disable sensor +#undef USE_SENSEAIR // Disable support for SenseAir K30, K70 and S8 CO2 sensor +#undef USE_NOVA_SDS // Disable support for SDS011 and SDS021 particle concentration sensor +#undef USE_PZEM004T // Disable PZEM004T energy sensor +#undef USE_IR_RECEIVE // Disable support for IR receiver +#undef USE_SERIAL_BRIDGE // Disable support for software Serial Bridge +#undef USE_SDM120 // Disable support for Eastron SDM120-Modbus energy meter +#undef USE_SDM630 // Disable support for Eastron SDM630-Modbus energy meter +#undef USE_ARILUX_RF // Disable support for Arilux RF remote controller +#undef USE_SR04 // Disable support for for HC-SR04 ultrasonic devices +#undef USE_TM1638 // Disable support for TM1638 switches copying Switch1 .. Switch8 +#undef USE_RF_FLASH // Disable support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB +#undef DEBUG_THEO // Disable debug code +#undef USE_DEBUG_DRIVER // Disable debug code #endif // USE_CLASSIC /*********************************************************************************************\ @@ -143,12 +142,11 @@ void KNX_CB_Action(message_t const &msg, void *arg); \*********************************************************************************************/ #ifdef USE_KNX_NO_EMULATION + #ifndef USE_KNX #define USE_KNX // Enable KNX IP Protocol Support (+23k code, +3k3 mem) #endif -#ifdef USE_EMULATION #undef USE_EMULATION // Disable Belkin WeMo and Hue Bridge emulation for Alexa (-16k code, -2k mem) -#endif #endif // USE_KNX_NO_EMULATION /*********************************************************************************************\ @@ -166,96 +164,55 @@ void KNX_CB_Action(message_t const &msg, void *arg); \*********************************************************************************************/ #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_DISCOVERY -#undef USE_DISCOVERY // Disable Discovery services for both MQTT and web server -#endif -#ifdef USE_DOMOTICZ + +#undef USE_ENERGY_SENSOR // Disable energy sensors +#undef USE_ARDUINO_OTA // Disable support for Arduino OTA +#undef USE_WPS // Disable support for WPS as initial wifi configuration tool +#undef USE_SMARTCONFIG // Disable support for Wifi SmartConfig as initial wifi configuration tool #undef USE_DOMOTICZ // Disable Domoticz -#endif -#ifdef USE_HOME_ASSISTANT #undef USE_HOME_ASSISTANT // Disable Home Assistant -#endif -#ifdef USE_KNX +#undef USE_MQTT_TLS // Disable TLS support won't work as the MQTTHost is not set #undef USE_KNX // Disable KNX IP Protocol Support -#endif -//#ifdef USE_WEBSERVER //#undef USE_WEBSERVER // Disable Webserver -//#endif -#ifdef USE_EMULATION +#undef USE_DISCOVERY // Disable Discovery services for both MQTT and web server #undef USE_EMULATION // Disable Wemo or Hue emulation -#endif -#ifdef USE_TIMERS #undef USE_TIMERS // Disable support for up to 16 timers -#endif -#ifdef USE_SUNRISE +#undef USE_TIMERS_WEB // Disable support for timer webpage #undef USE_SUNRISE // Disable support for Sunrise and sunset tools -#endif -#ifdef USE_RULES #undef USE_RULES // Disable support for rules -#endif -#ifdef USE_DHT #undef USE_DHT // Disable internal DHT sensor -#endif -#ifdef USE_DS18x20 #undef USE_DS18x20 // Disable DS18x20 sensor -#endif -#ifdef USE_DS18B20 +#undef USE_DS18x20_LEGACY // Disable DS18x20 sensor #undef USE_DS18B20 // Disable internal DS18B20 sensor -#endif -#ifdef USE_I2C #undef USE_I2C // Disable all I2C sensors and devices -#endif -#ifdef USE_SPI #undef USE_SPI // Disable all SPI devices -#endif -#ifdef USE_DISPLAY #undef USE_DISPLAY // Disable Display support -#endif -#ifdef USE_MHZ19 #undef USE_MHZ19 // Disable support for MH-Z19 CO2 sensor -#endif -#ifdef USE_SENSEAIR #undef USE_SENSEAIR // Disable support for SenseAir K30, K70 and S8 CO2 sensor -#endif -#ifdef USE_PMS5003 #undef USE_PMS5003 // Disable support for PMS5003 and PMS7003 particle concentration sensor -#endif -#ifdef USE_NOVA_SDS #undef USE_NOVA_SDS // Disable support for SDS011 and SDS021 particle concentration sensor -#endif -#ifdef USE_PZEM004T #undef USE_PZEM004T // Disable PZEM004T energy sensor -#endif -#ifdef USE_SERIAL_BRIDGE #undef USE_SERIAL_BRIDGE // Disable support for software Serial Bridge -#endif -#ifdef USE_IR_REMOTE +#undef USE_SDM120 // Disable support for Eastron SDM120-Modbus energy meter +#undef USE_SDM630 // Disable support for Eastron SDM630-Modbus energy meter #undef USE_IR_REMOTE // Disable IR driver -#endif -#ifdef USE_WS2812 #undef USE_WS2812 // Disable WS2812 Led string -#endif -#ifdef USE_ARILUX_RF #undef USE_ARILUX_RF // Disable support for Arilux RF remote controller -#endif -#ifdef USE_SR04 #undef USE_SR04 // Disable support for for HC-SR04 ultrasonic devices -#endif -#ifdef DEBUG_THEO +#undef USE_TM1638 // Disable support for TM1638 switches copying Switch1 .. Switch8 +#undef USE_RF_FLASH // Disable support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB #undef DEBUG_THEO // Disable debug code -#endif -#ifdef USE_DEBUG_DRIVER #undef USE_DEBUG_DRIVER // Disable debug code -#endif #endif // BE_MINIMAL /*********************************************************************************************\ * Mandatory defines satisfying possible disabled defines \*********************************************************************************************/ +#ifndef USE_WPS // See https://github.com/esp8266/Arduino/pull/4889 +#undef NO_EXTRA_4K_HEAP // Allocate 4k heap for WPS in ESP8166/Arduino core v2.4.2 (was always allocated in previous versions) +#endif + #ifndef SWITCH_MODE #define SWITCH_MODE TOGGLE // TOGGLE, FOLLOW or FOLLOW_INV (the wall switch state) #endif diff --git a/sonoff/support.ino b/sonoff/support.ino index 54ec20b73..4930f8e4b 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -735,6 +735,12 @@ void GetFeatures() #ifdef USE_KNX feature_drv1 |= 0x10000000; // xdrv_11_knx.ino #endif +#ifdef USE_WPS + feature_drv1 |= 0x20000000; // support.ino +#endif +#ifdef USE_SMARTCONFIG + feature_drv1 |= 0x40000000; // support.ino +#endif /*********************************************************************************************/ @@ -954,42 +960,49 @@ boolean WifiWpsConfigDone(void) boolean WifiWpsConfigBegin(void) { wps_result = 99; - if (!wifi_wps_disable()) { - return false; - } - if (!wifi_wps_enable(WPS_TYPE_PBC)) { - return false; // so far only WPS_TYPE_PBC is supported (SDK 2.0.0) - } - if (!wifi_set_wps_cb((wps_st_cb_t) &WifiWpsStatusCallback)) { - return false; - } - if (!wifi_wps_start()) { - return false; - } + if (!wifi_wps_disable()) { return false; } + if (!wifi_wps_enable(WPS_TYPE_PBC)) { return false; } // so far only WPS_TYPE_PBC is supported (SDK 2.0.0) + if (!wifi_set_wps_cb((wps_st_cb_t) &WifiWpsStatusCallback)) { return false; } + if (!wifi_wps_start()) { return false; } return true; } void WifiConfig(uint8_t type) { if (!wifi_config_type) { - if (type >= WIFI_RETRY) { // WIFI_RETRY and WIFI_WAIT - return; - } + if ((WIFI_RETRY == type) || (WIFI_WAIT == type)) { return; } #if defined(USE_WEBSERVER) && defined(USE_EMULATION) UdpDisconnect(); #endif // USE_EMULATION - WiFi.disconnect(); // Solve possible Wifi hangs + WiFi.disconnect(); // Solve possible Wifi hangs wifi_config_type = type; + +#ifndef USE_WPS + if (WIFI_WPSCONFIG == wifi_config_type) { wifi_config_type = WIFI_MANAGER; } +#endif // USE_WPS +#ifndef USE_WEBSERVER + if (WIFI_MANAGER == wifi_config_type) { wifi_config_type = WIFI_SMARTCONFIG; } +#endif // USE_WEBSERVER +#ifndef USE_SMARTCONFIG + if (WIFI_SMARTCONFIG == wifi_config_type) { wifi_config_type = WIFI_SERIAL; } +#endif // USE_SMARTCONFIG + wifi_config_counter = WIFI_CONFIG_SEC; // Allow up to WIFI_CONFIG_SECS seconds for phone to provide ssid/pswd wifi_counter = wifi_config_counter +5; blinks = 1999; if (WIFI_RESTART == wifi_config_type) { restart_flag = 2; } + else if (WIFI_SERIAL == wifi_config_type) { + AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_WCFG_6_SERIAL " " D_ACTIVE_FOR_3_MINUTES)); + } +#ifdef USE_SMARTCONFIG else if (WIFI_SMARTCONFIG == wifi_config_type) { AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_WCFG_1_SMARTCONFIG " " D_ACTIVE_FOR_3_MINUTES)); WiFi.beginSmartConfig(); } +#endif // USE_SMARTCONFIG +#ifdef USE_WPS else if (WIFI_WPSCONFIG == wifi_config_type) { if (WifiWpsConfigBegin()) { AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_WCFG_3_WPSCONFIG " " D_ACTIVE_FOR_3_MINUTES)); @@ -998,6 +1011,7 @@ void WifiConfig(uint8_t type) wifi_config_counter = 3; } } +#endif // USE_WPS #ifdef USE_WEBSERVER else if (WIFI_MANAGER == wifi_config_type) { AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_WCFG_2_WIFIMANAGER " " D_ACTIVE_FOR_3_MINUTES)); @@ -1023,17 +1037,11 @@ void WifiBegin(uint8_t flag) WiFi.disconnect(true); // Delete SDK wifi config 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 +#ifndef ARDUINO_ESP8266_RELEASE_2_4_1 // See https://github.com/arendst/Sonoff-Tasmota/issues/2559 - Sleep bug + if (Settings.sleep) { 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); -// } - if (!WiFi.getAutoConnect()) { - WiFi.setAutoConnect(true); - } +// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } + if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); } // WiFi.setAutoReconnect(true); switch (flag) { case 0: // AP1 @@ -1043,9 +1051,7 @@ void WifiBegin(uint8_t flag) case 2: // Toggle Settings.sta_active ^= 1; } // 3: Current AP - if (0 == strlen(Settings.sta_ssid[1])) { - Settings.sta_active = 0; - } + if ('\0' == Settings.sta_ssid[Settings.sta_active][0]) { Settings.sta_active ^= 1; } // Skip empty SSID if (Settings.ip_address[0]) { WiFi.config(Settings.ip_address[0], Settings.ip_address[1], Settings.ip_address[2], Settings.ip_address[3]); // Set static IP } @@ -1059,6 +1065,7 @@ void WifiBegin(uint8_t flag) void WifiCheckIp() { if ((WL_CONNECTED == WiFi.status()) && (static_cast(WiFi.localIP()) != 0)) { + global_state.wifi_down = 0; wifi_counter = WIFI_CHECK_SEC; wifi_retry = wifi_retry_init; AddLog_P((wifi_status != WL_CONNECTED) ? LOG_LEVEL_INFO : LOG_LEVEL_DEBUG_MORE, S_LOG_WIFI, PSTR(D_CONNECTED)); @@ -1070,6 +1077,8 @@ void WifiCheckIp() } wifi_status = WL_CONNECTED; } else { + global_state.wifi_down = 1; + uint8_t wifi_config_tool = Settings.sta_config; wifi_status = WiFi.status(); switch (wifi_status) { case WL_CONNECTED: @@ -1103,7 +1112,12 @@ void WifiCheckIp() if (!wifi_retry || ((wifi_retry_init / 2) == wifi_retry)) { AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_TIMEOUT)); } else { - AddLog_P(LOG_LEVEL_DEBUG, S_LOG_WIFI, PSTR(D_ATTEMPTING_CONNECTION)); + if (('\0' == Settings.sta_ssid[0][0]) && ('\0' == Settings.sta_ssid[1][0])) { + wifi_config_tool = WIFI_CONFIG_NO_SSID; // Skip empty SSIDs and start Wifi config tool + wifi_retry = 0; + } else { + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_WIFI, PSTR(D_ATTEMPTING_CONNECTION)); + } } } if (wifi_retry) { @@ -1116,7 +1130,7 @@ void WifiCheckIp() wifi_counter = 1; wifi_retry--; } else { - WifiConfig(Settings.sta_config); + WifiConfig(wifi_config_tool); wifi_counter = 1; wifi_retry = wifi_retry_init; } @@ -1127,6 +1141,7 @@ void WifiCheck(uint8_t param) { wifi_counter--; switch (param) { + case WIFI_SERIAL: case WIFI_SMARTCONFIG: case WIFI_MANAGER: case WIFI_WPSCONFIG: @@ -1137,12 +1152,16 @@ void WifiCheck(uint8_t param) wifi_config_counter--; wifi_counter = wifi_config_counter +5; if (wifi_config_counter) { +#ifdef USE_SMARTCONFIG if ((WIFI_SMARTCONFIG == wifi_config_type) && WiFi.smartConfigDone()) { wifi_config_counter = 0; } +#endif // USE_SMARTCONFIG +#ifdef USE_WPS if ((WIFI_WPSCONFIG == wifi_config_type) && WifiWpsConfigDone()) { wifi_config_counter = 0; } +#endif // USE_WPS if (!wifi_config_counter) { if (strlen(WiFi.SSID().c_str())) { strlcpy(Settings.sta_ssid[0], WiFi.SSID().c_str(), sizeof(Settings.sta_ssid[0])); @@ -1156,10 +1175,10 @@ void WifiCheck(uint8_t param) } } if (!wifi_config_counter) { - if (WIFI_SMARTCONFIG == wifi_config_type) { - WiFi.stopSmartConfig(); - } - SettingsSdkErase(); +#ifdef USE_SMARTCONFIG + if (WIFI_SMARTCONFIG == wifi_config_type) { WiFi.stopSmartConfig(); } +#endif // USE_SMARTCONFIG +// SettingsSdkErase(); // Disabled v6.1.0b due to possible bad wifi connects restart_flag = 2; } } else { @@ -1169,6 +1188,7 @@ void WifiCheck(uint8_t param) WifiCheckIp(); } if ((WL_CONNECTED == WiFi.status()) && (static_cast(WiFi.localIP()) != 0) && !wifi_config_type) { + global_state.wifi_down = 0; #ifdef BE_MINIMAL if (1 == RtcSettings.ota_loader) { RtcSettings.ota_loader = 0; @@ -1194,9 +1214,7 @@ void WifiCheck(uint8_t param) StopWebserver(); } #ifdef USE_EMULATION - if (Settings.flag2.emulation) { - UdpConnect(); - } + if (Settings.flag2.emulation) { UdpConnect(); } #endif // USE_EMULATION #endif // USE_WEBSERVER #ifdef USE_KNX @@ -1206,6 +1224,7 @@ void WifiCheck(uint8_t param) } #endif // USE_KNX } else { + global_state.wifi_down = 1; #if defined(USE_WEBSERVER) && defined(USE_EMULATION) UdpDisconnect(); #endif // USE_EMULATION @@ -1225,9 +1244,7 @@ int WifiState() if ((WL_CONNECTED == WiFi.status()) && (static_cast(WiFi.localIP()) != 0)) { state = WIFI_RESTART; } - if (wifi_config_type) { - state = wifi_config_type; - } + if (wifi_config_type) { state = wifi_config_type; } return state; } @@ -1240,6 +1257,8 @@ void WifiConnect() wifi_counter = 1; } +/* +// Enable from 6.0.0a until 6.1.0a - disabled due to possible cause of bad wifi connect on core 2.3.0 void WifiDisconnect() { // Courtesy of EspEasy @@ -1252,10 +1271,17 @@ void WifiDisconnect() void EspRestart() { - delay(100); // Allow time for message xfer + // This results in exception 3 on restarts + delay(100); // Allow time for message xfer - disabled v6.1.0b WifiDisconnect(); ESP.restart(); } +*/ + +void EspRestart() +{ + ESP.restart(); +} #ifdef USE_DISCOVERY /*********************************************************************************************\ @@ -2076,6 +2102,12 @@ void AddLogSerial(byte loglevel) AddLogSerial(loglevel, (uint8_t*)serial_in_buffer, serial_in_byte_counter); } +void AddLogMissed(char *sensor, uint8_t misses) +{ + snprintf_P(log_data, sizeof(log_data), PSTR("SNS: %s missed %d"), sensor, SENSOR_MAX_MISS - misses); + AddLog(LOG_LEVEL_DEBUG); +} + /*********************************************************************************************\ * \*********************************************************************************************/ diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 4b45118b8..7414fed78 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -44,7 +44,7 @@ \*********************************************************************************************/ // -- Master parameter control -------------------- -#define CFG_HOLDER 4617 // [Reset 1] Change this value to load SECTION1 configuration parameters to flash +#define CFG_HOLDER 4617 // [Reset 1] Change this value (max 32000) to load SECTION1 configuration parameters to flash // -- Project ------------------------------------- #define PROJECT "sonoff" // PROJECT is used as the default topic delimiter @@ -63,8 +63,13 @@ #define STA_PASS1 "" // [Password1] Wifi password #define STA_SSID2 "" // [Ssid2] Optional alternate AP Wifi SSID #define STA_PASS2 "" // [Password2] Optional alternate AP Wifi password -#define WIFI_CONFIG_TOOL WIFI_WPSCONFIG // [WifiConfig] Default tool if wifi fails to connect - // (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT) +#define WIFI_CONFIG_TOOL WIFI_WAIT // [WifiConfig] Default tool if wifi fails to connect + // (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL) +#define WIFI_CONFIG_NO_SSID WIFI_WPSCONFIG // Default tool if wifi fails to connect and no SSID is configured + // (WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_SERIAL) + // *** NOTE: When WPS is disabled by USE_WPS below, WIFI_WPSCONFIG will execute WIFI_MANAGER *** + // *** NOTE: When WIFI_MANAGER is disabled by USE_WEBSERVER below, WIFI_MANAGER will execute WIFI_SMARTCONFIG *** + // *** NOTE: When WIFI_SMARTCONFIG is disabled by USE_SMARTCONFIG below, WIFI_SMARTCONFIG will execute WIFI_SERIAL *** // -- Syslog -------------------------------------- #define SYS_LOG_HOST "" // [LogHost] (Linux) syslog host @@ -178,8 +183,6 @@ * - Disable a feature by preceding it with // \*********************************************************************************************/ -//#define USE_ARDUINO_OTA // Add optional support for Arduino OTA (+13k code) - // -- Localization -------------------------------- // If non selected the default en-GB will be used //#define MY_LANGUAGE bg-BG // Bulgarian in Bulgaria @@ -200,6 +203,13 @@ //#define MY_LANGUAGE zh-CN // Chinese (Simplified) in China //#define MY_LANGUAGE zh-TW // Chinese (Traditional) in Taiwan +// -- Wifi Config tools --------------------------- +//#define USE_WPS // Add support for WPS as initial wifi configuration tool (+33k code, 1k mem (5k mem with core v2.4.2+)) +//#define USE_SMARTCONFIG // Add support for Wifi SmartConfig as initial wifi configuration tool (+23k code, +0.6k mem) + +// -- OTA ----------------------------------------- +//#define USE_ARDUINO_OTA // Add optional support for Arduino OTA (+13k code) + /*-------------------------------------------------------------------------------------------*\ * Select ONE of possible three MQTT library types below \*-------------------------------------------------------------------------------------------*/ @@ -230,7 +240,7 @@ //#define USE_KNX // Enable KNX IP Protocol Support (+23k code, +3k3 mem) // -- HTTP ---------------------------------------- -#define USE_WEBSERVER // Enable web server and wifi manager (+66k code, +8k mem) +#define USE_WEBSERVER // Enable web server and Wifi Manager (+66k code, +8k mem) #define WEB_PORT 80 // Web server Port for User and Admin mode #define WEB_USERNAME "admin" // Web server Admin mode user name #define USE_EMULATION // Enable Belkin WeMo and Hue Bridge emulation for Alexa (+16k code, +2k mem) @@ -265,7 +275,7 @@ #define USE_HTU // Add I2C code for HTU21/SI7013/SI7020/SI7021 sensor (+1k5 code) #define USE_LM75AD // Add I2C code for LM75AD sensor (+0k5 code) #define USE_BMP // Add I2C code for BMP085/BMP180/BMP280/BME280 sensor (+4k code) -// #define USE_BME680 // Add additional support for BME680 sensor using Adafruit Sensor and BME680 libraries (+6k code) +// #define USE_BME680 // Add additional support for BME680 sensor using Bosch BME680 library (+4k code) #define USE_SGP30 // Add I2C code for SGP30 sensor (+1k1 code) #define USE_BH1750 // Add I2C code for BH1750 sensor (+0k5 code) // #define USE_VEML6070 // Add I2C code for VEML6070 sensor (+0k5 code) @@ -277,8 +287,13 @@ // #define USE_MGS // Add I2C code for Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code) #define MGS_SENSOR_ADDR 0x04 // Default Mutichannel Gas sensor i2c address // #define USE_APDS9960 // Add I2C code for APDS9960 Proximity Sensor. Disables SHT and VEML6070 (+4k7 code) + // #define USE_MPR121 // Enable MPR121 controller (I2C addresses 0x5A, 0x5B, 0x5C and 0x5D) in input mode for touch buttons - + +// #define USE_MCP230xx // Add I2C code for MCP23008/MCP23017 for GP INPUT ONLY providing command Sensor29 for configuration (+2k2 code) +// #define USE_MCP230xx_displaymain // Display pin status on Tasmota main page (+0k2 code) +// #define USE_MCP230xx_webconfig // Enable web config button and form to Tasmota web interface (+2k1 code) + #endif // USE_I2C // -- SPI sensors --------------------------------- @@ -314,9 +329,9 @@ #define USE_SR04 // Add support for HC-SR04 ultrasonic devices (+1k code) -//#define USE_TM1638 // Add support for TM1638 switches copying Switch1 .. Switch8 (+1k code) +#define USE_TM1638 // Add support for TM1638 switches copying Switch1 .. Switch8 (+1k code) -#define USE_RF_FLASH // Add support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB +#define USE_RF_FLASH // Add support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB (+3k code) /*********************************************************************************************\ * Debug features are only supported in development branch diff --git a/sonoff/xdrv_01_mqtt.ino b/sonoff/xdrv_01_mqtt.ino index a526f489d..4bfff0724 100644 --- a/sonoff/xdrv_01_mqtt.ino +++ b/sonoff/xdrv_01_mqtt.ino @@ -383,6 +383,7 @@ void MqttConnected() } mqtt_initial_connection_state = 0; rules_flag.mqtt_connected = 1; + global_state.mqtt_down = 0; } #ifdef USE_MQTT_TLS @@ -443,6 +444,7 @@ void MqttReconnect() mqtt_connected = false; mqtt_retry_counter = Settings.mqtt_retry; + global_state.mqtt_down = 1; #ifndef USE_MQTT_TLS #ifdef USE_DISCOVERY @@ -512,13 +514,17 @@ void MqttCheck() { if (Settings.flag.mqtt_enabled) { if (!MqttIsConnected()) { + global_state.mqtt_down = 1; if (!mqtt_retry_counter) { MqttReconnect(); } else { mqtt_retry_counter--; } + } else { + global_state.mqtt_down = 0; } } else { + global_state.mqtt_down = 0; if (mqtt_initial_connection_state) MqttReconnect(); } } diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino index b29e32ea2..3f6a7b628 100644 --- a/sonoff/xdrv_02_webserver.ino +++ b/sonoff/xdrv_02_webserver.ino @@ -190,6 +190,10 @@ const char HTTP_BTN_RSTRT[] PROGMEM = "
"; const char HTTP_BTN_MENU_MODULE[] PROGMEM = "
"; +#if defined(USE_I2C) && defined(USE_MCP230xx) && defined(USE_MCP230xx_webconfig) +const char HTTP_BTN_MCP230XX[] PROGMEM = + "
"; +#endif // USE_I2C and USE_MCP230xx and USE_MCP230xx_webconfig #if defined(USE_TIMERS) && defined(USE_TIMERS_WEB) const char HTTP_BTN_MENU_TIMER[] PROGMEM = "
"; @@ -367,8 +371,21 @@ void StartWebserver(int type, IPAddress ipweb) if (!WebServer) { WebServer = new ESP8266WebServer((HTTP_MANAGER==type) ? 80 : WEB_PORT); WebServer->on("/", HandleRoot); + WebServer->on("/up", HandleUpgradeFirmware); + WebServer->on("/u1", HandleUpgradeFirmwareStart); // OTA + WebServer->on("/u2", HTTP_POST, HandleUploadDone, HandleUploadLoop); + WebServer->on("/cs", HandleConsole); + WebServer->on("/ax", HandleAjaxConsoleRefresh); + WebServer->on("/ay", HandleAjaxStatusRefresh); + WebServer->on("/u2", HTTP_OPTIONS, HandlePreflightRequest); + WebServer->on("/cm", HandleHttpCommand); + WebServer->on("/rb", HandleRestart); +#ifndef BE_MINIMAL WebServer->on("/cn", HandleConfiguration); WebServer->on("/md", HandleModuleConfiguration); +#if defined(USE_I2C) && defined(USE_MCP230xx) && defined(USE_MCP230xx_webconfig) + WebServer->on("/mc", HandleMCP230xxConfiguration); +#endif // USE_I2C and USE_MCP230xx and USE_MCP230xx_webconfig #if defined(USE_TIMERS) && defined(USE_TIMERS_WEB) WebServer->on("/tm", HandleTimerConfiguration); #endif // USE_TIMERS and USE_TIMERS_WEB @@ -389,17 +406,7 @@ void StartWebserver(int type, IPAddress ipweb) WebServer->on("/sv", HandleSaveSettings); WebServer->on("/rs", HandleRestoreConfiguration); WebServer->on("/rt", HandleResetConfiguration); - WebServer->on("/up", HandleUpgradeFirmware); - WebServer->on("/u1", HandleUpgradeFirmwareStart); // OTA - WebServer->on("/u2", HTTP_POST, HandleUploadDone, HandleUploadLoop); - WebServer->on("/u2", HTTP_OPTIONS, HandlePreflightRequest); - WebServer->on("/cm", HandleHttpCommand); - WebServer->on("/cs", HandleConsole); - WebServer->on("/ax", HandleAjaxConsoleRefresh); - WebServer->on("/ay", HandleAjaxStatusRefresh); WebServer->on("/in", HandleInformation); - WebServer->on("/rb", HandleRestart); - WebServer->on("/fwlink", HandleRoot); // Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. #ifdef USE_EMULATION if (EMUL_WEMO == Settings.flag2.emulation) { WebServer->on("/upnp/control/basicevent1", HTTP_POST, HandleUpnpEvent); @@ -411,6 +418,8 @@ void StartWebserver(int type, IPAddress ipweb) WebServer->on("/description.xml", HandleUpnpSetupHue); } #endif // USE_EMULATION +#endif // Not BE_MINIMAL + WebServer->on("/fwlink", HandleRoot); // Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. WebServer->onNotFound(HandleNotFound); } reset_web_log_flag = 0; @@ -520,6 +529,7 @@ void HandleRoot() if (CaptivePortal()) { return; } // If captive portal redirect instead of displaying the page. if (HTTP_MANAGER == webserver_state) { +#ifndef BE_MINIMAL if ((Settings.web_password[0] != 0) && !(WebServer->hasArg("USER1")) && !(WebServer->hasArg("PASS1"))) { HandleWifiLogin(); } else { @@ -537,6 +547,7 @@ void HandleRoot() HandleWifiLogin(); } } +#endif // Not BE_MINIMAL } else { char stemp[10]; String page = FPSTR(HTTP_HEAD); @@ -672,6 +683,7 @@ boolean HttpUser() return status; } +#ifndef BE_MINIMAL void HandleConfiguration() { if (HttpUser()) { return; } @@ -681,6 +693,11 @@ void HandleConfiguration() page.replace(F("{v}"), FPSTR(S_CONFIGURATION)); page += FPSTR(HTTP_HEAD_STYLE); page += FPSTR(HTTP_BTN_MENU_MODULE); +#if defined(USE_I2C) && defined(USE_MCP230xx) && defined(USE_MCP230xx_webconfig) + if (MCP230xx_Type()) { // Configuration button will only show if MCP23008/MCP23017 was detected on I2C + page += FPSTR(HTTP_BTN_MCP230XX); + } +#endif // USE_I2C and USE_MCP230xx and USE_MCP230xx_webconfig #if defined(USE_TIMERS) && defined(USE_TIMERS_WEB) #ifdef USE_RULES page += FPSTR(HTTP_BTN_MENU_TIMER); @@ -1119,6 +1136,11 @@ void HandleSaveSettings() } AddLog(LOG_LEVEL_INFO); break; +#if defined(USE_I2C) && defined(USE_MCP230xx) && defined(USE_MCP230xx_webconfig) + case 8: + MCP230xx_SaveSettings(); + break; +#endif // USE_I2C and USE_MCP230xx and USE_MCP230xx_webconfig case 6: WebGetArg("g99", tmp, sizeof(tmp)); byte new_module = (!strlen(tmp)) ? MODULE : atoi(tmp); @@ -1205,6 +1227,122 @@ void HandleRestoreConfiguration() upload_file_type = UPL_SETTINGS; } +void HandleInformation() +{ + if (HttpUser()) { return; } + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_INFORMATION); + + char stopic[TOPSZ]; + + int freeMem = ESP.getFreeHeap(); + + String page = FPSTR(HTTP_HEAD); + page.replace(F("{v}"), FPSTR(S_INFORMATION)); + page += FPSTR(HTTP_HEAD_STYLE); + // page += F("
 Information "); + + page += F(""); + page += F("
"); + + // Save 1k of code space replacing table html with javascript replace codes + // }1 = + // }2 = + String func = FPSTR(HTTP_SCRIPT_INFO_BEGIN); + func += F("
"); + func += F(D_PROGRAM_VERSION "}2"); func += my_version; + func += F("}1" D_BUILD_DATE_AND_TIME "}2"); func += GetBuildDateAndTime(); + func += F("}1" D_CORE_AND_SDK_VERSION "}2" ARDUINO_ESP8266_RELEASE "/"); func += String(ESP.getSdkVersion()); + func += F("}1" D_UPTIME "}2"); func += GetDateAndTime(DT_UPTIME); + snprintf_P(stopic, sizeof(stopic), PSTR(" at %X"), GetSettingsAddress()); + func += F("}1" D_FLASH_WRITE_COUNT "}2"); func += String(Settings.save_flag); func += stopic; + func += F("}1" D_BOOT_COUNT "}2"); func += String(Settings.bootcount); + func += F("}1" D_RESTART_REASON "}2"); func += GetResetReason(); + uint8_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present; + if (SONOFF_IFAN02 == Settings.module) { maxfn = 1; } + for (byte i = 0; i < maxfn; i++) { + func += F("}1" D_FRIENDLY_NAME " "); func += i +1; func += F("}2"); func += Settings.friendlyname[i]; + } + + func += F("}1}2 "); // Empty line + func += F("}1" D_AP); func += String(Settings.sta_active +1); + func += F(" " D_SSID " (" D_RSSI ")}2"); func += Settings.sta_ssid[Settings.sta_active]; func += F(" ("); func += WifiGetRssiAsQuality(WiFi.RSSI()); func += F("%)"); + func += F("}1" D_HOSTNAME "}2"); func += my_hostname; + if (static_cast(WiFi.localIP()) != 0) { + func += F("}1" D_IP_ADDRESS "}2"); func += WiFi.localIP().toString(); + func += F("}1" D_GATEWAY "}2"); func += IPAddress(Settings.ip_address[1]).toString(); + func += F("}1" D_SUBNET_MASK "}2"); func += IPAddress(Settings.ip_address[2]).toString(); + func += F("}1" D_DNS_SERVER "}2"); func += IPAddress(Settings.ip_address[3]).toString(); + func += F("}1" D_MAC_ADDRESS "}2"); func += WiFi.macAddress(); + } + if (static_cast(WiFi.softAPIP()) != 0) { + func += F("}1" D_AP " " D_IP_ADDRESS "}2"); func += WiFi.softAPIP().toString(); + func += F("}1" D_AP " " D_GATEWAY "}2"); func += WiFi.softAPIP().toString(); + func += F("}1" D_AP " " D_MAC_ADDRESS "}2"); func += WiFi.softAPmacAddress(); + } + + func += F("}1}2 "); // Empty line + if (Settings.flag.mqtt_enabled) { + func += F("}1" D_MQTT_HOST "}2"); func += Settings.mqtt_host; + func += F("}1" D_MQTT_PORT "}2"); func += String(Settings.mqtt_port); + func += F("}1" D_MQTT_CLIENT " &
 " D_FALLBACK_TOPIC "}2"); func += mqtt_client; + func += F("}1" D_MQTT_USER "}2"); func += Settings.mqtt_user; + func += F("}1" D_MQTT_TOPIC "}2"); func += Settings.mqtt_topic; + func += F("}1" D_MQTT_GROUP_TOPIC "}2"); func += Settings.mqtt_grptopic; + GetTopic_P(stopic, CMND, mqtt_topic, ""); + func += F("}1" D_MQTT_FULL_TOPIC "}2"); func += stopic; + + } else { + func += F("}1" D_MQTT "}2" D_DISABLED); + } + + func += F("}1}2 "); // Empty line + func += F("}1" D_EMULATION "}2"); +#ifdef USE_EMULATION + if (EMUL_WEMO == Settings.flag2.emulation) { + func += F(D_BELKIN_WEMO); + } + else if (EMUL_HUE == Settings.flag2.emulation) { + func += F(D_HUE_BRIDGE); + } + else { + func += F(D_NONE); + } +#else + func += F(D_DISABLED); +#endif // USE_EMULATION + + func += F("}1" D_MDNS_DISCOVERY "}2"); +#ifdef USE_DISCOVERY + func += F(D_ENABLED); + func += F("}1" D_MDNS_ADVERTISE "}2"); +#ifdef WEBSERVER_ADVERTISE + func += F(D_WEB_SERVER); +#else + func += F(D_DISABLED); +#endif // WEBSERVER_ADVERTISE +#else + func += F(D_DISABLED); +#endif // USE_DISCOVERY + + func += F("}1}2 "); // Empty line + func += F("}1" D_ESP_CHIP_ID "}2"); func += String(ESP.getChipId()); + func += F("}1" D_FLASH_CHIP_ID "}2"); func += String(ESP.getFlashChipId()); + func += F("}1" D_FLASH_CHIP_SIZE "}2"); func += String(ESP.getFlashChipRealSize() / 1024); func += F("kB"); + func += F("}1" D_PROGRAM_FLASH_SIZE "}2"); func += String(ESP.getFlashChipSize() / 1024); func += F("kB"); + func += F("}1" D_PROGRAM_SIZE "}2"); func += String(ESP.getSketchSize() / 1024); func += F("kB"); + func += F("}1" D_FREE_PROGRAM_SPACE "}2"); func += String(ESP.getFreeSketchSpace() / 1024); func += F("kB"); + func += F("}1" D_FREE_MEMORY "}2"); func += String(freeMem / 1024); func += F("kB"); + func += F("
"); + func += FPSTR(HTTP_SCRIPT_INFO_END); + page.replace(F(""), func); + page.replace(F(""), F("")); + + // page += F("
"); + page += FPSTR(HTTP_BTN_MAIN); + ShowPage(page); +} +#endif // Not BE_MINIMAL + void HandleUpgradeFirmware() { if (HttpUser()) { return; } @@ -1629,121 +1767,6 @@ void HandleAjaxConsoleRefresh() WebServer->send(200, FPSTR(HDR_CTYPE_XML), message); } -void HandleInformation() -{ - if (HttpUser()) { return; } - AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_INFORMATION); - - char stopic[TOPSZ]; - - int freeMem = ESP.getFreeHeap(); - - String page = FPSTR(HTTP_HEAD); - page.replace(F("{v}"), FPSTR(S_INFORMATION)); - page += FPSTR(HTTP_HEAD_STYLE); - // page += F("
 Information "); - - page += F(""); - page += F("
"); - - // Save 1k of code space replacing table html with javascript replace codes - // }1 = - // }2 = - String func = FPSTR(HTTP_SCRIPT_INFO_BEGIN); - func += F("
"); - func += F(D_PROGRAM_VERSION "}2"); func += my_version; - func += F("}1" D_BUILD_DATE_AND_TIME "}2"); func += GetBuildDateAndTime(); - func += F("}1" D_CORE_AND_SDK_VERSION "}2" ARDUINO_ESP8266_RELEASE "/"); func += String(ESP.getSdkVersion()); - func += F("}1" D_UPTIME "}2"); func += GetDateAndTime(DT_UPTIME); - snprintf_P(stopic, sizeof(stopic), PSTR(" at %X"), GetSettingsAddress()); - func += F("}1" D_FLASH_WRITE_COUNT "}2"); func += String(Settings.save_flag); func += stopic; - func += F("}1" D_BOOT_COUNT "}2"); func += String(Settings.bootcount); - func += F("}1" D_RESTART_REASON "}2"); func += GetResetReason(); - uint8_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present; - if (SONOFF_IFAN02 == Settings.module) { maxfn = 1; } - for (byte i = 0; i < maxfn; i++) { - func += F("}1" D_FRIENDLY_NAME " "); func += i +1; func += F("}2"); func += Settings.friendlyname[i]; - } - - func += F("}1}2 "); // Empty line - func += F("}1" D_AP); func += String(Settings.sta_active +1); - func += F(" " D_SSID " (" D_RSSI ")}2"); func += Settings.sta_ssid[Settings.sta_active]; func += F(" ("); func += WifiGetRssiAsQuality(WiFi.RSSI()); func += F("%)"); - func += F("}1" D_HOSTNAME "}2"); func += my_hostname; - if (static_cast(WiFi.localIP()) != 0) { - func += F("}1" D_IP_ADDRESS "}2"); func += WiFi.localIP().toString(); - func += F("}1" D_GATEWAY "}2"); func += IPAddress(Settings.ip_address[1]).toString(); - func += F("}1" D_SUBNET_MASK "}2"); func += IPAddress(Settings.ip_address[2]).toString(); - func += F("}1" D_DNS_SERVER "}2"); func += IPAddress(Settings.ip_address[3]).toString(); - func += F("}1" D_MAC_ADDRESS "}2"); func += WiFi.macAddress(); - } - if (static_cast(WiFi.softAPIP()) != 0) { - func += F("}1" D_AP " " D_IP_ADDRESS "}2"); func += WiFi.softAPIP().toString(); - func += F("}1" D_AP " " D_GATEWAY "}2"); func += WiFi.softAPIP().toString(); - func += F("}1" D_AP " " D_MAC_ADDRESS "}2"); func += WiFi.softAPmacAddress(); - } - - func += F("}1}2 "); // Empty line - if (Settings.flag.mqtt_enabled) { - func += F("}1" D_MQTT_HOST "}2"); func += Settings.mqtt_host; - func += F("}1" D_MQTT_PORT "}2"); func += String(Settings.mqtt_port); - func += F("}1" D_MQTT_CLIENT " &
 " D_FALLBACK_TOPIC "}2"); func += mqtt_client; - func += F("}1" D_MQTT_USER "}2"); func += Settings.mqtt_user; - func += F("}1" D_MQTT_TOPIC "}2"); func += Settings.mqtt_topic; - func += F("}1" D_MQTT_GROUP_TOPIC "}2"); func += Settings.mqtt_grptopic; - GetTopic_P(stopic, CMND, mqtt_topic, ""); - func += F("}1" D_MQTT_FULL_TOPIC "}2"); func += stopic; - - } else { - func += F("}1" D_MQTT "}2" D_DISABLED); - } - - func += F("}1}2 "); // Empty line - func += F("}1" D_EMULATION "}2"); -#ifdef USE_EMULATION - if (EMUL_WEMO == Settings.flag2.emulation) { - func += F(D_BELKIN_WEMO); - } - else if (EMUL_HUE == Settings.flag2.emulation) { - func += F(D_HUE_BRIDGE); - } - else { - func += F(D_NONE); - } -#else - func += F(D_DISABLED); -#endif // USE_EMULATION - - func += F("}1" D_MDNS_DISCOVERY "}2"); -#ifdef USE_DISCOVERY - func += F(D_ENABLED); - func += F("}1" D_MDNS_ADVERTISE "}2"); -#ifdef WEBSERVER_ADVERTISE - func += F(D_WEB_SERVER); -#else - func += F(D_DISABLED); -#endif // WEBSERVER_ADVERTISE -#else - func += F(D_DISABLED); -#endif // USE_DISCOVERY - - func += F("}1}2 "); // Empty line - func += F("}1" D_ESP_CHIP_ID "}2"); func += String(ESP.getChipId()); - func += F("}1" D_FLASH_CHIP_ID "}2"); func += String(ESP.getFlashChipId()); - func += F("}1" D_FLASH_CHIP_SIZE "}2"); func += String(ESP.getFlashChipRealSize() / 1024); func += F("kB"); - func += F("}1" D_PROGRAM_FLASH_SIZE "}2"); func += String(ESP.getFlashChipSize() / 1024); func += F("kB"); - func += F("}1" D_PROGRAM_SIZE "}2"); func += String(ESP.getSketchSize() / 1024); func += F("kB"); - func += F("}1" D_FREE_PROGRAM_SPACE "}2"); func += String(ESP.getFreeSketchSpace() / 1024); func += F("kB"); - func += F("}1" D_FREE_MEMORY "}2"); func += String(freeMem / 1024); func += F("kB"); - func += F("
"); - func += FPSTR(HTTP_SCRIPT_INFO_END); - page.replace(F(""), func); - page.replace(F(""), F("")); - - // page += F("
"); - page += FPSTR(HTTP_BTN_MAIN); - ShowPage(page); -} - void HandleRestart() { if (HttpUser()) { return; } diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index e862ffdcd..3e12ef94f 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -17,8 +17,6 @@ along with this program. If not, see . */ -#define USE_ENERGY_SENSOR - #ifdef USE_ENERGY_SENSOR /*********************************************************************************************\ * HLW8012 and PZEM004T - Energy @@ -93,18 +91,18 @@ void EnergyUpdateToday() } /*********************************************************************************************\ - * HLW8012, BL0937 or HJL-01 - Energy (Sonoff Pow) + * HLW8012, BL0937 or HJL-01 - Energy (Sonoff Pow, HuaFan, KMC70011, BlitzWolf) * * Based on Source: Shenzhen Heli Technology Co., Ltd \*********************************************************************************************/ -// HLW8012 based (Sonoff Pow, KMC70011) +// HLW8012 based (Sonoff Pow, KMC70011, HuaFan) #define HLW_PREF 10000 // 1000.0W #define HLW_UREF 2200 // 220.0V #define HLW_IREF 4545 // 4.545A #define HLW_SEL_VOLTAGE 1 -// HJL-01 based (Homecube, BlitzWolf) +// HJL-01 based (BlitzWolf, Homecube, Gosund) #define HJL_PREF 1362 #define HJL_UREF 822 #define HJL_IREF 3300 diff --git a/sonoff/xdrv_07_domoticz.ino b/sonoff/xdrv_07_domoticz.ino index f2b972326..f29def2ce 100644 --- a/sonoff/xdrv_07_domoticz.ino +++ b/sonoff/xdrv_07_domoticz.ino @@ -271,14 +271,17 @@ boolean DomoticzCommand() boolean DomoticzSendKey(byte key, byte device, byte state, byte svalflg) { - if ((Settings.domoticz_key_idx[device -1] || Settings.domoticz_switch_idx[device -1]) && (svalflg)) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"command\":\"switchlight\",\"idx\":%d,\"switchcmd\":\"%s\"}"), - (key) ? Settings.domoticz_switch_idx[device -1] : Settings.domoticz_key_idx[device -1], (state) ? (2 == state) ? "Toggle" : "On" : "Off"); - MqttPublish(domoticz_in_topic); - return 1; - } else { - return 0; + boolean result = 0; + + if (device <= MAX_DOMOTICZ_IDX) { + if ((Settings.domoticz_key_idx[device -1] || Settings.domoticz_switch_idx[device -1]) && (svalflg)) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"command\":\"switchlight\",\"idx\":%d,\"switchcmd\":\"%s\"}"), + (key) ? Settings.domoticz_switch_idx[device -1] : Settings.domoticz_key_idx[device -1], (state) ? (2 == state) ? "Toggle" : "On" : "Off"); + MqttPublish(domoticz_in_topic); + result = 1; + } } + return result; } /*********************************************************************************************\ diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 1218b9854..2129fdbbe 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -253,7 +253,7 @@ bool RulesRuleMatch(byte rule_set, String &event, String &rule) } } else match = true; - if (Settings.flag.rules_once) { + if (bitRead(Settings.rule_once, rule_set)) { if (match) { // Only allow match state changes if (!bitRead(rules_triggers[rule_set], rules_trigger_count[rule_set])) { bitSet(rules_triggers[rule_set], rules_trigger_count[rule_set]); @@ -557,44 +557,38 @@ boolean RulesCommand() snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.mems[index -1]); } else if ((CMND_ADD == command_code) && (index > 0) && (index <= RULES_MAX_VARS)) { - if ( XdrvMailbox.data_len > 0 ) { + if (XdrvMailbox.data_len > 0) { double tempvar = CharToDouble(vars[index -1]) + CharToDouble(XdrvMailbox.data); - dtostrfd(tempvar,2,vars[index -1]); + dtostrfd(tempvar, 2, vars[index -1]); } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]); } else if ((CMND_SUB == command_code) && (index > 0) && (index <= RULES_MAX_VARS)) { - if ( XdrvMailbox.data_len > 0 ){ + if (XdrvMailbox.data_len > 0) { double tempvar = CharToDouble(vars[index -1]) - CharToDouble(XdrvMailbox.data); - dtostrfd(tempvar,2,vars[index -1]); + dtostrfd(tempvar, 2, vars[index -1]); } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]); } else if ((CMND_MULT == command_code) && (index > 0) && (index <= RULES_MAX_VARS)) { - if ( XdrvMailbox.data_len > 0 ){ + if (XdrvMailbox.data_len > 0) { double tempvar = CharToDouble(vars[index -1]) * CharToDouble(XdrvMailbox.data); - dtostrfd(tempvar,2,vars[index -1]); + dtostrfd(tempvar, 2, vars[index -1]); } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]); } else if ((CMND_SCALE == command_code) && (index > 0) && (index <= RULES_MAX_VARS)) { - if ( XdrvMailbox.data_len > 0 ) { + if (XdrvMailbox.data_len > 0) { if (strstr(XdrvMailbox.data, ",")) { // Process parameter entry - double value = 0; - double valueIN = 0; - double fromLow = 0; - double fromHigh = 0; - double toLow = 0; - double toHigh = 0; + char sub_string[XdrvMailbox.data_len +1]; - valueIN = CharToDouble(subStr(XdrvMailbox.data, ",", 1)); - fromLow = CharToDouble(subStr(XdrvMailbox.data, ",", 2)); - fromHigh = CharToDouble(subStr(XdrvMailbox.data, ",", 3)); - toLow = CharToDouble(subStr(XdrvMailbox.data, ",", 4)); - toHigh = CharToDouble(subStr(XdrvMailbox.data, ",", 5)); - - value = map_double(valueIN, fromLow, fromHigh, toLow, toHigh); - dtostrfd(value,2,vars[index -1]); + double valueIN = CharToDouble(subStr(sub_string, XdrvMailbox.data, ",", 1)); + double fromLow = CharToDouble(subStr(sub_string, XdrvMailbox.data, ",", 2)); + double fromHigh = CharToDouble(subStr(sub_string, XdrvMailbox.data, ",", 3)); + double toLow = CharToDouble(subStr(sub_string, XdrvMailbox.data, ",", 4)); + double toHigh = CharToDouble(subStr(sub_string, XdrvMailbox.data, ",", 5)); + double value = map_double(valueIN, fromLow, fromHigh, toLow, toHigh); + dtostrfd(value, 2, vars[index -1]); } } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]); @@ -610,24 +604,23 @@ double map_double(double x, double in_min, double in_max, double out_min, double } // Function to return a substring defined by a delimiter at an index -char* subStr (char* str, const char *delim, int index) { - char *act, *sub, *ptr; - static char copy[10]; +char* subStr(char* dest, char* str, const char *delim, int index) +{ + char *act; + char *sub; + char *ptr; int i; // Since strtok consumes the first arg, make a copy - strcpy(copy, str); - - for (i = 1, act = copy; i <= index; i++, act = NULL) { - sub = strtok_r(act, delim, &ptr); - if (sub == NULL) break; + strncpy(dest, str, strlen(str)); + for (i = 1, act = dest; i <= index; i++, act = NULL) { + sub = strtok_r(act, delim, &ptr); + if (sub == NULL) break; } - sub = LTrim(sub); - sub = RTrim(sub); + sub = Trim(sub); return sub; } - /*********************************************************************************************\ * Interface \*********************************************************************************************/ diff --git a/sonoff/xplg_ws2812.ino b/sonoff/xplg_ws2812.ino index 2e576bfc8..0d8846550 100644 --- a/sonoff/xplg_ws2812.ino +++ b/sonoff/xplg_ws2812.ino @@ -126,7 +126,6 @@ int mod(int a, int b) return ret; } -#define cmin(a,b) ((a)<(b)?(a):(b)) void Ws2812UpdatePixelColor(int position, struct WsColor hand_color, float offset) { @@ -140,9 +139,9 @@ void Ws2812UpdatePixelColor(int position, struct WsColor hand_color, float offse color = strip->GetPixelColor(mod_position); float dimmer = 100 / (float)Settings.light_dimmer; - color.R = cmin(color.R + ((hand_color.red / dimmer) * offset), 255); - color.G = cmin(color.G + ((hand_color.green / dimmer) * offset), 255); - color.B = cmin(color.B + ((hand_color.blue / dimmer) * offset), 255); + color.R = tmin(color.R + ((hand_color.red / dimmer) * offset), 255); + color.G = tmin(color.G + ((hand_color.green / dimmer) * offset), 255); + color.B = tmin(color.B + ((hand_color.blue / dimmer) * offset), 255); strip->SetPixelColor(mod_position, color); } diff --git a/sonoff/xsns_05_ds18b20.ino b/sonoff/xsns_05_ds18b20.ino index dabaf25d4..fa0f4fee8 100644 --- a/sonoff/xsns_05_ds18b20.ino +++ b/sonoff/xsns_05_ds18b20.ino @@ -26,9 +26,10 @@ #define W1_CONVERT_TEMP 0x44 #define W1_READ_SCRATCHPAD 0xBE -float ds18b20_last_temperature = 0; -uint16_t ds18b20_last_result = 0; +float ds18b20_temperature = 0; +uint8_t ds18b20_valid = 0; uint8_t ds18x20_pin = 0; +char ds18b20_types[] = "DS18B20"; /*********************************************************************************************\ * Embedded stripped and tuned OneWire library @@ -126,12 +127,7 @@ boolean OneWireCrc8(uint8_t *addr) /********************************************************************************************/ -void Ds18x20Init() -{ - ds18x20_pin = pin[GPIO_DSB]; -} - -void Ds18x20Convert() +void Ds18b20Convert() { OneWireReset(); OneWireWrite(W1_SKIP_ROM); // Address all Sensors on Bus @@ -139,25 +135,16 @@ void Ds18x20Convert() // delay(750); // 750ms should be enough for 12bit conv } -boolean Ds18b20Read(float &t) +boolean Ds18b20Read() { uint8_t data[9]; int8_t sign = 1; - if (!ds18b20_last_temperature) { - t = NAN; - } else { - ds18b20_last_result++; - if (ds18b20_last_result > 4) { // Reset after 4 misses - ds18b20_last_temperature = NAN; - } - t = ds18b20_last_temperature; - } - + if (ds18b20_valid) { ds18b20_valid--; } /* - if (!OneWireReadBit()) { //check measurement end + if (!OneWireReadBit()) { // Check end of measurement AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_BUSY)); - return !isnan(t); + return; } */ for (uint8_t retry = 0; retry < 3; retry++) { @@ -173,44 +160,55 @@ boolean Ds18b20Read(float &t) temp12 = (~temp12) +1; sign = -1; } - t = ConvertTemp(sign * temp12 * 0.0625); - ds18b20_last_result = 0; - } - if (!isnan(t)) { - ds18b20_last_temperature = t; + ds18b20_temperature = ConvertTemp(sign * temp12 * 0.0625); + ds18b20_valid = SENSOR_MAX_MISS; return true; } } AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_CRC_ERROR)); - return !isnan(t); + return false; +} + +/********************************************************************************************/ + +void Ds18b20EverySecond() +{ + ds18x20_pin = pin[GPIO_DSB]; + if (uptime &1) { + // 2mS + Ds18b20Convert(); // Start conversion, takes up to one second + } else { + // 12mS + if (!Ds18b20Read()) { // Read temperature + AddLogMissed(ds18b20_types, ds18b20_valid); + } + } } void Ds18b20Show(boolean json) { - float t; - - if (Ds18b20Read(t)) { // Check if read failed + if (ds18b20_valid) { // Check for valid temperature char temperature[10]; - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); - + dtostrfd(ds18b20_temperature, Settings.flag2.temperature_resolution, temperature); if(json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"DS18B20\":{\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, temperature); + snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMP, mqtt_data, ds18b20_types, temperature); #ifdef USE_DOMOTICZ - if (0 == tele_period) DomoticzSensor(DZ_TEMP, temperature); + if (0 == tele_period) { + DomoticzSensor(DZ_TEMP, temperature); + } #endif // USE_DOMOTICZ #ifdef USE_KNX if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, t); + KnxSensor(KNX_TEMPERATURE, ds18b20_temperature); } #endif // USE_KNX #ifdef USE_WEBSERVER } else { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, "DS18B20", temperature, TempUnit()); + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, ds18b20_types, temperature, TempUnit()); #endif // USE_WEBSERVER } } - Ds18x20Convert(); // Start conversion, takes up to one second } /*********************************************************************************************\ @@ -225,11 +223,8 @@ boolean Xsns05(byte function) if (pin[GPIO_DSB] < 99) { switch (function) { - case FUNC_INIT: - Ds18x20Init(); - break; - case FUNC_PREP_BEFORE_TELEPERIOD: - Ds18x20Convert(); // Start conversion, takes up to one second + case FUNC_EVERY_SECOND: + Ds18b20EverySecond(); break; case FUNC_JSON_APPEND: Ds18b20Show(1); diff --git a/sonoff/xsns_05_ds18x20.ino b/sonoff/xsns_05_ds18x20.ino index 292191b18..869deac8e 100644 --- a/sonoff/xsns_05_ds18x20.ino +++ b/sonoff/xsns_05_ds18x20.ino @@ -21,6 +21,7 @@ /*********************************************************************************************\ * DS18B20 - Temperature - Multiple sensors \*********************************************************************************************/ +//#define USE_DS18x20_RECONFIGURE // When sensor is lost keep retrying or re-configure #define DS18S20_CHIPID 0x10 // +/-0.5C 9-bit #define DS1822_CHIPID 0x22 // +/-2C 12-bit @@ -38,11 +39,16 @@ const char kDs18x20Types[] PROGMEM = "DS18x20|DS18S20|DS1822|DS18B20|MAX31850"; uint8_t ds18x20_chipids[] = { 0, DS18S20_CHIPID, DS1822_CHIPID, DS18B20_CHIPID, MAX31850_CHIPID }; -uint8_t ds18x20_address[DS18X20_MAX_SENSORS][8]; -uint8_t ds18x20_index[DS18X20_MAX_SENSORS] = { 0 }; + +struct DS18X20STRUCT { + uint8_t address[8]; + uint8_t index; + uint8_t valid; + float temperature; +} ds18x20_sensor[DS18X20_MAX_SENSORS]; uint8_t ds18x20_sensors = 0; uint8_t ds18x20_pin = 0; -char ds18x20_types[9]; +char ds18x20_types[12]; /*********************************************************************************************\ * Embedded tuned OneWire library @@ -246,28 +252,29 @@ void Ds18x20Init() uint64_t ids[DS18X20_MAX_SENSORS]; ds18x20_pin = pin[GPIO_DSB]; + OneWireResetSearch(); for (ds18x20_sensors = 0; ds18x20_sensors < DS18X20_MAX_SENSORS; ds18x20_sensors) { - if (!OneWireSearch(ds18x20_address[ds18x20_sensors])) { + if (!OneWireSearch(ds18x20_sensor[ds18x20_sensors].address)) { break; } - if (OneWireCrc8(ds18x20_address[ds18x20_sensors]) && - ((ds18x20_address[ds18x20_sensors][0] == DS18S20_CHIPID) || - (ds18x20_address[ds18x20_sensors][0] == DS1822_CHIPID) || - (ds18x20_address[ds18x20_sensors][0] == DS18B20_CHIPID) || - (ds18x20_address[ds18x20_sensors][0] == MAX31850_CHIPID))) { - ds18x20_index[ds18x20_sensors] = ds18x20_sensors; - ids[ds18x20_sensors] = ds18x20_address[ds18x20_sensors][0]; // Chip id + if (OneWireCrc8(ds18x20_sensor[ds18x20_sensors].address) && + ((ds18x20_sensor[ds18x20_sensors].address[0] == DS18S20_CHIPID) || + (ds18x20_sensor[ds18x20_sensors].address[0] == DS1822_CHIPID) || + (ds18x20_sensor[ds18x20_sensors].address[0] == DS18B20_CHIPID) || + (ds18x20_sensor[ds18x20_sensors].address[0] == MAX31850_CHIPID))) { + ds18x20_sensor[ds18x20_sensors].index = ds18x20_sensors; + ids[ds18x20_sensors] = ds18x20_sensor[ds18x20_sensors].address[0]; // Chip id for (uint8_t j = 6; j > 0; j--) { - ids[ds18x20_sensors] = ids[ds18x20_sensors] << 8 | ds18x20_address[ds18x20_sensors][j]; + ids[ds18x20_sensors] = ids[ds18x20_sensors] << 8 | ds18x20_sensor[ds18x20_sensors].address[j]; } ds18x20_sensors++; } } for (uint8_t i = 0; i < ds18x20_sensors; i++) { for (uint8_t j = i + 1; j < ds18x20_sensors; j++) { - if (ids[ds18x20_index[i]] > ids[ds18x20_index[j]]) { // Sort ascending - std::swap(ds18x20_index[i], ds18x20_index[j]); + if (ids[ds18x20_sensor[i].index] > ids[ds18x20_sensor[j].index]) { // Sort ascending + std::swap(ds18x20_sensor[i].index, ds18x20_sensor[j].index); } } } @@ -283,7 +290,7 @@ void Ds18x20Convert() // delay(750); // 750ms should be enough for 12bit conv } -boolean Ds18x20Read(uint8_t sensor, float &t) +bool Ds18x20Read(uint8_t sensor) { uint8_t data[9]; int8_t sign = 1; @@ -291,17 +298,17 @@ boolean Ds18x20Read(uint8_t sensor, float &t) int16_t temp14 = 0; float temp9 = 0.0; - t = NAN; - + uint8_t index = ds18x20_sensor[sensor].index; + if (ds18x20_sensor[index].valid) { ds18x20_sensor[index].valid--; } for (uint8_t retry = 0; retry < 3; retry++) { OneWireReset(); - OneWireSelect(ds18x20_address[ds18x20_index[sensor]]); + OneWireSelect(ds18x20_sensor[index].address); OneWireWrite(W1_READ_SCRATCHPAD); for (uint8_t i = 0; i < 9; i++) { data[i] = OneWireRead(); } if (OneWireCrc8(data)) { - switch(ds18x20_address[ds18x20_index[sensor]][0]) { + switch(ds18x20_sensor[index].address[0]) { case DS18S20_CHIPID: if (data[1] > 0x80) { data[0] = (~data[0]) +1; @@ -312,19 +319,20 @@ boolean Ds18x20Read(uint8_t sensor, float &t) } else { temp9 = (data[0] >> 1) * sign; } - t = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0)); - break; + ds18x20_sensor[index].temperature = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0)); + ds18x20_sensor[index].valid = SENSOR_MAX_MISS; + return true; case DS1822_CHIPID: case DS18B20_CHIPID: if (data[4] != 0x7F) { data[4] = 0x7F; // Set resolution to 12-bit OneWireReset(); - OneWireSelect(ds18x20_address[ds18x20_index[sensor]]); + OneWireSelect(ds18x20_sensor[index].address); OneWireWrite(W1_WRITE_SCRATCHPAD); OneWireWrite(data[2]); // Th Register OneWireWrite(data[3]); // Tl Register OneWireWrite(data[4]); // Configuration Register - OneWireSelect(ds18x20_address[ds18x20_index[sensor]]); + OneWireSelect(ds18x20_sensor[index].address); OneWireWrite(W1_WRITE_EEPROM); // Save scratchpad to EEPROM } temp12 = (data[1] << 8) + data[0]; @@ -332,72 +340,99 @@ boolean Ds18x20Read(uint8_t sensor, float &t) temp12 = (~temp12) +1; sign = -1; } - t = ConvertTemp(sign * temp12 * 0.0625); // Divide by 16 - break; + ds18x20_sensor[index].temperature = ConvertTemp(sign * temp12 * 0.0625); // Divide by 16 + ds18x20_sensor[index].valid = SENSOR_MAX_MISS; + return true; case MAX31850_CHIPID: temp14 = (data[1] << 8) + (data[0] & 0xFC); - t = ConvertTemp(temp14 * 0.0625); // Divide by 16 - break; + ds18x20_sensor[index].temperature = ConvertTemp(temp14 * 0.0625); // Divide by 16 + ds18x20_sensor[index].valid = SENSOR_MAX_MISS; + return true; } } - if (!isnan(t)) { - return true; - } } AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_CRC_ERROR)); return false; } +void Ds18x20Name(uint8_t sensor) +{ + uint8_t index = sizeof(ds18x20_chipids); + while (index) { + if (ds18x20_sensor[ds18x20_sensor[sensor].index].address[0] == ds18x20_chipids[index]) { + break; + } + index--; + } + GetTextIndexed(ds18x20_types, sizeof(ds18x20_types), index, kDs18x20Types); + if (ds18x20_sensors > 1) { + snprintf_P(ds18x20_types, sizeof(ds18x20_types), PSTR("%s-%d"), ds18x20_types, sensor +1); + } +} + +/********************************************************************************************/ + +void Ds18x20EverySecond() +{ + if (uptime &1) { + // 2mS + Ds18x20Convert(); // Start conversion, takes up to one second + } else { + for (uint8_t i = 0; i < ds18x20_sensors; i++) { + // 12mS per device + if (!Ds18x20Read(i)) { // Read temperature + Ds18x20Name(i); + AddLogMissed(ds18x20_types, ds18x20_sensor[ds18x20_sensor[i].index].valid); +#ifdef USE_DS18x20_RECONFIGURE + if (!ds18x20_sensor[ds18x20_sensor[i].index].valid) { + memset(&ds18x20_sensor, 0, sizeof(ds18x20_sensor)); + Ds18x20Init(); // Re-configure + } +#endif // USE_DS18x20_RECONFIGURE + } + } + } +} + void Ds18x20Show(boolean json) { char temperature[10]; - char stemp[12]; - float t; - bool domoticz_flag = true; for (uint8_t i = 0; i < ds18x20_sensors; i++) { - if (Ds18x20Read(i, t)) { // Check if read failed - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); + uint8_t index = ds18x20_sensor[i].index; - uint8_t index = sizeof(ds18x20_chipids); - while (index) { - if (ds18x20_address[ds18x20_index[i]][0] == ds18x20_chipids[index]) { - break; - } - index--; - } - GetTextIndexed(ds18x20_types, sizeof(ds18x20_types), index, kDs18x20Types); + if (ds18x20_sensor[index].valid) { // Check for valid temperature + dtostrfd(ds18x20_sensor[index].temperature, Settings.flag2.temperature_resolution, temperature); + + Ds18x20Name(i); - snprintf_P(stemp, sizeof(stemp), PSTR("%s-%d"), ds18x20_types, i +1); if (json) { if (1 == ds18x20_sensors) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, ds18x20_types, temperature); } else { char address[17]; for (byte j = 0; j < 6; j++) { - sprintf(address+2*j, "%02X", ds18x20_address[ds18x20_index[i]][6-j]); // Skip sensor type and crc + sprintf(address+2*j, "%02X", ds18x20_sensor[index].address[6-j]); // Skip sensor type and crc } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, stemp, address, temperature); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, ds18x20_types, address, temperature); } #ifdef USE_DOMOTICZ - if ((0 == tele_period) && domoticz_flag) { + if ((0 == tele_period) && (0 == i)) { DomoticzSensor(DZ_TEMP, temperature); - domoticz_flag = false; } #endif // USE_DOMOTICZ #ifdef USE_KNX if ((0 == tele_period) && (0 == i)) { - KnxSensor(KNX_TEMPERATURE, t); + KnxSensor(KNX_TEMPERATURE, ds18x20_sensor[index].temperature); } #endif // USE_KNX #ifdef USE_WEBSERVER } else { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, (1 == ds18x20_sensors) ? ds18x20_types : stemp, temperature, TempUnit()); + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, ds18x20_types, temperature, TempUnit()); #endif // USE_WEBSERVER } } } - Ds18x20Convert(); // Start conversion, takes up to one second } /*********************************************************************************************\ @@ -415,8 +450,8 @@ boolean Xsns05(byte function) case FUNC_INIT: Ds18x20Init(); break; - case FUNC_PREP_BEFORE_TELEPERIOD: - Ds18x20Convert(); // Start conversion, takes up to one second + case FUNC_EVERY_SECOND: + Ds18x20EverySecond(); break; case FUNC_JSON_APPEND: Ds18x20Show(1); diff --git a/sonoff/xsns_06_dht.ino b/sonoff/xsns_06_dht.ino index 91a154169..048337d25 100644 --- a/sonoff/xsns_06_dht.ino +++ b/sonoff/xsns_06_dht.ino @@ -28,7 +28,6 @@ #define DHT_MAX_SENSORS 3 #define DHT_MAX_RETRY 8 -#define MIN_INTERVAL 2000 uint32_t dht_max_cycles; uint8_t dht_data[5]; @@ -63,15 +62,10 @@ int32_t DhtExpectPulse(byte sensor, bool level) return count; } -void DhtRead(byte sensor) +boolean DhtRead(byte sensor) { int32_t cycles[80]; - uint32_t currenttime = millis(); - - if ((currenttime - Dht[sensor].lastreadtime) < MIN_INTERVAL) { - return; - } - Dht[sensor].lastreadtime = currenttime; + uint8_t error = 0; dht_data[0] = dht_data[1] = dht_data[2] = dht_data[3] = dht_data[4] = 0; @@ -99,27 +93,27 @@ void DhtRead(byte sensor) delayMicroseconds(10); if (-1 == DhtExpectPulse(sensor, LOW)) { AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_LOW " " D_PULSE)); - Dht[sensor].lastresult++; - return; + error = 1; } - if (-1 == DhtExpectPulse(sensor, HIGH)) { + else if (-1 == DhtExpectPulse(sensor, HIGH)) { AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_HIGH " " D_PULSE)); - Dht[sensor].lastresult++; - return; + error = 1; } - for (int i = 0; i < 80; i += 2) { - cycles[i] = DhtExpectPulse(sensor, LOW); - cycles[i+1] = DhtExpectPulse(sensor, HIGH); + else { + for (int i = 0; i < 80; i += 2) { + cycles[i] = DhtExpectPulse(sensor, LOW); + cycles[i+1] = DhtExpectPulse(sensor, HIGH); + } } interrupts(); + if (error) { return false; } for (int i = 0; i < 40; ++i) { int32_t lowCycles = cycles[2*i]; int32_t highCycles = cycles[2*i+1]; if ((-1 == lowCycles) || (-1 == highCycles)) { AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_PULSE)); - Dht[sensor].lastresult++; - return; + return false; } dht_data[i/8] <<= 1; if (highCycles > lowCycles) { @@ -127,57 +121,43 @@ void DhtRead(byte sensor) } } - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DHT D_RECEIVED " %02X, %02X, %02X, %02X, %02X =? %02X"), - dht_data[0], dht_data[1], dht_data[2], dht_data[3], dht_data[4], (dht_data[0] + dht_data[1] + dht_data[2] + dht_data[3]) & 0xFF); - AddLog(LOG_LEVEL_DEBUG); - - if (dht_data[4] == ((dht_data[0] + dht_data[1] + dht_data[2] + dht_data[3]) & 0xFF)) { - Dht[sensor].lastresult = 0; - } else { - AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_CHECKSUM_FAILURE)); - Dht[sensor].lastresult++; + uint8_t checksum = (dht_data[0] + dht_data[1] + dht_data[2] + dht_data[3]) & 0xFF; + if (dht_data[4] != checksum) { + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DHT D_CHECKSUM_FAILURE " %02X, %02X, %02X, %02X, %02X =? %02X"), + dht_data[0], dht_data[1], dht_data[2], dht_data[3], dht_data[4], checksum); + AddLog(LOG_LEVEL_DEBUG); + return false; } + + return true; } -boolean DhtReadTempHum(byte sensor, float &t, float &h) +void DhtReadTempHum(byte sensor) { - if (NAN == Dht[sensor].h) { - t = NAN; - h = NAN; - } else { - if (Dht[sensor].lastresult > DHT_MAX_RETRY) { // Reset after 8 misses - Dht[sensor].t = NAN; - Dht[sensor].h = NAN; - } - t = Dht[sensor].t; - h = Dht[sensor].h; + if ((NAN == Dht[sensor].h) || (Dht[sensor].lastresult > DHT_MAX_RETRY)) { // Reset after 8 misses + Dht[sensor].t = NAN; + Dht[sensor].h = NAN; } - - DhtRead(sensor); - if (!Dht[sensor].lastresult) { + if (DhtRead(sensor)) { switch (Dht[sensor].type) { case GPIO_DHT11: - h = dht_data[0]; - t = dht_data[2]; + Dht[sensor].h = dht_data[0]; + Dht[sensor].t = dht_data[2] + ((float)dht_data[3] * 0.1f); // Issue #3164 break; case GPIO_DHT22: case GPIO_SI7021: - h = ((dht_data[0] << 8) | dht_data[1]) * 0.1; - t = (((dht_data[2] & 0x7F) << 8 ) | dht_data[3]) * 0.1; + Dht[sensor].h = ((dht_data[0] << 8) | dht_data[1]) * 0.1; + Dht[sensor].t = (((dht_data[2] & 0x7F) << 8 ) | dht_data[3]) * 0.1; if (dht_data[2] & 0x80) { - t *= -1; + Dht[sensor].t *= -1; } break; } - t = ConvertTemp(t); - if (!isnan(t)) { - Dht[sensor].t = t; - } - if (!isnan(h)) { - Dht[sensor].h = h; - } + Dht[sensor].t = ConvertTemp(Dht[sensor].t); + Dht[sensor].lastresult = 0; + } else { + Dht[sensor].lastresult++; } - return (!isnan(t) && !isnan(h)); } boolean DhtSetup(byte pin, byte type) @@ -210,41 +190,46 @@ void DhtInit() } } +void DhtEverySecond() +{ + if (uptime &1) { + // <1mS + DhtReadPrep(); + } else { + for (byte i = 0; i < dht_sensors; i++) { + // DHT11 and AM2301 25mS per sensor, SI7021 5mS per sensor + DhtReadTempHum(i); + } + } +} + void DhtShow(boolean json) { char temperature[10]; char humidity[10]; - byte dsxflg = 0; for (byte i = 0; i < dht_sensors; i++) { - float t = NAN; - float h = NAN; - if (DhtReadTempHum(i, t, h)) { // Read temperature - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); - dtostrfd(h, Settings.flag2.humidity_resolution, humidity); + dtostrfd(Dht[i].t, Settings.flag2.temperature_resolution, temperature); + dtostrfd(Dht[i].h, Settings.flag2.humidity_resolution, humidity); - if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, Dht[i].stype, temperature, humidity); + if (json) { + snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, Dht[i].stype, temperature, humidity); #ifdef USE_DOMOTICZ - if ((0 == tele_period) && !dsxflg) { - DomoticzTempHumSensor(temperature, humidity); - dsxflg++; - } -#endif // USE_DOMOTICZ - -#ifdef USE_KNX - if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, t); - KnxSensor(KNX_HUMIDITY, h); - } -#endif // USE_KNX - -#ifdef USE_WEBSERVER - } else { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, Dht[i].stype, temperature, TempUnit()); - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_HUM, mqtt_data, Dht[i].stype, humidity); -#endif // USE_WEBSERVER + if ((0 == tele_period) && (0 == i)) { + DomoticzTempHumSensor(temperature, humidity); } +#endif // USE_DOMOTICZ +#ifdef USE_KNX + if ((0 == tele_period) && (0 == i)) { + KnxSensor(KNX_TEMPERATURE, Dht[i].t); + KnxSensor(KNX_HUMIDITY, Dht[i].h); + } +#endif // USE_KNX +#ifdef USE_WEBSERVER + } else { + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, Dht[i].stype, temperature, TempUnit()); + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_HUM, mqtt_data, Dht[i].stype, humidity); +#endif // USE_WEBSERVER } } } @@ -264,8 +249,8 @@ boolean Xsns06(byte function) case FUNC_INIT: DhtInit(); break; - case FUNC_PREP_BEFORE_TELEPERIOD: - DhtReadPrep(); + case FUNC_EVERY_SECOND: + DhtEverySecond(); break; case FUNC_JSON_APPEND: DhtShow(1); diff --git a/sonoff/xsns_07_sht1x.ino b/sonoff/xsns_07_sht1x.ino index 98837471b..510ee7be3 100644 --- a/sonoff/xsns_07_sht1x.ino +++ b/sonoff/xsns_07_sht1x.ino @@ -37,6 +37,10 @@ enum { uint8_t sht_sda_pin; uint8_t sht_scl_pin; uint8_t sht_type = 0; +char sht_types[] = "SHT1X"; +uint8_t sht_valid = 0; +float sht_temperature = 0; +float sht_humidity = 0; boolean ShtReset() { @@ -119,46 +123,32 @@ int ShtReadData() return val; } -boolean ShtReadTempHum(float &t, float &h) +boolean ShtRead() { - float tempRaw; - float humRaw; - float rhLinear; + if (sht_valid) { sht_valid--; } + if (!ShtReset()) { return false; } + if (!ShtSendCommand(SHT1X_CMD_MEASURE_TEMP)) { return false; } + if (!ShtAwaitResult()) { return false; } + float tempRaw = ShtReadData(); + if (!ShtSendCommand(SHT1X_CMD_MEASURE_RH)) { return false; } + if (!ShtAwaitResult()) { return false; } + float humRaw = ShtReadData(); - t = NAN; - h = NAN; - - if (!ShtReset()) { - return false; - } - if (!ShtSendCommand(SHT1X_CMD_MEASURE_TEMP)) { - return false; - } - if (!ShtAwaitResult()) { - return false; - } - tempRaw = ShtReadData(); // Temperature conversion coefficients from SHT1X datasheet for version 4 const float d1 = -39.7; // 3.5V const float d2 = 0.01; // 14-bit - t = d1 + (tempRaw * d2); - if (!ShtSendCommand(SHT1X_CMD_MEASURE_RH)) { - return false; - } - if (!ShtAwaitResult()) { - return false; - } - humRaw = ShtReadData(); - // Temperature conversion coefficients from SHT1X datasheet for version 4 + sht_temperature = d1 + (tempRaw * d2); const float c1 = -2.0468; const float c2 = 0.0367; const float c3 = -1.5955E-6; const float t1 = 0.01; const float t2 = 0.00008; - rhLinear = c1 + c2 * humRaw + c3 * humRaw * humRaw; - h = (t - 25) * (t1 + t2 * humRaw) + rhLinear; - t = ConvertTemp(t); - return (!isnan(t) && !isnan(h)); + float rhLinear = c1 + c2 * humRaw + c3 * humRaw * humRaw; + sht_humidity = (sht_temperature - 25) * (t1 + t2 * humRaw) + rhLinear; + sht_temperature = ConvertTemp(sht_temperature); + + sht_valid = SENSOR_MAX_MISS; + return true; } /********************************************************************************************/ @@ -169,12 +159,9 @@ void ShtDetect() return; } - float t; - float h; - sht_sda_pin = pin[GPIO_I2C_SDA]; sht_scl_pin = pin[GPIO_I2C_SCL]; - if (ShtReadTempHum(t, h)) { + if (ShtRead()) { sht_type = 1; AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND)); } else { @@ -183,38 +170,44 @@ void ShtDetect() } } +void ShtEverySecond() +{ + if (sht_type && !(uptime %4)) { // Update every 4 seconds + // 344mS + if (!ShtRead()) { + AddLogMissed(sht_types, sht_valid); +// if (!sht_valid) { sht_type = 0; } + } + } +} + void ShtShow(boolean json) { - if (sht_type) { - float t; - float h; + if (sht_valid) { + char temperature[10]; + char humidity[10]; - if (ShtReadTempHum(t, h)) { - char temperature[10]; - char humidity[10]; + dtostrfd(sht_temperature, Settings.flag2.temperature_resolution, temperature); + dtostrfd(sht_humidity, Settings.flag2.humidity_resolution, humidity); - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); - dtostrfd(h, Settings.flag2.humidity_resolution, humidity); - - if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, "SHT1X", temperature, humidity); + if (json) { + snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, sht_types, temperature, humidity); #ifdef USE_DOMOTICZ - if (0 == tele_period) DomoticzTempHumSensor(temperature, humidity); -#endif // USE_DOMOTICZ - -#ifdef USE_KNX - if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, t); - KnxSensor(KNX_HUMIDITY, h); - } -#endif // USE_KNX - -#ifdef USE_WEBSERVER - } else { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, "SHT1X", temperature, TempUnit()); - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_HUM, mqtt_data, "SHT1X", humidity); -#endif // USE_WEBSERVER + if (0 == tele_period) { + DomoticzTempHumSensor(temperature, humidity); } +#endif // USE_DOMOTICZ +#ifdef USE_KNX + if (0 == tele_period) { + KnxSensor(KNX_TEMPERATURE, sht_temperature); + KnxSensor(KNX_HUMIDITY, sht_humidity); + } +#endif // USE_KNX +#ifdef USE_WEBSERVER + } else { + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, sht_types, temperature, TempUnit()); + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_HUM, mqtt_data, sht_types, humidity); +#endif // USE_WEBSERVER } } } @@ -231,9 +224,13 @@ boolean Xsns07(byte function) if (i2c_flg) { switch (function) { - case FUNC_PREP_BEFORE_TELEPERIOD: +// case FUNC_PREP_BEFORE_TELEPERIOD: // As this is not a real I2C device it may interfere with other sensors + case FUNC_INIT: // Move detection to restart only removing interference ShtDetect(); break; + case FUNC_EVERY_SECOND: + ShtEverySecond(); + break; case FUNC_JSON_APPEND: ShtShow(1); break; diff --git a/sonoff/xsns_08_htu21.ino b/sonoff/xsns_08_htu21.ino index 3d9e21d3b..9534cbbce 100644 --- a/sonoff/xsns_08_htu21.ino +++ b/sonoff/xsns_08_htu21.ino @@ -58,8 +58,11 @@ const char kHtuTypes[] PROGMEM = "HTU21|SI7013|SI7020|SI7021|T/RH?"; uint8_t htu_address; uint8_t htu_type = 0; -uint8_t delay_temp; -uint8_t delay_humidity = 50; +uint8_t htu_delay_temp; +uint8_t htu_delay_humidity = 50; +uint8_t htu_valid = 0; +float htu_temperature = 0; +float htu_humidity = 0; char htu_types[7]; uint8_t HtuCheckCrc8(uint16_t data) @@ -135,87 +138,62 @@ void HtuInit() HtuSetResolution(HTU21_RES_RH12_T14); } -float HtuReadHumidity(void) +boolean HtuRead() { uint8_t checksum = 0; uint16_t sensorval = 0; - float humidity = 0.0; - Wire.beginTransmission(HTU21_ADDR); - Wire.write(HTU21_READHUM); - if (Wire.endTransmission() != 0) { - return 0.0; // In case of error - } - delay(delay_humidity); // Sensor time at max resolution - - Wire.requestFrom(HTU21_ADDR, 3); - if (3 <= Wire.available()) { - sensorval = Wire.read() << 8; // MSB - sensorval |= Wire.read(); // LSB - checksum = Wire.read(); - } - if (HtuCheckCrc8(sensorval) != checksum) { - return 0.0; // Checksum mismatch - } - - sensorval ^= 0x02; // clear status bits - humidity = 0.001907 * (float)sensorval - 6; - - if (humidity > 100) { - return 100.0; - } - if (humidity < 0) { - return 0.01; - } - - return humidity; -} - -float HtuReadTemperature() -{ - uint8_t checksum=0; - uint16_t sensorval=0; - float t; + if (htu_valid) { htu_valid--; } Wire.beginTransmission(HTU21_ADDR); Wire.write(HTU21_READTEMP); - if (Wire.endTransmission() != 0) { - return 0.0; // In case of error - } - delay(delay_temp); // Sensor time at max resolution + if (Wire.endTransmission() != 0) { return false; } // In case of error + delay(htu_delay_temp); // Sensor time at max resolution Wire.requestFrom(HTU21_ADDR, 3); if (3 == Wire.available()) { - sensorval = Wire.read() << 8; // MSB - sensorval |= Wire.read(); // LSB + sensorval = Wire.read() << 8; // MSB + sensorval |= Wire.read(); // LSB checksum = Wire.read(); } - if (HtuCheckCrc8(sensorval) != checksum) { - return 0.0; // Checksum mismatch + if (HtuCheckCrc8(sensorval) != checksum) { return false; } // Checksum mismatch + + htu_temperature = ConvertTemp(0.002681 * (float)sensorval - 46.85); + + Wire.beginTransmission(HTU21_ADDR); + Wire.write(HTU21_READHUM); + if (Wire.endTransmission() != 0) { return false; } // In case of error + delay(htu_delay_humidity); // Sensor time at max resolution + + Wire.requestFrom(HTU21_ADDR, 3); + if (3 <= Wire.available()) { + sensorval = Wire.read() << 8; // MSB + sensorval |= Wire.read(); // LSB + checksum = Wire.read(); + } + if (HtuCheckCrc8(sensorval) != checksum) { return false; } // Checksum mismatch + + sensorval ^= 0x02; // clear status bits + htu_humidity = 0.001907 * (float)sensorval - 6; + if (htu_humidity > 100) { htu_humidity = 100.0; } + if (htu_humidity < 0) { htu_humidity = 0.01; } + + if ((0.00 == htu_humidity) && (0.00 == htu_temperature)) { + htu_humidity = 0.0; + } + if ((htu_temperature > 0.00) && (htu_temperature < 80.00)) { + htu_humidity = (-0.15) * (25 - htu_temperature) + htu_humidity; } - t = ConvertTemp(0.002681 * (float)sensorval - 46.85); - return t; -} - -float HtuCompensatedHumidity(float humidity, float temperature) -{ - if(humidity == 0.00 && temperature == 0.00) { - return 0.0; - } - if(temperature > 0.00 && temperature < 80.00) { - return (-0.15)*(25-temperature)+humidity; - } - return humidity; + htu_valid = SENSOR_MAX_MISS; + return true; } /********************************************************************************************/ void HtuDetect() { - if (htu_type) { - return; - } + if (htu_type) { return; } htu_address = HTU21_ADDR; htu_type = HtuReadDeviceId(); @@ -224,8 +202,8 @@ void HtuDetect() HtuInit(); switch (htu_type) { case HTU21_CHIPID: - delay_temp = 50; - delay_humidity = 16; + htu_delay_temp = 50; + htu_delay_humidity = 16; break; case SI7021_CHIPID: index++; // 3 @@ -233,13 +211,13 @@ void HtuDetect() index++; // 2 case SI7013_CHIPID: index++; // 1 - delay_temp = 12; - delay_humidity = 23; + htu_delay_temp = 12; + htu_delay_humidity = 23; break; default: index = 4; - delay_temp = 50; - delay_humidity = 23; + htu_delay_temp = 50; + htu_delay_humidity = 23; } GetTextIndexed(htu_types, sizeof(htu_types), index, kHtuTypes); snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, htu_types, htu_address); @@ -247,31 +225,45 @@ void HtuDetect() } } +void HtuEverySecond() +{ + if (92 == (uptime %100)) { + // 1mS + HtuDetect(); + } + else if (uptime &1) { + // HTU21: 68mS, SI70xx: 37mS + if (htu_type) { + if (!HtuRead()) { + AddLogMissed(htu_types, htu_valid); +// if (!htu_valid) { htu_type = 0; } + } + } + } +} + void HtuShow(boolean json) { - if (htu_type) { + if (htu_valid) { char temperature[10]; char humidity[10]; - float t = HtuReadTemperature(); - float h = HtuReadHumidity(); - h = HtuCompensatedHumidity(h, t); - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); - dtostrfd(h, Settings.flag2.humidity_resolution, humidity); + dtostrfd(htu_temperature, Settings.flag2.temperature_resolution, temperature); + dtostrfd(htu_humidity, Settings.flag2.humidity_resolution, humidity); if (json) { snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, htu_types, temperature, humidity); #ifdef USE_DOMOTICZ - if (0 == tele_period) DomoticzTempHumSensor(temperature, humidity); + if (0 == tele_period) { + DomoticzTempHumSensor(temperature, humidity); + } #endif // USE_DOMOTICZ - #ifdef USE_KNX if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, t); - KnxSensor(KNX_HUMIDITY, h); + KnxSensor(KNX_TEMPERATURE, htu_temperature); + KnxSensor(KNX_HUMIDITY, htu_humidity); } #endif // USE_KNX - #ifdef USE_WEBSERVER } else { snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, htu_types, temperature, TempUnit()); @@ -293,9 +285,12 @@ boolean Xsns08(byte function) if (i2c_flg) { switch (function) { - case FUNC_PREP_BEFORE_TELEPERIOD: + case FUNC_INIT: HtuDetect(); break; + case FUNC_EVERY_SECOND: + HtuEverySecond(); + break; case FUNC_JSON_APPEND: HtuShow(1); break; diff --git a/sonoff/xsns_09_bmp.ino b/sonoff/xsns_09_bmp.ino index a3769f8bc..2ffe02ebe 100644 --- a/sonoff/xsns_09_bmp.ino +++ b/sonoff/xsns_09_bmp.ino @@ -45,6 +45,11 @@ uint8_t bmp_type = 0; uint8_t bmp_model = 0; char bmp_name[7]; +uint8_t bmp_valid = 0; +float bmp_temperature = 0.0; +float bmp_pressure = 0.0; +float bmp_humidity = 0.0; + /*********************************************************************************************\ * BMP085 and BME180 \*********************************************************************************************/ @@ -78,7 +83,6 @@ int16_t cal_md; uint16_t cal_ac4; uint16_t cal_ac5; uint16_t cal_ac6; -int32_t bmp180_b5 = 0; boolean Bmp180Calibration() { @@ -113,21 +117,15 @@ boolean Bmp180Calibration() return true; } -double Bmp180ReadTemperature() +void Bmp180Read() { I2cWrite8(bmp_address, BMP180_REG_CONTROL, BMP180_TEMPERATURE); delay(5); // 5ms conversion time int ut = I2cRead16(bmp_address, BMP180_REG_RESULT); - int32_t x1 = (ut - (int32_t)cal_ac6) * ((int32_t)cal_ac5) >> 15; - int32_t x2 = ((int32_t)cal_mc << 11) / (x1 + (int32_t)cal_md); - bmp180_b5 = x1 + x2; - - return ((bmp180_b5 + 8) >> 4) / 10.0; -} - -double Bmp180ReadPressure() -{ - int32_t p; + int32_t xt1 = (ut - (int32_t)cal_ac6) * ((int32_t)cal_ac5) >> 15; + int32_t xt2 = ((int32_t)cal_mc << 11) / (xt1 + (int32_t)cal_md); + int32_t bmp180_b5 = xt1 + xt2; + bmp_temperature = ((bmp180_b5 + 8) >> 4) / 10.0; I2cWrite8(bmp_address, BMP180_REG_CONTROL, BMP180_PRESSURE3); // Highest resolution delay(2 + (4 << BMP180_OSS)); // 26ms conversion time at ultra high resolution @@ -146,19 +144,18 @@ double Bmp180ReadPressure() uint32_t b4 = ((uint32_t)cal_ac4 * (uint32_t)(x3 + 32768)) >> 15; uint32_t b7 = ((uint32_t)up - b3) * (uint32_t)(50000UL >> BMP180_OSS); + int32_t p; if (b7 < 0x80000000) { p = (b7 * 2) / b4; } else { p = (b7 / b4) * 2; } - x1 = (p >> 8) * (p >> 8); x1 = (x1 * 3038) >> 16; x2 = (-7357 * p) >> 16; - p += ((x1 + x2 + (int32_t)3791) >> 4); - return p / 100.0; // convert to mbar + bmp_pressure = (float)p / 100.0; // convert to mbar } /*********************************************************************************************\ @@ -215,8 +212,6 @@ struct BME280CALIBDATA int8_t dig_H6; } Bme280CalibrationData; -int32_t t_fine; - boolean Bmx280Calibrate() { // if (I2cRead8(bmp_address, BMP_REGISTER_CHIPID) != BME280_CHIPID) return false; @@ -233,20 +228,6 @@ boolean Bmx280Calibrate() Bme280CalibrationData.dig_P7 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P7); Bme280CalibrationData.dig_P8 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P8); Bme280CalibrationData.dig_P9 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P9); -/* - if (BME280_CHIPID == bmp_type) { - Bme280CalibrationData.dig_H1 = I2cRead8(bmp_address, BME280_REGISTER_DIG_H1); - Bme280CalibrationData.dig_H2 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_H2); - Bme280CalibrationData.dig_H3 = I2cRead8(bmp_address, BME280_REGISTER_DIG_H3); - Bme280CalibrationData.dig_H4 = (I2cRead8(bmp_address, BME280_REGISTER_DIG_H4) << 4) | (I2cRead8(bmp_address, BME280_REGISTER_DIG_H4 + 1) & 0xF); - Bme280CalibrationData.dig_H5 = (I2cRead8(bmp_address, BME280_REGISTER_DIG_H5 + 1) << 4) | (I2cRead8(bmp_address, BME280_REGISTER_DIG_H5) >> 4); - Bme280CalibrationData.dig_H6 = (int8_t)I2cRead8(bmp_address, BME280_REGISTER_DIG_H6); - - // Set before CONTROL_meas (DS 5.4.3) - I2cWrite8(bmp_address, BME280_REGISTER_CONTROLHUMID, 0x05); // 16x oversampling (Adafruit) - } - I2cWrite8(bmp_address, BME280_REGISTER_CONTROL, 0xB7); // 16x oversampling, normal mode (Adafruit) -*/ if (BME280_CHIPID == bmp_type) { // #1051 Bme280CalibrationData.dig_H1 = I2cRead8(bmp_address, BME280_REGISTER_DIG_H1); Bme280CalibrationData.dig_H2 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_H2); @@ -267,62 +248,42 @@ boolean Bmx280Calibrate() return true; } -double Bme280ReadTemperature(void) +void Bme280Read(void) { - int32_t var1; - int32_t var2; - int32_t adc_T = I2cRead24(bmp_address, BME280_REGISTER_TEMPDATA); adc_T >>= 4; - var1 = ((((adc_T >> 3) - ((int32_t)Bme280CalibrationData.dig_T1 << 1))) * ((int32_t)Bme280CalibrationData.dig_T2)) >> 11; - var2 = (((((adc_T >> 4) - ((int32_t)Bme280CalibrationData.dig_T1)) * ((adc_T >> 4) - ((int32_t)Bme280CalibrationData.dig_T1))) >> 12) * + int32_t vart1 = ((((adc_T >> 3) - ((int32_t)Bme280CalibrationData.dig_T1 << 1))) * ((int32_t)Bme280CalibrationData.dig_T2)) >> 11; + int32_t vart2 = (((((adc_T >> 4) - ((int32_t)Bme280CalibrationData.dig_T1)) * ((adc_T >> 4) - ((int32_t)Bme280CalibrationData.dig_T1))) >> 12) * ((int32_t)Bme280CalibrationData.dig_T3)) >> 14; - t_fine = var1 + var2; - double T = (t_fine * 5 + 128) >> 8; - return T / 100.0; -} - -double Bme280ReadPressure(void) -{ - int64_t var1; - int64_t var2; - int64_t p; - - // Must be done first to get the t_fine variable set up - // Bme280ReadTemperature(); + int32_t t_fine = vart1 + vart2; + float T = (t_fine * 5 + 128) >> 8; + bmp_temperature = T / 100.0; int32_t adc_P = I2cRead24(bmp_address, BME280_REGISTER_PRESSUREDATA); adc_P >>= 4; - var1 = ((int64_t)t_fine) - 128000; - var2 = var1 * var1 * (int64_t)Bme280CalibrationData.dig_P6; + int64_t var1 = ((int64_t)t_fine) - 128000; + int64_t var2 = var1 * var1 * (int64_t)Bme280CalibrationData.dig_P6; var2 = var2 + ((var1 * (int64_t)Bme280CalibrationData.dig_P5) << 17); var2 = var2 + (((int64_t)Bme280CalibrationData.dig_P4) << 35); var1 = ((var1 * var1 * (int64_t)Bme280CalibrationData.dig_P3) >> 8) + ((var1 * (int64_t)Bme280CalibrationData.dig_P2) << 12); var1 = (((((int64_t)1) << 47) + var1)) * ((int64_t)Bme280CalibrationData.dig_P1) >> 33; if (0 == var1) { - return 0; // avoid exception caused by division by zero + return; // avoid exception caused by division by zero } - p = 1048576 - adc_P; + int64_t p = 1048576 - adc_P; p = (((p << 31) - var2) * 3125) / var1; var1 = (((int64_t)Bme280CalibrationData.dig_P9) * (p >> 13) * (p >> 13)) >> 25; var2 = (((int64_t)Bme280CalibrationData.dig_P8) * p) >> 19; p = ((p + var1 + var2) >> 8) + (((int64_t)Bme280CalibrationData.dig_P7) << 4); - return (double)p / 25600.0; -} + bmp_pressure = (float)p / 25600.0; -double Bme280ReadHumidity(void) -{ - int32_t v_x1_u32r; - - // Must be done first to get the t_fine variable set up - // Bme280ReadTemperature(); + if (BMP280_CHIPID == bmp_type) { return; } int32_t adc_H = I2cRead16(bmp_address, BME280_REGISTER_HUMIDDATA); - v_x1_u32r = (t_fine - ((int32_t)76800)); - + int32_t v_x1_u32r = (t_fine - ((int32_t)76800)); v_x1_u32r = (((((adc_H << 14) - (((int32_t)Bme280CalibrationData.dig_H4) << 20) - (((int32_t)Bme280CalibrationData.dig_H5) * v_x1_u32r)) + ((int32_t)16384)) >> 15) * (((((((v_x1_u32r * ((int32_t)Bme280CalibrationData.dig_H6)) >> 10) * @@ -332,8 +293,8 @@ double Bme280ReadHumidity(void) ((int32_t)Bme280CalibrationData.dig_H1)) >> 4)); v_x1_u32r = (v_x1_u32r < 0) ? 0 : v_x1_u32r; v_x1_u32r = (v_x1_u32r > 419430400) ? 419430400 : v_x1_u32r; - double h = (v_x1_u32r >> 12); - return h / 1024.0; + float h = (v_x1_u32r >> 12); + bmp_humidity = h / 1024.0; } #ifdef USE_BME680 @@ -345,17 +306,14 @@ double Bme280ReadHumidity(void) struct bme680_dev gas_sensor; +float bmp_gas_resistance = 0.0; +uint8_t bme680_state = 0; + static void BmeDelayMs(uint32_t ms) { delay(ms); } -uint8_t bme680_state = 0; -float bme680_temperature; -float bme680_pressure; -float bme680_humidity; -float bme680_gas_resistance; - boolean Bme680Init() { gas_sensor.dev_id = bmp_address; @@ -400,7 +358,7 @@ boolean Bme680Init() return true; } -void Bme680PerformReading() +void Bme680Read() { int8_t rslt = BME680_OK; @@ -424,14 +382,14 @@ void Bme680PerformReading() rslt = bme680_get_sensor_data(&data, &gas_sensor); if (rslt != BME680_OK) { return; } - bme680_temperature = data.temperature / 100.0; - bme680_humidity = data.humidity / 1000.0; - bme680_pressure = data.pressure; + bmp_temperature = data.temperature / 100.0; + bmp_humidity = data.humidity / 1000.0; + bmp_pressure = data.pressure / 100.0; /* Avoid using measurements from an unstable heating setup */ if (data.status & BME680_GASM_VALID_MSK) { - bme680_gas_resistance = data.gas_resistance; + bmp_gas_resistance = data.gas_resistance / 1000.0; } else { - bme680_gas_resistance = 0; + bmp_gas_resistance = 0; } } } @@ -444,9 +402,7 @@ void Bme680PerformReading() void BmpDetect() { - if (bmp_type) { - return; - } + if (bmp_type) { return; } for (byte i = 0; i < sizeof(bmp_addresses); i++) { bmp_address = bmp_addresses[i]; @@ -456,22 +412,21 @@ void BmpDetect() } } if (bmp_type) { + bmp_model = 0; boolean success = false; switch (bmp_type) { case BMP180_CHIPID: success = Bmp180Calibration(); break; - case BMP280_CHIPID: - bmp_model = 1; // 1 - success = Bmx280Calibrate(); - break; case BME280_CHIPID: - bmp_model = 2; // 2 + bmp_model++; // 2 + case BMP280_CHIPID: + bmp_model++; // 1 success = Bmx280Calibrate(); break; #ifdef USE_BME680 case BME680_CHIPID: - bmp_model = 3; // 2 + bmp_model = 3; // 3 success = Bme680Init(); break; #endif // USE_BME680 @@ -487,54 +442,57 @@ void BmpDetect() } } +void BmpRead() +{ + switch (bmp_type) { + case BMP180_CHIPID: + Bmp180Read(); + break; + case BMP280_CHIPID: + case BME280_CHIPID: + Bme280Read(); + break; +#ifdef USE_BME680 + case BME680_CHIPID: + Bme680Read(); + break; +#endif // USE_BME680 + } + if (bmp_temperature != 0.0) { bmp_temperature = ConvertTemp(bmp_temperature); } +} + +void BmpEverySecond() +{ + if (91 == (uptime %100)) { + // 1mS + BmpDetect(); + } + else { + // 2mS + BmpRead(); + } +} + void BmpShow(boolean json) { if (bmp_type) { - float t = 0.0; - float p = 0.0; - float h = 0.0; - float g = 0.0; float bmp_sealevel = 0.0; - - switch (bmp_type) { - case BMP180_CHIPID: - t = Bmp180ReadTemperature(); - p = Bmp180ReadPressure(); - break; - case BME280_CHIPID: - h = Bme280ReadHumidity(); - case BMP280_CHIPID: - t = Bme280ReadTemperature(); - p = Bme280ReadPressure(); - break; -#ifdef USE_BME680 - case BME680_CHIPID: - t = bme680_temperature; - p = bme680_pressure / 100.0; - h = bme680_humidity; - g = bme680_gas_resistance / 1000.0; - break; -#endif // USE_BME680 - } - if (t != 0.0) { - t = ConvertTemp(t); - } - if (p != 0.0) { -// bmp_sealevel = p / pow(1.0 - ((float)Settings.altitude / 44330.0), 5.255); // pow adds 8k to the code - bmp_sealevel = (p / FastPrecisePow(1.0 - ((float)Settings.altitude / 44330.0), 5.255)) - 21.6; - } - char temperature[10]; - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); char pressure[10]; - dtostrfd(p, Settings.flag2.pressure_resolution, pressure); char sea_pressure[10]; - dtostrfd(bmp_sealevel, Settings.flag2.pressure_resolution, sea_pressure); char humidity[10]; - dtostrfd(h, Settings.flag2.humidity_resolution, humidity); + + if (bmp_pressure != 0.0) { + bmp_sealevel = (bmp_pressure / FastPrecisePow(1.0 - ((float)Settings.altitude / 44330.0), 5.255)) - 21.6; + } + + dtostrfd(bmp_temperature, Settings.flag2.temperature_resolution, temperature); + dtostrfd(bmp_pressure, Settings.flag2.pressure_resolution, pressure); + dtostrfd(bmp_sealevel, Settings.flag2.pressure_resolution, sea_pressure); + dtostrfd(bmp_humidity, Settings.flag2.humidity_resolution, humidity); #ifdef USE_BME680 char gas_resistance[10]; - dtostrfd(g, 2, gas_resistance); + dtostrfd(bmp_gas_resistance, 2, gas_resistance); #endif // USE_BME680 if (json) { @@ -555,15 +513,15 @@ void BmpShow(boolean json) if (0 == tele_period) { DomoticzTempHumPressureSensor(temperature, humidity, pressure); #ifdef USE_BME680 - if (bmp_model >= 3) { DomoticzSensor(DZ_AIRQUALITY, (uint32_t)g); } + if (bmp_model >= 3) { DomoticzSensor(DZ_AIRQUALITY, (uint32_t)bmp_gas_resistance); } #endif // USE_BME680 } #endif // USE_DOMOTICZ #ifdef USE_KNX if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, t); - KnxSensor(KNX_HUMIDITY, h); + KnxSensor(KNX_TEMPERATURE, bmp_temperature); + KnxSensor(KNX_HUMIDITY, bmp_humidity); } #endif // USE_KNX @@ -599,13 +557,11 @@ boolean Xsns09(byte function) if (i2c_flg) { switch (function) { + case FUNC_INIT: + BmpDetect(); + break; case FUNC_EVERY_SECOND: - if (tele_period == Settings.tele_period -2) { // Allow 2 seconds to prepare BME680 readings - BmpDetect(); - } -#ifdef USE_BME680 - Bme680PerformReading(); -#endif // USE_BME680 + BmpEverySecond(); break; case FUNC_JSON_APPEND: BmpShow(1); diff --git a/sonoff/xsns_10_bh1750.ino b/sonoff/xsns_10_bh1750.ino index 9c02f02e0..1dd18d90a 100644 --- a/sonoff/xsns_10_bh1750.ino +++ b/sonoff/xsns_10_bh1750.ino @@ -33,14 +33,20 @@ uint8_t bh1750_address; uint8_t bh1750_addresses[] = { BH1750_ADDR1, BH1750_ADDR2 }; uint8_t bh1750_type = 0; +uint8_t bh1750_valid = 0; +uint16_t bh1750_illuminance = 0; +char bh1750_types[] = "BH1750"; -uint16_t Bh1750ReadLux() +bool Bh1750Read() { - Wire.requestFrom(bh1750_address, (uint8_t)2); + if (bh1750_valid) { bh1750_valid--; } + + if (2 != Wire.requestFrom(bh1750_address, (uint8_t)2)) { return false; } byte msb = Wire.read(); byte lsb = Wire.read(); - uint16_t value = ((msb << 8) | lsb) / 1.2; - return value; + bh1750_illuminance = ((msb << 8) | lsb) / 1.2; + bh1750_valid = SENSOR_MAX_MISS; + return true; } /********************************************************************************************/ @@ -57,31 +63,48 @@ void Bh1750Detect() Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE); if (!Wire.endTransmission()) { bh1750_type = 1; - snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "BH1750", bh1750_address); + snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, bh1750_types, bh1750_address); AddLog(LOG_LEVEL_DEBUG); break; } } } +void Bh1750EverySecond() +{ + if (90 == (uptime %100)) { + // 1mS + Bh1750Detect(); + } + else { + // 1mS + if (bh1750_type) { + if (!Bh1750Read()) { + AddLogMissed(bh1750_types, bh1750_valid); +// if (!bh1750_valid) { bh1750_type = 0; } + } + } + } +} + #ifdef USE_WEBSERVER const char HTTP_SNS_ILLUMINANCE[] PROGMEM = - "%s{s}BH1750 " D_ILLUMINANCE "{m}%d " D_UNIT_LUX "{e}"; // {s} = , {m} = , {e} = + "%s{s}%s " D_ILLUMINANCE "{m}%d " D_UNIT_LUX "{e}"; // {s} = , {m} = , {e} = #endif // USE_WEBSERVER void Bh1750Show(boolean json) { - if (bh1750_type) { - uint16_t illuminance = Bh1750ReadLux(); - + if (bh1750_valid) { if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"BH1750\":{\"" D_JSON_ILLUMINANCE "\":%d}"), mqtt_data, illuminance); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_ILLUMINANCE "\":%d}"), mqtt_data, bh1750_types, bh1750_illuminance); #ifdef USE_DOMOTICZ - if (0 == tele_period) DomoticzSensor(DZ_ILLUMINANCE, illuminance); + if (0 == tele_period) { + DomoticzSensor(DZ_ILLUMINANCE, bh1750_illuminance); + } #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ILLUMINANCE, mqtt_data, illuminance); + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ILLUMINANCE, mqtt_data, bh1750_types, bh1750_illuminance); #endif // USE_WEBSERVER } } @@ -99,9 +122,12 @@ boolean Xsns10(byte function) if (i2c_flg) { switch (function) { - case FUNC_PREP_BEFORE_TELEPERIOD: + case FUNC_INIT: Bh1750Detect(); break; + case FUNC_EVERY_SECOND: + Bh1750EverySecond(); + break; case FUNC_JSON_APPEND: Bh1750Show(1); break; diff --git a/sonoff/xsns_13_ina219.ino b/sonoff/xsns_13_ina219.ino index 50bcb1642..deb4d5f4f 100644 --- a/sonoff/xsns_13_ina219.ino +++ b/sonoff/xsns_13_ina219.ino @@ -93,6 +93,11 @@ uint32_t ina219_cal_value = 0; // The following multiplier is used to convert raw current values to mA, taking into account the current config settings uint32_t ina219_current_divider_ma = 0; +uint8_t ina219_valid = 0; +float ina219_voltage = 0; +float ina219_current = 0; +char ina219_types[] = "INA219"; + bool Ina219SetCalibration(uint8_t mode) { uint16_t config = 0; @@ -155,8 +160,20 @@ float Ina219GetCurrent_mA() return value; } +bool Ina219Read() +{ + ina219_voltage = Ina219GetBusVoltage_V() + (Ina219GetShuntVoltage_mV() / 1000); + ina219_current = Ina219GetCurrent_mA() / 1000; + ina219_valid = SENSOR_MAX_MISS; + return true; +} + /*********************************************************************************************\ * Command Sensor13 + * + * 0 - Max 32V 2A range + * 1 - Max 32V 1A range + * 2 - Max 16V 0.4A range \*********************************************************************************************/ bool Ina219CommandSensor() @@ -176,21 +193,36 @@ bool Ina219CommandSensor() void Ina219Detect() { - if (ina219_type) { - return; - } + if (ina219_type) { return; } for (byte i = 0; i < sizeof(ina219_addresses); i++) { ina219_address = ina219_addresses[i]; if (Ina219SetCalibration(Settings.ina219_mode)) { ina219_type = 1; - snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "INA219", ina219_address); + snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, ina219_types, ina219_address); AddLog(LOG_LEVEL_DEBUG); break; } } } +void Ina219EverySecond() +{ + if (87 == (uptime %100)) { + // 2mS + Ina219Detect(); + } + else { + // 3mS + if (ina219_type) { + if (!Ina219Read()) { + AddLogMissed(ina219_types, ina219_valid); +// if (!ina219_valid) { ina219_type = 0; } + } + } + } +} + #ifdef USE_WEBSERVER const char HTTP_SNS_INA219_DATA[] PROGMEM = "%s" "{s}INA219 " D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}" @@ -200,21 +232,19 @@ const char HTTP_SNS_INA219_DATA[] PROGMEM = "%s" void Ina219Show(boolean json) { - if (ina219_type) { + if (ina219_valid) { char voltage[10]; char current[10]; char power[10]; - float fvoltage = Ina219GetBusVoltage_V() + (Ina219GetShuntVoltage_mV() / 1000); - float fcurrent = Ina219GetCurrent_mA() / 1000; - float fpower = fvoltage * fcurrent; - dtostrfd(fvoltage, Settings.flag2.voltage_resolution, voltage); + float fpower = ina219_voltage * ina219_current; + dtostrfd(ina219_voltage, Settings.flag2.voltage_resolution, voltage); dtostrfd(fpower, Settings.flag2.wattage_resolution, power); - dtostrfd(fcurrent, Settings.flag2.current_resolution, current); + dtostrfd(ina219_current, Settings.flag2.current_resolution, current); if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"INA219\":{\"" D_JSON_VOLTAGE "\":%s,\"" D_JSON_CURRENT "\":%s,\"" D_JSON_POWERUSAGE "\":%s}"), - mqtt_data, voltage, current, power); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_VOLTAGE "\":%s,\"" D_JSON_CURRENT "\":%s,\"" D_JSON_POWERUSAGE "\":%s}"), + mqtt_data, ina219_types, voltage, current, power); #ifdef USE_DOMOTICZ if (0 == tele_period) { DomoticzSensor(DZ_VOLTAGE, voltage); @@ -244,9 +274,12 @@ boolean Xsns13(byte function) result = Ina219CommandSensor(); } break; - case FUNC_PREP_BEFORE_TELEPERIOD: + case FUNC_INIT: Ina219Detect(); break; + case FUNC_EVERY_SECOND: + Ina219EverySecond(); + break; case FUNC_JSON_APPEND: Ina219Show(1); break; diff --git a/sonoff/xsns_16_tsl2561.ino b/sonoff/xsns_16_tsl2561.ino index 63abbc4a1..ac0536c6a 100644 --- a/sonoff/xsns_16_tsl2561.ino +++ b/sonoff/xsns_16_tsl2561.ino @@ -63,9 +63,9 @@ void Tsl2561Show(boolean json) && Tsl2561Util::normalizedLuminosity(gain, exposure, full = scaledFull, ir = scaledIr) && Tsl2561Util::milliLux(full, ir, milliLux, Tsl2561::packageCS(id))) { - snprintf_P(log_data, sizeof(log_data), PSTR(D_ILLUMINANCE " g:%d, e:%d, f:%u, i:%u -> %u.%03u " D_UNIT_LUX), - gain, exposure, full, ir, milliLux/1000, milliLux%1000); - AddLog(LOG_LEVEL_DEBUG); +// snprintf_P(log_data, sizeof(log_data), PSTR(D_ILLUMINANCE " g:%d, e:%d, f:%u, i:%u -> %u.%03u " D_UNIT_LUX), +// gain, exposure, full, ir, milliLux/1000, milliLux%1000); +// AddLog(LOG_LEVEL_DEBUG); if (json) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"TSL2561\":{\"" D_JSON_ILLUMINANCE "\":%u.%03u}"), diff --git a/sonoff/xsns_22_sr04.ino b/sonoff/xsns_22_sr04.ino index 59781cb0e..775ea93c9 100644 --- a/sonoff/xsns_22_sr04.ino +++ b/sonoff/xsns_22_sr04.ino @@ -25,8 +25,6 @@ * References: * - https://www.dfrobot.com/wiki/index.php/Weather-proof_Ultrasonic_Sensor_SKU_:_SEN0207 \*********************************************************************************************/ -#define max(a,b) ((a)>(b)?(a):(b)) -#define min(a,b) ((a)<(b)?(a):(b)) uint8_t sr04_echo_pin = 0; uint8_t sr04_trig_pin = 0; @@ -42,7 +40,7 @@ uint8_t sr04_trig_pin = 0; #define PING_OVERHEAD 5 // Conversion from uS to distance (round result to nearest cm or inch). -#define EchoConvert(echoTime, conversionFactor) (max(((unsigned int)echoTime + conversionFactor / 2) / conversionFactor, (echoTime ? 1 : 0))) +#define EchoConvert(echoTime, conversionFactor) (tmax(((unsigned int)echoTime + conversionFactor / 2) / conversionFactor, (echoTime ? 1 : 0))) /********************************************************************************************/ @@ -74,7 +72,7 @@ uint16_t Sr04Ping(uint16_t max_cm_distance) uint16_t duration = 0; uint16_t maxEchoTime; - maxEchoTime = min(max_cm_distance + 1, (uint16_t) MAX_SENSOR_DISTANCE + 1) * US_ROUNDTRIP_CM; + maxEchoTime = tmin(max_cm_distance + 1, (uint16_t) MAX_SENSOR_DISTANCE + 1) * US_ROUNDTRIP_CM; /* The following trigPin/echoPin cycle is used to determine the distance of the nearest object by bouncing soundwaves off of it. */ diff --git a/sonoff/xsns_28_tm1638.ino b/sonoff/xsns_28_tm1638.ino index 6945261c8..a81344880 100644 --- a/sonoff/xsns_28_tm1638.ino +++ b/sonoff/xsns_28_tm1638.ino @@ -35,19 +35,20 @@ uint8_t tm1638_clock_pin = 0; uint8_t tm1638_data_pin = 0; uint8_t tm1638_strobe_pin = 0; uint8_t tm1638_displays = 8; -uint8_t tm1638_active_display = 0; +uint8_t tm1638_active_display = 1; uint8_t tm1638_intensity = 0; +uint8_t tm1638_state = 0; /*********************************************************************************************\ * Pieces from library https://github.com/rjbatista/tm1638-library + * and from library https://github.com/MartyMacGyver/TM1638-demos-and-examples \*********************************************************************************************/ void Tm16XXSend(byte data) { - for (int i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { + digitalWrite(tm1638_data_pin, !!(data & (1 << i))); digitalWrite(tm1638_clock_pin, LOW); - digitalWrite(tm1638_data_pin, data & 1 ? HIGH : LOW); - data >>= 1; delayMicroseconds(TM1638_CLOCK_DELAY); digitalWrite(tm1638_clock_pin, HIGH); } @@ -77,11 +78,10 @@ byte Tm16XXReceive() pinMode(tm1638_data_pin, INPUT); digitalWrite(tm1638_data_pin, HIGH); - for (int i = 0; i < 8; i++) { - temp >>= 1; + for (uint8_t i = 0; i < 8; ++i) { digitalWrite(tm1638_clock_pin, LOW); delayMicroseconds(TM1638_CLOCK_DELAY); - if (digitalRead(tm1638_data_pin)) { temp |= 0x80; } + temp |= digitalRead(tm1638_data_pin) << i; digitalWrite(tm1638_clock_pin, HIGH); } @@ -155,7 +155,7 @@ void TmInit() digitalWrite(tm1638_clock_pin, HIGH); Tm16XXSendCommand(0x40); - Tm16XXSendCommand(0x80 | (tm1638_active_display ? 8 : 0) | min(7, tm1638_intensity)); + Tm16XXSendCommand(0x80 | (tm1638_active_display ? 8 : 0) | tmin(7, tm1638_intensity)); digitalWrite(tm1638_strobe_pin, LOW); Tm16XXSend(0xC0); @@ -165,25 +165,32 @@ void TmInit() digitalWrite(tm1638_strobe_pin, HIGH); tm1638_type = 1; + tm1638_state = 1; } } void TmLoop() { - byte buttons = Tm1638GetButtons(); - for (byte i = 0; i < MAX_SWITCHES; i++) { - virtualswitch[i] = buttons &1; - byte color = (virtualswitch[i]) ? TM1638_COLOR_RED : TM1638_COLOR_NONE; - Tm1638SetLED(color, i); - buttons >>= 1; + if (tm1638_state) { + byte buttons = Tm1638GetButtons(); + for (byte i = 0; i < MAX_SWITCHES; i++) { + virtualswitch[i] = (buttons &1) ^1; + byte color = (virtualswitch[i]) ? TM1638_COLOR_NONE : TM1638_COLOR_RED; + Tm1638SetLED(color, i); + buttons >>= 1; + } + SwitchHandler(1); } - SwitchHandler(1); } +/* void TmShow(boolean json) { + if (tm1638_type) { + } } +*/ /*********************************************************************************************\ * Interface diff --git a/sonoff/xsns_29_mcp230xx.ino b/sonoff/xsns_29_mcp230xx.ino new file mode 100644 index 000000000..aa1a44fad --- /dev/null +++ b/sonoff/xsns_29_mcp230xx.ino @@ -0,0 +1,467 @@ +/* + xsns_29_mcp230xx.ino - Support for I2C MCP23008/MCP23017 GPIO Expander (INPUT ONLY!) + + Copyright (C) 2018 Andre Thomas and Theo Arends + + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_I2C +#ifdef USE_MCP230xx + +/*********************************************************************************************\ + MCP23008/17 - I2C GPIO EXPANDER + + Docs at https://www.microchip.com/wwwproducts/en/MCP23008 + https://www.microchip.com/wwwproducts/en/MCP23017 + + I2C Address: 0x20 - 0x27 + \*********************************************************************************************/ + +#define XSNS_29 29 + +#define MCP230xx_ADDRESS1 0x20 +#define MCP230xx_ADDRESS2 0x21 +#define MCP230xx_ADDRESS3 0x22 +#define MCP230xx_ADDRESS4 0x23 +#define MCP230xx_ADDRESS5 0x24 +#define MCP230xx_ADDRESS6 0x25 +#define MCP230xx_ADDRESS7 0x26 +#define MCP230xx_ADDRESS8 0x27 + +/* + Default register locations for MCP23008 - They change for MCP23017 in default bank mode +*/ + +uint8_t MCP230xx_IODIR = 0x00; +uint8_t MCP230xx_GPINTEN = 0x02; +uint8_t MCP230xx_IOCON = 0x05; +uint8_t MCP230xx_GPPU = 0x06; +uint8_t MCP230xx_INTF = 0x07; +uint8_t MCP230xx_INTCAP = 0x08; +uint8_t MCP230xx_GPIO = 0x09; + +uint8_t mcp230xx_type = 0; +uint8_t mcp230xx_address; +uint8_t mcp230xx_addresses[] = { MCP230xx_ADDRESS1, MCP230xx_ADDRESS2, MCP230xx_ADDRESS3, MCP230xx_ADDRESS4, MCP230xx_ADDRESS5, MCP230xx_ADDRESS6, MCP230xx_ADDRESS7, MCP230xx_ADDRESS8 }; +uint8_t mcp280xx_pincount = 0; + +const char MCP230XX_SENSOR_RESPONSE[] PROGMEM = "{\"Sensor29\":{\"D\":%i,\"MODE\":%i,\"PULL-UP\":%i}}"; + +#ifdef USE_WEBSERVER +#ifdef USE_MCP230xx_displaymain +const char HTTP_SNS_MCP230xx_GPIO[] PROGMEM = "%s{s}MCP230XX D%d{m}%d{e}"; // {s} = , {m} = , {e} = +#endif // USE_MCP230xx_displaymain +#ifdef USE_MCP230xx_webconfig +const char MCP230XX_OPTION_SELECTED[] PROGMEM = " selected"; +const char MCP230XX_OPTION_BLANK[] PROGMEM = ""; +const char MCP230XX_OPTION_CHECKED[] PROGMEM = " checked"; +const char HTTP_FORM_I2C_MCP230XX_T[] PROGMEM = ""; +const char HTTP_FORM_I2C_MCP230XX_TE[] PROGMEM = "
"; + +const char HTTP_FORM_MCP230XX[] PROGMEM = + "
 MCP230xx settings  
"; + +const char HTTP_FORM_I2C_MCP230XX[] PROGMEM = + "{b0
" + "Enable Pullup" + "" + ""; + +void HandleMCP230xxConfiguration() +{ + if (HttpUser()) { + return; + } + + AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_MCP230XX)); + + String page = FPSTR(HTTP_HEAD); + + page.replace("{v}", FPSTR(D_CONFIGURE_MCP230XX)); + + page += FPSTR(HTTP_HEAD_STYLE); + page += FPSTR(HTTP_FORM_MCP230XX); + + page += FPSTR(HTTP_FORM_I2C_MCP230XX_T); + + for (uint8_t idx = 0; idx < mcp280xx_pincount; idx++) { + page += FPSTR(HTTP_FORM_I2C_MCP230XX); + page.replace("{b0", "MCP230XX D" + String(idx)); + page.replace("{b1", "D" + String(idx)); + + // determine correct dropdown state + + uint8_t bitsetting = 0; // Default to disabled + if (Settings.mcp230xx_config[idx].enable) { + bitsetting = 1; // Default to normal enable (floating without interrupt) + if (Settings.mcp230xx_config[idx].inten) { // Int choice + bitsetting = 2; // Default to INT on Change (LOW to HIGH, and HIGH to LOW) + if (Settings.mcp230xx_config[idx].intmode) { // On comparison + bitsetting = 3; // On comparison default to LOW + if (Settings.mcp230xx_config[idx].intcomp) { + bitsetting = 4; // On comparison default to HIGH + } + } + } + } + switch (bitsetting) { + case 0 : page.replace("{s0", FPSTR(MCP230XX_OPTION_SELECTED)); break; + case 1 : page.replace("{s1", FPSTR(MCP230XX_OPTION_SELECTED)); break; + case 2 : page.replace("{s2", FPSTR(MCP230XX_OPTION_SELECTED)); break; + case 3 : page.replace("{s3", FPSTR(MCP230XX_OPTION_SELECTED)); break; + case 4 : page.replace("{s4", FPSTR(MCP230XX_OPTION_SELECTED)); break; + } + // replace remaining unselected options - if one was replaced above it will be ignored + page.replace("{s0", FPSTR(MCP230XX_OPTION_BLANK)); + page.replace("{s1", FPSTR(MCP230XX_OPTION_BLANK)); + page.replace("{s2", FPSTR(MCP230XX_OPTION_BLANK)); + page.replace("{s3", FPSTR(MCP230XX_OPTION_BLANK)); + page.replace("{s4", FPSTR(MCP230XX_OPTION_BLANK)); + + if (Settings.mcp230xx_config[idx].pullup) { + page.replace("{b2", FPSTR(MCP230XX_OPTION_CHECKED)); + } else { + page.replace("{b2", FPSTR(MCP230XX_OPTION_BLANK)); + } + } + + page += FPSTR(HTTP_FORM_I2C_MCP230XX_TE); + + page += FPSTR(HTTP_FORM_END); + page += FPSTR(HTTP_BTN_CONF); + ShowPage(page); +} + +void MCP230xx_SaveSettings() +{ + char stemp[8]; + for (uint8_t idx = 0; idx < mcp280xx_pincount; idx++) { + snprintf_P(stemp, sizeof(stemp), PSTR("D%d"), idx); + uint8_t _pinvalue = (!strlen(WebServer->arg(stemp).c_str() )) ? 0 : atoi(WebServer->arg(stemp).c_str() ); + if (_pinvalue) { + Settings.mcp230xx_config[idx].enable = 1; + if (_pinvalue >= 2) { + Settings.mcp230xx_config[idx].inten = 1; + if (_pinvalue >= 3) { + Settings.mcp230xx_config[idx].intmode = 1; + if (_pinvalue >= 4) { + Settings.mcp230xx_config[idx].intcomp = 1; + } else { + Settings.mcp230xx_config[idx].intcomp = 0; + } + } else { + Settings.mcp230xx_config[idx].intmode = 0; + Settings.mcp230xx_config[idx].intcomp = 0; + } + } else { + Settings.mcp230xx_config[idx].inten = 0; + Settings.mcp230xx_config[idx].intmode = 0; + Settings.mcp230xx_config[idx].intcomp = 0; + } + } else { + Settings.mcp230xx_config[idx].enable = 0; + Settings.mcp230xx_config[idx].inten = 0; + Settings.mcp230xx_config[idx].intmode = 0; + Settings.mcp230xx_config[idx].intcomp = 0; + } + Settings.mcp230xx_config[idx].b5 = 0; + Settings.mcp230xx_config[idx].b6 = 0; + Settings.mcp230xx_config[idx].b7 = 0; + if (Settings.mcp230xx_config[idx].enable) { + snprintf_P(stemp, sizeof(stemp), PSTR("epuD%d"), idx); + Settings.mcp230xx_config[idx].pullup = (!strlen(WebServer->arg(stemp).c_str() )) ? 0 : atoi(WebServer->arg(stemp).c_str() ); + } else { + Settings.mcp230xx_config[idx].pullup = 0; + } + } + MCP230xx_ApplySettings(); +} + +#endif // USE_MCP230xx_webconfig + +#endif // USE_WEBSERVER + +uint8_t MCP230xx_Type(void) { + return mcp230xx_type; +} + +uint8_t MCP230xx_readGPIO(uint8_t port) { + return I2cRead8(mcp230xx_address, MCP230xx_GPIO + port); +} + +void MCP230xx_ApplySettings(void) { + uint8_t reg_gppu = 0; + uint8_t reg_gpinten = 0; + for (uint8_t idx = 0; idx < 8; idx++) { + if (Settings.mcp230xx_config[idx].enable) { + if (Settings.mcp230xx_config[idx].inten) { // Int is enabled in some form or another + reg_gpinten |= (1 << idx); + } + if (Settings.mcp230xx_config[idx].pullup) { + reg_gppu |= (1 << idx); + } + } + } + I2cWrite8(mcp230xx_address, MCP230xx_GPPU, reg_gppu); + I2cWrite8(mcp230xx_address, MCP230xx_GPINTEN, reg_gpinten); + if (mcp230xx_type == 2) { // We have a MCP23017 + reg_gppu = 0; + reg_gpinten = 0; + for (uint8_t idx = 8; idx < 16; idx++) { + if (Settings.mcp230xx_config[idx].enable) { + if (Settings.mcp230xx_config[idx].inten) { // Int is enabled in some form or another + reg_gpinten |= (1 << idx - 8); + } + if (Settings.mcp230xx_config[idx].pullup) { + reg_gppu |= (1 << idx - 8); + } + } + } + I2cWrite8(mcp230xx_address, MCP230xx_GPPU + 1, reg_gppu); + I2cWrite8(mcp230xx_address, MCP230xx_GPINTEN + 1, reg_gpinten); + } +} + +void MCP230xx_Detect() +{ + uint8_t buffer; + + if (mcp230xx_type) { + return; + } + + for (byte i = 0; i < sizeof(mcp230xx_addresses); i++) { + mcp230xx_address = mcp230xx_addresses[i]; + I2cWrite8(mcp230xx_address, MCP230xx_IOCON, 0x80); // attempt to set bank mode - this will only work on MCP23017, so its the best way to detect the different chips 23008 vs 23017 + if (I2cValidRead8(&buffer, mcp230xx_address, MCP230xx_IOCON)) { + if (buffer == 0x00) { + mcp230xx_type = 1; // We have a MCP23008 + snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "MCP23008", mcp230xx_address); + AddLog(LOG_LEVEL_DEBUG); + mcp280xx_pincount = 8; + MCP230xx_ApplySettings(); + } else { + if (buffer == 0x80) { + mcp230xx_type = 2; // We have a MCP23017 + snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "MCP23017", mcp230xx_address); + AddLog(LOG_LEVEL_DEBUG); + mcp280xx_pincount = 16; + // Reset bank mode to 0 + I2cWrite8(mcp230xx_address, MCP230xx_IOCON, 0x00); + // Update register locations for MCP23017 + MCP230xx_GPINTEN = 0x04; + MCP230xx_GPPU = 0x0C; + MCP230xx_INTF = 0x0E; + MCP230xx_INTCAP = 0x10; + MCP230xx_GPIO = 0x12; + MCP230xx_ApplySettings(); + } + } + break; + } + } +} + +bool MCP230xx_CheckForInterrupt(void) { + uint8_t intf; + uint8_t mcp230xx_intcap = 0; + uint8_t report_int; + + if (I2cValidRead8(&intf, mcp230xx_address, MCP230xx_INTF)) { + if (intf > 0) { + if (I2cValidRead8(&mcp230xx_intcap, mcp230xx_address, MCP230xx_INTCAP)) { + for (uint8_t intp = 0; intp < 8; intp++) { + if ((intf >> intp) & 0x01) { // we know which pin caused interrupt + report_int = 0; + if (Settings.mcp230xx_config[intp].intmode) { // change on INT + if (((mcp230xx_intcap >> intp) & 0x01) == Settings.mcp230xx_config[intp].intcomp) report_int = 1; + } else { + report_int = 1; + } + if (report_int) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str()); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"MCP230XX_INT\":{\"Pin\":\"D%i\", \"State\":%i}"), mqtt_data, intp, ((mcp230xx_intcap >> intp) & 0x01)); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data); + MqttPublishPrefixTopic_P(RESULT_OR_STAT, mqtt_data); + } + } + } + } + } + } + if (mcp230xx_type == 2) { // We have a MCP23017 so we need to check the other 8 bits also + if (I2cValidRead8(&intf, mcp230xx_address, MCP230xx_INTF+1)) { + if (intf > 0) { + if (I2cValidRead8(&mcp230xx_intcap, mcp230xx_address, MCP230xx_INTCAP+1)) { + for (uint8_t intp = 0; intp < 8; intp++) { + if ((intf >> intp) & 0x01) { // we know which pin caused interrupt + report_int = 0; + if (Settings.mcp230xx_config[intp+8].intmode) { // change on INT + if (((mcp230xx_intcap >> intp) & 0x01) == Settings.mcp230xx_config[intp+8].intcomp) report_int = 1; + } else { + report_int = 1; + } + if (report_int) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str()); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"MCP230XX_INT\":{\"Pin\":\"D%i\", \"State\":%i}"), mqtt_data, intp+8, ((mcp230xx_intcap >> intp) & 0x01)); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data); + MqttPublishPrefixTopic_P(RESULT_OR_STAT, mqtt_data); + } + } + } + } + } + } + } +} + +void MCP230xx_Show(boolean json) +{ + if (mcp230xx_type) { + if (json) { + if (mcp230xx_type == 1) { + uint8_t gpio = MCP230xx_readGPIO(0); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"MCP23008\":{\"D0\":%i,\"D1\":%i,\"D2\":%i,\"D3\":%i,\"D4\":%i,\"D5\":%i,\"D6\":%i,\"D7\":%i}"), + mqtt_data,(gpio>>0)&1,(gpio>>1)&1,(gpio>>2)&1,(gpio>>3)&1,(gpio>>4)&1,(gpio>>5)&1,(gpio>>6)&1,(gpio>>7)&1); + } + if (mcp230xx_type == 2) { + uint8_t gpio1 = MCP230xx_readGPIO(0); + uint8_t gpio2 = MCP230xx_readGPIO(1); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"MCP23017\":{\"D0\":%i,\"D1\":%i,\"D2\":%i,\"D3\":%i,\"D4\":%i,\"D5\":%i,\"D6\":%i,\"D7\":%i,\"D8\":%i,\"D9\":%i,\"D10\":%i,\"D11\":%i,\"D12\":%i,\"D13\":%i,\"D14\":%i,\"D15\":%i}"), + mqtt_data, (gpio1>>0)&1,(gpio1>>1)&1,(gpio1>>2)&1,(gpio1>>3)&1,(gpio1>>4)&1,(gpio1>>5)&1,(gpio1>>6)&1,(gpio1>>7)&1,(gpio2>>0)&1,(gpio2>>1)&1,(gpio2>>2)&1,(gpio2>>3)&1,(gpio2>>4)&1,(gpio2>>5)&1,(gpio2>>6)&1,(gpio2>>7)&1); + } + +#ifdef USE_WEBSERVER +#ifdef USE_MCP230xx_displaymain + } else { + uint8_t gpio1 = MCP230xx_readGPIO(0); + uint8_t gpio2 = 0; + if (mcp230xx_type == 2) { + gpio2=MCP230xx_readGPIO(1); + } + uint16_t gpio = (gpio2 << 8) + gpio1; + + for (uint8_t pin = 0; pin < mcp280xx_pincount; pin++) { + if (Settings.mcp230xx_config[pin].enable) { + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_MCP230xx_GPIO, mqtt_data, pin, (gpio>>pin)&1); + } + } +#endif // USE_MCP230xx_displaymain +#endif // USE_WEBSERVER + } + } +} + +bool MCP230xx_Command(void) { + boolean serviced = true; + uint8_t _a, _b = 0; + uint8_t pin, pinmode, pullup = 0; + String data = XdrvMailbox.data; + _a = data.indexOf(","); + _b = data.indexOf(",", _a + 1); + if (_a < XdrvMailbox.data_len) { + if (_b < XdrvMailbox.data_len) { + pin = data.substring(0, _a).toInt(); + pinmode = data.substring(_a+1, _b).toInt(); + pullup = data.substring(_b+1, XdrvMailbox.data_len).toInt(); + if (pinmode) { + Settings.mcp230xx_config[pin].enable = 1; + if (pinmode >= 2) { + Settings.mcp230xx_config[pin].inten = 1; + if (pinmode >= 3) { + Settings.mcp230xx_config[pin].intmode = 1; + if (pinmode >= 4) { + Settings.mcp230xx_config[pin].intcomp = 1; + } else { + Settings.mcp230xx_config[pin].intcomp = 0; + } + } else { + Settings.mcp230xx_config[pin].intmode = 0; + Settings.mcp230xx_config[pin].intcomp = 0; + } + } else { + Settings.mcp230xx_config[pin].inten = 0; + Settings.mcp230xx_config[pin].intmode = 0; + Settings.mcp230xx_config[pin].intcomp = 0; + } + } else { + Settings.mcp230xx_config[pin].enable = 0; + Settings.mcp230xx_config[pin].inten = 0; + Settings.mcp230xx_config[pin].intmode = 0; + Settings.mcp230xx_config[pin].intcomp = 0; + } + Settings.mcp230xx_config[pin].b5 = 0; + Settings.mcp230xx_config[pin].b6 = 0; + Settings.mcp230xx_config[pin].b7 = 0; + if (Settings.mcp230xx_config[pin].enable) { + Settings.mcp230xx_config[pin].pullup = pullup; + } else { + Settings.mcp230xx_config[pin].pullup = 0; + } + MCP230xx_ApplySettings(); + snprintf_P(mqtt_data, sizeof(mqtt_data), MCP230XX_SENSOR_RESPONSE,pin,pinmode,pullup); + } else { + serviced = false; + } + } else { + serviced = false; + } + return serviced; +} + +/*********************************************************************************************\ + Interface + \*********************************************************************************************/ + +boolean Xsns29(byte function) +{ + boolean result = false; + + if (i2c_flg) { + switch (function) { + case FUNC_PREP_BEFORE_TELEPERIOD: + MCP230xx_Detect(); + break; + case FUNC_EVERY_50_MSECOND: + MCP230xx_CheckForInterrupt(); + break; + case FUNC_JSON_APPEND: + MCP230xx_Show(1); + break; + case FUNC_COMMAND: + if (XSNS_29 == XdrvMailbox.index) { + result = MCP230xx_Command(); + } + break; +#ifdef USE_WEBSERVER +#ifdef USE_MCP230xx_displaymain + case FUNC_WEB_APPEND: + MCP230xx_Show(0); + break; +#endif // USE_MCP230xx_displaymain +#endif // USE_WEBSERVER + } + } + return result; +} + +#endif // USE_MCP230xx +#endif // USE_I2C diff --git a/sonoff/xsns_interface.ino b/sonoff/xsns_interface.ino index 19cd86bb3..7c18fa723 100644 --- a/sonoff/xsns_interface.ino +++ b/sonoff/xsns_interface.ino @@ -146,6 +146,38 @@ boolean (* const xsns_func_ptr[])(byte) PROGMEM = { // Sensor Function Pointers &Xsns32, #endif +#ifdef XSNS_33 + &Xsns33, +#endif + +#ifdef XSNS_34 + &Xsns34, +#endif + +#ifdef XSNS_35 + &Xsns35, +#endif + +#ifdef XSNS_36 + &Xsns36, +#endif + +#ifdef XSNS_37 + &Xsns37, +#endif + +#ifdef XSNS_38 + &Xsns38, +#endif + +#ifdef XSNS_39 + &Xsns39, +#endif + +#ifdef XSNS_40 + &Xsns40, +#endif + // Optional user defined sensors in range 91 - 99 #ifdef XSNS_91 @@ -217,10 +249,40 @@ boolean XsnsCall(byte Function) { boolean result = false; +#ifdef PROFILE_XSNS_EVERY_SECOND + uint32_t profile_start_millis = millis(); +#endif // PROFILE_XSNS_EVERY_SECOND + for (byte x = 0; x < xsns_present; x++) { + +#ifdef PROFILE_XSNS_SENSOR_EVERY_SECOND + uint32_t profile_start_millis = millis(); +#endif // PROFILE_XSNS_SENSOR_EVERY_SECOND + result = xsns_func_ptr[x](Function); + +#ifdef PROFILE_XSNS_SENSOR_EVERY_SECOND + uint32_t profile_millis = millis() - profile_start_millis; + if (profile_millis) { + if (FUNC_EVERY_SECOND == Function) { + snprintf_P(log_data, sizeof(log_data), PSTR("PRF: At %08u XsnsCall %d to Sensor %d took %u mS"), uptime, Function, x, profile_millis); + AddLog(LOG_LEVEL_DEBUG); + } + } +#endif // PROFILE_XSNS_SENSOR_EVERY_SECOND + if (result) break; } +#ifdef PROFILE_XSNS_EVERY_SECOND + uint32_t profile_millis = millis() - profile_start_millis; + if (profile_millis) { + if (FUNC_EVERY_SECOND == Function) { + snprintf_P(log_data, sizeof(log_data), PSTR("PRF: At %08u XsnsCall %d took %u mS"), uptime, Function, profile_millis); + AddLog(LOG_LEVEL_DEBUG); + } + } +#endif // PROFILE_XSNS_EVERY_SECOND + return result; } diff --git a/tools/decode-status.py b/tools/decode-status.py index 0e3ae1bd0..60f69853d 100644 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -79,7 +79,8 @@ a_setoption = [ "KNX enhancement", "RF receive decimal", "IR receive decimal", - "Enforce HASS light group",""] + "Enforce HASS light group", + "Do not show Wifi and Mqtt state using Led"] a_features = [[ "","","USE_I2C","USE_SPI", @@ -89,7 +90,7 @@ a_features = [[ "USE_WS2812_DMA","USE_IR_REMOTE","USE_IR_HVAC","USE_IR_RECEIVE", "USE_DOMOTICZ","USE_DISPLAY","USE_HOME_ASSISTANT","USE_SERIAL_BRIDGE", "USE_TIMERS","USE_SUNRISE","USE_TIMERS_WEB","USE_RULES", - "USE_KNX","","","" + "USE_KNX","USE_WPS","USE_SMARTCONFIG","" ],[ "USE_CONFIG_OVERRIDE","BE_MINIMAL","USE_ALL_SENSORS","USE_CLASSIC", "USE_KNX_NO_EMULATION","","","",