Files
IoTManager/src/SSDP.cpp

64 lines
2.4 KiB
C++
Raw Normal View History

2020-10-18 00:07:57 +03:00
#include "SSDP.h"
2020-09-04 18:58:03 +03:00
#include "Global.h"
2020-10-18 00:07:57 +03:00
#ifdef SSDP_ENABLED
2020-09-02 22:34:49 +03:00
#ifdef ESP8266
2020-10-18 00:07:57 +03:00
#include <ESP8266SSDP.h>
2020-09-02 22:34:49 +03:00
#endif
#ifdef ESP32
2020-10-18 00:07:57 +03:00
#include <ESP32SSDP.h>
2020-09-02 22:34:49 +03:00
#endif
String xmlNode(String tags, String data);
String decToHex(uint32_t decValue, byte desiredStringLength);
2020-09-04 18:58:03 +03:00
//39164
//457684
2020-09-02 22:34:49 +03:00
void SsdpInit() {
server.on("/description.xml", HTTP_GET, [](AsyncWebServerRequest* request) {
2020-09-04 18:58:03 +03:00
String ssdpSend = F("<root xmlns=\"urn:schemas-upnp-org:device-1-0\">");
String ssdpHeder = xmlNode(F("major"), "1");
ssdpHeder += xmlNode(F("minor"), "0");
ssdpHeder = xmlNode(F("specVersion"), ssdpHeder);
ssdpHeder += xmlNode(F("URLBase"), "http://" + WiFi.localIP().toString());
String ssdpDescription = xmlNode(F("deviceType"), F("upnp:rootdevice"));
ssdpDescription += xmlNode(F("friendlyName"), jsonReadStr(configSetupJson, F("name")));
ssdpDescription += xmlNode(F("presentationURL"), "/");
ssdpDescription += xmlNode(F("serialNumber"), getChipId());
2020-09-02 22:34:49 +03:00
#ifdef ESP8266
2020-09-04 18:58:03 +03:00
ssdpDescription += xmlNode(F("modelName"), F("ESP8266"));
2020-09-02 22:34:49 +03:00
#endif
#ifdef ESP32
2020-09-04 18:58:03 +03:00
ssdpDescription += xmlNode(F("modelName"), F("ESP32"));
2020-09-02 22:34:49 +03:00
#endif
2020-09-04 18:58:03 +03:00
ssdpDescription += xmlNode(F("modelNumber"), getChipId());
ssdpDescription += xmlNode(F("modelURL"), F("https://github.com/IoTManagerProject/IoTManager/wiki"));
ssdpDescription += xmlNode(F("manufacturer"), F("Borisenko Dmitry"));
ssdpDescription += xmlNode(F("manufacturerURL"), F("https://github.com/IoTManagerProject/IoTManager"));
2020-10-18 02:27:08 +03:00
ssdpDescription += xmlNode(F("UDN"), "uuid:38323636-4558-4dda-9188-cda0e6" + decToHex(ESP_getChipId(), 6));
2020-09-02 22:34:49 +03:00
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 закаментируйте следующую строчку
2020-09-04 18:58:03 +03:00
SSDP.setDeviceType(F("upnp:rootdevice"));
SSDP.setSchemaURL(F("description.xml"));
2020-09-02 22:34:49 +03:00
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;
2020-09-03 23:29:34 +03:00
}
#endif