A dirty hack to reconnect to a better AP

Tue, 03 Oct 2023 19:55:34 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 03 Oct 2023 19:55:34 +0200
changeset 79
332e85569339
parent 78
e03d729aecb8
child 80
715785443a95

A dirty hack to reconnect to a better AP

main/co2meter.c file | annotate | diff | comparison | revisions
main/task_wifi.c file | annotate | diff | comparison | revisions
--- a/main/co2meter.c	Tue Oct 03 19:43:22 2023 +0200
+++ b/main/co2meter.c	Tue Oct 03 19:55:34 2023 +0200
@@ -186,8 +186,8 @@
 			user_refresh();
 			if (! ready_mqtt())
 			    connect_mqtt(true);
+		    	ESP_LOGI(TAG, "Loop => ML1_MQTT_CONNECT");
 		    }
-		    ESP_LOGI(TAG, "Loop => ML1_MQTT_CONNECT");
                     break;
 
 		case ML1_MQTT_CONNECT:
--- a/main/task_wifi.c	Tue Oct 03 19:43:22 2023 +0200
+++ b/main/task_wifi.c	Tue Oct 03 19:55:34 2023 +0200
@@ -102,6 +102,7 @@
             	/* Get the results so the memory used is freed. */
             	ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_num, accessp_records));
 		ESP_LOGI(TAG, "Event wifi Scane done, %d records", ap_num);
+		_wifi_BetterAP = false;
 		for (int i = 0; i < ap_num; i++) {
 		    wifi_ap_record_t ap = accessp_records[i];
 		    ESP_LOGI(TAG, "AP:%d bssid:%02x:%02x:%02x:%02x:%02x:%02x ssid:%s ch:%d rssi:%d",
@@ -114,6 +115,10 @@
 		}
             	_wifi_Scanned = ap_num;
             	_wifi_ScanDone = true;
+		if (_wifi_BetterAP) {
+		    ESP_LOGI(TAG, "Disconnect current AP");
+		    disconnect_WiFi();
+		}
 	    	break;
 	    }
 

mercurial