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.

85 lines
2.7 KiB

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