Tue, 03 Oct 2023 19:55:34 +0200
A dirty hack to reconnect to a better AP
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * @file task_wifi.c |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * @brief WiFi task. Connect to the known AP with the strongest signal. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | #include "config.h" |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
9 | #define MAX_AP_NUM 10 |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | static const char *TAG = "task_wifi"; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | SemaphoreHandle_t xSemaphoreWiFi = NULL; ///< Semaphore WiFi task. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | EventGroupHandle_t xEventGroupWifi; ///< Events WiFi task. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | uint16_t ap_num = MAX_AP_NUM; ///< Scan counter. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | wifi_ap_record_t *accessp_records; ///< [MAX_AP_NUM] records array with scan results. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | wifi_config_t *task_wifi_ConfigSTA = NULL; ///< Current STA configuration. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | WIFI_State *wifi_state = NULL; ///< Public state for other tasks. |
64
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
20 | esp_netif_t *sta_netif = NULL; ///< Station interface |
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
21 | |
70
e82bb707c671
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
22 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
23 | wifi_scan_config_t scan_config = { ///< WiFi scanner configuration. |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
24 | .ssid = (uint8_t *)CONFIG_ESP_WIFI_SSID, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
25 | .bssid = 0, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
26 | .channel = 0, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
27 | .show_hidden = false |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
28 | }; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
30 | bool _wifi_ScanDone = false; ///< Scan ready |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
31 | bool _wifi_BetterAP = false; ///< If better AP available. |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
32 | int8_t _wifi_RSSI = -127; ///< Latest RSSI level. |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
33 | uint16_t _wifi_Scanned = 0; ///< Total scanned APs. |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
35 | extern char hostname[]; ///< Generated hostname |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
36 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | |
48 | 39 | const int TASK_WIFI_REQUEST_STA_DISCONNECT = BIT0; ///< When set, means a client requested to disconnect from currently connected AP. |
40 | const int TASK_WIFI_REQUEST_STA_CONNECT = BIT1; ///< When set, means a client requested to connect to an access point. | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
41 | const int TASK_WIFI_REQUEST_STA_SCAN = BIT2; ///< When set, means a client requested a AP scan. |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
42 | const int TASK_WIFI_REQUEST_STA_STATUS = BIT3; ///< When set, means a client requested to update the connection status. |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
44 | const int TASK_WIFI_HAS_IP = BIT4; ///< Indicate that we have an IP address |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
45 | const int TASK_WIFI_STA_FAILED = BIT5; ///< Indicate that we could not get a connection to AP as station. |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
46 | const int TASK_WIFI_STA_DISCONNECTED = BIT6; ///< Indicate that we are disconnected from an ap station. |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
47 | const int TASK_WIFI_STA_CONNECTED = BIT7; ///< Indicate that we are connected to AP as station, flip of BIT5. |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | /** |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | * @brief Array with AP security names |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | const char *apsec[] = { "Open", "WEP", "WPA", "WPA2", "WPA WPA2", "Enterprise" }; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | /****************************************************************************/ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | bool ready_WiFi(void) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | if (wifi_state->STA_connected && wifi_state->STA_online) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | return true; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | return false; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
69 | void status_WiFi(void) |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
70 | { |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
71 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_STATUS); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
72 | } |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
73 | |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
74 | |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
75 | |
50
aae0056bc20b
Version 0.2.3 Added WiFi reconnect.
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
76 | void request_WiFi(void) |
aae0056bc20b
Version 0.2.3 Added WiFi reconnect.
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
77 | { |
aae0056bc20b
Version 0.2.3 Added WiFi reconnect.
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
78 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); |
aae0056bc20b
Version 0.2.3 Added WiFi reconnect.
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
79 | } |
aae0056bc20b
Version 0.2.3 Added WiFi reconnect.
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
80 | |
aae0056bc20b
Version 0.2.3 Added WiFi reconnect.
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
81 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
82 | void scan_WiFi(void) |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
83 | { |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
84 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_SCAN); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
85 | } |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
86 | |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
87 | |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
88 | void disconnect_WiFi(void) |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
89 | { |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
90 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_DISCONNECT); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
91 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
92 | } |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
93 | |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
94 | |
50
aae0056bc20b
Version 0.2.3 Added WiFi reconnect.
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
95 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
96 | static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
98 | switch (event_id) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
100 | case WIFI_EVENT_SCAN_DONE: |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
101 | { |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
102 | /* Get the results so the memory used is freed. */ |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
103 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_num, accessp_records)); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
104 | ESP_LOGI(TAG, "Event wifi Scane done, %d records", ap_num); |
79
332e85569339
A dirty hack to reconnect to a better AP
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
105 | _wifi_BetterAP = false; |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
106 | for (int i = 0; i < ap_num; i++) { |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
107 | wifi_ap_record_t ap = accessp_records[i]; |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
108 | ESP_LOGI(TAG, "AP:%d bssid:%02x:%02x:%02x:%02x:%02x:%02x ssid:%s ch:%d rssi:%d", |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
109 | i, ap.bssid[0], ap.bssid[1], ap.bssid[2], ap.bssid[3], ap.bssid[4], ap.bssid[5], |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
110 | ap.ssid, ap.primary, ap.rssi); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
111 | if (ap.rssi > CONFIG_ESP_WIFI_ROAMING_LEVEL && ap.rssi > (_wifi_RSSI + 3)) { |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
112 | _wifi_BetterAP = true; |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
113 | ESP_LOGI(TAG, "AP:%d is a better AP", i); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
114 | } |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
115 | } |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
116 | _wifi_Scanned = ap_num; |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
117 | _wifi_ScanDone = true; |
79
332e85569339
A dirty hack to reconnect to a better AP
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
118 | if (_wifi_BetterAP) { |
332e85569339
A dirty hack to reconnect to a better AP
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
119 | ESP_LOGI(TAG, "Disconnect current AP"); |
332e85569339
A dirty hack to reconnect to a better AP
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
120 | disconnect_WiFi(); |
332e85569339
A dirty hack to reconnect to a better AP
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
121 | } |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
122 | break; |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
123 | } |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
124 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
125 | case WIFI_EVENT_STA_START: |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
126 | { |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
127 | ESP_LOGI(TAG, "Event wifi START"); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
128 | // Set the configured hostname for the dhcp client. |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
129 | ESP_ERROR_CHECK(esp_netif_set_hostname(sta_netif, hostname)); |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
130 | esp_wifi_connect(); |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
131 | _wifi_BetterAP = false; |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
132 | break; |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
133 | } |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
134 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | case WIFI_EVENT_STA_CONNECTED: |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
136 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | wifi_event_sta_connected_t* event = (wifi_event_sta_connected_t*) event_data; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
138 | wifi_ap_record_t ap_info; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | esp_wifi_sta_get_ap_info(&ap_info); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
140 | ESP_LOGI(TAG, "Event STA connected, ssid:%s, bssid:" MACSTR ", channel:%d, rssi: %d, authmode:%s", |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
141 | ap_info.ssid, MAC2STR(ap_info.bssid), event->channel, ap_info.rssi, apsec[event->authmode]); |
27
8bb63daa7b46
Increased some lock timeouts. Application CPU speed from 160 to 240 MHz. Added timeout timers to the update process.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
142 | if (xSemaphoreTake(xSemaphoreWiFi, 35) == pdTRUE) { |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
143 | wifi_state->STA_connected = true; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
144 | wifi_state->STA_rssi = ap_info.rssi; |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
145 | wifi_state->STA_channel = ap_info.primary; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
146 | sprintf(wifi_state->STA_ssid, "%s", ap_info.ssid); |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
147 | snprintf(wifi_state->STA_bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x", |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
148 | ap_info.bssid[0], ap_info.bssid[1], ap_info.bssid[2], ap_info.bssid[3], ap_info.bssid[4], ap_info.bssid[5]); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
149 | xSemaphoreGive(xSemaphoreWiFi); |
23
58a328e91881
Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
150 | } else { |
58a328e91881
Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
151 | ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_CONNECTED"); |
58a328e91881
Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
152 | } |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
153 | _wifi_BetterAP = false; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
154 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
155 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
157 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
158 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
159 | case WIFI_EVENT_STA_DISCONNECTED: |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
160 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
161 | wifi_event_sta_disconnected_t* disconnected = (wifi_event_sta_disconnected_t*) event_data; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
162 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
163 | ESP_LOGI(TAG, "Event STA disconnected, ssid:%s, ssid_len:%d, bssid:" MACSTR ", reason:%d", |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
164 | disconnected->ssid, disconnected->ssid_len, MAC2STR(disconnected->bssid), disconnected->reason); |
27
8bb63daa7b46
Increased some lock timeouts. Application CPU speed from 160 to 240 MHz. Added timeout timers to the update process.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
165 | if (xSemaphoreTake(xSemaphoreWiFi, 35) == pdTRUE) { |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
166 | wifi_state->STA_connected = false; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
167 | wifi_state->STA_online = false; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
168 | wifi_state->STA_rssi = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
169 | xSemaphoreGive(xSemaphoreWiFi); |
23
58a328e91881
Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
170 | } else { |
58a328e91881
Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
171 | ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_DISCONNECTED"); |
58a328e91881
Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
172 | } |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
173 | _wifi_BetterAP = false; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
174 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
175 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
176 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
177 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
178 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
179 | default: |
70
e82bb707c671
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
180 | ESP_LOGW(TAG, "Unknown WiFi event %ld", event_id); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
181 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
182 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
183 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
184 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
185 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
186 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
187 | static void got_ip_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
188 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
189 | switch (event_id) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
190 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
191 | case IP_EVENT_STA_GOT_IP: |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
192 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_HAS_IP); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
193 | ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
194 | if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
195 | wifi_state->STA_online = true; |
64
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
196 | snprintf(wifi_state->STA_ip, 16, IPSTR, IP2STR(&event->ip_info.ip)); |
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
197 | snprintf(wifi_state->STA_nm, 16, IPSTR, IP2STR(&event->ip_info.netmask)); |
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
198 | snprintf(wifi_state->STA_gw, 16, IPSTR, IP2STR(&event->ip_info.gw)); |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
199 | xSemaphoreGive(xSemaphoreWiFi); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
200 | } else { |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
201 | ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_GOT_IP"); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
202 | } |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
203 | connect_mqtt(true); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
204 | break; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
205 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
206 | case IP_EVENT_STA_LOST_IP: |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
207 | ESP_LOGW(TAG, "Lost IP address"); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
208 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_HAS_IP); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
209 | if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
210 | wifi_state->STA_ip[0] = '\0'; |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
211 | wifi_state->STA_nm[0] = '\0'; |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
212 | wifi_state->STA_gw[0] = '\0'; |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
213 | wifi_state->STA_online = false; |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
214 | xSemaphoreGive(xSemaphoreWiFi); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
215 | } else { |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
216 | ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_LOST_IP"); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
217 | } |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
218 | break; |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
219 | |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
220 | case IP_EVENT_AP_STAIPASSIGNED: |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
221 | ESP_LOGI(TAG, "IP_EVENT_AP_STAIPASSIGNED"); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
222 | break; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
223 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
224 | default: |
70
e82bb707c671
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
225 | ESP_LOGW(TAG, "Unknown IP event %ld", event_id); |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
226 | break; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
227 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
228 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
229 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
230 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
231 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
232 | void task_wifi( void * pvParameters ) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
233 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
234 | ESP_LOGI(TAG, "Starting WiFi"); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
235 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
236 | /* event handler and event group for the wifi driver */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
237 | xEventGroupWifi = xEventGroupCreate(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
238 | /* initialize the tcp stack */ |
64
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
239 | ESP_ERROR_CHECK(esp_netif_init()); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
240 | ESP_ERROR_CHECK(esp_event_loop_create_default()); |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
241 | |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
242 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
243 | ESP_ERROR_CHECK(esp_wifi_init(&cfg)); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
244 | |
64
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
245 | sta_netif = esp_netif_create_default_wifi_sta(); |
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
246 | assert(sta_netif); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
247 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
248 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
249 | * memory allocation of objects used by the task |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
250 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
251 | accessp_records = (wifi_ap_record_t*)malloc(sizeof(wifi_ap_record_t) * MAX_AP_NUM); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
252 | xSemaphoreWiFi = xSemaphoreCreateMutex(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
253 | wifi_state = malloc(sizeof(WIFI_State)); |
32
7717ac1d2f7f
Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
254 | memset(wifi_state, 0x00, sizeof(WIFI_State)); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
255 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
256 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
257 | * init wifi as station |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
258 | */ |
64
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
259 | esp_event_handler_instance_t instance_any_id; |
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
260 | esp_event_handler_instance_t instance_got_ip; |
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
261 | ESP_ERROR_CHECK( esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, &instance_any_id) ); |
e63b17b80244
Changed to esp-idf 4.2.1 stable API.
Michiel Broek <mbroek@mbse.eu>
parents:
50
diff
changeset
|
262 | ESP_ERROR_CHECK( esp_event_handler_instance_register(IP_EVENT, ESP_EVENT_ANY_ID, &got_ip_event_handler, NULL, &instance_got_ip) ); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
263 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
264 | wifi_config_t wifi_config = { |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
265 | .sta = { |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
266 | .ssid = CONFIG_ESP_WIFI_SSID, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
267 | .password = CONFIG_ESP_WIFI_PASSWORD, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
268 | #if CONFIG_WIFI_ALL_CHANNEL_SCAN |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
269 | .scan_method = WIFI_ALL_CHANNEL_SCAN, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
270 | #elif CONFIG_WIFI_FAST_SCAN |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
271 | .scan_method = WIFI_FAST_SCAN, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
272 | #endif |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
273 | .failure_retry_cnt = 3, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
274 | .sort_method = WIFI_CONNECT_AP_BY_SIGNAL, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
275 | .threshold.rssi = CONFIG_ESP_FAST_SCAN_MINIMUM_SIGNAL, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
276 | .threshold.authmode = WIFI_AUTH_WPA2_PSK, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
277 | }, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
278 | }; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
279 | ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
280 | ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
281 | ESP_ERROR_CHECK(esp_wifi_start()); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
282 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
283 | // ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
284 | |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
285 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); |
48 | 286 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
287 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
288 | EventBits_t uxBits; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
289 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
290 | for(;;) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
291 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
292 | /* actions that can trigger: request a connection, a scan, or a disconnection */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
293 | uxBits = xEventGroupWaitBits(xEventGroupWifi, |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
294 | TASK_WIFI_REQUEST_STA_CONNECT | TASK_WIFI_REQUEST_STA_DISCONNECT | TASK_WIFI_REQUEST_STA_SCAN | TASK_WIFI_REQUEST_STA_STATUS, |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
295 | pdFALSE, pdFALSE, portMAX_DELAY ); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
296 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
297 | if (uxBits & TASK_WIFI_REQUEST_STA_DISCONNECT) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
298 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
299 | * user requested a disconnect, this will in effect disconnect the wifi |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
300 | */ |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
301 | ESP_LOGI(TAG, "Request STA disconnect"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
302 | ESP_ERROR_CHECK(esp_wifi_disconnect()); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
303 | xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED, pdFALSE, pdTRUE, portMAX_DELAY ); |
37
358bbd5b608e
menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
32
diff
changeset
|
304 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
305 | /* finally: release the scan request bit */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
306 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_DISCONNECT); |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
307 | ESP_LOGI(TAG, "Request STA disconnect is done"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | } else if (uxBits & TASK_WIFI_REQUEST_STA_CONNECT) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
310 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
311 | ESP_LOGI(TAG, "Request STA connect"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
312 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_FAILED); |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
313 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
314 | |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
315 | ESP_LOGI(TAG, "Connecting to `%s'", CONFIG_ESP_WIFI_SSID); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
316 | esp_err_t wifierror = esp_wifi_connect(); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
317 | if (wifierror != ESP_OK) { |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
318 | ESP_LOGE(TAG, "esp_wifi_connect() `%s' rc=%04x", CONFIG_ESP_WIFI_SSID, (int)wifierror); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
319 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_FAILED); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
320 | } |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
321 | uxBits = xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED | TASK_WIFI_STA_FAILED, pdFALSE, pdFALSE, 5000 / portTICK_PERIOD_MS); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
322 | // if (uxBits & TASK_WIFI_STA_CONNECTED) |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
323 | // xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); // Only clear when connected. |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
324 | |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
325 | } else if (uxBits & TASK_WIFI_REQUEST_STA_STATUS) { |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
326 | /* |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
327 | * Request WiFi update status, refresh the rssi. |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
328 | */ |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
329 | ESP_LOGD(TAG, "Request STA status"); |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
330 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_STATUS); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
331 | wifi_ap_record_t ap_info; |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
332 | esp_wifi_sta_get_ap_info(&ap_info); |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
333 | ESP_LOGI(TAG, "Event STA status, ssid:%s, bssid:" MACSTR ", rssi: %d", ap_info.ssid, MAC2STR(ap_info.bssid), ap_info.rssi); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
334 | _wifi_RSSI = ap_info.rssi; |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
335 | _wifi_BetterAP = false; |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
336 | if (xSemaphoreTake(xSemaphoreWiFi, 35) == pdTRUE) { |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
337 | wifi_state->STA_rssi = ap_info.rssi; |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
338 | wifi_state->STA_channel = ap_info.primary; |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
339 | snprintf(wifi_state->STA_bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x", |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
340 | ap_info.bssid[0], ap_info.bssid[1], ap_info.bssid[2], ap_info.bssid[3], ap_info.bssid[4], ap_info.bssid[5]); |
47
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
341 | xSemaphoreGive(xSemaphoreWiFi); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
342 | } else { |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
343 | ESP_LOGE(TAG, "lock error TASK_WIFI_REQUEST_STA_STATUS"); |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
344 | } |
1ab1f4a8c328
Version 0.2.2 Changed to use a permanent network and WiFi connection. Removed three mainloop stages. Removed MQTT sequence counter that was not used. Update WiFi rssi status during eacht measure cycle. Changed FreeRTOS schedulng to 500 Hz.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
345 | user_refresh(); |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
346 | |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
347 | } else if (uxBits & TASK_WIFI_REQUEST_STA_SCAN) { |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
348 | |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
349 | ESP_LOGI(TAG, "Request STA scan"); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
350 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_SCAN); |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
351 | /* safe guard against overflow */ |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
352 | ap_num = MAX_AP_NUM; |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
353 | _wifi_ScanDone = false; |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
354 | _wifi_BetterAP = false; |
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
355 | ESP_ERROR_CHECK(esp_wifi_scan_start(&scan_config, false)); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
356 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
357 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
358 | } /* for(;;) */ |
77
15dc572a7fcb
Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.
Michiel Broek <mbroek@mbse.eu>
parents:
70
diff
changeset
|
359 | // vTaskDelay(10 / portTICK_PERIOD_MS); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
360 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
361 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
362 |