main/task_wifi.c

Tue, 11 Apr 2023 11:11:13 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 11 Apr 2023 11:11:13 +0200
changeset 22
9c0bcc91fe1a
parent 18
12506716211c
child 23
2cc30d828d6e
permissions
-rw-r--r--

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.

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
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 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
60 {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 switch (event_id) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 case WIFI_EVENT_STA_START:
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 ESP_LOGI(TAG, "Event wifi START");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 // Set the hostname for the dhcp client.
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 #ifdef CONFIG_CODE_PRODUCTION
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 ESP_ERROR_CHECK(esp_netif_set_hostname(sta_netif, "balkon"));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 #endif
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 #ifdef CONFIG_CODE_TESTING
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 ESP_ERROR_CHECK(esp_netif_set_hostname(sta_netif, "wemos"));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 #endif
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 case WIFI_EVENT_STA_CONNECTED: {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 wifi_ap_record_t ap_info;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 esp_wifi_sta_get_ap_info(&ap_info);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 ESP_LOGI(TAG, "Event STA connected rssi=%d", ap_info.rssi);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 if (xSemaphoreTake(xSemaphoreWiFi, 35) == pdTRUE) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 wifi_state->STA_connected = true;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 wifi_state->STA_rssi = ap_info.rssi;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 xSemaphoreGive(xSemaphoreWiFi);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 } else {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_CONNECTED");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 break;
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
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 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
91 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
92 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
93
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
94 /*
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 * 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
96 * 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
97 */
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
98 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
99 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
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 /*
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 * 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
103 */
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 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
105 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
106 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
107 } 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
108 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
109 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
110 }
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
111 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 wifi_state->STA_connected = false;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 wifi_state->STA_online = false;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 xSemaphoreGive(xSemaphoreWiFi);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 } else {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_DISCONNECTED");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 break;
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
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 default:
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 ESP_LOGW(TAG, "Unknown WiFi event %d", (int)event_id);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 break;
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
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 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
132 {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 switch (event_id) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 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
136 //ESP_LOGE(TAG, "got_ip_event_handler()");
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_HAS_IP);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 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
139 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 wifi_state->STA_online = true;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 snprintf(wifi_state->STA_ip, 16, IPSTR, IP2STR(&event->ip_info.ip));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 snprintf(wifi_state->STA_nm, 16, IPSTR, IP2STR(&event->ip_info.netmask));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 snprintf(wifi_state->STA_gw, 16, IPSTR, IP2STR(&event->ip_info.gw));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 xSemaphoreGive(xSemaphoreWiFi);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 } else {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 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
147 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 case IP_EVENT_STA_LOST_IP:
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 ESP_LOGW(TAG, "Lost IP address");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_HAS_IP);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 wifi_state->STA_ip[0] = '\0';
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 wifi_state->STA_nm[0] = '\0';
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 wifi_state->STA_gw[0] = '\0';
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 wifi_state->STA_online = false;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 xSemaphoreGive(xSemaphoreWiFi);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 } else {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 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
161 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 break;
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 default:
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 ESP_LOGW(TAG, "Unknown IP event %d", (int)event_id);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 break;
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
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170
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
171 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
172 {
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 ESP_LOGI(TAG, "initialise_wifi() 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
174 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
175 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
176
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 /* 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
178 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
179 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
180 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
181
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 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
183 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
184
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 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
186 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
187
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 ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_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
189 ESP_ERROR_CHECK( esp_wifi_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
190
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 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
192 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
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 ESP_LOGI(TAG, "initialise_wifi() 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
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
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
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 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
199 {
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 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
201 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
202 .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
203 .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
204 .password = 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
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 };
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 // .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
208 // .pmf_cfg = {
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 // .capable = true,
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 // .required = false
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
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_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
214 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
215
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 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
217 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
218
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 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
220 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
221 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
222 } 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
223 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
224 }
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
225 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
226 }
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
227
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 void task_wifi( void * pvParameters )
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 {
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
231 uint64_t starttime = 0;
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232
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
233 ESP_LOGI(TAG, "Start WiFi");
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 esp_log_level_set("wifi", ESP_LOG_WARNING);
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 /*
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 * memory allocation of objects used by the task
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 */
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 wifi_state = malloc(sizeof(WIFI_State));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 memset(wifi_state, 0x00, sizeof(WIFI_State));
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 sprintf(wifi_state->STA_ssid, "%s", ESP_WIFI_SSID);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 /*
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
244 * 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
245 */
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
246 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
247
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
248 /*
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 * init wifi as station
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 */
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
251 init_wifi();
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 EventBits_t uxBits;
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 ESP_LOGI(TAG, "Startup completed, enter task loop");
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 for(;;) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257
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
258 /*
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
259 * 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
260 */
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 uxBits = xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT | TASK_WIFI_REQUEST_STA_DISCONNECT,
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 pdFALSE, pdFALSE, portMAX_DELAY );
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 if (uxBits & TASK_WIFI_REQUEST_STA_DISCONNECT) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 /*
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 * user requested a disconnect, this will in effect disconnect the wifi
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 */
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
268 ESP_LOGI(TAG, "Request STA disconnect");
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 ESP_ERROR_CHECK(esp_wifi_disconnect());
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED, pdFALSE, pdTRUE, portMAX_DELAY );
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271
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
272 /*
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
273 * 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
274 */
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_DISCONNECT);
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
276 ESP_LOGI(TAG, "Connection time %llu", (esp_timer_get_time() / 1000) - starttime);
4
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 } else if (uxBits & TASK_WIFI_REQUEST_STA_CONNECT) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279
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
280 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
281 starttime = esp_timer_get_time() / 1000;
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
282 wifi_connect();
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 /*
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 * 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
286 * 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
287 * 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
288 * 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
289 */
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 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
291
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 if (uxBits & (TASK_WIFI_STA_CONNECTED | TASK_WIFI_STA_FAILED)) {
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 /*
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 * only save the config if the connection was successful!
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 */
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
296 if (uxBits & TASK_WIFI_STA_FAILED) {
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 ESP_LOGI(TAG, "No AP found");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 vTaskDelay(3000 / portTICK_PERIOD_MS);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 ESP_LOGW(TAG, "Connection failed");
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300 /* failed attempt to connect regardles of the reason */
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303
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
304 /*
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
305 * 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
306 */
4
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT);
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 } /* for(;;) */
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 }
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312
d0155c16e992 Added Wifi task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313

mercurial