diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..da96567 --- /dev/null +++ b/keywords.txt @@ -0,0 +1,10 @@ +####################################### +# Syntax Coloring Map For Espalexa +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Espalexa KEYWORD1 +EspalexaDevice KEYWORD1 \ No newline at end of file diff --git a/library.properties b/library.properties index cbacdd1..ff24b23 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Espalexa -version=2.3.2 +version=2.3.3 author=Christian Schwinne maintainer=Christian Schwinne sentence=Library to control an ESP module with the Alexa voice assistant diff --git a/src/Espalexa.h b/src/Espalexa.h index 6adb967..7c079a3 100644 --- a/src/Espalexa.h +++ b/src/Espalexa.h @@ -10,7 +10,7 @@ */ /* * @title Espalexa library - * @version 2.3.2 + * @version 2.3.3 * @author Christian Schwinne * @license MIT * @contributors d-999 @@ -46,7 +46,7 @@ #include #ifdef ESPALEXA_DEBUG - #pragma message "Espalexa 2.3.2 debug mode" + #pragma message "Espalexa 2.3.3 debug mode" #define EA_DEBUG(x) Serial.print (x) #define EA_DEBUGLN(x) Serial.println (x) #else @@ -112,7 +112,7 @@ class Espalexa { } res += "\r\nFree Heap: " + (String)ESP.getFreeHeap(); res += "\r\nUptime: " + (String)millis(); - res += "\r\n\r\nEspalexa library v2.3.2 by Christian Schwinne 2019"; + res += "\r\n\r\nEspalexa library v2.3.3 by Christian Schwinne 2019"; server->send(200, "text/plain", res); } @@ -222,6 +222,7 @@ class Espalexa { void alexaOn(uint8_t deviceId) { devices[deviceId-1]->setValue(devices[deviceId-1]->getLastValue()); + devices[deviceId-1]->setPropertyChanged(1); devices[deviceId-1]->doCallback(); } @@ -229,6 +230,7 @@ class Espalexa { void alexaOff(uint8_t deviceId) { devices[deviceId-1]->setValue(0); + devices[deviceId-1]->setPropertyChanged(2); devices[deviceId-1]->doCallback(); } @@ -241,6 +243,7 @@ class Espalexa { } else { devices[deviceId-1]->setValue(briL+1); } + devices[deviceId-1]->setPropertyChanged(3); devices[deviceId-1]->doCallback(); } @@ -248,6 +251,7 @@ class Espalexa { void alexaCol(uint8_t deviceId, uint16_t hue, uint8_t sat) { devices[deviceId-1]->setColor(hue, sat); + devices[deviceId-1]->setPropertyChanged(4); devices[deviceId-1]->doCallback(); } @@ -255,6 +259,7 @@ class Espalexa { void alexaCt(uint8_t deviceId, uint16_t ct) { devices[deviceId-1]->setColor(ct); + devices[deviceId-1]->setPropertyChanged(5); devices[deviceId-1]->doCallback(); } @@ -346,6 +351,7 @@ class Espalexa { if (len > 0) { packetBuffer[len] = 0; } + espalexaUdp.flush(); String request = packetBuffer; EA_DEBUGLN(request); @@ -391,7 +397,8 @@ class Espalexa { { server = request; //copy request reference String req = request->url(); //body from global variable - if (request->hasParam("body", true)) // workaround should Alexa send incorrect content type + EA_DEBUGLN(request->contentType()); + if (request->hasParam("body", true)) // This is necessary, otherwise ESP crashes if there is no body { EA_DEBUG("BodyMethod2"); body = request->getParam("body", true)->value(); diff --git a/src/EspalexaDevice.cpp b/src/EspalexaDevice.cpp index 9ba1d9e..70f5cdb 100644 --- a/src/EspalexaDevice.cpp +++ b/src/EspalexaDevice.cpp @@ -39,6 +39,11 @@ String EspalexaDevice::getName() return _deviceName; } +uint8_t EspalexaDevice::getLastChangedProperty() +{ + return _changed; +} + uint8_t EspalexaDevice::getValue() { return _val; @@ -120,6 +125,12 @@ uint8_t EspalexaDevice::getLastValue() return _val_last; } +void EspalexaDevice::setPropertyChanged(uint8_t p) +{ + //0: initial 1: on 2: off 3: bri 4: col 5: ct + _changed = p; +} + //you need to re-discover the device for the Alexa name to change void EspalexaDevice::setName(String name) { diff --git a/src/EspalexaDevice.h b/src/EspalexaDevice.h index dc8040a..0974ff3 100644 --- a/src/EspalexaDevice.h +++ b/src/EspalexaDevice.h @@ -13,6 +13,7 @@ class EspalexaDevice { CallbackColFunction _callbackCol; uint8_t _val, _val_last, _sat = 0; uint16_t _hue = 0, _ct = 0; + uint8_t _changed = 0; public: EspalexaDevice(); @@ -23,12 +24,14 @@ class EspalexaDevice { bool isColorDevice(); bool isColorTemperatureMode(); String getName(); + uint8_t getLastChangedProperty(); uint8_t getValue(); uint16_t getHue(); uint8_t getSat(); uint16_t getCt(); uint32_t getColorRGB(); + void setPropertyChanged(uint8_t p); void setValue(uint8_t bri); void setPercent(uint8_t perc); void setName(String name);