diff --git a/libraries/ESP8266SSDP/ESP8266SSDP.cpp b/libraries/ESP8266SSDP/ESP8266SSDP.cpp index 7f5e3ceef1..900c2059fe 100644 --- a/libraries/ESP8266SSDP/ESP8266SSDP.cpp +++ b/libraries/ESP8266SSDP/ESP8266SSDP.cpp @@ -71,7 +71,7 @@ static const char _ssdp_packet_template[] PROGMEM = "%s" // _ssdp_response_template / _ssdp_notify_template "CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL "SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber - "USN: uuid:%s\r\n" // _uuid + "USN: %s\r\n" // _uuid "%s: %s\r\n" // "NT" or "ST", _deviceType "LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL "\r\n"; @@ -99,7 +99,7 @@ static const char _ssdp_schema_template[] PROGMEM = "%s" "%s" "%s" - "uuid:%s" + "%s" "" //"" //"" @@ -130,8 +130,10 @@ SSDPClass::SSDPClass() : _timer(0), _port(80), _ttl(SSDP_MULTICAST_TTL), + _respondToAddr(0,0,0,0), _respondToPort(0), _pending(false), + _st_is_uuid(false), _delay(0), _process_time(0), _notify_time(0) @@ -155,12 +157,13 @@ SSDPClass::~SSDPClass() { bool SSDPClass::begin() { end(); - + _pending = false; + _st_is_uuid = false; if (strcmp(_uuid,"") == 0) { uint32_t chipId = ESP.getChipId(); - sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x", - (uint16_t) ((chipId >> 16) & 0xff), + sprintf_P(_uuid, PSTR("uuid:38323636-4558-4dda-9188-cda0e6%02x%02x%02x"), + (uint16_t) ((chipId >> 16) & 0xff), (uint16_t) ((chipId >> 8) & 0xff), (uint16_t) chipId & 0xff); } @@ -178,7 +181,9 @@ bool SSDPClass::begin() { IPAddress mcast(SSDP_MULTICAST_ADDR); if (igmp_joingroup(local, mcast) != ERR_OK ) { - DEBUGV("SSDP failed to join igmp group"); +#ifdef DEBUG_SSDP + DEBUG_SSDP.printf_P(PSTR("SSDP failed to join igmp group\n")); +#endif return false; } @@ -241,7 +246,7 @@ void SSDPClass::_send(ssdp_method_t method) { _modelNumber, _uuid, (method == NONE) ? "ST" : "NT", - _deviceType, + (_st_is_uuid) ? _uuid : _deviceType, ip[0], ip[1], ip[2], ip[3], _port, _schemaURL ); @@ -373,10 +378,19 @@ void SSDPClass::_update() { #ifdef DEBUG_SSDP DEBUG_SSDP.printf("REJECT: %s\n", (char *)buffer); #endif + }else{ + _st_is_uuid = false; } // if the search type matches our type, we should respond instead of ABORT if (strcasecmp(buffer, _deviceType) == 0) { _pending = true; + _st_is_uuid = false; + _process_time = millis(); + state = KEY; + } + if (strcasecmp(buffer, _uuid) == 0) { + _pending = true; + _st_is_uuid = true; _process_time = millis(); state = KEY; } @@ -416,6 +430,7 @@ void SSDPClass::_update() { _send(NONE); } else if(_notify_time == 0 || (millis() - _notify_time) > (SSDP_INTERVAL * 1000L)){ _notify_time = millis(); + _st_is_uuid = false; _send(NOTIFY); } @@ -439,7 +454,7 @@ void SSDPClass::setDeviceType(const char *deviceType) { } void SSDPClass::setUUID(const char *uuid) { - strlcpy(_uuid, uuid, sizeof(_uuid)); + snprintf_P(_uuid, sizeof(_uuid), PSTR("uuid:%s"), uuid); } void SSDPClass::setName(const char *name) { diff --git a/libraries/ESP8266SSDP/ESP8266SSDP.h b/libraries/ESP8266SSDP/ESP8266SSDP.h index e320f058aa..5fbbf59364 100644 --- a/libraries/ESP8266SSDP/ESP8266SSDP.h +++ b/libraries/ESP8266SSDP/ESP8266SSDP.h @@ -35,7 +35,7 @@ License (MIT license): class UdpContext; -#define SSDP_UUID_SIZE 37 +#define SSDP_UUID_SIZE 42 #define SSDP_SCHEMA_URL_SIZE 64 #define SSDP_DEVICE_TYPE_SIZE 64 #define SSDP_FRIENDLY_NAME_SIZE 64 @@ -66,17 +66,17 @@ class SSDPClass{ void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); } void setDeviceType(const char *deviceType); - /*To define a custom UUID, you must call the method before begin(). Otherwise an automatic UUID based on CHIPID will be generated.*/ - void setUUID(const String& uuid) { setUUID(uuid.c_str()); } - void setUUID(const char *uuid); + /*To define a custom UUID, you must call the method before begin(). Otherwise an automatic UUID based on CHIPID will be generated.*/ + void setUUID(const String& uuid) { setUUID(uuid.c_str()); } + void setUUID(const char *uuid); - void setName(const String& name) { setName(name.c_str()); } + void setName(const String& name) { setName(name.c_str()); } void setName(const char *name); void setURL(const String& url) { setURL(url.c_str()); } void setURL(const char *url); void setSchemaURL(const String& url) { setSchemaURL(url.c_str()); } void setSchemaURL(const char *url); - void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); } + void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); } void setSerialNumber(const char *serialNumber); void setSerialNumber(const uint32_t serialNumber); void setModelName(const String& name) { setModelName(name.c_str()); } @@ -108,6 +108,7 @@ class SSDPClass{ uint16_t _respondToPort; bool _pending; + bool _st_is_uuid; unsigned short _delay; unsigned long _process_time; unsigned long _notify_time;