From 2c027d81f7f91e76726fffba132009a93eab68c7 Mon Sep 17 00:00:00 2001 From: Luc Date: Sat, 25 Jul 2015 05:51:01 +0800 Subject: [PATCH] Add SSDP Support SSDP protocol work outo the box with window Module is seen as "ESP Module" serial is Chip ID, and other information are espressif ones for ESP 01 Not sure if need to set module name in EEPROM to be configurable =>TBD --- esp8266/config.h | 4 ++++ esp8266/esp8266.ino | 16 ++++++++++++++++ esp8266/webinterface.cpp | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/esp8266/config.h b/esp8266/config.h index 5fe88b65..816c86fe 100644 --- a/esp8266/config.h +++ b/esp8266/config.h @@ -23,6 +23,10 @@ //in web browser by default : http:\\esp8266.local and connect //this feature does not work in AP mode #define MDNS_FEATURE + +//SSDD_FEATURE: this feature is a discovery protocol, supported on Windows out of the box +#define SSDP_FEATURE + #define PROGMEM2CHAR progmem2char extern char * progmem2char(const char* src); diff --git a/esp8266/esp8266.ino b/esp8266/esp8266.ino index 51936f08..105d3c8b 100644 --- a/esp8266/esp8266.ino +++ b/esp8266/esp8266.ino @@ -39,6 +39,9 @@ #ifdef MDNS_FEATURE #include #endif +#ifdef SSDP_FEATURE +#include +#endif extern "C" { #include "user_interface.h" } @@ -99,6 +102,19 @@ void setup() { } #endif +#ifdef SSDP_FEATURE + SSDP.setSchemaURL("description.xml"); + SSDP.setHTTPPort( wifi_config.iweb_port); + SSDP.setName("ESP8266 Module"); + SSDP.setSerialNumber(String(system_get_chip_id()).c_str()); + SSDP.setURL("/"); + SSDP.setModelName("ESP8266 01"); + SSDP.setModelNumber("01"); + SSDP.setModelURL("http://espressif.com/en/products/esp8266/"); + SSDP.setManufacturer("Espressif Systems"); + SSDP.setManufacturerURL("http://espressif.com"); + SSDP.begin(); +#endif } diff --git a/esp8266/webinterface.cpp b/esp8266/webinterface.cpp index 30ea033d..89fb1fc5 100644 --- a/esp8266/webinterface.cpp +++ b/esp8266/webinterface.cpp @@ -30,6 +30,9 @@ extern "C" { #include "user_interface.h" } +#ifdef SSDP_FEATURE +#include +#endif const char PAGE_HEAD_1[] PROGMEM = "\n\n\n\n" \ "\n"; @@ -126,6 +129,7 @@ const char SDK_VERSION_TITLE[] PROGMEM = "SDK Version: "; const char HTTP_START[] PROGMEM = "http://"; const char HTTP_MDNS_NAME[] PROGMEM = "mDNS name: "; const char HTTP_END[] PROGMEM = ".local"; +const char SSDP_PROTOCOL_NAME[] PROGMEM = "SSDP Protocol: "; const char VALUE_11B[] PROGMEM = "11b"; const char VALUE_11N[] PROGMEM = "11n"; const char VALUE_11G[] PROGMEM = "11g"; @@ -434,6 +438,9 @@ void handle_web_interface_root() LABEL_UNITS(PROGMEM2CHAR(HTTP_MDNS_NAME),sstatus.c_str(),PROGMEM2CHAR(HTTP_END)) } #endif + #ifdef SSDP_FEATURE + LABEL(PROGMEM2CHAR(SSDP_PROTOCOL_NAME),PROGMEM2CHAR(VALUE_YES)) + #endif istatus = wifi_get_phy_mode(); if (istatus==PHY_MODE_11B) sstatus=PROGMEM2CHAR(VALUE_11B); else if (istatus==PHY_MODE_11G) sstatus=PROGMEM2CHAR(VALUE_11G); @@ -1705,6 +1712,14 @@ if (web_interface->WebServer.hasArg(PROGMEM2CHAR(COMMAND_ID))) } } } + + #ifdef SSDP_FEATURE + void handle_SSDP(){ + SSDP.schema(web_interface->WebServer.client()); + Serial.printf("SSDP.\n"); + } + #endif + //URI Decoding function //no check if dst buffer is big enough to receive string so //use same size as src is a recommendation @@ -1752,6 +1767,9 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port) WebServer.on("/STATUS",HTTP_ANY, handle_web_interface_status); WebServer.on("/PRINTER",HTTP_ANY, handle_web_interface_printer); WebServer.on("/CMD",HTTP_ANY, handle_web_command); + #ifdef SSDP_FEATURE + WebServer.on("/description.xml", HTTP_GET, handle_SSDP); + #endif WebServer.onNotFound( handle_not_found); answer4M105="T:0 /0 "; answer4M114="X:0.0 Y:0.0 Z:0.000";