diff --git a/CHANGELOG.md b/CHANGELOG.md index b5fb5a14..a214c344 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### 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 +- Comment out hardware selection in hardware.h if using Arduino IDE + ### Changed - Using unreleased AsyncMqttClient with stability improvements +- Better decoupling between MQTT and relays/websockets ## [1.1.0] 2016-12-06 ### Added diff --git a/code/data/script.js.gz b/code/data/script.js.gz index df838103..046d536b 100644 Binary files a/code/data/script.js.gz and b/code/data/script.js.gz differ diff --git a/code/html/custom.js b/code/html/custom.js index 8b80db50..2fe39e42 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -70,7 +70,7 @@ function createRelays(count) { $(line).find("input").each(function() { $(this).attr("data", relayID); }); - if (count > 1) $(".relay_id", line).html(" " + relayID); + if (count > 1) $(".relay_id", line).html(" " + (relayID+1)); line.appendTo("#relays"); $(":checkbox", line).iphoneStyle({ onChange: doToggle, diff --git a/code/platformio.ini b/code/platformio.ini index 891e42c7..edc8d1d4 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -127,6 +127,27 @@ upload_speed = 115200 upload_port = "192.168.4.1" upload_flags = --auth=fibonacci --port 8266 +[env:sonoff-4ch-debug] +platform = espressif8266 +framework = arduino +board = esp01_1m +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +extra_script = pio_hooks.py +build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DSONOFF_4CH + +[env:sonoff-4ch-debug-ota] +platform = espressif8266 +framework = arduino +board = esp01_1m +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +extra_script = pio_hooks.py +build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DSONOFF_4CH +upload_speed = 115200 +upload_port = "192.168.4.1" +upload_flags = --auth=fibonacci --port 8266 + [env:slampher-debug] platform = espressif8266 framework = arduino @@ -189,31 +210,3 @@ build_flags = -g -DDEBUG_PORT=Serial -DDEBUG_PORT=Serial -DESP_RELAY_BOARD -DENA upload_speed = 115200 upload_port = "192.168.4.1" upload_flags = --auth=fibonacci --port 8266 - -# ------------------------------------------------------------------------------ - -[env:studio-lamp-device] -topic = /home/studio/lamp/ip -platform = espressif8266_stage -framework = arduino -board = esp01_1m -lib_deps = ${common.lib_deps} -lib_ignore = -extra_script = pio_hooks.py -build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DSONOFF -DENABLE_FAUXMO=1 -upload_speed = 115200 -upload_port = "192.168.4.1" -upload_flags = --auth=fibonacci --port 8266 - -[env:living-lamp-device] -topic = /home/living/lamp/ip -platform = espressif8266_stage -framework = arduino -board = esp01_1m -lib_deps = ${common.lib_deps} -lib_ignore = -extra_script = pio_hooks.py -build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DSONOFF -DENABLE_FAUXMO=1 -upload_speed = 115200 -upload_port = "192.168.4.1" -upload_flags = --auth=fibonacci --port 8266 diff --git a/code/src/button.ino b/code/src/button.ino index 4f5d6b26..baaaca41 100644 --- a/code/src/button.ino +++ b/code/src/button.ino @@ -55,21 +55,46 @@ void buttonLoop() { } #else -#ifdef BUTTON_PIN +#ifdef BUTTON1_PIN #include -DebounceEvent button1 = false; +#include + +std::vector _buttons; void buttonSetup() { - button1 = DebounceEvent(BUTTON_PIN); + + #ifdef BUTTON1_PIN + _buttons.push_back(new DebounceEvent(BUTTON1_PIN)); + #endif + #ifdef BUTTON2_PIN + _buttons.push_back(new DebounceEvent(BUTTON2_PIN)); + #endif + #ifdef BUTTON3_PIN + _buttons.push_back(new DebounceEvent(BUTTON3_PIN)); + #endif + #ifdef BUTTON4_PIN + _buttons.push_back(new DebounceEvent(BUTTON4_PIN)); + #endif + + DEBUG_MSG("[BUTTON] Number of buttons: %d\n", _buttons.size()); + } void buttonLoop() { - if (button1.loop()) { - if (button1.getEvent() == EVENT_SINGLE_CLICK) relayToggle(0); - if (button1.getEvent() == EVENT_DOUBLE_CLICK) createAP(); - if (button1.getEvent() == EVENT_LONG_CLICK) ESP.reset(); + + for (unsigned int i=0; i < _buttons.size(); i++) { + if (_buttons[i]->loop()) { + uint8_t event = _buttons[i]->getEvent(); + DEBUG_MSG("[BUTTON] Pressed #%d, event: %d\n", i, event); + if (i == 0) { + if (event == EVENT_DOUBLE_CLICK) createAP(); + if (event == EVENT_LONG_CLICK) ESP.reset(); + } + if (event == EVENT_SINGLE_CLICK) relayToggle(i); + } } + } #else diff --git a/code/src/config/hardware.h b/code/src/config/hardware.h index 9adec94e..babbfea0 100644 --- a/code/src/config/hardware.h +++ b/code/src/config/hardware.h @@ -6,7 +6,7 @@ #define MANUFACTURER "NODEMCU" #define DEVICE "LOLIN" - #define BUTTON_PIN 0 + #define BUTTON1_PIN 0 #define RELAY1_PIN 12 #define LED_PIN 2 #define LED_PIN_INVERSE 0 @@ -19,7 +19,7 @@ #define MANUFACTURER "ITEAD" #define DEVICE "SONOFF" - #define BUTTON_PIN 0 + #define BUTTON1_PIN 0 #define RELAY1_PIN 12 #define LED_PIN 13 #define LED_PIN_INVERSE 0 @@ -28,7 +28,7 @@ #define MANUFACTURER "ITEAD" #define DEVICE "SONOFF_TH" - #define BUTTON_PIN 0 + #define BUTTON1_PIN 0 #define RELAY1_PIN 12 #define LED_PIN 13 #define LED_PIN_INVERSE 0 @@ -37,7 +37,7 @@ #define MANUFACTURER "ITEAD" #define DEVICE "SONOFF_TOUCH" - #define BUTTON_PIN 0 + #define BUTTON1_PIN 0 #define RELAY1_PIN 12 #define LED_PIN 13 #define LED_PIN_INVERSE 1 @@ -46,7 +46,7 @@ #define MANUFACTURER "ITEAD" #define DEVICE "SONOFF_POW" - #define BUTTON_PIN 0 + #define BUTTON1_PIN 0 #define RELAY1_PIN 12 #define LED_PIN 15 #define LED_PIN_INVERSE 1 @@ -56,17 +56,32 @@ #define MANUFACTURER "ITEAD" #define DEVICE "SONOFF_DUAL" - #define BUTTON_PIN 0 + #define BUTTON1_PIN 0 #define LED_PIN 13 #define LED_PIN_INVERSE 0 #undef SERIAL_BAUDRATE #define SERIAL_BAUDRATE 19230 +#elif defined(SONOFF_4CH) + + #define MANUFACTURER "ITEAD" + #define DEVICE "SONOFF_4CH" + #define BUTTON1_PIN 0 + #define BUTTON2_PIN 9 + #define BUTTON3_PIN 10 + #define BUTTON4_PIN 14 + #define RELAY1_PIN 12 + #define RELAY2_PIN 5 + #define RELAY3_PIN 4 + #define RELAY4_PIN 15 + #define LED_PIN 13 + #define LED_PIN_INVERSE 1 + #elif defined(SLAMPHER) #define MANUFACTURER "ITEAD" #define DEVICE "SLAMPHER" - #define BUTTON_PIN 0 + #define BUTTON1_PIN 0 #define RELAY1_PIN 12 #define LED_PIN 13 #define LED_PIN_INVERSE 0 @@ -75,7 +90,7 @@ #define MANUFACTURER "ITEAD" #define DEVICE "S20" - #define BUTTON_PIN 0 + #define BUTTON1_PIN 0 #define RELAY1_PIN 12 #define LED_PIN 13 #define LED_PIN_INVERSE 0 @@ -88,7 +103,8 @@ #define MANUFACTURER "ELECTRODRAGON" #define DEVICE "ESP_RELAY_BOARD" - #define BUTTON_PIN 2 + #define BUTTON1_PIN 0 + #define BUTTON2_PIN 2 #define RELAY1_PIN 12 #define RELAY2_PIN 13 #define LED_PIN 16 @@ -102,7 +118,7 @@ #define MANUFACTURER "WORKCHOICE" #define DEVICE "ECOPLUG" - #define BUTTON_PIN 13 + #define BUTTON1_PIN 13 #define RELAY_PIN 15 #define LED_PIN 2 #define LED_PIN_INVERSE 1 @@ -115,7 +131,7 @@ #define MANUFACTURER "TINKERMAN" #define DEVICE "ESPURNA" - #define BUTTON_PIN 0 + #define BUTTON1_PIN 0 #define RELAY1_PIN 12 #define LED_PIN 13 #define LED_PIN_INVERSE 0 diff --git a/code/src/config/version.h b/code/src/config/version.h index b11726cc..f49016c7 100644 --- a/code/src/config/version.h +++ b/code/src/config/version.h @@ -1,4 +1,4 @@ #define APP_NAME "ESPurna" -#define APP_VERSION "1.1.0" +#define APP_VERSION "1.2.0" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" diff --git a/code/src/main.ino b/code/src/main.ino index e0dd71e6..c87b5c2b 100644 --- a/code/src/main.ino +++ b/code/src/main.ino @@ -104,9 +104,6 @@ void welcome() { void setup() { hardwareSetup(); - buttonSetup(); - ledSetup(); - welcome(); settingsSetup(); @@ -116,6 +113,8 @@ void setup() { } relaySetup(); + buttonSetup(); + ledSetup(); wifiSetup(); otaSetup(); mqttSetup(); diff --git a/code/src/relay.ino b/code/src/relay.ino index a27a4df2..77b7cb92 100644 --- a/code/src/relay.ino +++ b/code/src/relay.ino @@ -239,4 +239,6 @@ void relaySetup() { mqttRegister(relayMQTTCallback); + DEBUG_MSG("[RELAY] Number of relays: %d\n", _relays.size()); + }