Conversation
WalkthroughEnable all-channel WiFi scanning on non-ESP8266 and make WiFi connection calls BSSID-aware by passing an explicit BSSID to WiFi.begin when configured; also force reconnect when the stored BSSID changes. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@wled00/wled.cpp`:
- Line 508: The call to WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN) is only
available on ESP32 and breaks ESP8266 builds; wrap the WiFi.setScanMethod(...)
invocation with the platform guard used elsewhere (e.g., `#ifdef`
ARDUINO_ARCH_ESP32 ... `#endif`) so the call is compiled only for ESP32 targets;
ensure you use the same macro and placement style as surrounding guarded WiFi
calls in wled.cpp so builds for ESP8266 skip this API.
🧹 Nitpick comments (1)
wled00/wled.cpp (1)
732-739: BSSID check logic is correct, but duplicated and missing from the Enterprise path.This BSSID-detection block is repeated identically at lines 758–764. Consider extracting it into a small helper (or at least a lambda) to avoid the duplication.
Also, the WPA Enterprise (non-PSK) branch at line 754 does not forward the configured BSSID at all. If a user configures a BSSID and uses WPA Enterprise, the BSSID will be silently ignored. Worth a
// TODOor implementation if the ESP32WiFi.begin()overload for WPA2_AUTH_PEAP supports a BSSID parameter.♻️ Extract helper to reduce duplication
Define a local helper or lambda before both
#ifdefbranches:+ // helper: return BSSID pointer if any byte is non-zero, nullptr otherwise + auto getConfiguredBssid = [&]() -> uint8_t* { + for (size_t i = 0; i < sizeof(multiWiFi[selectedWiFi].bssid); i++) { + if (multiWiFi[selectedWiFi].bssid[i]) return multiWiFi[selectedWiFi].bssid; + } + return nullptr; + };Then in both call sites simply use:
WiFi.begin(multiWiFi[selectedWiFi].clientSSID, multiWiFi[selectedWiFi].clientPass, 0, getConfiguredBssid());
|
@coderabbitai the BSSID seems to be applied only after a reboot if changed at runtime through the UI. Can this be fixed? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 70690 🏁 Script executed: Length of output: 3618
In The fix: We need to check if the BSSID has changed and set // Around line 37-48 in wled00/set.cpp
char oldSSID[33]; strcpy(oldSSID, multiWiFi[n].clientSSID);
char oldPass[65]; strcpy(oldPass, multiWiFi[n].clientPass);
uint8_t oldBSSID[6]; memcpy(oldBSSID, multiWiFi[n].bssid, 6); // Save old BSSID
strlcpy(multiWiFi[n].clientSSID, request->arg(cs).c_str(), 33);
if (strlen(oldSSID) == 0 || strncmp(multiWiFi[n].clientSSID, oldSSID, 32) != 0) {
forceReconnect = true;
}
if (!isAsterisksOnly(request->arg(pw).c_str(), 65)) {
strlcpy(multiWiFi[n].clientPass, request->arg(pw).c_str(), 65);
forceReconnect = true;
}
fillStr2MAC(multiWiFi[n].bssid, request->arg(bs).c_str());
if (memcmp(oldBSSID, multiWiFi[n].bssid, 6) != 0) { // Check if BSSID changed
forceReconnect = true;
}This will trigger an immediate WiFi reconnection when the BSSID is changed through the UI, just like it does for SSID and password changes. Would you like me to implement this fix? Task: Fix BSSID runtime update requiring reboot
💡 Use |
wled00/wled.cpp
Outdated
| WiFi.begin(multiWiFi[selectedWiFi].clientSSID, multiWiFi[selectedWiFi].clientPass); | ||
| uint8_t *bssid = nullptr; | ||
| for (int i = 0; i < sizeof(multiWiFi[selectedWiFi].bssid); i++) { | ||
| if (multiWiFi[selectedWiFi].bssid[i]) { |
There was a problem hiding this comment.
is bssid[i] correct here? It looks a bit awkward to scan over all array items and then repeatedly copy a pointer.
might be clearer like this
bool bssidValid = false;
for (int i = ...) if (multiWiFi[selectedWiFi].bssid[i] != 0) bssidValid = true;
if (bssidValid) bssid = multiWiFi[selectedWiFi].bssid;There was a problem hiding this comment.
it only goes through the numbers in the selected wifi once, if one is non zero it assigns the pointer and moves on (break;)
There was a problem hiding this comment.
ah OK, did not see the break;.
Im my proposal the logic looks a bit clearer, even when a few cycles get wasted to check all 6 bytes of the BSSID.
up to you if you want to keep the current code
There was a problem hiding this comment.
I can add the != 0 and extend the comment.
| #else // WLED_ENABLE_WPA_ENTERPRISE | ||
| WiFi.begin(multiWiFi[selectedWiFi].clientSSID, multiWiFi[selectedWiFi].clientPass); // no harm if called multiple times | ||
| uint8_t *bssid = nullptr; | ||
| for (int i = 0; i < sizeof(multiWiFi[selectedWiFi].bssid); i++) { |
backport of upstream wled#5351
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@wled00/wled.cpp`:
- Around line 734-742: The bssid assignment inside the for-loop is misindented;
in the block that checks multiWiFi[selectedWiFi].bssid you should indent the
statement that sets bssid = multiWiFi[selectedWiFi].bssid by two spaces so it is
clearly inside the if block (matching the indentation of the subsequent break;)
— update the indentation in the block that touches variables bssid and
multiWiFi[selectedWiFi].bssid and ensure the file uses the project’s 2-space C++
indentation style for that if/for block and the WiFi.begin(...) call that
follows.
🧹 Nitpick comments (1)
wled00/wled.cpp (1)
734-742: Consider extracting the BSSID null-check into a small helper.The same "check if BSSID is non-zero, return pointer or nullptr" logic is duplicated in both the enterprise-PSK path (Lines 734-741) and the non-enterprise path (Lines 761-768). A tiny inline helper would reduce duplication:
// e.g. at file scope or as a static helper static uint8_t* getConfiguredBSSID(uint8_t* bssid, size_t len) { for (size_t i = 0; i < len; i++) { if (bssid[i] != 0) return bssid; } return nullptr; }Also applies to: 761-769
|
@softhack007 btw this change of scanning all WiFi "breaks" the bootup glitch fix - well not really but it needs to be extended. I have a solution: just always update NVM on bootup - it is quite safe and will not cause flash wear in any realistic use case. Will update that PR once this is merged. |
|
note to @netmindz this fix needs 0.15 backport |
As found in #5345:
WiFi.begin()if setFixes #5345
Summary by CodeRabbit
New Features
Bug Fixes