5.10.0h - Fix Wemo Emulation (#1486)

5.10.0h
 * Fix Wemo Emulation for Gen 2 devices (#1486)
This commit is contained in:
arendst 2018-01-02 16:08:27 +01:00
parent 24a6960749
commit b1585e8113
10 changed files with 126 additions and 18 deletions

View File

@ -1,7 +1,7 @@
## Sonoff-Tasmota
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.
Current version is **5.10.0g** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
Current version is **5.10.0h** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
### ATTENTION All versions

View File

@ -1,4 +1,7 @@
/* 5.10.0g
/* 5.10.0h
* Fix Wemo Emulation for Gen 2 devices (#1486)
*
* 5.10.0g
* Add 2nd Gen Alexa support to Wemo emulation discovery (#1357, #1450)
*
* 5.10.0f

View File

@ -441,6 +441,7 @@
#define D_WEMO "WeMo"
#define D_WEMO_BASIC_EVENT "WeMo basic event"
#define D_WEMO_EVENT_SERVICE "WeMo event service"
#define D_WEMO_META_SERVICE "WeMo meta service"
#define D_WEMO_SETUP "WeMo-Setup"
#define D_RESPONSE_SENT "Antwort gesendet"
@ -668,6 +669,16 @@
#define D_CMND_INA219MODE "Ina219Mode"
#define D_CMND_EXCEPTION "Exception"
// Commands xdrv_display.ino
#define D_CMND_DISPLAY "Display"
#define D_CMND_DISP_MODEL "Model"
#define D_CMND_DISP_MODE "Mode"
#define D_CMND_DISP_REFRESH "Refresh"
#define D_CMND_DISP_DIMMER "Dimmer"
#define D_CMND_DISP_COLS "Cols"
#define D_CMND_DISP_ROWS "Rows"
#define D_CMND_DISP_ADDRESS "Address"
// Commands xdrv_domoticz.ino
#define D_CMND_DOMOTICZ "Domoticz"
#define D_CMND_IDX "Idx"

View File

@ -441,6 +441,7 @@
#define D_WEMO "WeMo"
#define D_WEMO_BASIC_EVENT "WeMo basic event"
#define D_WEMO_EVENT_SERVICE "WeMo event service"
#define D_WEMO_META_SERVICE "WeMo meta service"
#define D_WEMO_SETUP "WeMo setup"
#define D_RESPONSE_SENT "Response sent"
@ -668,6 +669,16 @@
#define D_CMND_INA219MODE "Ina219Mode"
#define D_CMND_EXCEPTION "Exception"
// Commands xdrv_display.ino
#define D_CMND_DISPLAY "Display"
#define D_CMND_DISP_MODEL "Model"
#define D_CMND_DISP_MODE "Mode"
#define D_CMND_DISP_REFRESH "Refresh"
#define D_CMND_DISP_DIMMER "Dimmer"
#define D_CMND_DISP_COLS "Cols"
#define D_CMND_DISP_ROWS "Rows"
#define D_CMND_DISP_ADDRESS "Address"
// Commands xdrv_domoticz.ino
#define D_CMND_DOMOTICZ "Domoticz"
#define D_CMND_IDX "Idx"

View File

@ -441,6 +441,7 @@
#define D_WEMO "WeMo"
#define D_WEMO_BASIC_EVENT "WeMo evento base"
#define D_WEMO_EVENT_SERVICE "WeMo servizio eventi"
#define D_WEMO_META_SERVICE "WeMo meta service"
#define D_WEMO_SETUP "Impostazione WeMo"
#define D_RESPONSE_SENT "Risposta inviata"
@ -668,6 +669,16 @@
#define D_CMND_INA219MODE "Ina219Mode"
#define D_CMND_EXCEPTION "Exception"
// Commands xdrv_display.ino
#define D_CMND_DISPLAY "Display"
#define D_CMND_DISP_MODEL "Model"
#define D_CMND_DISP_MODE "Mode"
#define D_CMND_DISP_REFRESH "Refresh"
#define D_CMND_DISP_DIMMER "Dimmer"
#define D_CMND_DISP_COLS "Cols"
#define D_CMND_DISP_ROWS "Rows"
#define D_CMND_DISP_ADDRESS "Address"
// Commands xdrv_domoticz.ino
#define D_CMND_DOMOTICZ "Domoticz"
#define D_CMND_IDX "Idx"

View File

@ -441,6 +441,7 @@
#define D_WEMO "WeMo"
#define D_WEMO_BASIC_EVENT "WeMo basis gebeurtenis"
#define D_WEMO_EVENT_SERVICE "WeMo gebeurtenis dienst"
#define D_WEMO_META_SERVICE "WeMo meta service"
#define D_WEMO_SETUP "WeMo installatie"
#define D_RESPONSE_SENT "Antwoord verstuurd"
@ -668,6 +669,16 @@
#define D_CMND_INA219MODE "Ina219Mode"
#define D_CMND_EXCEPTION "Exception"
// Commands xdrv_display.ino
#define D_CMND_DISPLAY "Display"
#define D_CMND_DISP_MODEL "Model"
#define D_CMND_DISP_MODE "Mode"
#define D_CMND_DISP_REFRESH "Refresh"
#define D_CMND_DISP_DIMMER "Dimmer"
#define D_CMND_DISP_COLS "Cols"
#define D_CMND_DISP_ROWS "Rows"
#define D_CMND_DISP_ADDRESS "Address"
// Commands xdrv_domoticz.ino
#define D_CMND_DOMOTICZ "Domoticz"
#define D_CMND_IDX "Idx"

View File

@ -441,6 +441,7 @@
#define D_WEMO "WeMo"
#define D_WEMO_BASIC_EVENT "WeMo podstawowe zdarzenie"
#define D_WEMO_EVENT_SERVICE "WeMo zdarzenie service"
#define D_WEMO_META_SERVICE "WeMo meta service"
#define D_WEMO_SETUP "WeMo setup"
#define D_RESPONSE_SENT "Odpowiedz wyslana"
@ -668,6 +669,16 @@
#define D_CMND_INA219MODE "Ina219Mode"
#define D_CMND_EXCEPTION "Exception"
// Commands xdrv_display.ino
#define D_CMND_DISPLAY "Display"
#define D_CMND_DISP_MODEL "Model"
#define D_CMND_DISP_MODE "Mode"
#define D_CMND_DISP_REFRESH "Refresh"
#define D_CMND_DISP_DIMMER "Dimmer"
#define D_CMND_DISP_COLS "Cols"
#define D_CMND_DISP_ROWS "Rows"
#define D_CMND_DISP_ADDRESS "Address"
// Commands xdrv_domoticz.ino
#define D_CMND_DOMOTICZ "Domoticz"
#define D_CMND_IDX "Idx"

View File

@ -25,8 +25,8 @@
- Select IDE Tools - Flash Size: "1M (no SPIFFS)"
====================================================*/
#define VERSION 0x050A0007
#define VERSION_STRING "5.10.0g" // Would be great to have a macro that fills this from VERSION ...
#define VERSION 0x050A0008
#define VERSION_STRING "5.10.0h" // Would be great to have a macro that fills this from VERSION ...
// Location specific includes
#include "sonoff.h" // Enumaration used in user_config.h

View File

@ -338,6 +338,7 @@ void StartWebserver(int type, IPAddress ipweb)
if (EMUL_WEMO == Settings.flag2.emulation) {
WebServer->on("/upnp/control/basicevent1", HTTP_POST, HandleUpnpEvent);
WebServer->on("/eventservice.xml", HandleUpnpService);
WebServer->on("/metainfoservice.xml", HandleUpnpMetaService);
WebServer->on("/setup.xml", HandleUpnpSetupWemo);
}
if (EMUL_HUE == Settings.flag2.emulation) {
@ -1594,6 +1595,9 @@ void HandleRestart()
void HandleNotFound()
{
// snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP "Not fount (%s)"), WebServer->uri().c_str());
// AddLog(LOG_LEVEL_DEBUG);
if (CaptivePortal()) { // If captive portal redirect instead of displaying the error page.
return;
}

View File

@ -44,8 +44,8 @@ const char WEMO_MSEARCH[] PROGMEM =
"OPT: \"http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n"
"01-NLS: b9200ebb-736d-4b93-bf03-835149d13983\r\n"
"SERVER: Unspecified, UPnP/1.0, Unspecified\r\n"
"ST: urn:Belkin:device:**\r\n"
"USN: uuid:{r2::urn:Belkin:device:**\r\n"
"ST: {r3\r\n" // type1 = urn:Belkin:device:**, type2 = upnp:rootdevice
"USN: uuid:{r2::{r3\r\n" // type1 = urn:Belkin:device:**, type2 = upnp:rootdevice
"X-User-Agent: redsonic\r\n"
"\r\n";
@ -65,7 +65,7 @@ String WemoUuid()
return String(uuid);
}
void WemoRespondToMSearch()
void WemoRespondToMSearch(uint8_t echo_type)
{
char message[TOPSZ];
@ -73,14 +73,19 @@ void WemoRespondToMSearch()
String response = FPSTR(WEMO_MSEARCH);
response.replace("{r1", WiFi.localIP().toString());
response.replace("{r2", WemoUuid());
if (1 == echo_type) { // type1 echo 1g & dot 2g
response.replace("{r3", F("urn:Belkin:device:**"));
} else { // type2 echo 2g (echo, plus, show)
response.replace("{r3", F("upnp:rootdevice"));
}
PortUdp.write(response.c_str());
PortUdp.endPacket();
snprintf_P(message, sizeof(message), PSTR(D_RESPONSE_SENT));
} else {
snprintf_P(message, sizeof(message), PSTR(D_FAILED_TO_SEND_RESPONSE));
}
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPNP D_WEMO " %s " D_TO " %s:%d"),
message, PortUdp.remoteIP().toString().c_str(), PortUdp.remotePort());
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPNP D_WEMO " " D_JSON_TYPE " %d, %s " D_TO " %s:%d"),
echo_type, message, PortUdp.remoteIP().toString().c_str(), PortUdp.remotePort());
AddLog(LOG_LEVEL_DEBUG);
}
@ -220,12 +225,15 @@ void PollUdp()
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: M-SEARCH Packet received"));
// AddLog_P(LOG_LEVEL_DEBUG_MORE, request.c_str());
if ((EMUL_WEMO == Settings.flag2.emulation) &&
((request.indexOf(F("urn:belkin:device:**")) > 0) ||
(request.indexOf(F("upnp:rootdevice")) > 0) || // Needed by 2nd generation Echo
(request.indexOf(F("ssdpsearch:all")) > 0) ||
(request.indexOf(F("ssdp:all")) > 0))) {
WemoRespondToMSearch();
if (EMUL_WEMO == Settings.flag2.emulation) {
if (request.indexOf(F("urn:belkin:device:**")) > 0) { // type1 echo dot 2g, echo 1g's
WemoRespondToMSearch(1);
}
else if ((request.indexOf(F("upnp:rootdevice")) > 0) || // type2 Echo 2g (echo & echo plus)
(request.indexOf(F("ssdpsearch:all")) > 0) ||
(request.indexOf(F("ssdp:all")) > 0)) {
WemoRespondToMSearch(2);
}
}
else if ((EMUL_HUE == Settings.flag2.emulation) &&
((request.indexOf(F("urn:schemas-upnp-org:device:basic:1")) > 0) ||
@ -282,11 +290,35 @@ const char WEMO_EVENTSERVICE_XML[] PROGMEM =
"<defaultValue>0</defaultValue>"
"</stateVariable>"
"</serviceStateTable>"
"</scpd>\r\n"
"\r\n";
"</scpd>\r\n\r\n";
const char WEMO_METASERVICE_XML[] PROGMEM =
"<scpd xmlns=\"urn:Belkin:service-1-0\">"
"<specVersion>"
"<major>1</major>"
"<minor>0</minor>"
"</specVersion>"
"<actionList>"
"<action>"
"<name>GetMetaInfo</name>"
"<argumentList>"
"<retval />"
"<name>GetMetaInfo</name>"
"<relatedStateVariable>MetaInfo</relatedStateVariable>"
"<direction>in</direction>"
"</argumentList>"
"</action>"
"</actionList>"
"<serviceStateTable>"
"<stateVariable sendEvents=\"yes\">"
"<name>MetaInfo</name>"
"<dataType>string</dataType>"
"<defaultValue>0</defaultValue>"
"</stateVariable>"
"</serviceStateTable>"
"</scpd>\r\n\r\n";
const char WEMO_RESPONSE_STATE_SOAP[] PROGMEM =
// Reloxx13 from #1357
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
"<s:Body>"
"<u:SetBinaryStateResponse xmlns:u=\"urn:Belkin:service:basicevent:1\">"
@ -315,6 +347,13 @@ const char WEMO_SETUP_XML[] PROGMEM =
"<eventSubURL>/upnp/event/basicevent1</eventSubURL>"
"<SCPDURL>/eventservice.xml</SCPDURL>"
"</service>"
"<service>"
"<serviceType>urn:Belkin:service:metainfo:1</serviceType>"
"<serviceId>urn:Belkin:serviceId:metainfo1</serviceId>"
"<controlURL>/upnp/control/metainfo1</controlURL>"
"<eventSubURL>/upnp/event/metainfo1</eventSubURL>"
"<SCPDURL>/metainfoservice.xml</SCPDURL>"
"</service>"
"</serviceList>"
"</device>"
"</root>\r\n";
@ -350,6 +389,13 @@ void HandleUpnpService()
WebServer->send(200, FPSTR(HDR_CTYPE_PLAIN), FPSTR(WEMO_EVENTSERVICE_XML));
}
void HandleUpnpMetaService()
{
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_META_SERVICE));
WebServer->send(200, FPSTR(HDR_CTYPE_PLAIN), FPSTR(WEMO_METASERVICE_XML));
}
void HandleUpnpSetupWemo()
{
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_SETUP));