diff --git a/docs/source/Plugin/P000_events.repl b/docs/source/Plugin/P000_events.repl index c76f996ef9..b23bac7025 100644 --- a/docs/source/Plugin/P000_events.repl +++ b/docs/source/Plugin/P000_events.repl @@ -196,6 +196,50 @@ Reboot endon + " + " + ``p2pNode#Connected`` + + Added: 2024-05-01 + + Triggered when a new ESPEasy p2p node has been seen. + N.B. Only for nodes with a valid unit ID (not 0) + + Eventvalues: + + - Unit ID + + - Node name + + - Build number/date + "," + + .. code-block:: none + + on p2pNode#Connected do + LogEntry,'ESPEasy p2p node %eventvalue1% added: %eventvalue2% with build %eventvalue3%' + endon + + " + " + ``p2pNode#Disconnected`` + + Added: 2024-05-01 + + Triggered when a ESPEasy p2p node has been removed from the nodes list. + N.B. Only for nodes with a valid unit ID (not 0) + + Eventvalues: + + - Unit ID + "," + + .. code-block:: none + + on p2pNode#Disconnected do + LogEntry,`ESPEasy p2p node %eventvalue1% not seen for a while` + endon + " " ``WiFi#Connected`` diff --git a/platformio_core_defs.ini b/platformio_core_defs.ini index 7b4f2798fc..355a71c694 100644 --- a/platformio_core_defs.ini +++ b/platformio_core_defs.ini @@ -208,17 +208,8 @@ lib_ignore = ; ESP_IDF 5.1 [core_esp32_IDF5_1__3_0_0] -;platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.02.10/platform-espressif32.zip -;platform_packages = -;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2119/framework-arduinoespressif32-release_v5.1-a28d368.zip -;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2180/framework-arduinoespressif32-all-release_v5.1-735d740.zip -;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2189/framework-arduinoespressif32-all-release_v5.1-be1a568.zip -; Build with HWCDC fix. -;platform = https://github.com/Jason2866/platform-espressif32.git -;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2261/framework-arduinoespressif32-all-release_v5.1-11140aa.zip -platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.04.11/platform-espressif32.zip -;platform_packages = -platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2286/framework-arduinoespressif32-all-release_v5.1-11140aa.zip +platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.04.14/platform-espressif32.zip +platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2334/framework-arduinoespressif32-all-release_v5.1-08e138f.zip build_flags = -DESP32_STAGE -DESP_IDF_VERSION_MAJOR=5 -DLIBRARIES_NO_LOG=1 diff --git a/src/src/DataStructs/NodesHandler.cpp b/src/src/DataStructs/NodesHandler.cpp index 7766d205f1..1adc3bc978 100644 --- a/src/src/DataStructs/NodesHandler.cpp +++ b/src/src/DataStructs/NodesHandler.cpp @@ -10,6 +10,8 @@ #include "../Globals/ESPEasy_now_state.h" #endif +#include "../Globals/EventQueue.h" + #include "../DataTypes/NodeTypeID.h" #if FEATURE_MQTT @@ -28,6 +30,8 @@ #include "../Helpers/ESPEasy_time_calc.h" #include "../Helpers/Misc.h" #include "../Helpers/PeriodicalActions.h" +#include "../Helpers/StringConverter.h" +#include "../Helpers/StringGenerator_System.h" #define ESPEASY_NOW_ALLOWED_AGE_NO_TRACEROUTE 35000 @@ -99,6 +103,20 @@ bool NodesHandler::addNode(const NodeStruct& node) } } + if (isNewNode) { + if (Settings.UseRules && node.unit != 0) + { + // Generate event announcing new p2p node + // TODO TD-er: Maybe also add other info like ESP type, IP-address, etc? + eventQueue.addMove(strformat( + F("p2pNode#Connected=%d,'%s','%s'"), + node.unit, + node.getNodeName().c_str(), + formatSystemBuildNr(node.build).c_str() + )); + } + } + return isNewNode; } @@ -539,6 +557,11 @@ bool NodesHandler::refreshNodeList(unsigned long max_age_allowed, unsigned long& } #endif if (mustErase) { + if (Settings.UseRules && it->second.unit != 0) + { + // Add event about removing node from nodeslist. + eventQueue.addMove(strformat(F("p2pNode#Disconnected=%d"), it->second.unit)); + } { _nodes_mutex.lock(); it = _nodes.erase(it); diff --git a/src/src/DataStructs/WiFi_AP_Candidate.cpp b/src/src/DataStructs/WiFi_AP_Candidate.cpp index 9c1f41e982..e328d7e79d 100644 --- a/src/src/DataStructs/WiFi_AP_Candidate.cpp +++ b/src/src/DataStructs/WiFi_AP_Candidate.cpp @@ -20,6 +20,16 @@ WiFi_AP_Candidate::WiFi_AP_Candidate() : +#ifdef ESP32 +# if ESP_IDF_VERSION_MAJOR >= 5 +country({ + .cc = "01", + .schan = 1, + .nchan = 11, + .policy = WIFI_COUNTRY_POLICY_AUTO, +}), +#endif +#endif last_seen(0), rssi(0), channel(0), index(0), enc_type(0) { memset(&bits, 0, sizeof(bits)); @@ -82,6 +92,9 @@ WiFi_AP_Candidate::WiFi_AP_Candidate(uint8_t networkItem) : index(0) { bits.wps = it->wps; // FIXME TD-er: Maybe also add other info like 2nd channel, ftm and phy_lr support? +# if ESP_IDF_VERSION_MAJOR >= 5 + memcpy(&country, &(it->country), sizeof(wifi_country_t)); +#endif } #endif // ifdef ESP32 last_seen = millis(); @@ -196,6 +209,25 @@ String WiFi_AP_Candidate::toString(const String& separator) const { result += encryption_type(); +#ifdef ESP32 +# if ESP_IDF_VERSION_MAJOR >= 5 + // Country code string + if (country.cc[0] != '\0' && country.cc[1] != '\0') { + result += strformat(F(" '%c%c'"), country.cc[0], country.cc[1]); + switch (country.cc[2]) { + case 'O': // Outdoor + case 'I': // Indoor + case 'X': // "non-country" + result += strformat(F("(%c)"), country.cc[2]); + break; + } + } + if (country.nchan > 0) { + result += strformat(F(" ch: %d..%d"), country.schan, country.schan + country.nchan - 1); + } +#endif +#endif + if (phy_known()) { String phy_str; diff --git a/src/src/DataStructs/WiFi_AP_Candidate.h b/src/src/DataStructs/WiFi_AP_Candidate.h index b3ce8f8c35..bec19eeb9a 100644 --- a/src/src/DataStructs/WiFi_AP_Candidate.h +++ b/src/src/DataStructs/WiFi_AP_Candidate.h @@ -72,6 +72,12 @@ struct WiFi_AP_Candidate { // String key; + #ifdef ESP32 + # if ESP_IDF_VERSION_MAJOR >= 5 + wifi_country_t country; + #endif + #endif + unsigned long last_seen = 0u; MAC_address bssid; int8_t rssi{}; diff --git a/src/src/ESPEasyCore/ESPEasyWifi.cpp b/src/src/ESPEasyCore/ESPEasyWifi.cpp index a1a1340d2c..7d127e78c9 100644 --- a/src/src/ESPEasyCore/ESPEasyWifi.cpp +++ b/src/src/ESPEasyCore/ESPEasyWifi.cpp @@ -499,6 +499,19 @@ void AttemptWiFiConnect() { } #endif +#ifdef ESP32 + if (Settings.IncludeHiddenSSID()) { + wifi_country_t config = { + .cc = "01", + .schan = 1, + .nchan = 14, + .policy = WIFI_COUNTRY_POLICY_MANUAL, + }; + esp_wifi_set_country(&config); + } +#endif + + if ((Settings.HiddenSSID_SlowConnectPerBSSID() || !candidate.bits.isHidden) && candidate.allowQuickConnect()) { WiFi.begin(candidate.ssid.c_str(), key.c_str(), candidate.channel, candidate.bssid.mac); @@ -1031,6 +1044,18 @@ void WifiScan(bool async, uint8_t channel) { // Perform a disconnect after scanning. // See: https://github.com/letscontrolit/ESPEasy/pull/3579#issuecomment-967021347 async = false; + + if (Settings.IncludeHiddenSSID()) { + wifi_country_t config = { + .cc = "01", + .schan = 1, + .nchan = 14, + .policy = WIFI_COUNTRY_POLICY_MANUAL, + }; + esp_wifi_set_country(&config); + } + + #endif START_TIMER;