159 |
159 |
160 case SYSTEM_EVENT_STA_DISCONNECTED: |
160 case SYSTEM_EVENT_STA_DISCONNECTED: |
161 ESP_LOGI(TAG, "Event STA disconnected, turn on AP"); |
161 ESP_LOGI(TAG, "Event STA disconnected, turn on AP"); |
162 if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) { |
162 if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) { |
163 wifi_state->STA_connected = false; |
163 wifi_state->STA_connected = false; |
|
164 wifi_state->STA_online = false; |
164 wifi_state->STA_rssi = 0; |
165 wifi_state->STA_rssi = 0; |
165 xSemaphoreGive(xSemaphoreWiFi); |
166 xSemaphoreGive(xSemaphoreWiFi); |
166 } |
167 } |
167 // Turn on AP |
168 // Turn on AP |
168 ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA)); |
169 ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA)); |
183 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_HAS_IP); |
184 xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_HAS_IP); |
184 tcpip_adapter_ip_info_t ip; |
185 tcpip_adapter_ip_info_t ip; |
185 memset(&ip, 0, sizeof(tcpip_adapter_ip_info_t)); |
186 memset(&ip, 0, sizeof(tcpip_adapter_ip_info_t)); |
186 if (tcpip_adapter_get_ip_info(ESP_IF_WIFI_STA, &ip) == 0) { |
187 if (tcpip_adapter_get_ip_info(ESP_IF_WIFI_STA, &ip) == 0) { |
187 if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) { |
188 if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) { |
|
189 wifi_state->STA_online = true; |
188 snprintf(wifi_state->STA_ip, 15, IPSTR, IP2STR(&ip.ip)); |
190 snprintf(wifi_state->STA_ip, 15, IPSTR, IP2STR(&ip.ip)); |
189 snprintf(wifi_state->STA_nm, 15, IPSTR, IP2STR(&ip.netmask)); |
191 snprintf(wifi_state->STA_nm, 15, IPSTR, IP2STR(&ip.netmask)); |
190 snprintf(wifi_state->STA_gw, 15, IPSTR, IP2STR(&ip.gw)); |
192 snprintf(wifi_state->STA_gw, 15, IPSTR, IP2STR(&ip.gw)); |
191 xSemaphoreGive(xSemaphoreWiFi); |
193 xSemaphoreGive(xSemaphoreWiFi); |
192 } |
194 } |
198 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_HAS_IP); |
200 xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_HAS_IP); |
199 if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) { |
201 if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) { |
200 wifi_state->STA_ip[0] = '\0'; |
202 wifi_state->STA_ip[0] = '\0'; |
201 wifi_state->STA_nm[0] = '\0'; |
203 wifi_state->STA_nm[0] = '\0'; |
202 wifi_state->STA_gw[0] = '\0'; |
204 wifi_state->STA_gw[0] = '\0'; |
|
205 wifi_state->STA_online = false; |
203 xSemaphoreGive(xSemaphoreWiFi); |
206 xSemaphoreGive(xSemaphoreWiFi); |
204 } |
207 } |
205 break; |
208 break; |
206 |
209 |
207 // SYSTEM_EVENT_STA_WPS_ER_SUCCESS 9 |
210 // SYSTEM_EVENT_STA_WPS_ER_SUCCESS 9 |
297 xSemaphoreWiFi = xSemaphoreCreateMutex(); |
300 xSemaphoreWiFi = xSemaphoreCreateMutex(); |
298 wifi_state = malloc(sizeof(WIFI_State)); |
301 wifi_state = malloc(sizeof(WIFI_State)); |
299 wifi_state->AP_clients = 0; |
302 wifi_state->AP_clients = 0; |
300 wifi_state->AP_active = false; |
303 wifi_state->AP_active = false; |
301 wifi_state->STA_connected = false; |
304 wifi_state->STA_connected = false; |
|
305 wifi_state->STA_online = false; |
302 wifi_state->STA_rssi = 0; |
306 wifi_state->STA_rssi = 0; |
303 |
307 |
304 /* wifi scanner config */ |
308 /* wifi scanner config */ |
305 wifi_scan_config_t scan_config = { |
309 wifi_scan_config_t scan_config = { |
306 .ssid = 0, |
310 .ssid = 0, |