SSDP added

This commit is contained in:
Dmitry Borisenko
2020-08-28 23:18:18 +03:00
parent 3ab75bcea6
commit 21e7297035
9 changed files with 161 additions and 214 deletions

50
src/SSDP.cpp Normal file
View File

@@ -0,0 +1,50 @@
#include <ESP8266SSDP.h>
#include <SSDP.h>
#include "Global.h"
void SsdpInit() {
server.on("/description.xml", HTTP_GET, [](AsyncWebServerRequest* request) {
String ssdpSend = "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">";
String ssdpHeder = xmlNode("major", "1");
ssdpHeder += xmlNode("minor", "0");
ssdpHeder = xmlNode("specVersion", ssdpHeder);
ssdpHeder += xmlNode("URLBase", "http://" + WiFi.localIP().toString());
String ssdpDescription = xmlNode("deviceType", "upnp:rootdevice");
ssdpDescription += xmlNode("friendlyName", jsonReadStr(configSetupJson, "name"));
ssdpDescription += xmlNode("presentationURL", "/");
ssdpDescription += xmlNode("serialNumber", getChipId());
#ifdef ESP8266
ssdpDescription += xmlNode("modelName", "ESP8266");
#endif
#ifdef ESP32
ssdpDescription += xmlNode("modelName", "ESP32");
#endif
ssdpDescription += xmlNode("modelNumber", getChipId());
ssdpDescription += xmlNode("modelURL", "https://github.com/IoTManagerProject/IoTManager/wiki");
ssdpDescription += xmlNode("manufacturer", "Borisenko Dmitry");
ssdpDescription += xmlNode("manufacturerURL", "https://github.com/IoTManagerProject/IoTManager");
ssdpDescription += xmlNode("UDN", "uuid:38323636-4558-4dda-9188-cda0e6" + decToHex(ESP.getChipId(), 6));
ssdpDescription = xmlNode("device", ssdpDescription);
ssdpHeder += ssdpDescription;
ssdpSend += ssdpHeder;
ssdpSend += "</root>";
Serial.println("->!!!SSDP Get request received");
request->send(200, "text/xml", ssdpSend);
});
//Если версия 2.0.0 закаментируйте следующую строчку
SSDP.setDeviceType("upnp:rootdevice");
SSDP.setSchemaURL("description.xml");
SSDP.begin();
}
String xmlNode(String tags, String data) {
String temp = "<" + tags + ">" + data + "</" + tags + ">";
return temp;
}
String decToHex(uint32_t decValue, byte desiredStringLength) {
String hexString = String(decValue, HEX);
while (hexString.length() < desiredStringLength) hexString = "0" + hexString;
return hexString;
}