Skip to content

Conversation

@schlimmchen
Copy link
Member

This allows to configure a fixed BSSID to connect to using Wi-Fi. This can make sense if your Wi-Fi setup includes multiple Access Points broadcasting the same SSID and allows to force connecting to a specific one.

Closes #1716. This is not the "perfect" solution for that issue, but it is a working "manual" alternative.

@schlimmchen schlimmchen requested a review from AndreasBoehm May 11, 2025 19:27
@schlimmchen schlimmchen self-assigned this May 11, 2025
@github-actions
Copy link

github-actions bot commented May 11, 2025

Build Artifacts

Firmware built from this pull request's code:

Notice

  • These artifacts are ZIP files containing the factory update binary as well as the OTA update binary.
    Extract the binaries from the ZIP files first. Do not use the ZIP files themselves to perform an update.
  • These links point to artifacts of the latest successful build run.
  • The linked artifacts were built from 8788da0.

@schlimmchen
Copy link
Member Author

@markusdd Care to test? You should be able to safely upgrade to this version, then configure the expected BSSID using the Web UI.

Just now I remember that I did not test one thing: Shutting down the AP with the configured BSSID and observe what happens and also what happens once it comes back...

@markusdd
Copy link

markusdd commented May 11, 2025

Hi! The latter test would probably be important haha.

I will test this in about 10 days when I am back at where the setup is, just in case something goes sideways.

@schlimmchen
Copy link
Member Author

There you go:

[2025-05-11 21:42:43.754] WiFi disconnected: 200
[2025-05-11 21:42:43.755] Try reconnecting
[2025-05-11 21:42:43.756] [ 31576][E][WiFiClient.cpp:429] write(): fail on fd 50, errno: 113, "Software caused connection abort"
[2025-05-11 21:42:43.763] Network lost connection
[2025-05-11 21:42:43.769] Disconnected from MQTT.
[2025-05-11 21:42:43.769] Disconnect reason:TCP_DISCONNECTED
[2025-05-11 21:42:43.808] [ 31628][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:42:46.599] WiFi disconnected: 201
[2025-05-11 21:42:46.600] Try reconnecting
[2025-05-11 21:42:46.610] [ 34430][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:42:46.615] Network lost connection
[2025-05-11 21:42:46.628] [ 34448][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:42:49.445] WiFi disconnected: 201
[2025-05-11 21:42:49.445] Try reconnecting
[2025-05-11 21:42:49.454] Network lost connection
[2025-05-11 21:42:49.461] [ 37281][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:42:52.290] WiFi disconnected: 201
[2025-05-11 21:42:52.291] Try reconnecting
[2025-05-11 21:42:52.302] [ 40123][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:42:52.308] Network lost connection
[2025-05-11 21:42:52.321] [ 40141][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:42:55.136] WiFi disconnected: 201
[2025-05-11 21:42:55.137] Try reconnecting
[2025-05-11 21:42:55.185] [ 43006][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:42:55.191] Network lost connection
[2025-05-11 21:42:58.019] WiFi disconnected: 201
[2025-05-11 21:42:58.019] Try reconnecting
[2025-05-11 21:42:58.028] Network lost connection
[2025-05-11 21:42:59.095] [ 46916][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:43:00.864] WiFi disconnected: 201
[2025-05-11 21:43:00.865] Try reconnecting
[2025-05-11 21:43:00.873] Network lost connection
[2025-05-11 21:43:02.144] [ 49965][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:43:03.709] WiFi disconnected: 201
[2025-05-11 21:43:03.709] Try reconnecting
[2025-05-11 21:43:03.719] Network lost connection
[2025-05-11 21:43:05.181] [ 53002][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:43:06.553] WiFi disconnected: 201
[2025-05-11 21:43:06.554] Try reconnecting
[2025-05-11 21:43:06.569] [ 54390][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:43:06.575] Network lost connection
[2025-05-11 21:43:06.588] [ 54408][E][WiFiUdp.cpp:185] endPacket(): could not send data: 12
[2025-05-11 21:43:09.413] WiFi connected
[2025-05-11 21:43:09.426] [ 57246][E][WiFiUdp.cpp:185] endPacket(): could not send data: 118
[2025-05-11 21:43:10.418] WiFi got ip: 192.168.16.139
[2025-05-11 21:43:10.419] Network connected
[2025-05-11 21:43:10.420] Connecting to MQTT...
[2025-05-11 21:43:10.438] Connected to MQTT.

My confidence in this change is still high.

I will test this in about 10 days when I am back at where the setup is, just in case something goes sideways.

