Thu, 13 Apr 2023 12:08:24 +0200
Version 0.4.0. Disable normal logging mqtt.
4 | 1 | /** |
2 | * @file task_wifi.c | |
3 | * @brief WiFi task. Connects to a known Access Point. | |
4 | */ | |
5 | ||
6 | ||
7 | #include "config.h" | |
8 | ||
9 | ||
10 | static const char *TAG = "task_wifi"; | |
11 | ||
12 | #define ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID | |
13 | #define ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD | |
14 | ||
15 | SemaphoreHandle_t xSemaphoreWiFi = NULL; ///< Semaphore WiFi task. | |
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 | 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 | 22 | |
23 | ||
24 | const int TASK_WIFI_REQUEST_STA_DISCONNECT = BIT1; ///< When set, means a client requested to disconnect from currently connected AP. | |
25 | const int TASK_WIFI_REQUEST_STA_CONNECT = BIT2; ///< When set, means a client requested to connect to an access point. | |
26 | ||
27 | const int TASK_WIFI_HAS_IP = BIT3; ///< Indicate that we have an IP address | |
28 | const int TASK_WIFI_STA_FAILED = BIT5; ///< Indicate that we could not get a connection to AP as station. | |
29 | const int TASK_WIFI_STA_DISCONNECTED = BIT6; ///< Indicate that we are disconnected from an ap station. | |
30 | const int TASK_WIFI_STA_CONNECTED = BIT7; ///< Indicate that we are connected to AP as station, flip of BIT6. | |
31 | ||
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 | 37 | /****************************************************************************/ |
38 | ||
39 | ||
40 | bool ready_WiFi(void) | |
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 | 43 | return true; |
44 | return false; | |
45 | } | |
46 | ||
47 | ||
48 | ||
49 | void request_WiFi(bool connect) | |
50 | { | |
51 | if (connect) | |
52 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); | |
53 | else | |
54 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_DISCONNECT); | |
55 | } | |
56 | ||
57 | ||
58 | ||
59 | static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) | |
60 | { | |
61 | switch (event_id) { | |
62 | ||
63 | case WIFI_EVENT_STA_START: | |
64 | ESP_LOGI(TAG, "Event wifi START"); | |
65 | // Set the hostname for the dhcp client. | |
66 | #ifdef CONFIG_CODE_PRODUCTION | |
67 | ESP_ERROR_CHECK(esp_netif_set_hostname(sta_netif, "balkon")); | |
68 | #endif | |
69 | #ifdef CONFIG_CODE_TESTING | |
70 | ESP_ERROR_CHECK(esp_netif_set_hostname(sta_netif, "wemos")); | |
71 | #endif | |
72 | break; | |
73 | ||
74 | case WIFI_EVENT_STA_CONNECTED: { | |
75 | wifi_ap_record_t ap_info; | |
76 | esp_wifi_sta_get_ap_info(&ap_info); | |
77 | ESP_LOGI(TAG, "Event STA connected rssi=%d", ap_info.rssi); | |
78 | if (xSemaphoreTake(xSemaphoreWiFi, 35) == pdTRUE) { | |
79 | wifi_state->STA_connected = true; | |
80 | wifi_state->STA_rssi = ap_info.rssi; | |
81 | xSemaphoreGive(xSemaphoreWiFi); | |
82 | } else { | |
83 | ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_CONNECTED"); | |
84 | } | |
85 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); | |
86 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); | |
87 | break; | |
88 | } | |
89 | ||
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 | 112 | wifi_state->STA_connected = false; |
113 | wifi_state->STA_online = false; | |
114 | xSemaphoreGive(xSemaphoreWiFi); | |
115 | } else { | |
116 | ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_DISCONNECTED"); | |
117 | } | |
118 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); | |
119 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); | |
120 | break; | |
121 | } | |
122 | ||
123 | default: | |
124 | ESP_LOGW(TAG, "Unknown WiFi event %d", (int)event_id); | |
125 | break; | |
126 | } | |
127 | } | |
128 | ||
129 | ||
130 | ||
131 | static void got_ip_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) | |
132 | { | |
133 | switch (event_id) { | |
134 | ||
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 | 137 | xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_HAS_IP); |
138 | ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; | |
139 | if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { | |
140 | wifi_state->STA_online = true; | |
141 | snprintf(wifi_state->STA_ip, 16, IPSTR, IP2STR(&event->ip_info.ip)); | |
142 | snprintf(wifi_state->STA_nm, 16, IPSTR, IP2STR(&event->ip_info.netmask)); | |
143 | snprintf(wifi_state->STA_gw, 16, IPSTR, IP2STR(&event->ip_info.gw)); | |
144 | xSemaphoreGive(xSemaphoreWiFi); | |
145 | } else { | |
146 | ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_GOT_IP"); | |
147 | } | |
148 | break; | |
149 | ||
150 | case IP_EVENT_STA_LOST_IP: | |
151 | ESP_LOGW(TAG, "Lost IP address"); | |
152 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_HAS_IP); | |
153 | if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { | |
154 | wifi_state->STA_ip[0] = '\0'; | |
155 | wifi_state->STA_nm[0] = '\0'; | |
156 | wifi_state->STA_gw[0] = '\0'; | |
157 | wifi_state->STA_online = false; | |
158 | xSemaphoreGive(xSemaphoreWiFi); | |
159 | } else { | |
160 | ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_LOST_IP"); | |
161 | } | |
162 | break; | |
163 | ||
164 | default: | |
165 | ESP_LOGW(TAG, "Unknown IP event %d", (int)event_id); | |
166 | break; | |
167 | } | |
168 | } | |
169 | ||
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_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
|
174 | 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
|
175 | |
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 | /* 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
|
177 | 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
|
178 | 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
|
179 | 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
|
180 | |
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 | 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
|
182 | 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
|
183 | |
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(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
|
185 | 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
|
186 | |
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 | 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
|
188 | 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
|
189 | |
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 | 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
|
191 | 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
|
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 | |
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 | 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
|
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 | 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
|
198 | 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
|
199 | .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
|
200 | .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
|
201 | .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
|
202 | .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
|
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 | }; |
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 | // .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
|
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 | 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
|
208 | 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
|
209 | |
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 | 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
|
211 | 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
|
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 | 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
|
214 | 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
|
215 | 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
|
216 | } 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
|
217 | 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
|
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 | 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
|
220 | } |
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 | |
4 | 222 | |
223 | void task_wifi( void * pvParameters ) | |
224 | { | |
24
74609f70411e
Reduced I2C master speed from 400 to 100 Khz. Hope to get power-on init for BMP280 more reliable. Added warnings for I2C devices that are missing. Some logmessages reduced to debug log messages. Added extra 10 mSec delays before read shunt voltage in the INA219 task. Removed and reduced log levels in the MQTT task. Show received data events. Remove WiFi total time debug logging, it's ok now.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
225 | // uint64_t starttime = 0; |
4 | 226 | |
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
|
227 | 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
|
228 | esp_log_level_set("wifi", ESP_LOG_ERROR); |
4 | 229 | |
230 | /* | |
231 | * memory allocation of objects used by the task | |
232 | */ | |
233 | wifi_state = malloc(sizeof(WIFI_State)); | |
234 | memset(wifi_state, 0x00, sizeof(WIFI_State)); | |
235 | ||
236 | /* | |
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
|
237 | * 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
|
238 | */ |
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
|
239 | 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
|
240 | |
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 | /* |
4 | 242 | * init wifi as station |
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 | init_wifi(); |
4 | 245 | 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
|
246 | 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
|
247 | 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
|
248 | ESP_LOGI(TAG, "Startup completed, maximum transmit power %d dBm", tx_level / 4); |
4 | 249 | |
250 | for(;;) { | |
251 | ||
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
|
252 | /* |
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
|
253 | * 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
|
254 | */ |
4 | 255 | uxBits = xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT | TASK_WIFI_REQUEST_STA_DISCONNECT, |
256 | pdFALSE, pdFALSE, portMAX_DELAY ); | |
257 | ||
258 | if (uxBits & TASK_WIFI_REQUEST_STA_DISCONNECT) { | |
259 | /* | |
260 | * user requested a disconnect, this will in effect disconnect the wifi | |
261 | */ | |
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
|
262 | ESP_LOGI(TAG, "Request STA disconnect"); |
4 | 263 | ESP_ERROR_CHECK(esp_wifi_disconnect()); |
264 | xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED, pdFALSE, pdTRUE, portMAX_DELAY ); | |
265 | ||
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
|
266 | /* |
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
|
267 | * 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
|
268 | */ |
4 | 269 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_DISCONNECT); |
24
74609f70411e
Reduced I2C master speed from 400 to 100 Khz. Hope to get power-on init for BMP280 more reliable. Added warnings for I2C devices that are missing. Some logmessages reduced to debug log messages. Added extra 10 mSec delays before read shunt voltage in the INA219 task. Removed and reduced log levels in the MQTT task. Show received data events. Remove WiFi total time debug logging, it's ok now.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
270 | // ESP_LOGI(TAG, "Connection time %llu", (esp_timer_get_time() / 1000) - starttime); |
4 | 271 | |
272 | } else if (uxBits & TASK_WIFI_REQUEST_STA_CONNECT) { | |
273 | ||
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
|
274 | ESP_LOGI(TAG, "Request STA connect `%s' `%s'", ESP_WIFI_SSID, ESP_WIFI_PASS); |
24
74609f70411e
Reduced I2C master speed from 400 to 100 Khz. Hope to get power-on init for BMP280 more reliable. Added warnings for I2C devices that are missing. Some logmessages reduced to debug log messages. Added extra 10 mSec delays before read shunt voltage in the INA219 task. Removed and reduced log levels in the MQTT task. Show received data events. Remove WiFi total time debug logging, it's ok now.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
275 | // starttime = esp_timer_get_time() / 1000; |
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 | wifi_connect(); |
4 | 277 | |
278 | /* | |
279 | * 3 scenarios here: connection is successful and TASK_WIFI_STA_CONNECTED will be posted | |
280 | * or it's a failure and we get a TASK_WIFI_STA_FAILED with a reason code. | |
281 | * Or, option 3, the 5 seconds timeout is reached. This happens when the AP is not in range. | |
282 | * Note that the reason code is not exploited. For all intent and purposes a failure is a failure. | |
283 | */ | |
284 | uxBits = xEventGroupWaitBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED | TASK_WIFI_STA_FAILED, pdFALSE, pdFALSE, 5000 / portTICK_PERIOD_MS); | |
285 | ||
286 | if (uxBits & (TASK_WIFI_STA_CONNECTED | TASK_WIFI_STA_FAILED)) { | |
287 | /* | |
288 | * only save the config if the connection was successful! | |
289 | */ | |
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
|
290 | if (uxBits & TASK_WIFI_STA_FAILED) { |
4 | 291 | ESP_LOGI(TAG, "No AP found"); |
292 | vTaskDelay(3000 / portTICK_PERIOD_MS); | |
293 | ESP_LOGW(TAG, "Connection failed"); | |
294 | /* failed attempt to connect regardles of the reason */ | |
295 | } | |
296 | } | |
297 | ||
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
|
298 | /* |
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
|
299 | * 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
|
300 | */ |
4 | 301 | xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); |
302 | } | |
303 | ||
304 | } /* for(;;) */ | |
305 | } | |
306 | ||
307 |