Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. /*
  2. SSDP MODULE
  3. Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
  4. Uses SSDP library by PawelDino (https://github.com/PawelDino)
  5. https://github.com/esp8266/Arduino/issues/2283#issuecomment-299635604
  6. */
  7. #if SSDP_SUPPORT
  8. #include <ESP8266SSDP.h>
  9. const char _ssdp_template[] PROGMEM =
  10. "<?xml version=\"1.0\"?>"
  11. "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">"
  12. "<specVersion>"
  13. "<major>1</major>"
  14. "<minor>0</minor>"
  15. "</specVersion>"
  16. "<URLBase>http://%s:%u/</URLBase>"
  17. "<device>"
  18. "<deviceType>%s</deviceType>"
  19. "<friendlyName>%s</friendlyName>"
  20. "<presentationURL>/</presentationURL>"
  21. "<serialNumber>%u</serialNumber>"
  22. "<modelName>%s</modelName>"
  23. "<modelNumber>%s</modelNumber>"
  24. "<modelURL>%s</modelURL>"
  25. "<manufacturer>%s</manufacturer>"
  26. "<manufacturerURL>%s</manufacturerURL>"
  27. "<UDN>uuid:38323636-4558-4dda-9188-cda0e6%06x</UDN>"
  28. "</device>"
  29. "</root>\r\n"
  30. "\r\n";
  31. void ssdpSetup() {
  32. webServer()->on("/description.xml", HTTP_GET, [](AsyncWebServerRequest *request) {
  33. DEBUG_MSG_P(PSTR("[SSDP] Schema request\n"));
  34. IPAddress ip = WiFi.localIP();
  35. uint32_t chipId = ESP.getChipId();
  36. char response[strlen_P(_ssdp_template) + 100];
  37. snprintf_P(response, sizeof(response), _ssdp_template,
  38. ip.toString().c_str(), // ip
  39. webPort(), // port
  40. SSDP_DEVICE_TYPE, // device type
  41. getSetting("hostname").c_str(), // friendlyName
  42. chipId, // serialNumber
  43. APP_NAME, // modelName
  44. APP_VERSION, // modelNumber
  45. APP_WEBSITE, // modelURL
  46. DEVICE_NAME, // manufacturer
  47. "", // manufacturerURL
  48. chipId // UUID
  49. );
  50. request->send(200, "text/xml", response);
  51. });
  52. SSDP.setSchemaURL("description.xml");
  53. SSDP.setHTTPPort(webPort());
  54. SSDP.setDeviceType(SSDP_DEVICE_TYPE); //https://github.com/esp8266/Arduino/issues/2283
  55. SSDP.setName(getSetting("hostname"));
  56. SSDP.setSerialNumber(String(ESP.getChipId()));
  57. SSDP.setModelName(APP_NAME);
  58. SSDP.setModelNumber(APP_VERSION);
  59. SSDP.setModelURL(APP_WEBSITE);
  60. SSDP.setManufacturer(DEVICE_NAME);
  61. SSDP.setManufacturerURL("");
  62. SSDP.setURL("/");
  63. SSDP.begin();
  64. DEBUG_MSG_P(PSTR("[SSDP] Started\n"));
  65. }
  66. #endif // SSDP_SUPPORT