main/task_wifi.c

Sun, 10 Sep 2023 17:29:15 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 10 Sep 2023 17:29:15 +0200
changeset 37
50dbb626fbab
parent 35
9827c5a08c63
permissions
-rw-r--r--

Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.

4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file task_wifi.c
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief WiFi task. Connects to a known Access Point.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 */
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 #include "config.h"
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 static const char *TAG = "task_wifi";
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 #define ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 #define ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 SemaphoreHandle_t xSemaphoreWiFi = NULL; ///< Semaphore WiFi task.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 EventGroupHandle_t xEventGroupWifi; ///< Events WiFi task.
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
17 esp_event_handler_instance_t instance_any_id; ///< WiFi event handler.
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
18 esp_event_handler_instance_t instance_got_ip; ///< IP event handler.
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
19
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 WIFI_State *wifi_state = NULL; ///< Public state for other tasks.
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
21 esp_netif_t *sta_netif = NULL; ///< Station interface.
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 const int TASK_WIFI_REQUEST_STA_DISCONNECT = BIT1; ///< When set, means a client requested to disconnect from currently connected AP.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 const int TASK_WIFI_REQUEST_STA_CONNECT = BIT2; ///< When set, means a client requested to connect to an access point.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 const int TASK_WIFI_HAS_IP = BIT3; ///< Indicate that we have an IP address
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 const int TASK_WIFI_STA_FAILED = BIT5; ///< Indicate that we could not get a connection to AP as station.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 const int TASK_WIFI_STA_DISCONNECTED = BIT6; ///< Indicate that we are disconnected from an ap station.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 const int TASK_WIFI_STA_CONNECTED = BIT7; ///< Indicate that we are connected to AP as station, flip of BIT6.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
33 static void init_wifi(void);
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
34 void wifi_connect(void);
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
35
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
36
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 /****************************************************************************/
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 bool ready_WiFi(void)
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 {
15
64028e178ff1 Splitted wifi and mqtt connect states to make the connections more robust. Protect the mqtt connection request against requests when a request is already done or in progress.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
42 if ((xEventGroupGetBits(xEventGroupWifi) & (TASK_WIFI_STA_CONNECTED | TASK_WIFI_HAS_IP)) == (TASK_WIFI_STA_CONNECTED | TASK_WIFI_HAS_IP))
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 return true;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 return false;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 void request_WiFi(bool connect)
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 if (connect)
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 else
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_DISCONNECT);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 switch (event_id) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 case WIFI_EVENT_STA_START:
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 ESP_LOGI(TAG, "Event wifi START");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 // Set the hostname for the dhcp client.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 #ifdef CONFIG_CODE_PRODUCTION
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 ESP_ERROR_CHECK(esp_netif_set_hostname(sta_netif, "balkon"));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 #endif
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 #ifdef CONFIG_CODE_TESTING
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 ESP_ERROR_CHECK(esp_netif_set_hostname(sta_netif, "wemos"));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 #endif
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 case WIFI_EVENT_STA_CONNECTED: {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 wifi_ap_record_t ap_info;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 esp_wifi_sta_get_ap_info(&ap_info);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 ESP_LOGI(TAG, "Event STA connected rssi=%d", ap_info.rssi);
35
9827c5a08c63 Version 0.4.2, some code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
77 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 wifi_state->STA_connected = true;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 wifi_state->STA_rssi = ap_info.rssi;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 xSemaphoreGive(xSemaphoreWiFi);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 } else {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_CONNECTED");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 case WIFI_EVENT_STA_DISCONNECTED: {
15
64028e178ff1 Splitted wifi and mqtt connect states to make the connections more robust. Protect the mqtt connection request against requests when a request is already done or in progress.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
90 wifi_event_sta_disconnected_t* disconnected = (wifi_event_sta_disconnected_t*) event_data;
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
91 ESP_LOGI(TAG, "Event STA disconnected, reason: %d", disconnected->reason);
15
64028e178ff1 Splitted wifi and mqtt connect states to make the connections more robust. Protect the mqtt connection request against requests when a request is already done or in progress.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
92
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
93 /*
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
94 * If it's not a normal request to disconnect, make sure the mqtt
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
95 * connection will be removed.
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
96 */
15
64028e178ff1 Splitted wifi and mqtt connect states to make the connections more robust. Protect the mqtt connection request against requests when a request is already done or in progress.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
97 if (disconnected->reason != 8)
64028e178ff1 Splitted wifi and mqtt connect states to make the connections more robust. Protect the mqtt connection request against requests when a request is already done or in progress.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
98 request_mqtt(false);
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
99
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
100 /*
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
101 * Error conditions.
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
102 */
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
103 if (disconnected->reason == 2) {
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
104 ESP_LOGW(TAG, "Auth Expire: try to recover");
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
105 wifi_connect();
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
106 } else if (disconnected->reason == 39) {
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
107 ESP_LOGW(TAG, "Timeout: try to recover");
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
108 ESP_ERROR_CHECK(esp_wifi_connect());
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
109 }
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
110 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 wifi_state->STA_connected = false;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 wifi_state->STA_online = false;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 xSemaphoreGive(xSemaphoreWiFi);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 } else {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_DISCONNECTED");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 default:
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 ESP_LOGW(TAG, "Unknown WiFi event %d", (int)event_id);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 static void got_ip_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 switch (event_id) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 case IP_EVENT_STA_GOT_IP:
6
bad3414f7bc4 Added the getTempBaro and getVoltsCurrent functions to process the measured data. Added some main task code. Added subscribe to MQTT events.
Michiel Broek <mbroek@mbse.eu>
parents: 5
diff changeset
135 //ESP_LOGE(TAG, "got_ip_event_handler()");
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_HAS_IP);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 wifi_state->STA_online = true;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 snprintf(wifi_state->STA_ip, 16, IPSTR, IP2STR(&event->ip_info.ip));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 snprintf(wifi_state->STA_nm, 16, IPSTR, IP2STR(&event->ip_info.netmask));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 snprintf(wifi_state->STA_gw, 16, IPSTR, IP2STR(&event->ip_info.gw));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 xSemaphoreGive(xSemaphoreWiFi);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 } else {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_GOT_IP");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 case IP_EVENT_STA_LOST_IP:
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 ESP_LOGW(TAG, "Lost IP address");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_HAS_IP);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 wifi_state->STA_ip[0] = '\0';
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 wifi_state->STA_nm[0] = '\0';
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 wifi_state->STA_gw[0] = '\0';
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 wifi_state->STA_online = false;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 xSemaphoreGive(xSemaphoreWiFi);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 } else {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_LOST_IP");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 default:
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 ESP_LOGW(TAG, "Unknown IP event %d", (int)event_id);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
170 static void init_wifi(void)
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
171 {
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
172 ESP_ERROR_CHECK(esp_event_loop_create_default());
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
173 xSemaphoreWiFi = xSemaphoreCreateMutex();
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
174
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
175 /* initialize the tcp stack */
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
176 ESP_ERROR_CHECK(esp_netif_init());
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
177 sta_netif = esp_netif_create_default_wifi_sta();
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
178 assert(sta_netif);
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
179
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
180 wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
181 ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_config));
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
182
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
183 ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, &instance_any_id) );
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
184 ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, ESP_EVENT_ANY_ID, &got_ip_event_handler, NULL, &instance_got_ip) );
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
185
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
186 ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
23
2cc30d828d6e Shorter delays during wifi connect timeout. Some code cleanup in the main state table. Report WiFi TX power during init. Removed SSID from WIFI_State because it wasn't used.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
187 ESP_ERROR_CHECK(esp_wifi_start());
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
188
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
189 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED);
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
190 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED);
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
191 }
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
192
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
193
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
194 void wifi_connect(void)
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
195 {
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
196 ESP_LOGI(TAG, "wifi_connect() start");
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
197 wifi_config_t wifi_Config = { ///< Current STA configuration.
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
198 .sta = {
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
199 .ssid = ESP_WIFI_SSID,
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
200 .password = ESP_WIFI_PASS,
23
2cc30d828d6e Shorter delays during wifi connect timeout. Some code cleanup in the main state table. Report WiFi TX power during init. Removed SSID from WIFI_State because it wasn't used.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
201 .threshold.authmode = WIFI_AUTH_WPA2_PSK,
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
202 },
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
203 };
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
204 // .threshold.authmode = WIFI_AUTH_WPA2_PSK,
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
205
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
206 ESP_ERROR_CHECK(esp_wifi_disconnect());
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
207 ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_Config) );
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
208
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
209 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_FAILED);
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
210 esp_err_t wifierror = esp_wifi_connect();
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
211
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
212 if (wifierror != ESP_OK) {
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
213 ESP_LOGE(TAG, "esp_wifi_connect() rc=%04x %s", (int)wifierror, esp_err_to_name(wifierror));
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
214 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_FAILED);
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
215 } else {
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
216 ESP_LOGI(TAG, "Connected Ok");
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
217 }
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
218 ESP_LOGI(TAG, "wifi_connect() done");
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
219 }
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
220
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 void task_wifi( void * pvParameters )
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 {
23
2cc30d828d6e Shorter delays during wifi connect timeout. Some code cleanup in the main state table. Report WiFi TX power during init. Removed SSID from WIFI_State because it wasn't used.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
224 ESP_LOGI(TAG, "Starting WiFi task");
2cc30d828d6e Shorter delays during wifi connect timeout. Some code cleanup in the main state table. Report WiFi TX power during init. Removed SSID from WIFI_State because it wasn't used.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
225 esp_log_level_set("wifi", ESP_LOG_ERROR);
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 /*
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 * memory allocation of objects used by the task
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 */
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 wifi_state = malloc(sizeof(WIFI_State));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 memset(wifi_state, 0x00, sizeof(WIFI_State));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 /*
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
234 * event group for the wifi driver
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
235 */
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
236 xEventGroupWifi = xEventGroupCreate();
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
237
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
238 /*
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 * init wifi as station
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 */
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
241 init_wifi();
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 EventBits_t uxBits;
23
2cc30d828d6e Shorter delays during wifi connect timeout. Some code cleanup in the main state table. Report WiFi TX power during init. Removed SSID from WIFI_State because it wasn't used.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
243 int8_t tx_level;
2cc30d828d6e Shorter delays during wifi connect timeout. Some code cleanup in the main state table. Report WiFi TX power during init. Removed SSID from WIFI_State because it wasn't used.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
244 ESP_ERROR_CHECK(esp_wifi_get_max_tx_power(&tx_level));
2cc30d828d6e Shorter delays during wifi connect timeout. Some code cleanup in the main state table. Report WiFi TX power during init. Removed SSID from WIFI_State because it wasn't used.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
245 ESP_LOGI(TAG, "Startup completed, maximum transmit power %d dBm", tx_level / 4);
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 for(;;) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
249 /*
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
250 * Actions that can trigger: request a connection or a disconnection
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
251 */
35
9827c5a08c63 Version 0.4.2, some code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
252 uxBits = xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT | TASK_WIFI_REQUEST_STA_DISCONNECT, pdFALSE, pdFALSE, portMAX_DELAY );
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 if (uxBits & TASK_WIFI_REQUEST_STA_DISCONNECT) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 /*
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 * user requested a disconnect, this will in effect disconnect the wifi
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 */
7
2b337dd92f25 Added volts/current loop calculations. Added millis() timer running on the hardware clock. Completed most of the main state loop. Added MQTT wait for disconnect. MQTT disconnect in two passes, disconnect and stop.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
258 ESP_LOGI(TAG, "Request STA disconnect");
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 ESP_ERROR_CHECK(esp_wifi_disconnect());
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED, pdFALSE, pdTRUE, portMAX_DELAY );
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
262 /*
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
263 * Finally: release the request bit
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
264 */
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_DISCONNECT);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 } else if (uxBits & TASK_WIFI_REQUEST_STA_CONNECT) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
269 ESP_LOGI(TAG, "Request STA connect `%s' `%s'", ESP_WIFI_SSID, ESP_WIFI_PASS);
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
270 wifi_connect();
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 /*
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 * 3 scenarios here: connection is successful and TASK_WIFI_STA_CONNECTED will be posted
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 * or it's a failure and we get a TASK_WIFI_STA_FAILED with a reason code.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 * Or, option 3, the 5 seconds timeout is reached. This happens when the AP is not in range.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 * Note that the reason code is not exploited. For all intent and purposes a failure is a failure.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 */
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 uxBits = xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED | TASK_WIFI_STA_FAILED, pdFALSE, pdFALSE, 5000 / portTICK_PERIOD_MS);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280 if (uxBits & (TASK_WIFI_STA_CONNECTED | TASK_WIFI_STA_FAILED)) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 /*
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 * only save the config if the connection was successful!
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 */
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
284 if (uxBits & TASK_WIFI_STA_FAILED) {
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 ESP_LOGI(TAG, "No AP found");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 vTaskDelay(3000 / portTICK_PERIOD_MS);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 ESP_LOGW(TAG, "Connection failed");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 /* failed attempt to connect regardles of the reason */
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291
22
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
292 /*
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
293 * Finally: release the request bit
9c0bcc91fe1a Decreased WiFi transmit level to 13. Level 15 is unstable, skip 14 just to be sure. It seems to be the bad designed antenna circuit on the ESP32-C3 Lolin v2.1.0 board. The board also benefits from a ground plane connected to the shield of the USB connector. The final implementation needs an external antenna anyway so the onboard antenna will go away. In the meanwhile, the wifi task is now more robust. Also, in testing mode there is no battery alarm, only when building for production.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
294 */
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 } /* for(;;) */
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301

mercurial