Skip to content

Commit

Permalink
(2.3.3) Fixed ESP32 disconnect
Browse files Browse the repository at this point in the history
Added getLastChangedProperty()
  • Loading branch information
Aircoookie committed Feb 6, 2019
1 parent fdee318 commit db991ea
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
10 changes: 10 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#######################################
# Syntax Coloring Map For Espalexa
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

Espalexa KEYWORD1
EspalexaDevice KEYWORD1
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/Espalexa.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
/*
* @title Espalexa library
* @version 2.3.2
* @version 2.3.3
* @author Christian Schwinne
* @license MIT
* @contributors d-999
Expand Down Expand Up @@ -46,7 +46,7 @@
#include <WiFiUdp.h>

#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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -222,13 +222,15 @@ class Espalexa {
void alexaOn(uint8_t deviceId)
{
devices[deviceId-1]->setValue(devices[deviceId-1]->getLastValue());
devices[deviceId-1]->setPropertyChanged(1);
devices[deviceId-1]->doCallback();
}

//called when Alexa sends OFF command
void alexaOff(uint8_t deviceId)
{
devices[deviceId-1]->setValue(0);
devices[deviceId-1]->setPropertyChanged(2);
devices[deviceId-1]->doCallback();
}

Expand All @@ -241,20 +243,23 @@ class Espalexa {
} else {
devices[deviceId-1]->setValue(briL+1);
}
devices[deviceId-1]->setPropertyChanged(3);
devices[deviceId-1]->doCallback();
}

//called when Alexa sends HUE command
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();
}

//called when Alexa sends CT command (color temperature)
void alexaCt(uint8_t deviceId, uint16_t ct)
{
devices[deviceId-1]->setColor(ct);
devices[deviceId-1]->setPropertyChanged(5);
devices[deviceId-1]->doCallback();
}

Expand Down Expand Up @@ -346,6 +351,7 @@ class Espalexa {
if (len > 0) {
packetBuffer[len] = 0;
}
espalexaUdp.flush();

String request = packetBuffer;
EA_DEBUGLN(request);
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions src/EspalexaDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ String EspalexaDevice::getName()
return _deviceName;
}

uint8_t EspalexaDevice::getLastChangedProperty()
{
return _changed;
}

uint8_t EspalexaDevice::getValue()
{
return _val;
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions src/EspalexaDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit db991ea

Please sign in to comment.