From e002753a2c875901340d437a84f0520df17a8677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Wed, 15 Aug 2018 23:13:26 +0200 Subject: [PATCH 1/2] Using unreleased fauxmoESP 3.0.0 --- README.md | 6 +-- code/espurna/alexa.ino | 101 +++++++++++++++++++++++++++++------------ code/platformio.ini | 2 +- 3 files changed, 75 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 4ba35419..b3a0ffa1 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. [![version](https://img.shields.io/badge/version-1.13.2b-brightgreen.svg)](CHANGELOG.md) -[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna/tree/dev/) -[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) -[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) +[![branch](https://img.shields.io/badge/branch-alexa-orange.svg)](https://github.com/xoseperez/espurna/tree/alexa/) +[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=alexa)](https://travis-ci.org/xoseperez/espurna) +[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/alexa.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
[![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=xose%2eperez%40gmail%2ecom&lc=US&no_note=0¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest) diff --git a/code/espurna/alexa.ino b/code/espurna/alexa.ino index 81815d8b..f1d552a3 100644 --- a/code/espurna/alexa.ino +++ b/code/espurna/alexa.ino @@ -11,13 +11,13 @@ Copyright (C) 2016-2018 by Xose PĂ©rez #include fauxmoESP alexa; -struct AlexaDevChange { - AlexaDevChange(unsigned char device_id, bool state) : device_id(device_id), state(state) {}; - unsigned char device_id = 0; - bool state = false; -}; #include -static std::queue _alexa_dev_changes; +typedef struct { + unsigned char device_id; + bool state; + unsigned char value; +} alexa_queue_element_t; +static std::queue _alexa_queue; // ----------------------------------------------------------------------------- // ALEXA @@ -29,15 +29,19 @@ bool _alexaWebSocketOnReceive(const char * key, JsonVariant& value) { void _alexaWebSocketOnSend(JsonObject& root) { root["alexaVisible"] = 1; - root["alexaEnabled"] = getSetting("alexaEnabled", ALEXA_ENABLED).toInt() == 1; + root["alexaEnabled"] = alexaEnabled(); } void _alexaConfigure() { - alexa.enable(getSetting("alexaEnabled", ALEXA_ENABLED).toInt() == 1); + alexa.enable(wifiConnected() && alexaEnabled()); } // ----------------------------------------------------------------------------- +bool alexaEnabled() { + return (getSetting("alexaEnabled", ALEXA_ENABLED).toInt() == 1); +} + void alexaSetup() { // Backwards compatibility @@ -46,32 +50,56 @@ void alexaSetup() { // Load & cache settings _alexaConfigure(); - #if WEB_SUPPORT + // Uses hostname as base name for all devices + // TODO: use custom switch name when available + String hostname = getSetting("hostname"); + + // Lights + #if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT + + // Global switch + alexa.addDevice(hostname.c_str()); + + // For each channel + for (unsigned char i = 1; i <= lightChannels(); i++) { + alexa.addDevice((hostname + " " + i).c_str()); + } + + // Relays + #else + + unsigned int relays = relayCount(); + if (relays == 1) { + alexa.addDevice(hostname.c_str()); + } else { + for (unsigned int i=1; i<=relays; i++) { + alexa.addDevice((hostname + " " + i).c_str()); + } + } - // Websockets + #endif + + // Websockets + #if WEB_SUPPORT wsOnSendRegister(_alexaWebSocketOnSend); wsOnAfterParseRegister(_alexaConfigure); wsOnReceiveRegister(_alexaWebSocketOnReceive); - #endif - unsigned int relays = relayCount(); - String hostname = getSetting("hostname"); - if (relays == 1) { - alexa.addDevice(hostname.c_str()); - } else { - for (unsigned int i=0; i Date: Wed, 15 Aug 2018 23:42:55 +0200 Subject: [PATCH 2/2] Reference fauxmoESP 3.0.0 --- code/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/platformio.ini b/code/platformio.ini index 791ae6ea..78a2c147 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -76,6 +76,7 @@ lib_deps = https://github.com/plerup/espsoftwareserial#3.4.1 https://github.com/me-no-dev/ESPAsyncTCP#55cd520 https://github.com/me-no-dev/ESPAsyncWebServer#05306e4 + https://bitbucket.org/xoseperez/fauxmoesp.git#3.0.0 https://github.com/xoseperez/hlw8012.git#1.1.0 https://github.com/markszabo/IRremoteESP8266#v2.2.0 https://github.com/xoseperez/justwifi.git#2.0.1 @@ -90,7 +91,6 @@ lib_deps = https://github.com/LowPowerLab/RFM69#1.1.3 https://github.com/xoseperez/Time NewPing -# https://bitbucket.org/xoseperez/fauxmoesp.git#2.4.2 lib_ignore = # ------------------------------------------------------------------------------