133 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { |
133 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { |
134 wifi_state->STA_connected = true; |
134 wifi_state->STA_connected = true; |
135 wifi_state->STA_rssi = ap_info.rssi; |
135 wifi_state->STA_rssi = ap_info.rssi; |
136 sprintf(wifi_state->STA_ssid, "%s", ap_info.ssid); |
136 sprintf(wifi_state->STA_ssid, "%s", ap_info.ssid); |
137 xSemaphoreGive(xSemaphoreWiFi); |
137 xSemaphoreGive(xSemaphoreWiFi); |
138 } |
138 } else { |
|
139 ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_CONNECTED"); |
|
140 } |
139 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); |
141 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); |
140 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); |
142 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); |
141 break; |
143 break; |
142 } |
144 } |
143 |
145 |
150 if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) { |
152 if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) { |
151 wifi_state->STA_connected = false; |
153 wifi_state->STA_connected = false; |
152 wifi_state->STA_online = false; |
154 wifi_state->STA_online = false; |
153 wifi_state->STA_rssi = 0; |
155 wifi_state->STA_rssi = 0; |
154 xSemaphoreGive(xSemaphoreWiFi); |
156 xSemaphoreGive(xSemaphoreWiFi); |
155 } |
157 } else { |
|
158 ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_DISCONNECTED"); |
|
159 } |
156 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); |
160 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); |
157 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); |
161 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); |
158 break; |
162 break; |
159 } |
163 } |
160 |
164 |
177 wifi_state->STA_online = true; |
181 wifi_state->STA_online = true; |
178 snprintf(wifi_state->STA_ip, 16, "%s", ip4addr_ntoa(&event->ip_info.ip)); |
182 snprintf(wifi_state->STA_ip, 16, "%s", ip4addr_ntoa(&event->ip_info.ip)); |
179 snprintf(wifi_state->STA_nm, 16, "%s", ip4addr_ntoa(&event->ip_info.netmask)); |
183 snprintf(wifi_state->STA_nm, 16, "%s", ip4addr_ntoa(&event->ip_info.netmask)); |
180 snprintf(wifi_state->STA_gw, 16, "%s", ip4addr_ntoa(&event->ip_info.gw)); |
184 snprintf(wifi_state->STA_gw, 16, "%s", ip4addr_ntoa(&event->ip_info.gw)); |
181 xSemaphoreGive(xSemaphoreWiFi); |
185 xSemaphoreGive(xSemaphoreWiFi); |
|
186 } else { |
|
187 ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_GOT_IP"); |
182 } |
188 } |
183 break; |
189 break; |
184 |
190 |
185 case IP_EVENT_STA_LOST_IP: |
191 case IP_EVENT_STA_LOST_IP: |
186 ESP_LOGW(TAG, "Lost IP address"); |
192 ESP_LOGW(TAG, "Lost IP address"); |
189 wifi_state->STA_ip[0] = '\0'; |
195 wifi_state->STA_ip[0] = '\0'; |
190 wifi_state->STA_nm[0] = '\0'; |
196 wifi_state->STA_nm[0] = '\0'; |
191 wifi_state->STA_gw[0] = '\0'; |
197 wifi_state->STA_gw[0] = '\0'; |
192 wifi_state->STA_online = false; |
198 wifi_state->STA_online = false; |
193 xSemaphoreGive(xSemaphoreWiFi); |
199 xSemaphoreGive(xSemaphoreWiFi); |
|
200 } else { |
|
201 ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_LOST_IP"); |
194 } |
202 } |
195 break; |
203 break; |
196 |
204 |
197 default: |
205 default: |
198 ESP_LOGI(TAG, "Unknown IP event %d", event_id); |
206 ESP_LOGI(TAG, "Unknown IP event %d", event_id); |