modified: main/src/wifi.c
This commit is contained in:
1 parent
c5a1e1a80c
commit
cd4cc48e2d
1 file changed
+7
-9
@@ -11,9 +11,9 @@
|
||||
static const char * TAG = "wifi.c";
|
||||
|
||||
esp_err_t wifi_init() {
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
// Init IP Stack
|
||||
tcpip_adapter_init();
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -27,34 +27,32 @@ static bool wait_for_connected() {
|
||||
ESP_LOGI(TAG, "IP Address: " IPSTR, IP2STR(&ip_info.ip));
|
||||
return ESP_OK;
|
||||
}
|
||||
vTaskDelay(1500 / portTICK_RATE_MS);
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
}
|
||||
ESP_LOGE(TAG, "Timed out waiting for ip address from dhcp server.");
|
||||
ESP_LOGE(TAG, "Timedout waiting for ip address from dhcp server.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
// Function to turn on WiFi
|
||||
esp_err_t wifi_on() {
|
||||
// Init wifi
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
|
||||
// Configure Wifi AP settings
|
||||
wifi_config_t sta_config = {
|
||||
.sta = {
|
||||
.ssid = CONFIG_ESP_WIFI_SSID,
|
||||
.password = CONFIG_ESP_WIFI_PASSWORD,
|
||||
},
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &sta_config));
|
||||
//ESP_ERROR_CHECK(esp_wifi_start());
|
||||
//ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
|
||||
// Enable power saving
|
||||
//ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM));
|
||||
//ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
|
||||
|
||||
ESP_LOGI(TAG, "Turning WiFi ON...");
|
||||
esp_wifi_start(); // Start WiFi
|
||||
|
||||
Reference in new issue
Block a user