From 642695906066b0c076233f2ac725170b4c0996e9 Mon Sep 17 00:00:00 2001 From: Yuri Trikoz Date: Sun, 18 Oct 2020 02:27:08 +0300 Subject: [PATCH] ESP32 SSDP --- include/Utils/SysUtils.h | 4 +++- platformio.ini | 1 + src/SSDP.cpp | 2 +- src/Utils/SysUtils.cpp | 33 ++++++++++++++++++++++----------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/Utils/SysUtils.h b/include/Utils/SysUtils.h index 1686e51f..de03e287 100644 --- a/include/Utils/SysUtils.h +++ b/include/Utils/SysUtils.h @@ -2,6 +2,8 @@ #include #include "Global.h" +uint32_t ESP_getChipId(); + const String getChipId(); void setLedStatus(LedStatus_t status); @@ -14,4 +16,4 @@ const String getHeapStats(); const String getMacAddress(); -void setChipId(); \ No newline at end of file +void setChipId(); diff --git a/platformio.ini b/platformio.ini index 91d47aa1..ccf0d6b1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -36,6 +36,7 @@ lib_deps = AsyncTCP ESP32Servo LITTLEFS + luc-github/ESP32SSDP monitor_filters = esp32_exception_decoder ;upload_speed = 921600 monitor_speed = 115200 diff --git a/src/SSDP.cpp b/src/SSDP.cpp index f6dfc790..3b2f3c89 100644 --- a/src/SSDP.cpp +++ b/src/SSDP.cpp @@ -33,7 +33,7 @@ void SsdpInit() { 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")); - ssdpDescription += xmlNode(F("UDN"), "uuid:38323636-4558-4dda-9188-cda0e6" + decToHex(ESP.getChipId(), 6)); + ssdpDescription += xmlNode(F("UDN"), "uuid:38323636-4558-4dda-9188-cda0e6" + decToHex(ESP_getChipId(), 6)); ssdpDescription = xmlNode("device", ssdpDescription); ssdpHeder += ssdpDescription; ssdpSend += ssdpHeder; diff --git a/src/Utils/SysUtils.cpp b/src/Utils/SysUtils.cpp index 48704aea..eefdc87a 100644 --- a/src/Utils/SysUtils.cpp +++ b/src/Utils/SysUtils.cpp @@ -3,28 +3,39 @@ #include "Global.h" #include "Utils/PrintMessage.h" - const String getUniqueId(const char* name) { return String(name) + getMacAddress(); } -const String getChipId() { - String res; +uint32_t ESP_getChipId(void) { #ifdef ESP32 - char buf[32] = {0}; - uint32_t mac = ESP.getEfuseMac(); - sprintf(buf, "%0X", mac); - res = String(buf); + uint32_t id = 0; + for (uint32_t i = 0; i < 17; i = i + 8) { + id |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; + } + return id; +#else + return ESP.getChipId(); #endif -#ifdef ESP8266 - res = String(ESP.getChipId()) + "-" + String(ESP.getFlashChipId()); +} + +uint32_t ESP_getFlashChipId(void) { +#ifdef ESP32 + // Нет аналогичной (без доп.кода) функций в 32 + // надо использовать другой id - варианты есть + return ESP_getChipId(); +#else + return ESP.getFlashChipId(); #endif - return res; +} + +const String getChipId() { + return String(ESP_getChipId()) + "-" + String(ESP_getFlashChipId()); } void setChipId() { chipId = getChipId(); - SerialPrint("I","System","id: " + chipId); + SerialPrint("I", "System", "id: " + chipId); } #ifdef ESP8266