# HG changeset patch # User Michiel Broek # Date 1584188555 -3600 # Node ID d43ea0c916de6f6d61a3bed991ced6d6768b9386 # Parent 1ab1f4a8c328f4ecb53ab25b5569edfe1881bce7 A bit of code cleanup diff -r 1ab1f4a8c328 -r d43ea0c916de main/task_wifi.c --- a/main/task_wifi.c Sat Mar 14 13:07:02 2020 +0100 +++ b/main/task_wifi.c Sat Mar 14 13:22:35 2020 +0100 @@ -31,15 +31,14 @@ uint16_t _wifi_Scanned = 0; ///< Total scanned APs. -const int TASK_WIFI_REQUEST_WIFI_SCAN = BIT0; ///< When set, means a client requested to scan wireless networks. -const int TASK_WIFI_REQUEST_STA_DISCONNECT = BIT1; ///< When set, means a client requested to disconnect from currently connected AP. -const int TASK_WIFI_REQUEST_STA_CONNECT = BIT2; ///< When set, means a client requested to connect to an access point. -const int TASK_WIFI_REQUEST_STA_STATUS = BIT8; +const int TASK_WIFI_REQUEST_STA_DISCONNECT = BIT0; ///< When set, means a client requested to disconnect from currently connected AP. +const int TASK_WIFI_REQUEST_STA_CONNECT = BIT1; ///< When set, means a client requested to connect to an access point. +const int TASK_WIFI_REQUEST_STA_STATUS = BIT2; ///< When set, means a client requested to update the connection status. const int TASK_WIFI_HAS_IP = BIT3; ///< Indicate that we have an IP address const int TASK_WIFI_STA_FAILED = BIT4; ///< Indicate that we could not get a connection to AP as station. const int TASK_WIFI_STA_DISCONNECTED = BIT5; ///< Indicate that we are disconnected from an ap station. -const int TASK_WIFI_STA_CONNECTED = BIT6; ///< Indicate that we are connected to AP as station, flip of BIT6. +const int TASK_WIFI_STA_CONNECTED = BIT6; ///< Indicate that we are connected to AP as station, flip of BIT5. @@ -123,46 +122,6 @@ connect_mqtt(false); xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); - - //if (disconnected->reason == WIFI_REASON_NO_AP_FOUND && ! _wifi_ScanAPs) { - // ESP_LOGI(TAG, "Request scan for another AP"); - // _wifi_ScanAPs = true; - // _wifi_ScanDone = false; - // ap_num = MAX_AP_NUM; - // ESP_ERROR_CHECK(esp_wifi_scan_start(&scan_config, false)); - // xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); // Keep looping active. - // break; - //} - - //if (disconnected->reason == WIFI_REASON_NO_AP_FOUND && _wifi_ScanAPs && _wifi_ScanDone) { - // ESP_LOGD(TAG, "Scan completed, look for another AP, found:%d", _wifi_Scanned); - // _wifi_ScanAPs = false; - // _wifi_ScanDone = false; - // for (int i = 0; i < _wifi_Scanned; i++) { - // ap = accessp_records[i]; - // if ((read_station(ap.ssid) != -1)) { - // if (wifiStation.hide) { - // continue; // Blacklisted. - // } - /* We know this one */ - // wifi_config_t* config = task_wifi_ConfigSTA; - // memset(config, 0x00, sizeof(wifi_config_t)); - // memcpy(config->sta.ssid, wifiStation.SSID, strlen(wifiStation.SSID)); - // memcpy(config->sta.password, wifiStation.Password, strlen(wifiStation.Password)); - // ESP_LOGD(TAG, "new AP %s %s", wifiStation.SSID, wifiStation.Password); - // xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); - // break; - // } - // } - // break; - //} - - /* - * Reconnect previous AP. - */ - //if (FetchStaConfig()) { - // xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); - //} break; } @@ -259,6 +218,7 @@ ESP_ERROR_CHECK(esp_wifi_start()); xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_CONNECT); + xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED); xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED); EventBits_t uxBits; @@ -266,7 +226,7 @@ /* actions that can trigger: request a connection, a scan, or a disconnection */ uxBits = xEventGroupWaitBits(xEventGroupWifi, - TASK_WIFI_REQUEST_STA_CONNECT | TASK_WIFI_REQUEST_WIFI_SCAN | TASK_WIFI_REQUEST_STA_DISCONNECT | TASK_WIFI_REQUEST_STA_STATUS, + TASK_WIFI_REQUEST_STA_CONNECT | TASK_WIFI_REQUEST_STA_DISCONNECT | TASK_WIFI_REQUEST_STA_STATUS, pdFALSE, pdFALSE, portMAX_DELAY ); if (uxBits & TASK_WIFI_REQUEST_STA_DISCONNECT) { @@ -336,7 +296,7 @@ xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_REQUEST_STA_STATUS); wifi_ap_record_t ap_info; esp_wifi_sta_get_ap_info(&ap_info); - ESP_LOGI(TAG, "Event STA status, ssid:%s, bssid:" MACSTR ", rssi: %d", ap_info.ssid, MAC2STR(ap_info.bssid), ap_info.rssi); + ESP_LOGD(TAG, "Event STA status, ssid:%s, bssid:" MACSTR ", rssi: %d", ap_info.ssid, MAC2STR(ap_info.bssid), ap_info.rssi); if (xSemaphoreTake(xSemaphoreWiFi, 35) == pdTRUE) { wifi_state->STA_rssi = ap_info.rssi; xSemaphoreGive(xSemaphoreWiFi);