Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use bssid to connect to best WIFI and added option to always perform a WIFI-scan #241

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Wlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void Wlan_Init(void) {
handleWifiStateInit();
}

void connectToKnownNetwork(WiFiSettings settings) {
void connectToKnownNetwork(WiFiSettings settings, byte *bssid = nullptr) {
// set hostname on connect, because when resetting wifi config elsewhere it could be reset
if (hostname.compareTo("-1")) {
WiFi.setHostname(hostname.c_str());
Expand All @@ -145,7 +145,7 @@ void connectToKnownNetwork(WiFiSettings settings) {

Log_Printf(LOGLEVEL_NOTICE, wifiConnectionInProgress, settings.ssid);

WiFi.begin(settings.ssid, settings.password);
WiFi.begin(settings.ssid, settings.password, 0, bssid);
}

void handleWifiStateInit() {
Expand All @@ -160,7 +160,12 @@ void handleWifiStateInit() {
connectionAttemptCounter = 0;
connectStartTimestamp = 0;
connectionFailedTimestamp = 0;
wifiState = WIFI_STATE_CONNECT_LAST;
#ifdef ALWAYS_SCAN_WIFI_ON_STARTUP
Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed please use a NVS setting here, e.g.
bool performScan = gPrefsSettings.getBool("ALWAYS_SCAN_WIFI_ON_STARTUP", true);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do so.
Where can we modify this option afterwards? Shall we add a checkbox in the wifi-settings in the Webserver for that or would you just leave it that way for now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would preset performScan with true, so at default ESPuino startup performs a scan and always connects to stronger WiFi (same name).

We could add this setting later in Web-UI. At this moment we can live without it ;-)
Just my opinion..

WiFi.scanNetworks(true, false, true, 120);
wifiState = WIFI_STATE_SCAN_CONN;
#else
wifiState = WIFI_STATE_CONNECT_LAST;
#endif
}

void handleWifiStateConnectLast() {
Expand Down Expand Up @@ -246,10 +251,11 @@ void handleWifiStateScanConnect() {
for (int i = scanIndex; i < wifiScanCompleteResult; i++) {
// try to connect to wifi network with index i
String issid = WiFi.SSID(i);
byte *bssid = WiFi.BSSID(i);
// check if ssid name matches any saved ssid
for (int j = 0; j < numKnownNetworks; j++) {
if (strncmp(issid.c_str(), knownNetworks[j].ssid, 32) ==0 ) {
connectToKnownNetwork(knownNetworks[j]);
connectToKnownNetwork(knownNetworks[j], bssid);

connectStartTimestamp = millis();

Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
//#define SAVE_PLAYPOS_BEFORE_SHUTDOWN // When playback is active and mode audiobook was selected, last play-position is saved automatically when shutdown is initiated
//#define SAVE_PLAYPOS_WHEN_RFID_CHANGE // When playback is active and mode audiobook was selected, last play-position is saved automatically for old playlist when new RFID-tag is applied
//#define HALLEFFECT_SENSOR_ENABLE // Support for hallsensor. For fine-tuning please adjust HallEffectSensor.h Please note: only user-support provided (https://forum.espuino.de/t/magnetische-hockey-tags/1449/35)
//#define ALWAYS_SCAN_WIFI_ON_STARTUP // Slows down first connection but ensures to always connect to the best WIFI
Copy link
Collaborator

@tueddy tueddy Jun 5, 2023

Choose a reason for hiding this comment

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

This would be obsolete if we use a NVS setting


//################## set PAUSE_WHEN_RFID_REMOVED behaviour #############################
#ifdef PAUSE_WHEN_RFID_REMOVED
Expand Down