Understandable. Download the firmware just-in-time when starting to test, so updates to this PR are part of your test.

@tbnobody I would appreciate your comment on this PR. If there is something that makes you hesitate to include this upstream, let me know.

@tbnobody
Copy link

Hm would make sense to implement something like this. The integrated roaming seems to be a little bit unstable. I am not even sure if the sdkconfig used by the arduino framework supports 802.11k.
I also saw, that WLED also has the option for the bssid.

Just a few remarks (I haven't looked at the code in very detail):

  • make sure it does also work as expected with the wifi watchdog introduced in tbnobody@39b8d3f
  • serializeBssid and deserializeBssid could either be static or const
  • Would it make sense to create a define like MAC_LEN or something like this to replace all the occurrences of 6?

@AndreasBoehm AndreasBoehm requested a review from Copilot May 12, 2025 05:00

This comment was marked as outdated.

@schlimmchen
Copy link
Member Author

make sure it does also work as expected with the wifi watchdog introduced in tbnobody@39b8d3f

Will do. After looking at the commit, I don't see that there should be an issue.

serializeBssid and deserializeBssid could either be static or const

Yes, thanks,

Would it make sense to create a define like MAC_LEN or something like this to replace all the occurrences of 6?

Hm, the value will not ever change, but for clarity it makes sense. I put it in defaults.h. Does feel a bit uncomfortable there, though.

@tbnobody
Copy link

Hm, the value will not ever change, but for clarity it makes sense. I put it in defaults.h. Does feel a bit uncomfortable there, though.

defaults.h is maybe the wrong location. What do you think of just the configuration.cpp file? Its not required in any header file. It would maybe just make the code more readable.

@schlimmchen schlimmchen force-pushed the schlimmchen/feature/fixed-bssid branch from c5acd14 to d8cc99c Compare May 12, 2025 19:28
@schlimmchen
Copy link
Member Author

schlimmchen commented May 12, 2025

defaults.h is maybe the wrong location. What do you think of just the configuration.cpp file?

I ended up putting it in Configuration.h so we can also use that define for the BSSID array size within the Configuration. The #define has good company there (string lengths for the configuration struct are close by).

@AndreasBoehm AndreasBoehm requested a review from Copilot May 14, 2025 05:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for connecting to a fixed Wi‑Fi BSSID by extending the configuration interfaces and network connection logic.

  • Added an input field for setting the Wi‑Fi BSSID in the NetworkAdminView.
  • Updated type declarations and localization for the BSSID configuration.
  • Extended network configuration serialization/deserialization and connection logic to handle the fixed BSSID.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
webapp/src/views/NetworkAdminView.vue Adds a new input element for the Wi‑Fi BSSID configuration.
webapp/src/types/NetworkConfig.ts Extends the NetworkConfig interface with a bssid field.
webapp/src/locales/en.json & de.json Adds localization strings for Wi‑Fi BSSID and its tooltip.
src/WebApi_network.cpp Updates GET/POST handlers to process the bssid value.
src/NetworkSettings.cpp Adjusts connection logic to include BSSID comparison.
src/Configuration.cpp Implements serialization/deserialization functions for BSSID.
include/defaults.h & include/Configuration.h Defines constants and updates configuration structure with BSSID.

Comment on lines +1201 to +1284
if (cleanBssidStr.length() != 12) { return; }

Copy link

Copilot AI May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider logging a warning or error when the BSSID string length is invalid. This can help diagnose issues when an incorrect BSSID is provided, instead of silently failing.

Suggested change
if (cleanBssidStr.length() != 12) { return; }
if (cleanBssidStr.length() != 12) {
MessageOutput::logWarning("Invalid BSSID string length: " + String(cleanBssidStr.length()) + ". Expected length is 12.");
return;
}

Copilot uses AI. Check for mistakes.
return true;
}

for (int i = 0; i < WIFI_BSSID_OCTETS; i++) {
Copy link

Copilot AI May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using std::memcmp to compare the BSSID arrays, which may simplify the code and improve clarity.

Copilot uses AI. Check for mistakes.
Copy link
Member

@AndreasBoehm AndreasBoehm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine. Haven't tried it yet.

@schlimmchen schlimmchen marked this pull request as draft May 16, 2025 11:23
@schlimmchen
Copy link
Member Author

Will rebase after merging upstream release and will address Copilot's latest comments.

@AndreasBoehm AndreasBoehm force-pushed the schlimmchen/feature/fixed-bssid branch from d8cc99c to f0ce840 Compare September 3, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DTU get's stuck in bad wifi connection although a better endpoint is available

5 participants