6.5.0.2 Change UDP initial message handling

6.5.0.2 20190325
 * Change UDP initial message handling from string to char using static memory and add debug info (#5505)
This commit is contained in:
Theo Arends 2019-03-25 16:03:28 +01:00
parent 57cb570b8f
commit 1c7fb82af8
3 changed files with 29 additions and 21 deletions

View File

@ -1,4 +1,7 @@
/* 6.5.0.1 20190319 /* 6.5.0.2 20190325
* Change UDP initial message handling from string to char using static memory and add debug info (#5505)
*
* 6.5.0.1 20190319
* Change Web GUI sensor data collection * Change Web GUI sensor data collection
* *
* 6.5.0 20190319 * 6.5.0 20190319

View File

@ -20,7 +20,7 @@
#ifndef _SONOFF_VERSION_H_ #ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_
#define VERSION 0x06050001 #define VERSION 0x06050002
#define D_PROGRAMNAME "Sonoff-Tasmota" #define D_PROGRAMNAME "Sonoff-Tasmota"
#define D_AUTHOR "Theo Arends" #define D_AUTHOR "Theo Arends"

View File

@ -222,26 +222,26 @@ bool UdpConnect(void)
void PollUdp(void) void PollUdp(void)
{ {
if (udp_connected && !udp_response_mutex) { if (udp_connected && !udp_response_mutex && devices_present) {
if (PortUdp.parsePacket()) { if (PortUdp.parsePacket()) {
int len = PortUdp.read(packet_buffer, UDP_BUFFER_SIZE -1); int len = PortUdp.read(packet_buffer, UDP_BUFFER_SIZE -1);
if (len > 0) { if (len > 0) {
packet_buffer[len] = 0; packet_buffer[len] = 0;
} }
String request = packet_buffer;
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: Packet received")); AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: Packet (%d)"), len);
// AddLog_P(LOG_LEVEL_DEBUG_MORE, packet_buffer); // AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("\n%s"), packet_buffer);
if (request.indexOf("M-SEARCH") >= 0) {
request.toLowerCase();
request.replace(" ", "");
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: M-SEARCH Packet received"));
// AddLog_P(LOG_LEVEL_DEBUG_MORE, request.c_str());
if (strstr_P(packet_buffer, PSTR("M-SEARCH"))) {
udp_remote_ip = PortUdp.remoteIP(); udp_remote_ip = PortUdp.remoteIP();
udp_remote_port = PortUdp.remotePort(); udp_remote_port = PortUdp.remotePort();
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: M-SEARCH Packet from %s:%d\n%s"),
udp_remote_ip.toString().c_str(), udp_remote_port, packet_buffer);
String request = packet_buffer;
request.toLowerCase();
request.replace(" ", "");
if (EMUL_WEMO == Settings.flag2.emulation) { if (EMUL_WEMO == Settings.flag2.emulation) {
if (request.indexOf(F("urn:belkin:device:**")) > 0) { // type1 echo dot 2g, echo 1g's if (request.indexOf(F("urn:belkin:device:**")) > 0) { // type1 echo dot 2g, echo 1g's
udp_response_mutex = true; udp_response_mutex = true;
@ -384,6 +384,9 @@ void HandleUpnpEvent(void)
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT)); AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT));
String request = WebServer->arg(0); String request = WebServer->arg(0);
// AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("\n%s"), request.c_str());
String state_xml = FPSTR(WEMO_RESPONSE_STATE_SOAP); String state_xml = FPSTR(WEMO_RESPONSE_STATE_SOAP);
//differentiate get and set state //differentiate get and set state
if (request.indexOf(F("SetBinaryState")) > 0) { if (request.indexOf(F("SetBinaryState")) > 0) {
@ -837,14 +840,16 @@ void HandleHueApi(String *path)
void HueWemoAddHandlers(void) void HueWemoAddHandlers(void)
{ {
if (EMUL_WEMO == Settings.flag2.emulation) { if (devices_present) {
WebServer->on("/upnp/control/basicevent1", HTTP_POST, HandleUpnpEvent); if (EMUL_WEMO == Settings.flag2.emulation) {
WebServer->on("/eventservice.xml", HandleUpnpService); WebServer->on("/upnp/control/basicevent1", HTTP_POST, HandleUpnpEvent);
WebServer->on("/metainfoservice.xml", HandleUpnpMetaService); WebServer->on("/eventservice.xml", HandleUpnpService);
WebServer->on("/setup.xml", HandleUpnpSetupWemo); WebServer->on("/metainfoservice.xml", HandleUpnpMetaService);
} WebServer->on("/setup.xml", HandleUpnpSetupWemo);
if (EMUL_HUE == Settings.flag2.emulation) { }
WebServer->on("/description.xml", HandleUpnpSetupHue); if (EMUL_HUE == Settings.flag2.emulation) {
WebServer->on("/description.xml", HandleUpnpSetupHue);
}
} }
} }