From 12bbfd962b0529d5d33bec995a15a1a16c0aef9e Mon Sep 17 00:00:00 2001 From: reloxx13 Date: Wed, 13 Dec 2017 23:39:54 +0100 Subject: [PATCH 1/2] Add WeMo GetBinaryState --- sonoff/xdrv_wemohue.ino | 93 ++++++++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 24 deletions(-) diff --git a/sonoff/xdrv_wemohue.ino b/sonoff/xdrv_wemohue.ino index 9fbb3cd35..ad339a382 100755 --- a/sonoff/xdrv_wemohue.ino +++ b/sonoff/xdrv_wemohue.ino @@ -242,18 +242,18 @@ void PollUdp() const char WEMO_EVENTSERVICE_XML[] PROGMEM = "" - "" - "" - "SetBinaryState" - "" - "" - "" - "BinaryState" - "BinaryState" - "in" - "" - "" - "" + "" + "" + "SetBinaryState" + "" + "" + "" + "BinaryState" + "BinaryState" + "in" + "" + "" + "" "" "BinaryState" "Boolean" @@ -263,14 +263,43 @@ const char WEMO_EVENTSERVICE_XML[] PROGMEM = "level" "string" "0" - "" - "" + "" + "" + "" + "" + "GetBinaryState" + "" + "" + "" + "BinaryState" + "BinaryState" + "out" + "" + "" "" "\r\n" "\r\n"; +const char WEMO_SETSTATE_XML[] PROGMEM = +"" + "" + "" + "{x1" + "" + "" +"\r\n" +"\r\n"; +const char WEMO_GETSTATE_XML[] PROGMEM = +"" + "" + "" + "{x1" + "" + "" +"\r\n" +"\r\n"; const char WEMO_SETUP_XML[] PROGMEM = "" - "" + "" "" "urn:Belkin:device:controllee:1" "{x1" @@ -297,17 +326,34 @@ const char WEMO_SETUP_XML[] PROGMEM = void HandleUpnpEvent() { - AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT)); String request = WebServer->arg(0); - if (request.indexOf(F("State>1 0) { -// ExecuteCommandPower(1, 1); - ExecuteCommandPower(devices_present, 1); + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT)); + //differentiate get and set state + if (request.indexOf(F("SetBinaryState")) > 0) { + String setstate_xml = FPSTR(WEMO_SETSTATE_XML); + if (request.indexOf(F("State>1 0) { + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " SET STATE 1")); + ExecuteCommandPower(devices_present, 1); + setstate_xml.replace("{x1", "1"); + } + else if (request.indexOf(F("State>0 0) { + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " SET STATE 0")); + ExecuteCommandPower(devices_present, 0); + setstate_xml.replace("{x1", "0"); + } + WebServer->send(200, FPSTR(HDR_CTYPE_XML), setstate_xml.c_str()); } - if (request.indexOf(F("State>0 0) { -// ExecuteCommandPower(1, 0); - ExecuteCommandPower(devices_present, 0); + else if(request.indexOf(F("GetBinaryState")) > 0){ + String getstate_xml = FPSTR(WEMO_GETSTATE_XML); + char svalue[80]; + /** TODO: can only return one device status for now in response, + * check how to response multi device status to echo + */ + snprintf_P(svalue, sizeof(svalue), PSTR("%d"), bitRead(power, 1 -1)); + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " GET STATE")); + getstate_xml.replace("{x1", svalue); + WebServer->send(200, FPSTR(HDR_CTYPE_XML), getstate_xml.c_str()); } - WebServer->send(200, FPSTR(HDR_CTYPE_PLAIN), ""); } void HandleUpnpService() @@ -720,4 +766,3 @@ void HandleHueApi(String *path) } #endif // USE_WEBSERVER #endif // USE_EMULATION - From f2362af36f51ccfadbbe971f12dc1983215a51e6 Mon Sep 17 00:00:00 2001 From: Nils Sdun Date: Fri, 15 Dec 2017 13:13:53 +0100 Subject: [PATCH 2/2] save some bytes, merge set and get to one pattern --- sonoff/xdrv_wemohue.ino | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/sonoff/xdrv_wemohue.ino b/sonoff/xdrv_wemohue.ino index ad339a382..f8dfb7cc8 100755 --- a/sonoff/xdrv_wemohue.ino +++ b/sonoff/xdrv_wemohue.ino @@ -279,21 +279,12 @@ const char WEMO_EVENTSERVICE_XML[] PROGMEM = "" "\r\n" "\r\n"; -const char WEMO_SETSTATE_XML[] PROGMEM = +const char WEMO_RESPONSE_STATE_XML[] PROGMEM = "" "" - "" - "{x1" - "" - "" -"\r\n" -"\r\n"; -const char WEMO_GETSTATE_XML[] PROGMEM = -"" - "" - "" - "{x1" - "" + "" + "{x2" + "" "" "\r\n" "\r\n"; @@ -326,33 +317,33 @@ const char WEMO_SETUP_XML[] PROGMEM = void HandleUpnpEvent() { - String request = WebServer->arg(0); AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT)); + String request = WebServer->arg(0); + String state_xml = FPSTR(WEMO_RESPONSE_STATE_XML); //differentiate get and set state if (request.indexOf(F("SetBinaryState")) > 0) { - String setstate_xml = FPSTR(WEMO_SETSTATE_XML); if (request.indexOf(F("State>1 0) { AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " SET STATE 1")); ExecuteCommandPower(devices_present, 1); - setstate_xml.replace("{x1", "1"); + state_xml.replace("{x1", "Set"); + state_xml.replace("{x2", "1"); } else if (request.indexOf(F("State>0 0) { AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " SET STATE 0")); ExecuteCommandPower(devices_present, 0); - setstate_xml.replace("{x1", "0"); + + state_xml.replace("{x1", "Set"); + state_xml.replace("{x2", "0"); } - WebServer->send(200, FPSTR(HDR_CTYPE_XML), setstate_xml.c_str()); + WebServer->send(200, FPSTR(HDR_CTYPE_XML), state_xml.c_str()); } else if(request.indexOf(F("GetBinaryState")) > 0){ - String getstate_xml = FPSTR(WEMO_GETSTATE_XML); char svalue[80]; - /** TODO: can only return one device status for now in response, - * check how to response multi device status to echo - */ snprintf_P(svalue, sizeof(svalue), PSTR("%d"), bitRead(power, 1 -1)); AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT " GET STATE")); - getstate_xml.replace("{x1", svalue); - WebServer->send(200, FPSTR(HDR_CTYPE_XML), getstate_xml.c_str()); + state_xml.replace("{x1", "Get"); + state_xml.replace("{x2", svalue); + WebServer->send(200, FPSTR(HDR_CTYPE_XML), state_xml.c_str()); } }