mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-15 00:02:49 +03:00
Add ability to change schema url, http port and add base url
This commit is contained in:
committed by
Ivan Grokhotkov
parent
3c54cb0a26
commit
bd6c4acfd8
@ -42,6 +42,7 @@ extern "C" {
|
|||||||
#define SSDP_BUFFER_SIZE 64
|
#define SSDP_BUFFER_SIZE 64
|
||||||
|
|
||||||
#define SSDP_UUID_SIZE 37
|
#define SSDP_UUID_SIZE 37
|
||||||
|
#define SSDP_SCHEMA_URL_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 32
|
||||||
#define SSDP_PRESENTATION_URL_SIZE 128
|
#define SSDP_PRESENTATION_URL_SIZE 128
|
||||||
@ -69,7 +70,7 @@ const char* _ssdp_packet_template =
|
|||||||
"CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL
|
"CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL
|
||||||
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
|
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
|
||||||
"USN: uuid:%s\r\n" // _uuid
|
"USN: uuid:%s\r\n" // _uuid
|
||||||
"LOCATION: http://%u.%u.%u.%u/ssdp/schema.xml\r\n" // WiFi.localIP()
|
"LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _shemaURL
|
||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
const char* _ssdp_schema_template =
|
const char* _ssdp_schema_template =
|
||||||
@ -84,6 +85,7 @@ const char* _ssdp_schema_template =
|
|||||||
"<major>1</major>"
|
"<major>1</major>"
|
||||||
"<minor>0</minor>"
|
"<minor>0</minor>"
|
||||||
"</specVersion>"
|
"</specVersion>"
|
||||||
|
"<URLBase>http://%u.%u.%u.%u:%u/</URLBase>" // WiFi.localIP(), _port
|
||||||
"<device>"
|
"<device>"
|
||||||
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
|
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
|
||||||
"<friendlyName>%s</friendlyName>"
|
"<friendlyName>%s</friendlyName>"
|
||||||
@ -94,13 +96,14 @@ const char* _ssdp_schema_template =
|
|||||||
"<modelURL>%s</modelURL>"
|
"<modelURL>%s</modelURL>"
|
||||||
"<manufacturer>%s</manufacturer>"
|
"<manufacturer>%s</manufacturer>"
|
||||||
"<manufacturerURL>%s</manufacturerURL>"
|
"<manufacturerURL>%s</manufacturerURL>"
|
||||||
"<UDN>%s</UDN>"
|
"<UDN>uuid:%s</UDN>"
|
||||||
"</device>"
|
"</device>"
|
||||||
"</root>\r\n"
|
"</root>\r\n"
|
||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
SSDPClass::SSDPClass(){
|
SSDPClass::SSDPClass(){
|
||||||
_uuid = (char*)os_malloc(SSDP_UUID_SIZE);
|
_uuid = (char*)os_malloc(SSDP_UUID_SIZE);
|
||||||
|
_schemaURL = (char*)os_malloc(SSDP_SCHEMA_URL_SIZE);
|
||||||
_friendlyName = (char*)os_malloc(SSDP_FRIENDLY_NAME_SIZE);
|
_friendlyName = (char*)os_malloc(SSDP_FRIENDLY_NAME_SIZE);
|
||||||
_presentationURL = (char*)os_malloc(SSDP_PRESENTATION_URL_SIZE);
|
_presentationURL = (char*)os_malloc(SSDP_PRESENTATION_URL_SIZE);
|
||||||
_serialNumber = (char*)os_malloc(SSDP_SERIAL_NUMBER_SIZE);
|
_serialNumber = (char*)os_malloc(SSDP_SERIAL_NUMBER_SIZE);
|
||||||
@ -119,11 +122,14 @@ SSDPClass::SSDPClass(){
|
|||||||
_modelURL[0] = '\0';
|
_modelURL[0] = '\0';
|
||||||
_manufacturer[0] = '\0';
|
_manufacturer[0] = '\0';
|
||||||
_manufacturerURL[0] = '\0';
|
_manufacturerURL[0] = '\0';
|
||||||
|
sprintf(_schemaURL, "ssdp/schema.xml");
|
||||||
|
_port = 80;
|
||||||
_pending = false;
|
_pending = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDPClass::~SSDPClass(){
|
SSDPClass::~SSDPClass(){
|
||||||
os_free(_uuid);
|
os_free(_uuid);
|
||||||
|
os_free(_schemaURL);
|
||||||
os_free(_friendlyName);
|
os_free(_friendlyName);
|
||||||
os_free(_presentationURL);
|
os_free(_presentationURL);
|
||||||
os_free(_serialNumber);
|
os_free(_serialNumber);
|
||||||
@ -183,14 +189,16 @@ void SSDPClass::send(ssdp_method_t method){
|
|||||||
SSDP_INTERVAL,
|
SSDP_INTERVAL,
|
||||||
_modelName, _modelNumber,
|
_modelName, _modelNumber,
|
||||||
_uuid,
|
_uuid,
|
||||||
(uint8_t)(ip & 0xFF), (uint8_t)((ip >> 8) & 0xFF), (uint8_t)((ip >> 16) & 0xFF), (uint8_t)((ip >> 24) & 0xFF)
|
(uint8_t)(ip & 0xFF), (uint8_t)((ip >> 8) & 0xFF), (uint8_t)((ip >> 16) & 0xFF), (uint8_t)((ip >> 24) & 0xFF), _port, _schemaURL
|
||||||
);
|
);
|
||||||
|
|
||||||
_server.endPacket();
|
_server.endPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSDPClass::schema(WiFiClient client){
|
void SSDPClass::schema(WiFiClient client){
|
||||||
|
uint32_t ip = WiFi.localIP();
|
||||||
client.printf(_ssdp_schema_template,
|
client.printf(_ssdp_schema_template,
|
||||||
|
(uint8_t)(ip & 0xFF), (uint8_t)((ip >> 8) & 0xFF), (uint8_t)((ip >> 16) & 0xFF), (uint8_t)((ip >> 24) & 0xFF), _port,
|
||||||
_friendlyName,
|
_friendlyName,
|
||||||
_presentationURL,
|
_presentationURL,
|
||||||
_serialNumber,
|
_serialNumber,
|
||||||
@ -300,6 +308,14 @@ uint8_t SSDPClass::update(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SSDPClass::setSchemaURL(char *url){
|
||||||
|
strcpy(_schemaURL, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSDPClass::setHTTPPort(uint16_t port){
|
||||||
|
_port = port;
|
||||||
|
}
|
||||||
|
|
||||||
void SSDPClass::setName(char *name){
|
void SSDPClass::setName(char *name){
|
||||||
strcpy(_friendlyName, name);
|
strcpy(_friendlyName, name);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,8 @@ class SSDPClass{
|
|||||||
|
|
||||||
void setName(char *name);
|
void setName(char *name);
|
||||||
void setURL(char *url);
|
void setURL(char *url);
|
||||||
|
void setSchemaURL(char *url);
|
||||||
|
void setHTTPPort(uint16_t port);
|
||||||
void setSerialNumber(char *serialNumber);
|
void setSerialNumber(char *serialNumber);
|
||||||
void setModelName(char *name);
|
void setModelName(char *name);
|
||||||
void setModelNumber(char *num);
|
void setModelNumber(char *num);
|
||||||
@ -67,7 +69,8 @@ class SSDPClass{
|
|||||||
unsigned long _process_time;
|
unsigned long _process_time;
|
||||||
unsigned long _notify_time;
|
unsigned long _notify_time;
|
||||||
|
|
||||||
uint8_t *_mac;
|
uint16_t _port;
|
||||||
|
char *_schemaURL;
|
||||||
char *_uuid;
|
char *_uuid;
|
||||||
char *_friendlyName;
|
char *_friendlyName;
|
||||||
char *_serialNumber;
|
char *_serialNumber;
|
||||||
|
@ -18,24 +18,26 @@ void setup() {
|
|||||||
if(WiFi.waitForConnectResult() == WL_CONNECTED){
|
if(WiFi.waitForConnectResult() == WL_CONNECTED){
|
||||||
|
|
||||||
Serial.printf("Starting HTTP...\n");
|
Serial.printf("Starting HTTP...\n");
|
||||||
HTTP.on("/", HTTP_GET, [](){
|
HTTP.on("/index.html", HTTP_GET, [](){
|
||||||
HTTP.send(200, "text/plain", "Hello World!");
|
HTTP.send(200, "text/plain", "Hello World!");
|
||||||
});
|
});
|
||||||
HTTP.on("/ssdp/schema.xml", HTTP_GET, [](){
|
HTTP.on("/description.xml", HTTP_GET, [](){
|
||||||
SSDP.schema(HTTP.client());
|
SSDP.schema(HTTP.client());
|
||||||
});
|
});
|
||||||
HTTP.begin();
|
HTTP.begin();
|
||||||
|
|
||||||
Serial.printf("Starting SSDP...\n");
|
Serial.printf("Starting SSDP...\n");
|
||||||
SSDP.begin();
|
SSDP.begin();
|
||||||
SSDP.setName((char*)"ESP8266");
|
SSDP.setSchemaURL((char*)"description.xml");
|
||||||
SSDP.setSerialNumber((char*)"A0123456789");
|
SSDP.setHTTPPort(80);
|
||||||
SSDP.setURL((char*)"/");
|
SSDP.setName((char*)"Philips hue clone");
|
||||||
SSDP.setModelName((char*)"ESP-12e");
|
SSDP.setSerialNumber((char*)"001788102201");
|
||||||
SSDP.setModelNumber((char*)"1.0");
|
SSDP.setURL((char*)"index.html");
|
||||||
SSDP.setModelURL((char*)"http://12e.espressif.com");
|
SSDP.setModelName((char*)"Philips hue bridge 2012");
|
||||||
SSDP.setManufacturer((char*)"Espressif");
|
SSDP.setModelNumber((char*)"929000226503");
|
||||||
SSDP.setManufacturerURL((char*)"http://espressif.com");
|
SSDP.setModelURL((char*)"http://www.meethue.com");
|
||||||
|
SSDP.setManufacturer((char*)"Royal Philips Electronics");
|
||||||
|
SSDP.setManufacturerURL((char*)"http://www.philips.com");
|
||||||
|
|
||||||
Serial.printf("Ready!\n");
|
Serial.printf("Ready!\n");
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,6 +19,8 @@ send KEYWORD2
|
|||||||
schema KEYWORD2
|
schema KEYWORD2
|
||||||
setName KEYWORD2
|
setName KEYWORD2
|
||||||
setURL KEYWORD2
|
setURL KEYWORD2
|
||||||
|
setHTTPPort KEYWORD2
|
||||||
|
setSchemaURL KEYWORD2
|
||||||
setSerialNumber KEYWORD2
|
setSerialNumber KEYWORD2
|
||||||
setModelName KEYWORD2
|
setModelName KEYWORD2
|
||||||
setModelNumber KEYWORD2
|
setModelNumber KEYWORD2
|
||||||
|
Reference in New Issue
Block a user