mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-25 20:02:37 +03:00
adding a few new features to the packet format
* can now specify the TTL programmatically * can now define the device type urn (up to 64 chars) ** still defaults to `Basic:1` * can now set the serial number using a `uint32_t`, formatted as %08X
This commit is contained in:
parent
dba2f92f78
commit
430331a4f8
@ -89,7 +89,7 @@ static const char* _ssdp_schema_template =
|
||||
"</specVersion>"
|
||||
"<URLBase>http://%u.%u.%u.%u:%u/</URLBase>" // WiFi.localIP(), _port
|
||||
"<device>"
|
||||
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
|
||||
"<deviceType>%s</deviceType>"
|
||||
"<friendlyName>%s</friendlyName>"
|
||||
"<presentationURL>%s</presentationURL>"
|
||||
"<serialNumber>%s</serialNumber>"
|
||||
@ -128,6 +128,7 @@ SSDPClass::SSDPClass() :
|
||||
_server(0),
|
||||
_timer(new SSDPTimer),
|
||||
_port(80),
|
||||
_ttl(SSDP_MULTICAST_TTL),
|
||||
_respondToPort(0),
|
||||
_pending(false),
|
||||
_delay(0),
|
||||
@ -136,6 +137,7 @@ _notify_time(0)
|
||||
{
|
||||
_uuid[0] = '\0';
|
||||
_modelNumber[0] = '\0';
|
||||
sprintf(_deviceType, "urn:schemas-upnp-org:device:Basic:1");
|
||||
_friendlyName[0] = '\0';
|
||||
_presentationURL[0] = '\0';
|
||||
_serialNumber[0] = '\0';
|
||||
@ -185,7 +187,7 @@ bool SSDPClass::begin(){
|
||||
}
|
||||
|
||||
_server->setMulticastInterface(ifaddr);
|
||||
_server->setMulticastTTL(SSDP_MULTICAST_TTL);
|
||||
_server->setMulticastTTL(_ttl);
|
||||
_server->onRx(std::bind(&SSDPClass::_update, this));
|
||||
if (!_server->connect(multicast_addr, SSDP_PORT)) {
|
||||
return false;
|
||||
@ -239,6 +241,7 @@ void SSDPClass::schema(WiFiClient client){
|
||||
uint32_t ip = WiFi.localIP();
|
||||
client.printf(_ssdp_schema_template,
|
||||
IP2STR(&ip), _port,
|
||||
_deviceType,
|
||||
_friendlyName,
|
||||
_presentationURL,
|
||||
_serialNumber,
|
||||
@ -365,6 +368,10 @@ void SSDPClass::setHTTPPort(uint16_t port){
|
||||
_port = port;
|
||||
}
|
||||
|
||||
void SSDPClass::setDeviceType(const char *deviceType){
|
||||
strlcpy(_deviceType, deviceType, sizeof(_deviceType));
|
||||
}
|
||||
|
||||
void SSDPClass::setName(const char *name){
|
||||
strlcpy(_friendlyName, name, sizeof(_friendlyName));
|
||||
}
|
||||
@ -377,6 +384,10 @@ void SSDPClass::setSerialNumber(const char *serialNumber){
|
||||
strlcpy(_serialNumber, serialNumber, sizeof(_serialNumber));
|
||||
}
|
||||
|
||||
void SSDPClass::setSerialNumber(const uint32_t serialNumber){
|
||||
snprintf(_serialNumber, sizeof(uint32_t), "%08X", serialNumber);
|
||||
}
|
||||
|
||||
void SSDPClass::setModelName(const char *name){
|
||||
strlcpy(_modelName, name, sizeof(_modelName));
|
||||
}
|
||||
@ -397,6 +408,10 @@ void SSDPClass::setManufacturerURL(const char *url){
|
||||
strlcpy(_manufacturerURL, url, sizeof(_manufacturerURL));
|
||||
}
|
||||
|
||||
void SSDPClass::setTTL(const uint8_t ttl){
|
||||
_ttl = ttl;
|
||||
}
|
||||
|
||||
void SSDPClass::_onTimerStatic(SSDPClass* self) {
|
||||
self->_update();
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ class UdpContext;
|
||||
|
||||
#define SSDP_UUID_SIZE 37
|
||||
#define SSDP_SCHEMA_URL_SIZE 64
|
||||
#define SSDP_DEVICE_TYPE_SIZE 64
|
||||
#define SSDP_FRIENDLY_NAME_SIZE 64
|
||||
#define SSDP_SERIAL_NUMBER_SIZE 32
|
||||
#define SSDP_PRESENTATION_URL_SIZE 128
|
||||
@ -64,6 +65,8 @@ class SSDPClass{
|
||||
|
||||
void schema(WiFiClient client);
|
||||
|
||||
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
|
||||
void setDeviceType(const char *deviceType);
|
||||
void setName(const String& name) { setName(name.c_str()); }
|
||||
void setName(const char *name);
|
||||
void setURL(const String& url) { setURL(url.c_str()); }
|
||||
@ -72,6 +75,7 @@ class SSDPClass{
|
||||
void setSchemaURL(const char *url);
|
||||
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()); }
|
||||
void setModelName(const char *name);
|
||||
void setModelNumber(const String& num) { setModelNumber(num.c_str()); }
|
||||
@ -83,6 +87,7 @@ class SSDPClass{
|
||||
void setManufacturerURL(const String& url) { setManufacturerURL(url.c_str()); }
|
||||
void setManufacturerURL(const char *url);
|
||||
void setHTTPPort(uint16_t port);
|
||||
void setTTL(uint8_t ttl);
|
||||
|
||||
protected:
|
||||
void _send(ssdp_method_t method);
|
||||
@ -93,6 +98,7 @@ class SSDPClass{
|
||||
UdpContext* _server;
|
||||
SSDPTimer* _timer;
|
||||
uint16_t _port;
|
||||
uint8_t _ttl;
|
||||
|
||||
IPAddress _respondToAddr;
|
||||
uint16_t _respondToPort;
|
||||
@ -104,6 +110,7 @@ class SSDPClass{
|
||||
|
||||
char _schemaURL[SSDP_SCHEMA_URL_SIZE];
|
||||
char _uuid[SSDP_UUID_SIZE];
|
||||
char _deviceType[SSDP_DEVICE_TYPE_SIZE];
|
||||
char _friendlyName[SSDP_FRIENDLY_NAME_SIZE];
|
||||
char _serialNumber[SSDP_SERIAL_NUMBER_SIZE];
|
||||
char _presentationURL[SSDP_PRESENTATION_URL_SIZE];
|
||||
|
Loading…
x
Reference in New Issue
Block a user