Skip to content

Conversation

MaxineMuster
Copy link
Contributor

A try to address #1684

NOT tested. If it works as expected, it should log the best AP for a SSID (on UART).
If it works as expected, I coud try to set BSSID for the "wifi_sta_connect()"-call.

So if there is anybody able to test this PR? @divadiow ?

@NonPIayerCharacter
Copy link
Contributor

Mutex instead of waiting cycle?
OS_MutexCreate at function beginning
OS_MutexLock before scan
OS_MutexUnlock in scan callback
OS_MutexLock before connect (with 500ms timeout?)
OS_MutexDelete before return

@MaxineMuster
Copy link
Contributor Author

All the waiting is useless.

The scan is actually only done inside "wifi_sta_connect(&connect, &scan_cfg);"
so I can't set BSSID before.

I'm actually trying to use a global pointer for connect.bssid and, if a BSSID is found, setting this pointer.

char connect_bssid=NULL;


void wifi_init_sta(const char* oob_ssid, const char* connect_key, obkStaticIP_t *ip)
{
    sta_ps_mode_t ps_mode = PM_WIFI_DEFAULT_PS_MODE;
	wifi_sta_connect_t connect = {
		.ssid    = oob_ssid,
		.pwd     = connect_key,
		.bssid   = connect_bssid,
		.psk_value = NULL,
	};

	 ......

//inside  scan callback:


	if (! strcmp(searchssid,ap_info->ssid)){
		LOG(LOG_LVL_INFO, "TEST AP: for SSID=%s found BSSID %02X:%02X:%02X:%02X:%02X:%02X with RSSI=%i  ... ", searchssid, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], ap_info->rssi);
		if (ap_info->rssi > actrssi) {
			for (int i=0; i<6; i++) t_bssid[i]=mac[i];
			LOG(LOG_LVL_INFO, "better than prior best RSSI=%i\r\n",actrssi);
			actrssi=ap_info->rssi;
			connect_bssid=t_bssid;	// found a value, so set .bssid value of connect
		} 
		else {
			LOG(LOG_LVL_INFO, "best RSSI=%i is still\r\n",actrssi);
		}

So I hope to be able to set SSID before AP is selected inside wifi library ...

I hope to be able to do some test later today

@MaxineMuster
Copy link
Contributor Author

MaxineMuster commented Jun 26, 2025

I'm running out of ideas, the scan-callback is not always called/finished before the library tries joining

INSIDE wifi_init_sta, no static IP - using DHCP
[WLIB_I]LN882H WiFi Lib Ver: 1.3.0 [build time:Aug  7 2023 17:32:24][0x010300ff]
[WLIB_I]STA_Startup.
STA startup!
[WLIB_I]Disconnected.
Info:MAIN:Time 5, idle 0/s, free 91856, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 0/0 
[WLIB_E]HwEr:UKI:0
Info:MAIN:Registered for wifi changes
Info:MAIN:Connecting to SSID [XXXXXX]
psk value :
...
Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
[WLIB_I]Disconnected.
[WLIB_I]Status: Scan Successful. Initiating Join: 
[WLIB_I]SSID      = XXXXXX
[WLIB_I]BSSID     = XX:XX:XX:XX:XX:91
[WLIB_I]Channel   = 6
[WLIB_I]RSSI      = -63
[WLIB_I]StationID = 00:50:XX:XXf:XX:XX
[WLIB_I]Status: Initiating Authentication.
TEST AP: for SSID=XXXXXX found BSSID XX:XX:XX:XX:XX:9D with RSSI=-63  ... better than prior best RSSI=-5000
        CH= 8,RSSI= -63,BSSID:[XX:XX:XX:XX:XX:9D],SSID:"XXXXXX"
[WLIB_I]Status: Authentication Successful. Initiating Association.
TEST AP: for SSID=XXXXXX found BSSID XX:XX:XX:XX:XX:91 with RSSI=-64  ... best RSSI=-63 is still BSSID XX:XX:XX:XX:XX:9D - firstrun=1
        CH= 6,RSSI= -64,BSSID:[XX:XX:XX:XX:XX:91],SSID:"XXXXXX"
        CH= 8,RSSI= -64,BSSID:[XX:XX:XX:XX:XX:9D],SSID:""
[WLIB_I]Peer's HT-Capabilities:
[WLIB_I]ht_capable             = 1
[WLIB_I]ldpc_cod_cap           = 0
[WLIB_I]smps_mode              = 3
[WLIB_I]greenfield             = 0
[WLIB_I]short_gi_20            = 1

So this shows:

  • The "better" AP is found, but not used.
  • Joining might start before we can set BSSID.

Will continue next days...

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.

2 participants