1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Include SetUUID for SSDP (#4981)

* Include SetUUID for SSDP

Inclusion of the SetUUID Method for Custom UUID

* Ajusts PR

* Include IconList Object on XML
This commit is contained in:
Laercio Mendonça 2018-07-30 02:52:16 -03:00 committed by Develo
parent 0899ae9d3e
commit 75a6a3f073
3 changed files with 164 additions and 131 deletions

View File

@ -45,7 +45,6 @@ extern "C" {
#include "lwip/igmp.h" #include "lwip/igmp.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#include "include/UdpContext.h" #include "include/UdpContext.h"
//#define DEBUG_SSDP Serial //#define DEBUG_SSDP Serial
#define SSDP_INTERVAL 1200 #define SSDP_INTERVAL 1200
@ -56,8 +55,6 @@ extern "C" {
#define SSDP_MULTICAST_TTL 2 #define SSDP_MULTICAST_TTL 2
static const IPAddress SSDP_MULTICAST_ADDR(239, 255, 255, 250); static const IPAddress SSDP_MULTICAST_ADDR(239, 255, 255, 250);
static const char _ssdp_response_template[] PROGMEM = static const char _ssdp_response_template[] PROGMEM =
"HTTP/1.1 200 OK\r\n" "HTTP/1.1 200 OK\r\n"
"EXT:\r\n"; "EXT:\r\n";
@ -99,7 +96,7 @@ static const char _ssdp_schema_template[] PROGMEM =
"<modelURL>%s</modelURL>" "<modelURL>%s</modelURL>"
"<manufacturer>%s</manufacturer>" "<manufacturer>%s</manufacturer>"
"<manufacturerURL>%s</manufacturerURL>" "<manufacturerURL>%s</manufacturerURL>"
"<UDN>uuid:%s</UDN>" "<UDN>UUID: %s</UDN>"
"</device>" "</device>"
//"<iconList>" //"<iconList>"
//"<icon>" //"<icon>"
@ -155,12 +152,13 @@ SSDPClass::~SSDPClass(){
bool SSDPClass::begin() { bool SSDPClass::begin() {
_pending = false; _pending = false;
if (strcmp(_uuid,"") == 0) {
uint32_t chipId = ESP.getChipId(); uint32_t chipId = ESP.getChipId();
sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x", sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x",
(uint16_t) ((chipId >> 16) & 0xff), (uint16_t) ((chipId >> 16) & 0xff),
(uint16_t) ((chipId >> 8) & 0xff), (uint16_t) ((chipId >> 8) & 0xff),
(uint16_t) chipId & 0xff ); (uint16_t) chipId & 0xff );
}
#ifdef DEBUG_SSDP #ifdef DEBUG_SSDP
DEBUG_SSDP.printf("SSDP UUID: %s\n", (char *)_uuid); DEBUG_SSDP.printf("SSDP UUID: %s\n", (char *)_uuid);
@ -210,7 +208,8 @@ void SSDPClass::_send(ssdp_method_t method){
_ssdp_packet_template, _ssdp_packet_template,
valueBuffer, valueBuffer,
SSDP_INTERVAL, SSDP_INTERVAL,
_modelName, _modelNumber, _modelName,
_modelNumber,
_uuid, _uuid,
(method == NONE) ? "ST" : "NT", (method == NONE) ? "ST" : "NT",
_deviceType, _deviceType,
@ -294,22 +293,40 @@ void SSDPClass::_update(){
else state = URI; else state = URI;
cursor = 0; cursor = 0;
} else if(cursor < SSDP_METHOD_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; } } else if (cursor < SSDP_METHOD_SIZE - 1) {
buffer[cursor++] = c;
buffer[cursor] = '\0';
}
break; break;
case URI: case URI:
if (c == ' ') { if (c == ' ') {
if (strcmp(buffer, "*")) state = ABORT; if (strcmp(buffer, "*")) state = ABORT;
else state = PROTO; else state = PROTO;
cursor = 0; cursor = 0;
} else if(cursor < SSDP_URI_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; } } else if (cursor < SSDP_URI_SIZE - 1) {
buffer[cursor++] = c;
buffer[cursor] = '\0';
}
break; break;
case PROTO: case PROTO:
if(cr == 2){ state = KEY; cursor = 0; } if (cr == 2) {
state = KEY;
cursor = 0;
}
break; break;
case KEY: case KEY:
if(cr == 4){ _pending = true; _process_time = millis(); } if (cr == 4) {
else if(c == ' '){ cursor = 0; state = VALUE; } _pending = true;
else if(c != '\r' && c != '\n' && c != ':' && cursor < SSDP_BUFFER_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; } _process_time = millis();
}
else if (c == ' ') {
cursor = 0;
state = VALUE;
}
else if (c != '\r' && c != '\n' && c != ':' && cursor < SSDP_BUFFER_SIZE - 1) {
buffer[cursor++] = c;
buffer[cursor] = '\0';
}
break; break;
case VALUE: case VALUE:
if (cr == 2) { if (cr == 2) {
@ -340,7 +357,11 @@ void SSDPClass::_update(){
break; break;
} }
if(state != ABORT){ state = KEY; header = START; cursor = 0; } if (state != ABORT) {
state = KEY;
header = START;
cursor = 0;
}
} else if (c != '\r' && c != '\n') { } else if (c != '\r' && c != '\n') {
if (header == START) { if (header == START) {
if (strncmp(buffer, "MA", 2) == 0) header = MAN; if (strncmp(buffer, "MA", 2) == 0) header = MAN;
@ -348,7 +369,10 @@ void SSDPClass::_update(){
else if (strcmp(buffer, "MX") == 0) header = MX; else if (strcmp(buffer, "MX") == 0) header = MX;
} }
if(cursor < SSDP_BUFFER_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; } if (cursor < SSDP_BUFFER_SIZE - 1) {
buffer[cursor++] = c;
buffer[cursor] = '\0';
}
} }
break; break;
case ABORT: case ABORT:
@ -385,6 +409,10 @@ void SSDPClass::setDeviceType(const char *deviceType){
strlcpy(_deviceType, deviceType, sizeof(_deviceType)); strlcpy(_deviceType, deviceType, sizeof(_deviceType));
} }
void SSDPClass::setUUID(const char *uuid) {
strlcpy(_uuid, uuid, sizeof(_uuid));
}
void SSDPClass::setName(const char *name) { void SSDPClass::setName(const char *name) {
strlcpy(_friendlyName, name, sizeof(_friendlyName)); strlcpy(_friendlyName, name, sizeof(_friendlyName));
} }
@ -421,6 +449,7 @@ void SSDPClass::setManufacturerURL(const char *url){
strlcpy(_manufacturerURL, url, sizeof(_manufacturerURL)); strlcpy(_manufacturerURL, url, sizeof(_manufacturerURL));
} }
void SSDPClass::setTTL(const uint8_t ttl) { void SSDPClass::setTTL(const uint8_t ttl) {
_ttl = ttl; _ttl = ttl;
} }

View File

@ -39,7 +39,7 @@ class UdpContext;
#define SSDP_SCHEMA_URL_SIZE 64 #define SSDP_SCHEMA_URL_SIZE 64
#define SSDP_DEVICE_TYPE_SIZE 64 #define SSDP_DEVICE_TYPE_SIZE 64
#define SSDP_FRIENDLY_NAME_SIZE 64 #define SSDP_FRIENDLY_NAME_SIZE 64
#define SSDP_SERIAL_NUMBER_SIZE 32 #define SSDP_SERIAL_NUMBER_SIZE 37
#define SSDP_PRESENTATION_URL_SIZE 128 #define SSDP_PRESENTATION_URL_SIZE 128
#define SSDP_MODEL_NAME_SIZE 64 #define SSDP_MODEL_NAME_SIZE 64
#define SSDP_MODEL_URL_SIZE 128 #define SSDP_MODEL_URL_SIZE 128
@ -60,13 +60,15 @@ class SSDPClass{
public: public:
SSDPClass(); SSDPClass();
~SSDPClass(); ~SSDPClass();
bool begin(); bool begin();
void schema(WiFiClient client); void schema(WiFiClient client);
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); } void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
void setDeviceType(const char *deviceType); 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);
void setName(const String& name) { setName(name.c_str()); } void setName(const String& name) { setName(name.c_str()); }
void setName(const char *name); void setName(const char *name);
void setURL(const String& url) { setURL(url.c_str()); } void setURL(const String& url) { setURL(url.c_str()); }

View File

@ -15,6 +15,7 @@ SSDP KEYWORD1
begin KEYWORD2 begin KEYWORD2
schema KEYWORD2 schema KEYWORD2
setUUID KEYWORD2
setName KEYWORD2 setName KEYWORD2
setURL KEYWORD2 setURL KEYWORD2
setHTTPPort KEYWORD2 setHTTPPort KEYWORD2
@ -30,6 +31,7 @@ setManufacturerURL KEYWORD2
# Constants (LITERAL1) # Constants (LITERAL1)
####################################### #######################################
SSDP_INTERVAL LITERAL1 SSDP_INTERVAL LITERAL1
SSDP_UUID LITERAL1
SSDP_PORT LITERAL1 SSDP_PORT LITERAL1
SSDP_METHOD_SIZE LITERAL1 SSDP_METHOD_SIZE LITERAL1
SSDP_URI_SIZE LITERAL1 SSDP_URI_SIZE LITERAL1