diff --git a/CHANGELOG.md b/CHANGELOG.md index 688b3968..b41f4a4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,23 +3,64 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [Unreleased] +## [1.4.2] 2017-01-09 +### Fixed +- Fixed error in relay identification from MQTT messages (issue #31) + +## [1.4.1] 2017-01-05 +### Added +- Alexa support by default on all devices +- Added support for Wemos D1 Mini board with official Relay Shield + +### Fixed +- Multi-packet websocket frames + +## [1.4.0] 2016-12-31 +### Added +- Domoticz support via MQTT (https://www.domoticz.com/wiki/MQTT) +- Support for static IP connections + +### Fixed +- Enforce minimum password strength in web interface (#16) + +### Changed +- Using default client_id provided by AsyncMqttClient +- Allow up to 5 different WIFI networks + +### Removed +- File system version file + +## [1.3.1] 2016-12-31 +### Fixed +- data_dir fix for PlatformIO + +## [1.3.0] 2016-12-30 +### Changed +- Arduino IDE support (changes in the folder structure and documentation) + +## [1.2.0] 2016-12-27 ### Added -- Added last-modified header to static contents -- Added support for multi-button boards (SONOFF_4CH) +- Force password changing if it's the default one +- Added Last-Modified header to static contents +- Added DNS captive portal for AP mode +- Added support for Sonoff 4CH - Added support for WorkChoice ecoPlug (ECOPLUG). Thanks to David Myers - Added support for Sonoff SV -- Added DNS captive portal for AP mode -- Force password changing if it's the default one +- Added support for Sonoff Touch - Comment out hardware selection in hardware.h if using Arduino IDE +- Added support for MQTT get/set suffixes (/status, /set, ...) +- Added support for LED notifications via MQTT +- Added EEPROM check commands to terminal interface ### Changed - Using unreleased AsyncMqttClient with stability improvements - Better decoupling between MQTT and relays/websockets +- Skipping retained MQTT messages (configurable) ### Fixed -- Issue #14 MQTT Connection with Username an Password not working - Issue #11 Compile error when building sonoff-dual-debug +- Issue #14 MQTT Connection with Username an Password not working +- Issue #17 Moved static variable 'pending' to class variable ## [1.1.0] 2016-12-06 ### Added @@ -105,8 +146,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Moving wifi management to library (JustWifi) - -### Changed - Split code into modules ## [0.9.6] 2016-08-12 diff --git a/README.md b/README.md index 561c41b5..4a9031c3 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,50 @@ -# ESPurna +# ESPurna Firmware -ESPurna ("spark" in Catalan) is a custom C firmware for ESP8266 based smart switches. -It was originally developed with the **[ITead Sonoff][1]** in mind but now it supports a growing number of ESP8266-based boards. +ESPurna ("spark" in Catalan) is a custom firmware for ESP8266 based smart switches. +It was originally developed with the **[IteadStudio Sonoff](https://www.itead.cc/sonoff-wifi-wireless-switch.html)** in mind but now it supports a growing number of ESP8266-based boards. +It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. + +**Current Release Version is 1.4.2**, read the [changelog](CHANGELOG.md). ## Features -* **Asynchronous WebServer for configuration** and simple relay toggle with **basic authentication** -* Communication between webserver and webclient via **websockets** with secure ticket check -* **Flashing firmware Over-The-Air** (OTA) -* Up to **3 configurable WIFI networks**, connects to the strongest signal -* **MQTT support** with configurable host and topic -* **REST API** to query and set relay statuses -* Support for **multi-relay boards** (Sonoff Dual, Electrodragon ESP Relay Board,...) -* Manual switch ON/OFF with button (single click the button) -* AP mode backup (double click the button) -* Manual reset the board (long click the button) -* Visual status of the connection via the LED -* **Alexa** integration (Amazon Echo or Dot) by emulating a Belkin WeMo switch -* Support for **automatic over-the-air updates** through the [NoFUSS Library][2] -* Support for **DHT22** and **DS18B20** sensors -* Support for the **HLW8012** power sensor present in the Sonoff POW -* Support for **current monitoring** through the [EmonLiteESP Library][3] using a non-intrusive current sensor ([requires some hacking][4]) -* Command line configuration - -## Index - -* [Supported hardware](docs/Hardware.md) -* [Build and flash the firmware](docs/Firmware.md) -* [Build and flash the filesystem](docs/Filesystem.md) -* [Configuration](docs/Configuration.md) -* [Over-the-air updates](docs/OTA.md) -* [Sensors](docs/Sensors.md) -* [Troubleshooting](docs/Troubleshooting.md) +* Support for **multiple ESP8266-based boards** ([check list](#supported-hardware)) +* Wifi **AP Mode** or **STA mode** with **multiple network definitions** and static IP support +* **MQTT** enabled + * Switch on/off and toggle relays + * LED notifications +* Support for different **sensors** + * DHT11 / DHT22 / DHT21 / AM2301 + * DS18B20 + * HLW8012 (Sonoff POW) + * Non-invasive current sensor using the [EmonLiteESP Library](https://bitbucket.org/xoseperez/emonliteesp) (requires some hacking) +* Fast asynchronous **HTTP Server** + * Basic authentication + * Web-based configuration + * Relay switching from the web + * Websockets-based communication between the device and the browser +* **REST API** + * GET and PUT relay status +* **Command line configuration** +* **Over-The-Air** (OTA) updates even for 1Mb boards + * Manually from PlatformIO or Arduino Inside + * Automatic updates through the [NoFUSS Library](https://bitbucket.org/xoseperez/nofuss) +* **Alexa** integration using the [FauxmoESP Library](https://bitbucket.org/xoseperez/fauxmoesp) +* [**Domoticz**](https://domoticz.com/) integration via MQTT + +## Documentation + +For more information please refer to the [ESPurna Wiki](https://bitbucket.org/xoseperez/espurna/wiki/Home). + + +## Supported hardware + +|![IteadStudio S20](images/devices/s20.jpg) **IteadStudio S20**|![IteadStudio Slampher](images/devices/slampher.jpg) **IteadStudio Slampher**|![IteadStudio Sonoff 4CH](images/devices/sonoff-4ch.jpg) **IteadStudio Sonoff 4CH**| +|![IteadStudio Sonoff Basic](images/devices/sonoff-basic.jpg) **IteadStudio Sonoff Basic**|![IteadStudio Motor Switch](images/devices/motor-switch.jpg) **IteadStudio Motor Switch**|![IteadStudio 1CH Inching](images/devices/1ch-inching.jpg) **IteadStudio 1CH Inching**| +|![IteadStudio Sonoff Dual](images/devices/sonoff-dual.jpg) **IteadStudio Sonoff Dual**|![IteadStudio Sonoff POW](images/devices/sonoff-pow.jpg) **IteadStudio Sonoff POW**|![IteadStudio Sonoff TH10/TH16](images/devices/sonoff-th10-th16.jpg) **IteadStudio Sonoff TH10/TH16**| +|![IteadStudio Sonoff RF](images/devices/sonoff-rf.jpg) **IteadStudio Sonoff RF**|![IteadStudio Sonoff SV](images/devices/sonoff-sv.jpg) **IteadStudio Sonoff SV**|![IteadStudio Sonoff Touch](images/devices/sonoff-touch.jpg) **IteadStudio Sonoff Touch**| +|![Wemos D1 Mini Relay Shield](images/devices/d1mini.jpg) **Wemos D1 Mini Relay Shield**|![Electrodragon Relay Board](images/devices/electrodragon-relay-board.jpg) **Electrodragon Relay Board**|![WorkChoice EcoPlug](images/devices/workchoice-ecoplug.jpg) **WorkChoice EcoPlug**| + ## License @@ -49,9 +62,3 @@ 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 . - - -[1]: https://www.itead.cc/sonoff-wifi-wireless-switch.html -[2]: https://bitbucket.org/xoseperez/nofuss -[3]: https://bitbucket.org/xoseperez/emonliteesp -[4]: http://tinkerman.cat/your-laundry-is-done/ diff --git a/code/build-all b/code/build-all index 9a7cfec2..3581c6a1 100755 --- a/code/build-all +++ b/code/build-all @@ -1,13 +1,10 @@ #!/bin/bash -mv platformio.ini platformio.backup -cp platformio.custom.ini platformio.ini - # Environments to build -ENVIRONMENTS="sonoff-debug sonoff-dht22-debug sonoff-ds18b20-debug s20-debug sonoff-pow-debug slampher-debug" +ENVIRONMENTS="sonoff-debug sonoff-dht22-debug sonoff-ds18b20-debug sonoff-pow-debug sonoff-dual-debug sonoff-4ch-debug electrodragon-debug ecoplug-debug" # Get current version -version=`cat src/config/version.h | grep APP_VERSION | awk '{print $3}' | sed 's/"//g'` +version=`cat espurna/config/version.h | grep APP_VERSION | awk '{print $3}' | sed 's/"//g'` echo $version # Create output folder @@ -15,11 +12,9 @@ mkdir -p firmware # Build all the required firmwares for environment in $ENVIRONMENTS; do - platformio run -vv -e $environment + platformio run -e $environment mv .pioenvs/$environment/firmware.bin firmware/espurna-$version-$environment.bin done platformio run -vv -t uploadfs -e node-debug mv .pioenvs/node-debug/spiffs.bin firmware/espurna-$version-spiffs.bin - -mv platformio.backup platformio.ini diff --git a/code/data/fsversion b/code/data/fsversion deleted file mode 100644 index 9084fa2f..00000000 --- a/code/data/fsversion +++ /dev/null @@ -1 +0,0 @@ -1.1.0 diff --git a/code/data/index.html.gz b/code/data/index.html.gz deleted file mode 100644 index 42bf102c..00000000 Binary files a/code/data/index.html.gz and /dev/null differ diff --git a/code/data/script.js.gz b/code/data/script.js.gz deleted file mode 100644 index 046d536b..00000000 Binary files a/code/data/script.js.gz and /dev/null differ diff --git a/code/data/style.css.gz b/code/data/style.css.gz deleted file mode 100644 index 1ed7c596..00000000 Binary files a/code/data/style.css.gz and /dev/null differ diff --git a/code/src/button.ino b/code/espurna/button.ino similarity index 100% rename from code/src/button.ino rename to code/espurna/button.ino diff --git a/code/src/config/all.h b/code/espurna/config/all.h similarity index 100% rename from code/src/config/all.h rename to code/espurna/config/all.h diff --git a/code/src/config/debug.h b/code/espurna/config/debug.h similarity index 100% rename from code/src/config/debug.h rename to code/espurna/config/debug.h diff --git a/code/src/config/general.h b/code/espurna/config/general.h similarity index 89% rename from code/src/config/general.h rename to code/espurna/config/general.h index cfb4338b..c8d0fdad 100644 --- a/code/src/config/general.h +++ b/code/espurna/config/general.h @@ -6,7 +6,6 @@ #define HOSTNAME DEVICE #define BUFFER_SIZE 1024 #define HEARTBEAT_INTERVAL 300000 -#define FS_VERSION_FILE "/fsversion" //-------------------------------------------------------------------------------- // RELAY @@ -51,7 +50,7 @@ // ----------------------------------------------------------------------------- #define WIFI_RECONNECT_INTERVAL 300000 -#define WIFI_MAX_NETWORKS 3 +#define WIFI_MAX_NETWORKS 5 #define ADMIN_PASS "fibonacci" #define HTTP_USERNAME "admin" #define WS_BUFFER_SIZE 5 @@ -77,6 +76,8 @@ #define MQTT_QOS 0 #define MQTT_KEEPALIVE 30 #define MQTT_RECONNECT_DELAY 10000 +#define MQTT_SKIP_RETAINED 1 +#define MQTT_SKIP_TIME 1000 #define MQTT_RELAY_TOPIC "/relay" #define MQTT_LED_TOPIC "/led" #define MQTT_IP_TOPIC "/ip" @@ -94,6 +95,14 @@ #define MQTT_USE_SETTER "" +// ----------------------------------------------------------------------------- +// DOMOTICZ +// ----------------------------------------------------------------------------- + +#define ENABLE_DOMOTICZ 1 +#define DOMOTICZ_IN_TOPIC "domoticz/in" +#define DOMOTICZ_OUT_TOPIC "domoticz/out" + // ----------------------------------------------------------------------------- // NTP // ----------------------------------------------------------------------------- @@ -107,4 +116,4 @@ // FAUXO // ----------------------------------------------------------------------------- -#define FAUXMO_ENABLED 0 +#define FAUXMO_ENABLED 1 diff --git a/code/src/config/hardware.h b/code/espurna/config/hardware.h similarity index 85% rename from code/src/config/hardware.h rename to code/espurna/config/hardware.h index a67a7261..f5f67cf8 100644 --- a/code/src/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -7,12 +7,12 @@ //#define NODEMCUV2 //#define SONOFF //#define SONOFF_TH +//#define SLAMPHER +//#define S20 +//#define SONOFF_SV //#define SONOFF_POW //#define SONOFF_DUAL //#define SONOFF_4CH -//#define SONOFF_SV -//#define SLAMPHER -//#define S20 //#define ESP_RELAY_BOARD //#define ECOPLUG //#define ESPURNA @@ -22,11 +22,15 @@ //#define ENABLE_EMON 1 //#define ENABLE_HLW8018 1 //#define ENABLE_RF 1 -//#define ENABLE_FAUXMO 1 +//#define ENABLE_FAUXMO 0 //#define ENABLE_NOFUSS 1 +#ifndef ENABLE_FAUXMO + #define ENABLE_FAUXMO 1 +#endif + // ----------------------------------------------------------------------------- -// NODEMCUv2 development board +// Development boards // ----------------------------------------------------------------------------- #if defined(NODEMCUV2) @@ -35,6 +39,16 @@ #define DEVICE "LOLIN" #define BUTTON1_PIN 0 #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 + #define LED1_PIN 2 + #define LED1_PIN_INVERSE 1 + +#elif defined(D1_RELAYSHIELD) + + #define MANUFACTURER "WEMOS" + #define DEVICE "D1_MINI" + #define RELAY1_PIN 5 + #define RELAY1_PIN_INVERSE 0 #define LED1_PIN 2 #define LED1_PIN_INVERSE 1 @@ -48,6 +62,7 @@ #define DEVICE "SONOFF" #define BUTTON1_PIN 0 #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 #define LED1_PIN 13 #define LED1_PIN_INVERSE 1 @@ -57,6 +72,37 @@ #define DEVICE "SONOFF_TH" #define BUTTON1_PIN 0 #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 + #define LED1_PIN 13 + #define LED1_PIN_INVERSE 1 + +#elif defined(SONOFF_SV) + + #define MANUFACTURER "ITEAD" + #define DEVICE "SONOFF_SV" + #define BUTTON1_PIN 0 + #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 + #define LED1_PIN 13 + #define LED1_PIN_INVERSE 1 + +#elif defined(SLAMPHER) + + #define MANUFACTURER "ITEAD" + #define DEVICE "SLAMPHER" + #define BUTTON1_PIN 0 + #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 + #define LED1_PIN 13 + #define LED1_PIN_INVERSE 1 + +#elif defined(S20) + + #define MANUFACTURER "ITEAD" + #define DEVICE "S20" + #define BUTTON1_PIN 0 + #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 #define LED1_PIN 13 #define LED1_PIN_INVERSE 1 @@ -66,6 +112,7 @@ #define DEVICE "SONOFF_TOUCH" #define BUTTON1_PIN 0 #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 #define LED1_PIN 13 #define LED1_PIN_INVERSE 1 @@ -75,6 +122,7 @@ #define DEVICE "SONOFF_POW" #define BUTTON1_PIN 0 #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 #define LED1_PIN 15 #define LED1_PIN_INVERSE 0 #define ENABLE_POW 1 @@ -98,36 +146,13 @@ #define BUTTON3_PIN 10 #define BUTTON4_PIN 14 #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 #define RELAY2_PIN 5 + #define RELAY2_PIN_INVERSE 0 #define RELAY3_PIN 4 + #define RELAY3_PIN_INVERSE 0 #define RELAY4_PIN 15 - #define LED1_PIN 13 - #define LED1_PIN_INVERSE 1 - -#elif defined(SONOFF_SV) - - #define MANUFACTURER "ITEAD" - #define DEVICE "SONOFF_SV" - #define BUTTON1_PIN 0 - #define RELAY1_PIN 12 - #define LED1_PIN 13 - #define LED1_PIN_INVERSE 1 - -#elif defined(SLAMPHER) - - #define MANUFACTURER "ITEAD" - #define DEVICE "SLAMPHER" - #define BUTTON1_PIN 0 - #define RELAY1_PIN 12 - #define LED1_PIN 13 - #define LED1_PIN_INVERSE 1 - -#elif defined(S20) - - #define MANUFACTURER "ITEAD" - #define DEVICE "S20" - #define BUTTON1_PIN 0 - #define RELAY1_PIN 12 + #define RELAY4_PIN_INVERSE 0 #define LED1_PIN 13 #define LED1_PIN_INVERSE 1 @@ -153,7 +178,9 @@ #define BUTTON1_PIN 0 #define BUTTON2_PIN 2 #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 #define RELAY2_PIN 13 + #define RELAY2_PIN_INVERSE 0 #define LED1_PIN 16 #define LED1_PIN_INVERSE 0 @@ -166,7 +193,8 @@ #define MANUFACTURER "WORKCHOICE" #define DEVICE "ECOPLUG" #define BUTTON1_PIN 13 - #define RELAY_PIN 15 + #define RELAY1_PIN 15 + #define RELAY1_PIN_INVERSE 0 #define LED1_PIN 2 #define LED1_PIN_INVERSE 0 @@ -180,6 +208,7 @@ #define DEVICE "ESPURNA" #define BUTTON1_PIN 0 #define RELAY1_PIN 12 + #define RELAY1_PIN_INVERSE 0 #define LED1_PIN 13 #define LED1_PIN_INVERSE 0 diff --git a/code/src/config/sensors.h b/code/espurna/config/sensors.h similarity index 100% rename from code/src/config/sensors.h rename to code/espurna/config/sensors.h diff --git a/code/src/config/version.h b/code/espurna/config/version.h similarity index 79% rename from code/src/config/version.h rename to code/espurna/config/version.h index f49016c7..448d7a24 100644 --- a/code/src/config/version.h +++ b/code/espurna/config/version.h @@ -1,4 +1,4 @@ #define APP_NAME "ESPurna" -#define APP_VERSION "1.2.0" +#define APP_VERSION "1.4.2" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" diff --git a/code/data/favicon.ico b/code/espurna/data/favicon.ico similarity index 100% rename from code/data/favicon.ico rename to code/espurna/data/favicon.ico diff --git a/code/data/images/check.png b/code/espurna/data/images/check.png similarity index 100% rename from code/data/images/check.png rename to code/espurna/data/images/check.png diff --git a/code/espurna/data/index.html.gz b/code/espurna/data/index.html.gz new file mode 100644 index 00000000..2e18235d Binary files /dev/null and b/code/espurna/data/index.html.gz differ diff --git a/code/data/password.html.gz b/code/espurna/data/password.html.gz similarity index 100% rename from code/data/password.html.gz rename to code/espurna/data/password.html.gz diff --git a/code/espurna/data/script.js.gz b/code/espurna/data/script.js.gz new file mode 100644 index 00000000..777cb053 Binary files /dev/null and b/code/espurna/data/script.js.gz differ diff --git a/code/espurna/data/style.css.gz b/code/espurna/data/style.css.gz new file mode 100644 index 00000000..c6e249dc Binary files /dev/null and b/code/espurna/data/style.css.gz differ diff --git a/code/src/dht.ino b/code/espurna/dht.ino similarity index 88% rename from code/src/dht.ino rename to code/espurna/dht.ino index 5dd07492..4da26661 100644 --- a/code/src/dht.ino +++ b/code/espurna/dht.ino @@ -60,8 +60,8 @@ void dhtLoop() { DEBUG_MSG("[DHT] Humidity: %s\n", dhtHumidity); // Send MQTT messages - mqttSend((char *) getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), dhtTemperature); - mqttSend((char *) getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), dhtHumidity); + mqttSend(getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), dhtTemperature); + mqttSend(getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), dhtHumidity); // Update websocket clients char buffer[100]; diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino new file mode 100644 index 00000000..be9b4e59 --- /dev/null +++ b/code/espurna/domoticz.ino @@ -0,0 +1,78 @@ +/* + +ESPurna +DOMOTICZ MODULE + +Copyright (C) 2016 by Xose Pérez + +*/ + +#if ENABLE_DOMOTICZ + +#include +#include + +void domoticzMQTTCallback(unsigned int type, const char * topic, const char * payload) { + + String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); + + if (type == MQTT_CONNECT_EVENT) { + mqttSubscribeRaw(dczTopicOut.c_str()); + } + + if (type == MQTT_MESSAGE_EVENT) { + + // Check topic + if (dczTopicOut.equals(topic)) { + + // Parse response + DynamicJsonBuffer jsonBuffer; + JsonObject& root = jsonBuffer.parseObject((char *) payload); + if (!root.success()) { + DEBUG_MSG("[DOMOTICZ] Error parsing data\n"); + return; + } + + // IDX + unsigned long idx = root["idx"]; + int relayID = domoticzRelay(idx); + if (relayID >= 0) { + unsigned long value = root["nvalue"]; + DEBUG_MSG("[DOMOTICZ] Received value %d for IDX %d\n", value, idx); + relayStatus(relayID, value == 1); + } + + } + + } + +} + +int domoticzIdx(unsigned int relayID) { + return getSetting("dczIdx" + String(relayID)).toInt(); +} + +int domoticzRelay(unsigned int idx) { + for (int relayID=0; relayID 0) { + unsigned int value = relayStatus(relayID) ? 1 : 0; + char payload[45]; + sprintf(payload, "{\"idx\": %d, \"nvalue\": %d, \"svalue\": \"\"}", idx, value); + mqttSendRaw(getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC).c_str(), payload); + } +} + +void domoticzSetup() { + mqttRegister(domoticzMQTTCallback); +} + +#endif diff --git a/code/src/ds18b20.ino b/code/espurna/ds18b20.ino similarity index 93% rename from code/src/ds18b20.ino rename to code/espurna/ds18b20.ino index 02ecdd0f..7ea03cf1 100644 --- a/code/src/ds18b20.ino +++ b/code/espurna/ds18b20.ino @@ -54,7 +54,7 @@ void dsLoop() { DEBUG_MSG("[DS18B20] Temperature: %s\n", dsTemperature); // Send MQTT messages - mqttSend((char *) getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), dsTemperature); + mqttSend(getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), dsTemperature); // Update websocket clients char buffer[100]; diff --git a/code/src/emon.ino b/code/espurna/emon.ino similarity index 96% rename from code/src/emon.ino rename to code/espurna/emon.ino index 7a85ba0a..7bb21e20 100644 --- a/code/src/emon.ino +++ b/code/espurna/emon.ino @@ -104,7 +104,7 @@ void powerMonitorLoop() { if (measurements == EMON_MEASUREMENTS) { double p = (sum - max - min) * mainsVoltage / (measurements - 2); sprintf(power, "%d", int(p)); - mqttSend((char *) getSetting("emonPowerTopic", EMON_POWER_TOPIC).c_str(), power); + mqttSend(getSetting("emonPowerTopic", EMON_POWER_TOPIC).c_str(), power); sum = 0; measurements = 0; } diff --git a/code/src/main.ino b/code/espurna/espurna.ino similarity index 92% rename from code/src/main.ino rename to code/espurna/espurna.ino index 8019104d..e91a6d30 100644 --- a/code/src/main.ino +++ b/code/espurna/espurna.ino @@ -28,7 +28,7 @@ along with this program. If not, see . #include #include #include -#include "FS.h" + void mqttRegister(void (*callback)(unsigned int, const char *, const char *)); template bool setSetting(const String& key, T value); template String getSetting(const String& key, T defaultValue); @@ -48,18 +48,6 @@ void hardwareSetup() { SPIFFS.begin(); } -void getFSVersion(char * buffer) { - File h = SPIFFS.open(FS_VERSION_FILE, "r"); - if (!h) { - DEBUG_MSG("[SPIFFS] Could not open file system version file.\n"); - strcpy(buffer, APP_VERSION); - return; - } - size_t size = h.size(); - h.readBytes(buffer, size - 1); - h.close(); -} - void hardwareLoop() { // Heartbeat @@ -67,7 +55,7 @@ void hardwareLoop() { if (mqttConnected()) { if ((millis() - last_heartbeat > HEARTBEAT_INTERVAL) || (last_heartbeat == 0)) { last_heartbeat = millis(); - mqttSend((char *) MQTT_HEARTBEAT_TOPIC, (char *) "1"); + mqttSend(MQTT_HEARTBEAT_TOPIC, "1"); DEBUG_MSG("[BEAT] Free heap: %d\n", ESP.getFreeHeap()); DEBUG_MSG("[NTP] Time: %s\n", (char *) NTP.getTimeDateString().c_str()); } @@ -125,6 +113,9 @@ void setup() { webSetup(); ntpSetup(); + #if ENABLE_DOMOTICZ + domoticzSetup(); + #endif #if ENABLE_FAUXMO fauxmoSetup(); #endif @@ -159,6 +150,9 @@ void loop() { mqttLoop(); ntpLoop(); + #if ENABLE_FAUXMO + fauxmoLoop(); + #endif #ifndef SONOFF_DUAL settingsLoop(); #endif diff --git a/code/src/fauxmo.ino b/code/espurna/fauxmo.ino similarity index 78% rename from code/src/fauxmo.ino rename to code/espurna/fauxmo.ino index 1d131892..939f1e94 100644 --- a/code/src/fauxmo.ino +++ b/code/espurna/fauxmo.ino @@ -32,15 +32,14 @@ void fauxmoSetup() { fauxmo.addDevice((hostname + "_" + i).c_str()); } } - fauxmo.onMessage([relays](const char * name, bool state) { + fauxmo.onMessage([relays](unsigned char device_id, const char * name, bool state) { DEBUG_MSG("[FAUXMO] %s state: %s\n", name, state ? "ON" : "OFF"); - unsigned int id = 0; - if (relays > 1) { - id = name[strlen(name)-1] - '0'; - if (id >= relays) id = 0; - } - relayStatus(id, state); + relayStatus(device_id, state); }); } +void fauxmoLoop() { + fauxmo.handle(); +} + #endif diff --git a/code/src/led.ino b/code/espurna/led.ino similarity index 86% rename from code/src/led.ino rename to code/espurna/led.ino index 6a4a06a2..24d14ed8 100644 --- a/code/src/led.ino +++ b/code/espurna/led.ino @@ -22,25 +22,25 @@ std::vector _leds; bool ledAuto; bool ledStatus(unsigned char id) { - if (id <= _leds.size()) return false; + if (id >= _leds.size()) return false; bool status = digitalRead(_leds[id].pin); return _leds[id].reverse ? !status : status; } bool ledStatus(unsigned char id, bool status) { - if (id <= _leds.size()) return false; + if (id >= _leds.size()) return false; bool s = _leds[id].reverse ? !status : status; digitalWrite(_leds[id].pin, _leds[id].reverse ? !status : status); return status; } bool ledToggle(unsigned char id) { - if (id <= _leds.size()) return false; + if (id >= _leds.size()) return false; return ledStatus(id, !ledStatus(id)); } void ledBlink(unsigned char id, unsigned long delayOff, unsigned long delayOn) { - if (id <= _leds.size()) return; + if (id >= _leds.size()) return; static unsigned long next = millis(); if (next < millis()) { next += (ledToggle(id) ? delayOn : delayOff); @@ -74,13 +74,16 @@ void ledMQTTCallback(unsigned int type, const char * topic, const char * payload if (type == MQTT_MESSAGE_EVENT) { // Match topic - String t = String(topic); + String t = String(topic + mqttTopicRootLength()); if (!t.startsWith(MQTT_LED_TOPIC)) return; if (!t.endsWith(mqttSetter)) return; // Get led ID - unsigned int ledID = topic[strlen(MQTT_LED_TOPIC)+1] - '0'; - if (ledID >= ledCount()) ledID = 0; + unsigned int ledID = topic[strlen(topic) - mqttSetter.length() - 1] - '0'; + if (ledID >= ledCount()) { + DEBUG_MSG("[LED] Wrong ledID (%d)\n", ledID); + return; + } // get value unsigned int value = (char)payload[0] - '0'; @@ -134,6 +137,7 @@ void ledSetup() { mqttRegister(ledMQTTCallback); DEBUG_MSG("[LED] Number of leds: %d\n", _leds.size()); + DEBUG_MSG("[LED] Led auto indicator is %s\n", ledAuto ? "ON" : "OFF" ); } diff --git a/code/src/mqtt.ino b/code/espurna/mqtt.ino similarity index 60% rename from code/src/mqtt.ino rename to code/espurna/mqtt.ino index d69b5d82..d47d5f58 100644 --- a/code/src/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -15,6 +15,9 @@ AsyncMqttClient mqtt; String mqttTopic; std::vector _mqtt_callbacks; +#if MQTT_SKIP_RETAINED + unsigned long mqttConnectedAt = 0; +#endif // ----------------------------------------------------------------------------- // MQTT @@ -34,17 +37,32 @@ void buildTopics() { mqttTopic.replace("{identifier}", getSetting("hostname")); } +unsigned int mqttTopicRootLength() { + return mqttTopic.length(); +} + +void mqttSendRaw(const char * topic, const char * message) { + if (mqtt.connected()) { + DEBUG_MSG("[MQTT] Sending %s %s\n", topic, message); + mqtt.publish(topic, MQTT_QOS, MQTT_RETAIN, message); + } +} + void mqttSend(const char * topic, const char * message) { - if (!mqtt.connected()) return; String path = mqttTopic + String(topic); - DEBUG_MSG("[MQTT] Sending %s %s\n", (char *) path.c_str(), message); - mqtt.publish(path.c_str(), MQTT_QOS, MQTT_RETAIN, message); + mqttSendRaw(path.c_str(), message); +} + +void mqttSubscribeRaw(const char * topic) { + if (mqtt.connected()) { + DEBUG_MSG("[MQTT] Subscribing to %s\n", topic); + mqtt.subscribe(topic, MQTT_QOS); + } } void mqttSubscribe(const char * topic) { String path = mqttTopic + String(topic); - DEBUG_MSG("[MQTT] Subscribing to %s\n", (char *) path.c_str()); - mqtt.subscribe(path.c_str(), MQTT_QOS); + mqttSubscribeRaw(path.c_str()); } void mqttRegister(void (*callback)(unsigned int, const char *, const char *)) { @@ -55,16 +73,17 @@ void _mqttOnConnect(bool sessionPresent) { DEBUG_MSG("[MQTT] Connected!\n"); + #if MQTT_SKIP_RETAINED + mqttConnectedAt = millis(); + #endif + // Build MQTT topics buildTopics(); mqtt.setWill((mqttTopic + MQTT_HEARTBEAT_TOPIC).c_str(), MQTT_QOS, MQTT_RETAIN, (char *) "0"); // Say hello and report our IP and VERSION - mqttSend((char *) MQTT_IP_TOPIC, (char *) getIP().c_str()); - mqttSend((char *) MQTT_VERSION_TOPIC, (char *) APP_VERSION); - char buffer[50]; - getFSVersion(buffer); - mqttSend((char *) MQTT_FSVERSION_TOPIC, buffer); + mqttSend(MQTT_IP_TOPIC, getIP().c_str()); + mqttSend(MQTT_VERSION_TOPIC, APP_VERSION); // Send connect event to subscribers for (unsigned char i = 0; i < _mqtt_callbacks.size(); i++) { @@ -86,12 +105,24 @@ void _mqttOnDisconnect(AsyncMqttClientDisconnectReason reason) { void _mqttOnMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) { - DEBUG_MSG("[MQTT] Received %s %c\n", topic, payload[0]); + char message[len+1]; + strlcpy(message, payload, len+1); + + DEBUG_MSG("[MQTT] Received %s => %s", topic, message); + + #if MQTT_SKIP_RETAINED + if (millis() - mqttConnectedAt < MQTT_SKIP_TIME) { + DEBUG_MSG(" - SKIPPED\n"); + return; + } + #endif + + DEBUG_MSG("\n"); // Send message event to subscribers // Topic is set to the specific part each one might be checking for (unsigned char i = 0; i < _mqtt_callbacks.size(); i++) { - (*_mqtt_callbacks[i])(MQTT_MESSAGE_EVENT, topic + mqttTopic.length(), payload); + (*_mqtt_callbacks[i])(MQTT_MESSAGE_EVENT, topic, message); } } @@ -100,32 +131,20 @@ void mqttConnect() { if (!mqtt.connected()) { - String host = getSetting("mqttServer", MQTT_SERVER); - String port = getSetting("mqttPort", MQTT_PORT); - String user = getSetting("mqttUser"); - String pass = getSetting("mqttPassword"); - - if (host.length() == 0) return; - - DEBUG_MSG("[MQTT] Connecting to broker at %s", (char *) host.c_str()); - - mqtt.setServer(host.c_str(), port.toInt()); - mqtt - .setKeepAlive(MQTT_KEEPALIVE) - .setCleanSession(false) - .setClientId(getSetting("hostname", HOSTNAME).c_str()); - - if ((user != "") && (pass != "")) { - DEBUG_MSG(" as user '%s'.\n", (char *) user.c_str()); - char username[user.length()+1]; - user.toCharArray(username, user.length()+1); - char password[pass.length()+1]; - pass.toCharArray(password, pass.length()+1); - mqtt.setCredentials(username, password); - } else { - DEBUG_MSG(" anonymously\n"); + char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str()); + if (strlen(host) == 0) return; + unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt(); + char * user = strdup(getSetting("mqttUser").c_str()); + char * pass = strdup(getSetting("mqttPassword").c_str()); + + DEBUG_MSG("[MQTT] Connecting to broker at %s", host); + mqtt.setServer(host, port); + mqtt.setKeepAlive(MQTT_KEEPALIVE).setCleanSession(false); + if ((strlen(user) > 0) && (strlen(pass) > 0)) { + DEBUG_MSG(" as user '%s'.", user); + mqtt.setCredentials(user, pass); } - + DEBUG_MSG("\n"); mqtt.connect(); } diff --git a/code/src/nofuss.ino b/code/espurna/nofuss.ino similarity index 100% rename from code/src/nofuss.ino rename to code/espurna/nofuss.ino diff --git a/code/src/ntp.ino b/code/espurna/ntp.ino similarity index 100% rename from code/src/ntp.ino rename to code/espurna/ntp.ino diff --git a/code/src/ota.ino b/code/espurna/ota.ino similarity index 100% rename from code/src/ota.ino rename to code/espurna/ota.ino diff --git a/code/src/pow.ino b/code/espurna/pow.ino similarity index 97% rename from code/src/pow.ino rename to code/espurna/pow.ino index 428838e5..bf820296 100644 --- a/code/src/pow.ino +++ b/code/espurna/pow.ino @@ -151,7 +151,7 @@ void powLoop() { wsSend(buffer); if (--report_count == 0) { - mqttSend((char *) getSetting("powPowerTopic", POW_POWER_TOPIC).c_str(), (char *) String(power).c_str()); + mqttSend(getSetting("powPowerTopic", POW_POWER_TOPIC).c_str(), String(power).c_str()); report_count = POW_REPORT_EVERY; } diff --git a/code/src/relay.ino b/code/espurna/relay.ino similarity index 87% rename from code/src/relay.ino rename to code/espurna/relay.ino index 1396f172..9e896cab 100644 --- a/code/src/relay.ino +++ b/code/espurna/relay.ino @@ -12,7 +12,11 @@ Copyright (C) 2016 by Xose Pérez #include #include -std::vector _relays; +typedef struct { + unsigned char pin; + bool reverse; +} relay_t; +std::vector _relays; bool recursive = false; #ifdef SONOFF_DUAL unsigned char dualRelayStatus = 0; @@ -28,7 +32,7 @@ void relayMQTT(unsigned char id) { String mqttGetter = getSetting("mqttGetter", MQTT_USE_GETTER); char buffer[strlen(MQTT_RELAY_TOPIC) + mqttGetter.length() + 3]; sprintf(buffer, "%s/%d%s", MQTT_RELAY_TOPIC, id, mqttGetter.c_str()); - mqttSend(buffer, (char *) (relayStatus(id) ? "1" : "0")); + mqttSend(buffer, relayStatus(id) ? "1" : "0"); } void relayMQTT() { @@ -60,7 +64,8 @@ bool relayStatus(unsigned char id) { return ((dualRelayStatus & (1 << id)) > 0); #else if (id >= _relays.size()) return false; - return (digitalRead(_relays[id]) == HIGH); + bool status = (digitalRead(_relays[id].pin) == HIGH); + return _relays[id].reverse ? !status : status; #endif } @@ -151,7 +156,7 @@ bool relayStatus(unsigned char id, bool status, bool report) { Serial.flush(); #else - digitalWrite(_relays[id], status); + digitalWrite(_relays[id].pin, _relays[id].reverse ? !status : status); #endif if (!recursive) { @@ -160,6 +165,10 @@ bool relayStatus(unsigned char id, bool status, bool report) { relaySave(); } + #ifdef ENABLE_DOMOTICZ + domoticzSend(id); + #endif + } if (report) relayMQTT(id); @@ -242,8 +251,6 @@ unsigned char relayCount() { void relayMQTTCallback(unsigned int type, const char * topic, const char * payload) { - static bool isFirstMessage = true; - String mqttSetter = getSetting("mqttSetter", MQTT_USE_SETTER); String mqttGetter = getSetting("mqttGetter", MQTT_USE_GETTER); bool sameSetGet = mqttGetter.compareTo(mqttSetter) == 0; @@ -264,7 +271,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo if (type == MQTT_MESSAGE_EVENT) { // Match topic - String t = String(topic); + String t = String(topic + mqttTopicRootLength()); if (!t.startsWith(MQTT_RELAY_TOPIC)) return; if (!t.endsWith(mqttSetter)) return; @@ -278,8 +285,11 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo } // Get relay ID - unsigned int relayID = topic[strlen(MQTT_RELAY_TOPIC)+1] - '0'; - if (relayID >= relayCount()) relayID = 0; + unsigned int relayID = topic[strlen(topic) - mqttSetter.length() - 1] - '0'; + if (relayID >= relayCount()) { + DEBUG_MSG("[RELAY] Wrong relayID (%d)\n", relayID); + return; + } // Action to perform if (value == 2) { @@ -297,22 +307,22 @@ void relaySetup() { #ifdef SONOFF_DUAL // Two dummy relays for the dual - _relays.push_back(0); - _relays.push_back(0); + _relays.push_back((relay_t) {0, 0}); + _relays.push_back((relay_t) {0, 0}); #else #ifdef RELAY1_PIN - _relays.push_back(RELAY1_PIN); + _relays.push_back((relay_t) { RELAY1_PIN, RELAY1_PIN_INVERSE }); #endif #ifdef RELAY2_PIN - _relays.push_back(RELAY2_PIN); + _relays.push_back((relay_t) { RELAY2_PIN, RELAY2_PIN_INVERSE }); #endif #ifdef RELAY3_PIN - _relays.push_back(RELAY3_PIN); + _relays.push_back((relay_t) { RELAY3_PIN, RELAY3_PIN_INVERSE }); #endif #ifdef RELAY4_PIN - _relays.push_back(RELAY4_PIN); + _relays.push_back((relay_t) { RELAY4_PIN, RELAY4_PIN_INVERSE }); #endif #endif @@ -321,7 +331,7 @@ void relaySetup() { byte relayMode = getSetting("relayMode", RELAY_MODE).toInt(); for (unsigned int i=0; i < _relays.size(); i++) { - pinMode(_relays[i], OUTPUT); + pinMode(_relays[i].pin, OUTPUT); if (relayMode == RELAY_MODE_OFF) relayStatus(i, false); if (relayMode == RELAY_MODE_ON) relayStatus(i, true); } diff --git a/code/src/rf.ino b/code/espurna/rf.ino similarity index 100% rename from code/src/rf.ino rename to code/espurna/rf.ino diff --git a/code/src/settings.ino b/code/espurna/settings.ino similarity index 100% rename from code/src/settings.ino rename to code/espurna/settings.ino diff --git a/code/src/web.ino b/code/espurna/web.ino similarity index 81% rename from code/src/web.ino rename to code/espurna/web.ino index 4bbaa97b..151deb7d 100644 --- a/code/src/web.ino +++ b/code/espurna/web.ino @@ -94,6 +94,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { bool fauxmoEnabled = false; #endif unsigned int network = 0; + unsigned int dczIdx = 0; String adminPass; for (unsigned int i=0; i= relayCount()) continue; + key = key + String(dczIdx); + ++dczIdx; + } + + #else + + if (key.startsWith("dcz")) continue; + #endif // Check password @@ -142,10 +161,23 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { } if (key == "pass") { key = key + String(network); + } + if (key == "ip") { + key = key + String(network); + } + if (key == "gw") { + key = key + String(network); + } + if (key == "mask") { + key = key + String(network); + } + if (key == "dns") { + key = key + String(network); ++network; } if (value != getSetting(key)) { + //DEBUG_MSG("[WEBSOCKET] Storing %s = %s\n", key.c_str(), value.c_str()); setSetting(key, value); dirty = true; if (key.startsWith("mqtt")) dirtyMQTT = true; @@ -165,6 +197,26 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { } #endif + // Clean wifi networks + for (int i = 0; i < network; i++) { + if (getSetting("pass" + String(i)).length() == 0) delSetting("pass" + String(i)); + if (getSetting("ip" + String(i)).length() == 0) delSetting("ip" + String(i)); + if (getSetting("gw" + String(i)).length() == 0) delSetting("gw" + String(i)); + if (getSetting("mask" + String(i)).length() == 0) delSetting("mask" + String(i)); + if (getSetting("dns" + String(i)).length() == 0) delSetting("dns" + String(i)); + } + for (int i = network; i 0) { + dirty = true; + } + delSetting("ssid" + String(i)); + delSetting("pass" + String(i)); + delSetting("ip" + String(i)); + delSetting("gw" + String(i)); + delSetting("mask" + String(i)); + delSetting("dns" + String(i)); + } + // Save settings if (dirty) { @@ -225,7 +277,7 @@ void _wsStart(uint32_t client_id) { root["device"] = String(DEVICE); root["hostname"] = getSetting("hostname", HOSTNAME); root["network"] = getNetwork(); - root["ip"] = getIP(); + root["deviceip"] = getIP(); root["mqttStatus"] = mqttConnected(); root["mqttServer"] = getSetting("mqttServer", MQTT_SERVER); @@ -249,6 +301,19 @@ void _wsStart(uint32_t client_id) { root["apiEnabled"] = getSetting("apiEnabled").toInt() == 1; root["apiKey"] = getSetting("apiKey"); + #if ENABLE_DOMOTICZ + + root["dczVisible"] = 1; + root["dczTopicIn"] = getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC); + root["dczTopicOut"] = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); + + JsonArray& dczIdx = root.createNestedArray("dczIdx"); + for (byte i=0; iid(), len, len ? (char*) data : ""); } else if(type == WS_EVT_DATA) { - _wsParse(client->id(), data, len); + + AwsFrameInfo * info = (AwsFrameInfo*)arg; + + // First packet + if (info->index == 0) { + //Serial.printf("Before malloc: %d\n", ESP.getFreeHeap()); + message = (uint8_t*) malloc(info->len); + //Serial.printf("After malloc: %d\n", ESP.getFreeHeap()); + } + + // Store data + memcpy(message + info->index, data, len); + + // Last packet + if (info->index + len == info->len) { + _wsParse(client->id(), message, info->len); + //Serial.printf("Before free: %d\n", ESP.getFreeHeap()); + free(message); + //Serial.printf("After free: %d\n", ESP.getFreeHeap()); + } + } } diff --git a/code/src/wifi.ino b/code/espurna/wifi.ino similarity index 85% rename from code/src/wifi.ino rename to code/espurna/wifi.ino index e8c1bb39..22ec197a 100644 --- a/code/src/wifi.ino +++ b/code/espurna/wifi.ino @@ -52,9 +52,24 @@ void wifiConfigure() { jw.setSoftAP(getSetting("hostname", HOSTNAME).c_str(), getSetting("adminPass", ADMIN_PASS).c_str()); jw.setAPMode(AP_MODE_ALONE); jw.cleanNetworks(); - if (getSetting("ssid0").length() > 0) jw.addNetwork(getSetting("ssid0").c_str(), getSetting("pass0").c_str()); - if (getSetting("ssid1").length() > 0) jw.addNetwork(getSetting("ssid1").c_str(), getSetting("pass1").c_str()); - if (getSetting("ssid2").length() > 0) jw.addNetwork(getSetting("ssid2").c_str(), getSetting("pass2").c_str()); + for (int i = 0; i< WIFI_MAX_NETWORKS; i++) { + if (getSetting("ssid" + String(i)).length() == 0) break; + if (getSetting("ip" + String(i)).length() == 0) { + jw.addNetwork( + getSetting("ssid" + String(i)).c_str(), + getSetting("pass" + String(i)).c_str() + ); + } else { + jw.addNetwork( + getSetting("ssid" + String(i)).c_str(), + getSetting("pass" + String(i)).c_str(), + getSetting("ip" + String(i)).c_str(), + getSetting("gw" + String(i)).c_str(), + getSetting("mask" + String(i)).c_str(), + getSetting("dns" + String(i)).c_str() + ); + } + } } void wifiSetup() { diff --git a/code/gulpfile.js b/code/gulpfile.js index ce6a8134..1bf02633 100644 --- a/code/gulpfile.js +++ b/code/gulpfile.js @@ -34,9 +34,11 @@ const useref = require('gulp-useref'); const gulpif = require('gulp-if'); const inline = require('gulp-inline'); +const destination = 'espurna/data/'; + /* Clean destination folder */ gulp.task('clean', function() { - del(['data/*']); + del([ destination + '*']); return true; }); @@ -46,7 +48,7 @@ gulp.task('files', function() { 'html/**/*.{jpg,jpeg,png,ico,gif}', 'html/fsversion' ]) - .pipe(gulp.dest('data/')); + .pipe(gulp.dest(destination)); }); @@ -66,7 +68,7 @@ gulp.task('inline', function() { minifyJS: true })) .pipe(gzip()) - .pipe(gulp.dest('data')); + .pipe(gulp.dest(destination)); }) /* Process HTML, CSS, JS */ @@ -83,10 +85,10 @@ gulp.task('html', function() { minifyJS: true }))) .pipe(gzip()) - .pipe(gulp.dest('data')); + .pipe(gulp.dest(destination)); }); /* Build file system */ gulp.task('buildfs_split', ['clean', 'files', 'html']); gulp.task('buildfs_inline', ['clean', 'files', 'inline']); -gulp.task('default', ['buildfs_inline']); +gulp.task('default', ['buildfs_split']); diff --git a/code/html/custom.css b/code/html/custom.css index c129c81b..8a1aac33 100644 --- a/code/html/custom.css +++ b/code/html/custom.css @@ -41,6 +41,15 @@ background: rgb(0, 202, 0); margin-left: 5px; } +.button-add-network { + background: rgb(28, 184, 65); +} +.button-del-network { + background: rgb(202, 60, 60); +} +.button-more-network { + background: rgb(223, 117, 20); +} .pure-g { margin-bottom: 20px; } @@ -57,10 +66,23 @@ div.hint { font-size: 80%; color: #ccc; } - +.break { + margin-top: 5px; +} +#networks .pure-g { + padding-bottom: 10px; + margin-bottom: 5px; + border-bottom: 2px dashed #e5e5e5; +} +#networks div.more { + display: none; +} .module { display: none; } -#relayTemplate { +.template { display: none; } +.pure-form .center { + margin: .5em 0 .2em; +} diff --git a/code/html/custom.js b/code/html/custom.js index 2fe39e42..c6a2791a 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -1,10 +1,42 @@ var websock; var password = false; +var maxNetworks; + +// http://www.the-art-of-web.com/javascript/validate-password/ +function checkPassword(str) { + // at least one number, one lowercase and one uppercase letter + // at least eight characters that are letters, numbers or the underscore + var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{8,}$/; + return re.test(str); +} + +function validateForm() { + + var form = $("#formSave"); + + // password + var adminPass1 = $("input[name='adminPass1']", form).val(); + if (adminPass1.length > 0 && !checkPassword(adminPass1)) { + alert("The password you have entered is not valid, it must have at least 8 characters, 1 lower and 1 uppercase and 1 number!"); + return false; + } + + var adminPass2 = $("input[name='adminPass2']", form).val(); + if (adminPass1 != adminPass2) { + alert("Passwords are different!"); + return false; + } + + return true; + +} function doUpdate() { - var data = $("#formSave").serializeArray(); - websock.send(JSON.stringify({'config': data})); - $(".powExpected").val(0); + if (validateForm()) { + var data = $("#formSave").serializeArray(); + websock.send(JSON.stringify({'config': data})); + $(".powExpected").val(0); + } return false; } @@ -84,6 +116,55 @@ function createRelays(count) { } +function createIdxs(count) { + + var current = $("#idxs > div").length; + if (current > 0) return; + + var template = $("#idxTemplate .pure-g")[0]; + for (var id=0; id 1) $(".id", line).html(" " + id); + line.appendTo("#idxs"); + } + +} + +function delNetwork() { + var parent = $(this).parents(".pure-g"); + $(parent).remove(); +} + +function moreNetwork() { + var parent = $(this).parents(".pure-g"); + $("div.more", parent).toggle(); +} + +function addNetwork() { + + var numNetworks = $("#networks > div").length; + if (numNetworks >= maxNetworks) { + alert("Max number of networks reached"); + return; + } + + var tabindex = 200 + numNetworks * 10; + var template = $("#networkTemplate").children(); + var line = $(template).clone(); + $(line).find("input").each(function() { + $(this).attr("tabindex", tabindex++); + }); + $(line).find(".button-del-network").on('click', delNetwork); + $(line).find(".button-more-network").on('click', moreNetwork); + line.appendTo("#networks"); + + return line; + +} + function processData(data) { // title @@ -130,17 +211,32 @@ function processData(data) { } + if (key == "maxNetworks") { + maxNetworks = parseInt(data.maxNetworks); + return; + } + // Wifi if (key == "wifi") { - var groups = $("#panel-wifi .pure-g"); - for (var i in data.wifi) { + + var networks = data.wifi; + + for (var i in networks) { + + // add a new row + var line = addNetwork(); + + // fill in the blanks var wifi = data.wifi[i]; Object.keys(wifi).forEach(function(key) { - var id = "input[name=" + key + "]"; - if ($(id, groups[i]).length) $(id, groups[i]).val(wifi[key]); + var element = $("input[name=" + key + "]", line); + if (element.length) element.val(wifi[key]); }); - }; + + } + return; + } // Relay status @@ -162,6 +258,19 @@ function processData(data) { } + // Domoticz + if (key == "dczIdx") { + var idxs = data.dczIdx; + createIdxs(idxs.length); + + for (var i in idxs) { + var element = $(".dczIdx[data=" + i + "]"); + if (element.length > 0) element.val(idxs[i]); + } + + return; + } + // Messages if (key == "message") { @@ -172,7 +281,6 @@ function processData(data) { // Enable options if (key.endsWith("Visible")) { var module = key.slice(0,-7); - console.log(module); $(".module-" + module).show(); return; } @@ -244,6 +352,7 @@ function init() { $(".button-reconnect").on('click', doReconnect); $(".button-apikey").on('click', doGenerateAPIKey); $(".pure-menu-link").on('click', showPanel); + $(".button-add-network").on('click', addNetwork); $.ajax({ 'method': 'GET', diff --git a/code/html/fsversion b/code/html/fsversion deleted file mode 100644 index 9084fa2f..00000000 --- a/code/html/fsversion +++ /dev/null @@ -1 +0,0 @@ -1.1.0 diff --git a/code/html/index.html b/code/html/index.html index e0a53f72..82ab1ba9 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -52,6 +52,10 @@ MQTT +
  • + DOMOTICZ +
  • +
  • POWER
  • @@ -107,8 +111,8 @@
    - - + +
    @@ -139,14 +143,6 @@
    -
    -
    -
    -
    -
    -
    - - @@ -242,14 +238,16 @@
    - +
     
    -
    The administrator password is used to access this web interface (user 'admin'), but also to connect to the device when in AP mode or to flash a new firmware over-the-air (OTA).
    +
    + The administrator password is used to access this web interface (user 'admin'), but also to connect to the device when in AP mode or to flash a new firmware over-the-air (OTA).
    + It should have at least eight characters (letters, numbers or the underscore) and at least one number, one lowercase and one uppercase letter.
    - +
    @@ -259,7 +257,7 @@
    - +
     
    This is the key you will have to pass with every HTTP request to the API, either to get or write values.
    @@ -273,51 +271,17 @@

    WIFI

    -

    You can configure up to 3 different WiFi networks. The device will try to connect in order of signal strength.

    +

    You can configure up to 5 different WiFi networks. The device will try to connect in order of signal strength.

    - First network - -
    -
    - - -
    -
    - - -
    -
    - - Second network - -
    -
    - - -
    -
    - - -
    +
    - Third network - -
    -
    - - -
    -
    - - -
    -
    +
    @@ -336,29 +300,65 @@
    - +
    - +
    - +
    - +
    - - + +
     
    -
    Send a 0 or a 1 as a payload to the provided topic below to switch it on or off. You can also send a 2 to toggle its current state. The switch will also report its current open/close status to the same topic and its IP address, hertbeat, firmware version and file system version to the topic you define plus "/ip", "/heartbeat", "/version" and "/fsversion" respectively.
    +
    This is the root topic for this device. The {identifier} placeholder will be replaces by the device hostname.
    + - <root>/relay/# Send a 0 or a 1 as a payload to this topic to switch it on or off. You can also send a 2 to toggle its current state. Replace # with the relay ID (starting from 0). If the board has only one relay it will be 0.
    + - <root>/led/# Send a 0 or a 1 as a payload to this topic to set the onboard LED to the given state, send a 3 to turn it back to WIFI indicator. Replace # with the LED ID (starting from 0). If the board has only one LED it will be 0.
    + - <root>/ip The device will report to this topic its IP.
    + - <root>/heartbeat The device will report to this topic every few minutes.
    + - <root>/version The device will report to this topic its firmware version on boot.
    +
    + + +
    + +
    + +
    + +
    +

    DOMOTICZ

    +

    + Configure the connection to your Domoticz server. +

    +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    @@ -381,7 +381,7 @@
    - +
     
    If you are using a pure resistive load like a bulb this will be writen on it, otherwise use a socket multimeter to get this value.
    @@ -396,6 +396,69 @@
    + + +
    + +
    + + +
    +
    + +
    + +
    + + + + +
    + + + +
    +
    Leave empty for DNS negotiation
    + + + +
    +
    Set when using a static IP
    + + + +
    +
    Usually 255.255.255.0 for /24 networks
    + + + +
    +
    Set the Domain Name Server IP to use when using a static IP
    + +
    +
    + +
    + +
    + +
    + +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    Set to 0 to disable notifications.
    +
    +
    + diff --git a/code/lib/DebounceEvent/DebounceEvent.cpp b/code/lib/DebounceEvent/DebounceEvent.cpp deleted file mode 100644 index fccb41e4..00000000 --- a/code/lib/DebounceEvent/DebounceEvent.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - - Debounce buttons and trigger events - Copyright (C) 2015 by Xose Pérez - - 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 . - -*/ - -#include -#include "DebounceEvent.h" - -DebounceEvent::DebounceEvent(uint8_t pin, callback_t callback, uint8_t defaultStatus, unsigned long delay) { - _callback = callback; - DebounceEvent(pin, defaultStatus, delay); -} - -DebounceEvent::DebounceEvent(uint8_t pin, uint8_t defaultStatus, unsigned long delay) { - - // store configuration - _pin = pin; - _status = _defaultStatus = defaultStatus; - _delay = delay; - - // set up button - if (_defaultStatus == LOW) { - pinMode(_pin, INPUT); - } else { - pinMode(_pin, INPUT_PULLUP); - } - -} - -bool DebounceEvent::loop() { - - // holds whether status has changed or not - bool changed = false; - _event = EVENT_NONE; - - if (digitalRead(_pin) != _status) { - - // Debounce - delay(_delay); - uint8_t newStatus = digitalRead(_pin); - if (newStatus != _status) { - - changed = true; - _clicked = false; - _status = newStatus; - - // released - if (_status == _defaultStatus) { - - // get event - if (millis() - _this_start > LONG_CLICK_DELAY) { - _event = EVENT_LONG_CLICK; - } else if (millis() - _last_start < DOUBLE_CLICK_DELAY ) { - _event = EVENT_DOUBLE_CLICK; - } else { - - // We are not setting the event type here because we still don't - // know what kind of event it will be (it might be a double click). - // Instead we are setting the _clicked variable to check later - _clicked = true; - changed = false; - - } - - // pressed - } else { - - _last_start = _this_start; - _this_start = millis(); - _event = EVENT_PRESSED; - - } - - } - } - - if (_clicked && (millis() - _this_start > DOUBLE_CLICK_DELAY) && (!changed) && (_status == _defaultStatus)) { - _clicked = false; - changed = true; - _event = EVENT_SINGLE_CLICK; - } - - if (changed) { - if (_callback) { - _callback(_pin, EVENT_CHANGED); - _callback(_pin, _event); - } - } - - return changed; - -} - -bool DebounceEvent::pressed() { - return (_status != _defaultStatus); -} - -uint8_t DebounceEvent::getEvent() { - return _event; -} diff --git a/code/lib/DebounceEvent/DebounceEvent.h b/code/lib/DebounceEvent/DebounceEvent.h deleted file mode 100644 index b7b30b51..00000000 --- a/code/lib/DebounceEvent/DebounceEvent.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - - Debounce buttons and trigger events - Copyright (C) 2015 by Xose Pérez - - 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 . - -*/ - -#ifndef _DEBOUNCE_EVENT_h -#define _DEBOUNCE_EVENT_h - -#define DEBOUNCE_DELAY 50 -#define LONG_CLICK_DELAY 1000 -#define DOUBLE_CLICK_DELAY 500 - -#define EVENT_NONE 0 -#define EVENT_CHANGED 1 -#define EVENT_PRESSED 2 -#define EVENT_RELEASED 3 -#define EVENT_SINGLE_CLICK 3 -#define EVENT_DOUBLE_CLICK 4 -#define EVENT_LONG_CLICK 5 - -typedef void(*callback_t)(uint8_t pin, uint8_t event); - -class DebounceEvent { - - private: - - uint8_t _pin; - uint8_t _status; - uint8_t _event; - bool _clicked = false; - unsigned long _this_start; - unsigned long _last_start; - uint8_t _defaultStatus; - unsigned long _delay; - callback_t _callback = false; - - public: - - DebounceEvent(uint8_t pin, callback_t callback, uint8_t defaultStatus = HIGH, unsigned long delay = DEBOUNCE_DELAY); - DebounceEvent(uint8_t pin, uint8_t defaultStatus = HIGH, unsigned long delay = DEBOUNCE_DELAY); - bool pressed(); - bool loop(); - uint8_t getEvent(); - -}; - -#endif diff --git a/code/lib/WProgram/WProgram.h b/code/lib/WProgram/WProgram.h deleted file mode 100644 index dca27d86..00000000 --- a/code/lib/WProgram/WProgram.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/code/pio_hooks.py b/code/pio_hooks.py index 7abf6075..5b818421 100644 --- a/code/pio_hooks.py +++ b/code/pio_hooks.py @@ -5,24 +5,7 @@ import socket from SCons.Script import DefaultEnvironment env = DefaultEnvironment() -def is_valid_ip(ip): - try: - socket.inet_aton(ip) - return True - except socket.error: - return False - def before_build_spiffs(source, target, env): - env.Execute("gulp buildfs_split") - -def before_upload(source, target, env): - upload_port = env.get('UPLOAD_PORT', False) - if upload_port and upload_port[0] == '/': - cmd = ["mosquitto_sub", "-t", upload_port, "-h", "192.168.1.10", "-N", "-C", "1"] - ip = subprocess.check_output(cmd) - if is_valid_ip(ip): - env['UPLOAD_PORT'] = '"' + ip + '"' + env.Execute("gulp") -#env.AddPreAction("uploadfs", before_upload) -#env.AddPreAction("upload", before_upload) env.AddPreAction(".pioenvs/%s/spiffs.bin" % env['PIOENV'], before_build_spiffs) diff --git a/code/platformio.custom.ini b/code/platformio.custom.ini deleted file mode 100644 index d5e637fe..00000000 --- a/code/platformio.custom.ini +++ /dev/null @@ -1,132 +0,0 @@ -# -# PLEASE NOTE: -# This platformio.ini file is not standard and uses a custom feature. -# The "include" option is not supported by the official version. -# Check my PR for this feature here: -# https://github.com/platformio/platformio/pull/790 -# - -[platformio] -env_default = node-debug - -[common] -platform = espressif8266_stage -framework = arduino -extra_script = pio_hooks.py -#lib_ignore = FauxmoESP, ESPAsyncUDP -lib_deps = - DHT sensor library - Adafruit Unified Sensor - Time - ArduinoJson - ESPAsyncTCP - ESPAsyncWebServer - https://github.com/marvinroger/async-mqtt-client - ESPAsyncUDP - Embedis - NtpClientLib - https://bitbucket.org/xoseperez/justwifi.git - https://bitbucket.org/xoseperez/nofuss.git - https://bitbucket.org/xoseperez/hlw8012.git - https://bitbucket.org/xoseperez/emonliteesp.git - https://bitbucket.org/xoseperez/fauxmoESP.git - https://github.com/jccprj/RemoteSwitch-arduino-library - -[ota] -upload_speed = 115200 -upload_port = "192.168.4.1" -upload_flags = --auth=fibonacci --port 8266 - -[def] -build_flags_debug = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DENABLE_FAUXMO=1 -build_flags_ota = -Wl,-Tesp8266.flash.1m128.ld -DENABLE_FAUXMO=1 - - -# ------------------------------------------------------------------------------ - -[env:node-debug] -include = common -board = nodemcuv2 -platform = espressif8266 -build_flags = -g -DNODEMCUV2 -DDEBUG_PORT=Serial - -[env:node-debug-ota] -include = env:node-debug,ota - -[env:sonoff-debug] -include = common -board = esp01_1m -build_flags = ${def.build_flags_debug} -DSONOFF - -[env:sonoff-ota] -include = env:sonoff-debug,ota -build_flags = ${def.build_flags_ota} -DSONOFF - -[env:sonoff-dht22-debug] -include = env:sonoff-debug -build_flags = ${def.build_flags_debug} -DSONOFF -DENABLE_DHT=1 - -[env:sonoff-ds18b20-debug] -include = env:sonoff-debug -build_flags = ${def.build_flags_debug} -DSONOFF -DENABLE_DS18B20=1 - -[env:sonoff-pow-debug] -include = common -board = esp01_1m -build_flags = ${def.build_flags_debug} -DSONOFF_POW - -[env:sonoff-pow-ota] -include = env:sonoff-pow-debug,ota -build_flags = ${def.build_flags_ota} -DSONOFF_POW - -[env:sonoff-dual-debug] -include = common -board = esp12e -build_flags = ${def.build_flags_debug} -DSONOFF_DUAL - -[env:sonoff-dual-ota] -include = env:sonoff-dual-debug,ota -build_flags = ${def.build_flags_ota} -DSONOFF_DUAL - -[env:slampher-debug] -include = common -board = esp01_1m -build_flags = ${def.build_flags_debug} -DSLAMPHER - -[env:slampher-ota] -include = env:slampher-debug,ota -build_flags = ${def.build_flags_ota} -DSLAMPHER - -[env:s20-debug] -include = common -board = esp01_1m -build_flags = ${def.build_flags_debug} -DS20 - -[env:s20-ota] -include = env:s20-debug,ota -build_flags = ${def.build_flags_ota} -DS20 - -[env:electrodragon-debug] -include = common -board = esp12e -build_flags = -g -DDEBUG_PORT=Serial -DESP_RELAY_BOARD -DENABLE_FAUXMO=1 -DENABLE_DHT=1 - -[env:electrodragon-ota] -include = env:electrodragon-debug,ota -build_flags = -DESP_RELAY_BOARD -DENABLE_FAUXMO=1 -DENABLE_DHT=1 - -# ------------------------------------------------------------------------------ - -[env:studio-lamp-device] -topic = /home/studio/lamp/ip -include = env:sonoff-debug-ota -platform = espressif8266_stage -build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DSONOFF -DENABLE_FAUXMO=1 -lib_ignore = - -[env:living-lamp-device] -topic = /home/living/lamp/ip -include = env:s20-debug-ota -platform = espressif8266_stage -build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DS20 -DENABLE_FAUXMO=1 -lib_ignore = diff --git a/code/platformio.ini b/code/platformio.ini index 11563e47..f4256545 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -1,5 +1,7 @@ [platformio] -env_default = node-debug +env_default = d1-debug +src_dir = espurna +data_dir = espurna/data [common] lib_deps = @@ -10,21 +12,42 @@ lib_deps = ESPAsyncTCP ESPAsyncWebServer https://github.com/marvinroger/async-mqtt-client - ESPAsyncUDP Embedis NtpClientLib OneWire DallasTemperature - https://bitbucket.org/xoseperez/justwifi.git + JustWifi + HLW8012 + https://bitbucket.org/xoseperez/fauxmoesp.git https://bitbucket.org/xoseperez/nofuss.git - https://bitbucket.org/xoseperez/hlw8012.git https://bitbucket.org/xoseperez/emonliteesp.git - https://bitbucket.org/xoseperez/fauxmoESP.git - https://github.com/jccprj/RemoteSwitch-arduino-library -lib_ignore = FauxmoESP, ESPAsyncUDP + https://bitbucket.org/xoseperez/debounceevent.git + https://github.com/xoseperez/RemoteSwitch-arduino-library.git +lib_ignore = # ------------------------------------------------------------------------------ +[env:d1-debug] +platform = espressif8266 +framework = arduino +board = d1_mini +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +extra_script = pio_hooks.py +build_flags = -g -DD1_RELAYSHIELD -DDEBUG_PORT=Serial -DDEBUG_FAUXMO=Serial -DNOWSAUTH + +[env:d1-debug-ota] +platform = espressif8266 +framework = arduino +board = d1_mini +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +extra_script = pio_hooks.py +build_flags = -g -DD1_RELAYSHIELD -DDEBUG_PORT=Serial -DDEBUG_FAUXMO=Serial -DNOWSAUTH +upload_speed = 115200 +upload_port = "192.168.4.1" +upload_flags = --auth=fibonacci --port 8266 + [env:node-debug] platform = espressif8266 framework = arduino @@ -32,7 +55,7 @@ board = nodemcuv2 lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} extra_script = pio_hooks.py -build_flags = -g -DNODEMCUV2 -DDEBUG_PORT=Serial -DNOWSAUTH +build_flags = -g -DNODEMCUV2 -DDEBUG_PORT=Serial -DDEBUG_FAUXMO=Serial -DNOWSAUTH [env:node-debug-ota] platform = espressif8266 @@ -41,7 +64,7 @@ board = nodemcuv2 lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} extra_script = pio_hooks.py -build_flags = -g -DNODEMCUV2 -DDEBUG_PORT=Serial -DNOWSAUTH +build_flags = -g -DNODEMCUV2 -DDEBUG_PORT=Serial -DDEBUG_FAUXMO=Serial -DNOWSAUTH upload_speed = 115200 upload_port = "192.168.4.1" upload_flags = --auth=fibonacci --port 8266 diff --git a/docs/Configuration.md b/docs/Configuration.md deleted file mode 100644 index 680c49af..00000000 --- a/docs/Configuration.md +++ /dev/null @@ -1,21 +0,0 @@ -# Configuration - -*TODO* - -## First boot - -On normal boot (i.e. button not pressed) it will execute the firmware. It configures the hardware (button, LED, relay), the SPIFFS memory access, the WIFI, the WebServer and MQTT connection and whatever other enabled modules. - -Obviously the default values for WIFI network and MQTT will probably not match your requirements. The device will start in Soft AP creating a WIFI SSID named "DEVICE_XXXXXX", where DEVICE will be an identifier of your device and XXXXXX are the last 3 bytes of the radio MAC. Connect with phone, PC, laptop, whatever to that network, password is "fibonacci". Once connected browse to 192.168.4.1. It will then present an **authentication challenge**. Default user and password are "admin" and "fibonacci" (again). Then you will be presented a configuration page where you will be able to define different configuration parameters, including changing the default password. The same password is used for the WIFI Access Point, for the web interface and for the OTA firmware upload. - -## WiFi configuration - -You can configure up to three WIFI networks. It will then try to connect to the configure WIFI networks in order of signal strength. If none of the 3 attempts succeed it will default to SoftAP mode again. You can also switch to SoftAP mode by double click the on-board button or reset the board long clicking it. - -## MQTT - -Once connected to an access point (so in station mode) the board will try to connect the MQTT server defined. - -The device will publish the relay state to the given topic and it will subscribe to the same topic for remote switching. Don't worry, it avoids infinite loops. - -You can also use "{identifier}" as place holder in the topic. It will be translated to your device ID (same as the soft AP network it creates). diff --git a/docs/Filesystem.md b/docs/Filesystem.md deleted file mode 100644 index 608c0db8..00000000 --- a/docs/Filesystem.md +++ /dev/null @@ -1,77 +0,0 @@ -# Filesystem - -## Introduction - -Normally when you flash an ESP8266 you only flash the firmware, like for any other microcontroller. But the ESP8266 has plenty of room and normally it is split into different partitions. One such partition is used to store web files like a normal webserver. - -Problem is that, even thou the ESP8266 is a very capable microcontroller it has its limitations and does not handle very well concurrent connections. This is specially true for the *default* webserver that comes with the Arduino Core for ESP8266. - -On the other side, to provide a good user experience and work with a comfortable development environment you end up having different files: scripts, stylesheet files, images,... The browser will load the index.html file and quickly request for all those other files and the ESP8266 will easily struggle trying to serve them all. - -So the trick here is to squeeze them all into one single compressed file just before uploading it. Luckily, we can do that automatically. - -## Web interface build process - -The build process reads the HTML files, looks for the stylesheet and script files linked there, grabs them, minifies them and includes them inline, in the same order they are loaded. The resulting single HTML file is then cleaned, further minified and compressed resulting in a single index.html.gz file. This way the ESP8266 webserver can serve it really fast. - -To build this file we are using **[Gulp][1]**, a build system built in [node.js][2]. So you will need node (and [npm][3], its package manager) first. [Read the documentation][4] on how to install them. - -Once you have node and npm installed, go to the 'code' folder and install all the dependencies with: - -``` -npm install -``` - -It will take a minute or two. Then you are ready to build the webserver files with: - -``` -gulp -``` - -It will create a populate a 'data' folder with all the required files. - -## Images - -Along with the HTML, CSS and JS files compressed into the index.html.gz file, the ESPurna firmware uses some images in its web interface. These are the favicon.ico file and a **sprite** for the iPhone style buttons in the interface. Again the idea is to use the minimum possible number of files. - -## Flashing it - -### Using PlatformIO - -[PlatformIO][5] allows the developer to define hooks to be executed before or after certain actions. This is really cool since we can plug one such hook to the *uploadfs* target to automatically build the web interface before uploading it to the board. - -This is done by specifying the script with the hook definitions in the *extra_script* option in the platformio.ini file. The script, written in python, binds the target file (spiffs.bin) to a method that executes the gulp command we have seen before. - -``` -#!/bin/python - -from SCons.Script import DefaultEnvironment -env = DefaultEnvironment() - -def before_build_spiffs(source, target, env): - env.Execute("gulp buildfs") - -env.AddPreAction(".pioenvs/%s/spiffs.bin" % env['PIOENV'], before_build_spiffs) -``` - -The included platformio.ini file has all this already configured, so you don't have to worry about it. Just type: - -``` -pio run -t uploadfs -e sonoff -``` - -(or whatever other enviroment) and you are good to go. - -### Using Arduino IDE - -First you will have to manually build the data folder contents using gulp (see [instructions above](#web-interface-build-process)). - -Then you will have to have the "[ESP8266 Sketch Data Upload][6]" utility installed. Check the instructions in the previous link. The data folder should be a subfolder of the code folder for the tool to find it. Then just execute it and it will upload the data folder contents to your board. - - -[1]: http://gulpjs.com/ -[2]: https://nodejs.org/en/ -[3]: https://www.npmjs.com/ -[4]: https://docs.npmjs.com/getting-started/installing-node -[5]: http://www.platformio.org -[6]: https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md#uploading-files-to-file-system diff --git a/docs/Firmware.md b/docs/Firmware.md deleted file mode 100644 index 648edb4e..00000000 --- a/docs/Firmware.md +++ /dev/null @@ -1,56 +0,0 @@ -# Firmware - -## Build the firmware - -The project is ready to be build using [PlatformIO][1]. -Please refer to their web page for instructions on how to install the builder. - -If you are using PlatformIO /strongly recommended) it will take care of the library dependencies. Otherwise you will have to install them manually: - -* Benoit Blanchon's [ArduinoJson](https://github.com/bblanchon/ArduinoJson) -* Hristo Gochkov's [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) -* Hristo Gochkov's [ESPAsyncUDP](https://github.com/me-no-dev/ESPAsyncUDP) -* Hristo Gochkov's [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) -* Marvin Roger's [AyncMqttClient](https://github.com/marvinroger/async-mqtt-client) -* Adafruit's [DHT Sensor Library](https://github.com/adafruit/DHT-sensor-library) (required if compiling with DHT support: -DENABLE_DHT) -* Adafruit's [Unified Sensor Library](https://github.com/adafruit/Adafruit_Sensor) (required if compiling with DHT support: -DENABLE_DHT) -* Paul Stoffregen (et al.) [OneWire](https://github.com/PaulStoffregen/OneWire) -* Miles Burton (et al.) [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library) -* The PatternAgents (et al.) [Embedis](https://github.com/thingSoC/embedis) -* German Martin's [NtpCLientLib](https://github.com/gmag11/NtpClient) -* Michael Maregolis & Paul Stoffregen's [Time](https://github.com/PaulStoffregen/Time) -* Randy Simons' [RemoteSwitch](https://github.com/jccprj/RemoteSwitch-arduino-library) (required if using custom RF module: -DENABLE_RF) - -And my own libraries: - -* [JustWifi](https://bitbucket.org/xoseperez/justwifi.git) -* [FauxmoESP](https://bitbucket.org/xoseperez/fauxmoesp.git) (required if compiling with WeMo emulation support: -DENABLE_FAUXMO) -* [HLW8012](https://bitbucket.org/xoseperez/hlw8012.git) (required if compiling for Sonoff POW: -DENABLE_POW) -* [EmonLiteESP](https://bitbucket.org/xoseperez/emonliteesp.git) (required if compiling with Energy Monitoring support: -DENABLE_EMON) -* [NoFUSS](https://bitbucket.org/xoseperez/nofuss.git) (required if compiling with NoFUSS Automatic OTA support: -DENABLE_NOFUSS) - -**Note**: The fauxmoESP library requires the staging version of Arduino Core for ESP8266. Either you are using Arduino IDE or PlatformIO you will have to manually install this. Check the [documentation for the fauxmoESP library](https://bitbucket.org/xoseperez/fauxmoesp) for more info. - -Once you have all the code, you can check if it's working by: - -```bash -> pio run -e node-debug -``` - -If it compiles you are ready to flash the firmware. - -## Flash your board - -Wire your board (check the [Hardware page](Hardware.md)) and flash the firmware (with ```upload```): - -```bash -> pio run -t upload -e sonoff -``` - -(or any other environment, depending on the board you are working with). - -Library dependencies are automatically managed via PlatformIO Library Manager or included via submodules and linked from the "lib" folder. - -Once the firmware is uploaded next step is to upload the web interface. Check how to [build and flash the filesystem](Filesystem.md). - -[1]: http://www.platformio.org diff --git a/docs/Hardware.md b/docs/Hardware.md deleted file mode 100644 index a62ce51f..00000000 --- a/docs/Hardware.md +++ /dev/null @@ -1,216 +0,0 @@ -# Supported Hardware - -This is the official list of supported hardware for the ESPurna firmware. The hardware configuration for each of these boards can be selected by supplying the build flag (see [Firmware section](Firmware.h)). - -**CAUTION: Never ever connect any of these devices to your computer and to mains at the same time. Never ever manipulate them while connected to mains. Seriously. I don't want you to die. I hold no responsibility for any damage to you, your family, your house,... for any action or results derived from flashing or using these devices.** - -* [IteadStudio Sonoff](#iteadstudio-sonoff) -* [IteadStudio Sonoff RF](#iteadstudio-sonoff-rf) -* [IteadStudio Sonoff TH](#iteadstudio-sonoff-th) -* [IteadStudio Sonoff POW](#iteadstudio-sonoff-pow) -* [IteadStudio Sonoff DUAL](#iteadstudio-sonoff-dual) -* [IteadStudio Sonoff TOUCH](#iteadstudio-sonoff-touch) -* [IteadStudio Sonoff 4CH](#iteadstudio-sonoff-4ch) -* [IteadStudio Sonoff SV](#iteadstudio-sonoff-sv) -* [IteadStudio Slampher](#iteadstudio-slampher) -* [IteadStudio S20](#iteadstudio-s20) -* [Electrodragon ESP Relay Board](#electrodragon-esp-relay-board) -* [WorkChoice EcoPlug](#workchoice-ecoplug) - -## IteadStudio Sonoff - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/sonoff-wifi-wireless-switch.html](https://www.itead.cc/sonoff-wifi-wireless-switch.html)| -|Build flag|SONOFF| - -The [IteadStudio Sonoff][1] has an ESP8266 on board with a 8Mbit flash memory chip, a mains to 3V3 transformer and a relay (GPIO12). It also features a button (GPIO0), an LED (GPIO13) and an unpopulated header you can use to reprogram it. - -### Flashing - -![Sonoff - Inside front view](images/sonoff-flash.jpg) - -The unpopulated header in the Sonoff has all the required pins. My board has a 5 pins header in-line with the button. They are (from the button outwards) 3V3, RX, TX, GND and GPIO14. - -Last one is not necessary. Mind it's a **3V3 device**, if connected to 5V you will probably fry it. Button is connected to GPIO0 on the ESP8266 chip, so to enter flash mode you have to hold the button pressed while powering on the board, then you can release it again. - -## IteadStudio Sonoff RF - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/sonoff-rf.html][2]| -|Build flag|SONOFF_RF| - -### Flashing - -![Sonoff POW - Inside back view](images/sonoff-rf-flash.jpg) - -The Sonoff RF has the same unpopulated header as the Sonoff. It is a 5 pins header in-line with the button. They are (from the button outwards) 3V3, RX, TX, GND and GPIO14. - -Solder a male or female header here and connect your USB-to-UART programmer (remember **it's a 3V3 device**). This time through **the button is not connected to GPIO0** but to a EFM8BB1 microcontroller that also monitors the RF module output. - -There are a couple of ways to enter flash mode. Some recommend to move 0Ohm R9 resistor to R21 to connect the button directly to the ESP8266 GPIO0 and use it in the same way as for the Sonoff or Sonoff TH. The drawback is the by doing that you lose the RF capability. - -My recommendation is to **temporary shortcut the bottom pad of the unpopulated R21 footprint** (see the image above) and connect your USB-to-UART board at the same time. You will have to do it just once (unless there is something really wrong in the firmware) and use OTA updates from there on. - - -## IteadStudio Sonoff TH - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/sonoff-th.html](https://www.itead.cc/sonoff-th.html)| -|Build flag|SONOFF_TH| - -### Flashing - -![Sonoff TH - Inside back view](images/sonoff-th-flash.jpg) - -You have all the required pins in an unpopulated header in one of the corners of the board (see top left corner in the image above). Solder a 4 pins male or female header here and connect it to your favourite USB-to-UART module. Remember: **it's a 3V3 device**!!. - -As in the Sonoff the button is connected to GPIO0, so to enter flash mode press and hold the button and connect the programmer to your computer to power the board. - -## IteadStudio Sonoff POW - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/sonoff-pow.html](https://www.itead.cc/sonoff-pow.html)| -|Build flag|SONOFF_POW| - -### Flashing - -![Sonoff POW - Inside back view](images/sonoff-pow-flash.jpg) - -Same as for the [Sonoff TH](#iteadstudio-sonoff-th) above. - -## IteadStudio Sonoff DUAL - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/sonoff-dual.html](https://www.itead.cc/sonoff-dual.html)| -|Build flag|SONOFF_DUAL| - -### Flashing - -![Sonoff DUAL - Inside back view](images/sonoff-dual-flash.jpg) - -The Sonoff Dual it's a bit tricky to flash since GPIO0 is not connected to the button as in the TH or POW, but to the pin 15 in the SIL F330 chip that manages the buttons and the relays. SO you have to locate a pad connected to GPIO and short it to ground while powering the device. - -In the picture above you have a location of an available and easily accessible GPIO0 pad. The other required pins are brought out in the top header. Remember it's a *3V3* device. - -Once flashed use OTA to update the firmware or the filesystem. - -## IteadStudio Sonoff TOUCH - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/sonoff-touch.html](https://www.itead.cc/sonoff-touch.html)| -|Build flag|SONOFF_TOUCH| - -### Flashing - -*TODO* - -## IteadStudio Sonoff 4CH - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/sonoff-4ch.html](https://www.itead.cc/sonoff-4ch.html)| -|Build flag|SONOFF_4CH| - -### Flashing - -*TODO* - -## IteadStudio Sonoff SV - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/sonoff-sv.html](https://www.itead.cc/sonoff-sv.html)| -|Build flag|SONOFF_SV| - -### Flashing - -*TODO* - -## IteadStudio Slampher - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/slampher.html](https://www.itead.cc/slampher.html)| -|Build flag|SLAMPHER| - -### Flashing - -![Slampher - Inside front view](images/slampher-flash1.jpg) -![Slampher - Flashing short](images/slampher-flash2.jpg) - -There is a 4 pin unpopulated header in a border near the ESP8266 chip. Starting form the little white mark this header brings out 3V3, RX, TX and GND. Solder a male or female header here and connect your USB-to-UART programmer (remember it's a 3V3 device). This time through **the button is not connected to GPIO0** but to a EFM8BB1 microcontroller that also monitors the RF module output. - -There are a couple of ways to enter flash mode. Some recommend to move R21 to R20 (at the top right of the first picture above) to connect the button directly to the ESP8266 GPIO0 and use it in the same way as for the Sonoff or Sonoff TH. The drawback is the by doing that you lose the RF capability. - -My recommendation is to **temporary shortcut the right pad of the unpopulated R20 footprint** (see second image above) and connect your USB-to-UART board at the same time. You will have to do it just once (unless there is something really wrong in the firmware) and use OTA updates from there on. - -## IteadStudio S20 Smart Socket - -|Property|Value| -|---|---| -|Manufacturer|Itead Studio| -|Web page|[https://www.itead.cc/smart-socket.html](https://www.itead.cc/smart-socket.html)| -|Build flag|S20| - -### Flashing - -![S20 Smart Socket - Inside front view](images/s20-flash.jpg) - -There is a labeled header in the front of the PCB and the button is connected to GPIO0, so no problems here. - -Solder a 4 pin male or female header and connect it to your USB-to-UART bridge. Again, remember **it's a 3V3 device**. Then press and hold the button and connect the programmer to your computer. The microcontroller will boot into flash mode and you are ready to update the firmware. - -## Electrodragon ESP Relay Board - -|Property|Value| -|---|---| -|Manufacturer|Electrodragon| -|Web page|[http://www.electrodragon.com/product/wifi-iot-relay-board-based-esp8266/](http://www.electrodragon.com/product/wifi-iot-relay-board-based-esp8266/)| -|Build flag|ESP_RELAY_BOARD| - -### Flashing - -![Electrodragon ESP Relay Board - Front view](images/electrodragon-flash.jpg) - -The Electrodragon ESP Relay Board is pretty easy to flash IF you do not follow their wiki, it's all wrong. Check the picture above and note that: - -* Power the board from the 5V pin, GND to GND -* The RX pin in the header should go to your programmer TX pin and -* The TX pin in the header should go to your programmer RX pin -* The button labeled BTN2 is connected to GPIO0, so hold it down while powering the board, I've had better results keeping it down until the flashing starts - -## WorkChoice EcoPlug - -|Property|Value| -|---|---| -|Manufacturer|WorkChoice| -|Web page (non-official)|[http://thegreatgeekery.blogspot.com.es/2016/02/ecoplug-wifi-switch-hacking.html](http://thegreatgeekery.blogspot.com.es/2016/02/ecoplug-wifi-switch-hacking.html)| -|Build flag|ECOPLUG| - -### Flashing - -*TODO* - - - -[1]: https://www.itead.cc/sonoff-wifi-wireless-switch.html -[2]: https://www.itead.cc/sonoff-rf.html -[2]: https://www.itead.cc/sonoff-th.html -[4]: https://www.itead.cc/sonoff-pow.html -[5]: https://www.itead.cc/slampher.html -[6]: https://www.itead.cc/smart-socket.html diff --git a/docs/OTA.md b/docs/OTA.md deleted file mode 100644 index 38ec909d..00000000 --- a/docs/OTA.md +++ /dev/null @@ -1,28 +0,0 @@ -# Over-the-air updates - -## Manually driven OTA updates - -Once you have flashed your board with the ESPurna firmware you can flash it again over-the-air using PlatformIO and the ```ota``` environment: - -```bash -> pio run -t upload -e node-debug-ota -> pio run -t uploadfs -e node-debug-ota -``` - -When using OTA environment it defaults to the IP address of the device in SoftAP mode. If you want to flash it when connected to your home network best way is to supply the IP of the device: - -```bash -> pio run -t upload -e node-debug-ota --upload-port 192.168.1.151 -> pio run -t uploadfs -e node-debug-ota --upload-port 192.168.1.151 -``` - -Please note that if you have changed the admin password from the web interface you will have to change it too in the platformio.ini file for the OTA to work. Check for the *upload_flags* option in your ota-enabled environment. - -## Automatic OTA updates - -You can also use the automatic OTA update feature. Check the [NoFUSS library][6] for more info. - -This options is disabled by default. Enable it in your firmware with the -DENABLE_FUSS build flag. - - -[6]: https://bitbucket.org/xoseperez/nofuss diff --git a/docs/Sensors.md b/docs/Sensors.md deleted file mode 100644 index 34bd1811..00000000 --- a/docs/Sensors.md +++ /dev/null @@ -1,3 +0,0 @@ -# Sensors - -*TODO* diff --git a/docs/Troubleshooting.md b/docs/Troubleshooting.md deleted file mode 100644 index 4e318157..00000000 --- a/docs/Troubleshooting.md +++ /dev/null @@ -1,13 +0,0 @@ -# Troubleshooting - -## Problems resetting the board - -After flashing the firmware via serial do a hard reset of the device (unplug & plug). There is an issue with the ESP.reset() method. Check [https://github.com/esp8266/Arduino/issues/1017][1] for more info. - -## Can't find espresiff8266_stage platform - -The fauxmoESP library requires the staging version of Arduino Core for ESP8266. Either you are using Arduino IDE or PlatformIO you will have to manually install this. Check the [documentation for the fauxmoESP library][2] for more info. - - -[1]: https://github.com/esp8266/Arduino/issues/1017 -[2]: https://bitbucket.org/xoseperez/fauxmoesp diff --git a/docs/images/electrodragon-flash.jpg b/docs/images/electrodragon-flash.jpg deleted file mode 100644 index b440bbdd..00000000 Binary files a/docs/images/electrodragon-flash.jpg and /dev/null differ diff --git a/docs/images/s20-flash.jpg b/docs/images/s20-flash.jpg deleted file mode 100644 index 6d0a4315..00000000 Binary files a/docs/images/s20-flash.jpg and /dev/null differ diff --git a/docs/images/slampher-flash1.jpg b/docs/images/slampher-flash1.jpg deleted file mode 100644 index 25bcc29e..00000000 Binary files a/docs/images/slampher-flash1.jpg and /dev/null differ diff --git a/docs/images/slampher-flash2.jpg b/docs/images/slampher-flash2.jpg deleted file mode 100644 index a3ab9b0b..00000000 Binary files a/docs/images/slampher-flash2.jpg and /dev/null differ diff --git a/docs/images/sonoff-dual-flash.jpg b/docs/images/sonoff-dual-flash.jpg deleted file mode 100644 index 93dd3c70..00000000 Binary files a/docs/images/sonoff-dual-flash.jpg and /dev/null differ diff --git a/docs/images/sonoff-flash.jpg b/docs/images/sonoff-flash.jpg deleted file mode 100644 index cf667938..00000000 Binary files a/docs/images/sonoff-flash.jpg and /dev/null differ diff --git a/docs/images/sonoff-pow-flash.jpg b/docs/images/sonoff-pow-flash.jpg deleted file mode 100644 index 7d177e48..00000000 Binary files a/docs/images/sonoff-pow-flash.jpg and /dev/null differ diff --git a/docs/images/sonoff-rf-flash.jpg b/docs/images/sonoff-rf-flash.jpg deleted file mode 100644 index 8265b982..00000000 Binary files a/docs/images/sonoff-rf-flash.jpg and /dev/null differ diff --git a/docs/images/sonoff-th-flash.jpg b/docs/images/sonoff-th-flash.jpg deleted file mode 100644 index 2e3dc3a1..00000000 Binary files a/docs/images/sonoff-th-flash.jpg and /dev/null differ diff --git a/images/devices/1ch-inching.jpg b/images/devices/1ch-inching.jpg new file mode 100644 index 00000000..fc227042 Binary files /dev/null and b/images/devices/1ch-inching.jpg differ diff --git a/images/devices/d1mini.jpg b/images/devices/d1mini.jpg new file mode 100644 index 00000000..8ebb4b2d Binary files /dev/null and b/images/devices/d1mini.jpg differ diff --git a/images/devices/electrodragon-relay-board.jpg b/images/devices/electrodragon-relay-board.jpg new file mode 100644 index 00000000..8a6ac83b Binary files /dev/null and b/images/devices/electrodragon-relay-board.jpg differ diff --git a/images/devices/motor-switch.jpg b/images/devices/motor-switch.jpg new file mode 100644 index 00000000..576de922 Binary files /dev/null and b/images/devices/motor-switch.jpg differ diff --git a/images/devices/s20.jpg b/images/devices/s20.jpg new file mode 100644 index 00000000..695850a5 Binary files /dev/null and b/images/devices/s20.jpg differ diff --git a/images/devices/slampher.jpg b/images/devices/slampher.jpg new file mode 100644 index 00000000..d62d051f Binary files /dev/null and b/images/devices/slampher.jpg differ diff --git a/images/devices/sonoff-4ch.jpg b/images/devices/sonoff-4ch.jpg new file mode 100644 index 00000000..dea3fa45 Binary files /dev/null and b/images/devices/sonoff-4ch.jpg differ diff --git a/images/devices/sonoff-basic.jpg b/images/devices/sonoff-basic.jpg new file mode 100644 index 00000000..26f034cb Binary files /dev/null and b/images/devices/sonoff-basic.jpg differ diff --git a/images/devices/sonoff-dual.jpg b/images/devices/sonoff-dual.jpg new file mode 100644 index 00000000..8dbc4a37 Binary files /dev/null and b/images/devices/sonoff-dual.jpg differ diff --git a/images/devices/sonoff-led.jpg b/images/devices/sonoff-led.jpg new file mode 100644 index 00000000..33215c81 Binary files /dev/null and b/images/devices/sonoff-led.jpg differ diff --git a/images/devices/sonoff-pow.jpg b/images/devices/sonoff-pow.jpg new file mode 100644 index 00000000..c5458e25 Binary files /dev/null and b/images/devices/sonoff-pow.jpg differ diff --git a/images/devices/sonoff-rf.jpg b/images/devices/sonoff-rf.jpg new file mode 100644 index 00000000..70a14bb6 Binary files /dev/null and b/images/devices/sonoff-rf.jpg differ diff --git a/images/devices/sonoff-sv.jpg b/images/devices/sonoff-sv.jpg new file mode 100644 index 00000000..86ea2c44 Binary files /dev/null and b/images/devices/sonoff-sv.jpg differ diff --git a/images/devices/sonoff-th10-th16.jpg b/images/devices/sonoff-th10-th16.jpg new file mode 100644 index 00000000..a3e728d3 Binary files /dev/null and b/images/devices/sonoff-th10-th16.jpg differ diff --git a/images/devices/sonoff-touch.jpg b/images/devices/sonoff-touch.jpg new file mode 100644 index 00000000..5156a2cb Binary files /dev/null and b/images/devices/sonoff-touch.jpg differ diff --git a/images/devices/workchoice-ecoplug.jpg b/images/devices/workchoice-ecoplug.jpg new file mode 100644 index 00000000..2605517b Binary files /dev/null and b/images/devices/workchoice-ecoplug.jpg differ