From c20226748ce6e218b1fa4c3f13d63c51c8b0b659 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Sat, 28 Dec 2019 00:42:35 +0100 Subject: [PATCH] start as ap if station is not available --- main/main.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/main/main.c b/main/main.c index 2a9900a..44bc899 100644 --- a/main/main.c +++ b/main/main.c @@ -8,8 +8,8 @@ #include "esp_log.h" #include "nvs_flash.h" -#define WIFI_SSID "MYSSID" -#define WIFI_PASS "MYPASSWORD" +#define WIFI_SSID "AndroidAP" +#define WIFI_PASS "uyts6533" // Event group @@ -99,5 +99,30 @@ void app_main() printf("Connecting to %s\n", WIFI_SSID); // start the main task - xTaskCreate(&main_task, "main_task", 2048, NULL, 5, NULL); + //xTaskCreate(&main_task, "main_task", 2048, NULL, 5, NULL); + + EventBits_t uxBits; + uxBits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, false, true, 5000 / portTICK_PERIOD_MS); + if( ( uxBits & CONNECTED_BIT ) != 0 ) + { + printf("Connected!\n"); + } + else{ + printf("Not connected!\n"); + ESP_ERROR_CHECK(esp_wifi_stop()); + + esp_wifi_set_mode(WIFI_MODE_AP); + wifi_config_t ap_config = { + .ap = { + .ssid = "lamp", + .channel = 0, + .authmode = WIFI_AUTH_OPEN, + .ssid_hidden = 0, + .max_connection = 1, + .beacon_interval = 100 + } + }; + esp_wifi_set_config(WIFI_IF_AP, &ap_config); + ESP_ERROR_CHECK(esp_wifi_start()); + } }