Skip to content

Commit

Permalink
Merge pull request letscontrolit#5036 from TD-er/bugfix/connect_hidde…
Browse files Browse the repository at this point in the history
…n_ssid_channel12

[Hidden SSID] Fix ESP32 connecting to hidden SSID with channel > 11
  • Loading branch information
TD-er committed May 1, 2024
2 parents 2306cd6 + bd7c7d6 commit e35d205
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 11 deletions.
44 changes: 44 additions & 0 deletions docs/source/Plugin/P000_events.repl
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
13 changes: 2 additions & 11 deletions platformio_core_defs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/src/DataStructs/NodesHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "../Globals/ESPEasy_now_state.h"
#endif

#include "../Globals/EventQueue.h"

#include "../DataTypes/NodeTypeID.h"

#if FEATURE_MQTT
Expand All @@ -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

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions src/src/DataStructs/WiFi_AP_Candidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions src/src/DataStructs/WiFi_AP_Candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down
25 changes: 25 additions & 0 deletions src/src/ESPEasyCore/ESPEasyWifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e35d205

Please sign in to comment.