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.

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