1
0
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:
John Doe
2015-07-05 12:40:59 +03:00
committed by Ivan Grokhotkov
parent 3c54cb0a26
commit bd6c4acfd8
4 changed files with 37 additions and 14 deletions

View File

@ -42,6 +42,7 @@ extern "C" {
#define SSDP_BUFFER_SIZE 64
#define SSDP_UUID_SIZE 37
#define SSDP_SCHEMA_URL_SIZE 64
#define SSDP_FRIENDLY_NAME_SIZE 64
#define SSDP_SERIAL_NUMBER_SIZE 32
#define SSDP_PRESENTATION_URL_SIZE 128
@ -69,7 +70,7 @@ const char* _ssdp_packet_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
"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";
const char* _ssdp_schema_template =
@ -84,6 +85,7 @@ const char* _ssdp_schema_template =
"<major>1</major>"
"<minor>0</minor>"
"</specVersion>"
"<URLBase>http://%u.%u.%u.%u:%u/</URLBase>" // WiFi.localIP(), _port
"<device>"
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
"<friendlyName>%s</friendlyName>"
@ -94,13 +96,14 @@ const char* _ssdp_schema_template =
"<modelURL>%s</modelURL>"
"<manufacturer>%s</manufacturer>"
"<manufacturerURL>%s</manufacturerURL>"
"<UDN>%s</UDN>"
"<UDN>uuid:%s</UDN>"
"</device>"
"</root>\r\n"
"\r\n";
SSDPClass::SSDPClass(){
_uuid = (char*)os_malloc(SSDP_UUID_SIZE);
_schemaURL = (char*)os_malloc(SSDP_SCHEMA_URL_SIZE);
_friendlyName = (char*)os_malloc(SSDP_FRIENDLY_NAME_SIZE);
_presentationURL = (char*)os_malloc(SSDP_PRESENTATION_URL_SIZE);
_serialNumber = (char*)os_malloc(SSDP_SERIAL_NUMBER_SIZE);
@ -119,11 +122,14 @@ SSDPClass::SSDPClass(){
_modelURL[0] = '\0';
_manufacturer[0] = '\0';
_manufacturerURL[0] = '\0';
sprintf(_schemaURL, "ssdp/schema.xml");
_port = 80;
_pending = false;
}
SSDPClass::~SSDPClass(){
os_free(_uuid);
os_free(_schemaURL);
os_free(_friendlyName);
os_free(_presentationURL);
os_free(_serialNumber);
@ -183,14 +189,16 @@ void SSDPClass::send(ssdp_method_t method){
SSDP_INTERVAL,
_modelName, _modelNumber,
_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();
}
void SSDPClass::schema(WiFiClient client){
uint32_t ip = WiFi.localIP();
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,
_presentationURL,
_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){
strcpy(_friendlyName, name);
}

View File

@ -53,6 +53,8 @@ class SSDPClass{
void setName(char *name);
void setURL(char *url);
void setSchemaURL(char *url);
void setHTTPPort(uint16_t port);
void setSerialNumber(char *serialNumber);
void setModelName(char *name);
void setModelNumber(char *num);
@ -67,7 +69,8 @@ class SSDPClass{
unsigned long _process_time;
unsigned long _notify_time;
uint8_t *_mac;
uint16_t _port;
char *_schemaURL;
char *_uuid;
char *_friendlyName;
char *_serialNumber;

View File

@ -18,24 +18,26 @@ void setup() {
if(WiFi.waitForConnectResult() == WL_CONNECTED){
Serial.printf("Starting HTTP...\n");
HTTP.on("/", HTTP_GET, [](){
HTTP.on("/index.html", HTTP_GET, [](){
HTTP.send(200, "text/plain", "Hello World!");
});
HTTP.on("/ssdp/schema.xml", HTTP_GET, [](){
HTTP.on("/description.xml", HTTP_GET, [](){
SSDP.schema(HTTP.client());
});
HTTP.begin();
Serial.printf("Starting SSDP...\n");
SSDP.begin();
SSDP.setName((char*)"ESP8266");
SSDP.setSerialNumber((char*)"A0123456789");
SSDP.setURL((char*)"/");
SSDP.setModelName((char*)"ESP-12e");
SSDP.setModelNumber((char*)"1.0");
SSDP.setModelURL((char*)"http://12e.espressif.com");
SSDP.setManufacturer((char*)"Espressif");
SSDP.setManufacturerURL((char*)"http://espressif.com");
SSDP.setSchemaURL((char*)"description.xml");
SSDP.setHTTPPort(80);
SSDP.setName((char*)"Philips hue clone");
SSDP.setSerialNumber((char*)"001788102201");
SSDP.setURL((char*)"index.html");
SSDP.setModelName((char*)"Philips hue bridge 2012");
SSDP.setModelNumber((char*)"929000226503");
SSDP.setModelURL((char*)"http://www.meethue.com");
SSDP.setManufacturer((char*)"Royal Philips Electronics");
SSDP.setManufacturerURL((char*)"http://www.philips.com");
Serial.printf("Ready!\n");
} else {

View File

@ -19,6 +19,8 @@ send KEYWORD2
schema KEYWORD2
setName KEYWORD2
setURL KEYWORD2
setHTTPPort KEYWORD2
setSchemaURL KEYWORD2
setSerialNumber KEYWORD2
setModelName KEYWORD2
setModelNumber KEYWORD2