diff --git a/README.md b/README.md index 1d38e53..d3887bd 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,13 @@ open internet is working ( ie, connect to a well known service over HTTP ), the acid test is if _your_ service works, so an API call which says "not working" from the application level is far better. +Interate with NVS. Having non-volitile storage inside the ESP32 is awesome, and +there's a claim in the wifi library that it'll log you into APs that you've logged +into before, using NVS, but no clear idea how that works. Can you attempt to attach +but with no password? Instead, I think you have to actively manage NVS, which would be +super cool because you could have a website where you put in an AP name and password, +instead of having them hardcoded. + Support shutting down Test adding an AP while running ( coded to work but not tested ) diff --git a/components/WiFiMulti-idf/CMakeLists.txt b/components/WiFiMulti-idf/CMakeLists.txt index 0c663c3..8fcb9fe 100644 --- a/components/WiFiMulti-idf/CMakeLists.txt +++ b/components/WiFiMulti-idf/CMakeLists.txt @@ -8,5 +8,5 @@ set(srcs # going to hack by adding the ESP32 define in the h file #`target_compile_options(${COMPONENT_LIB} PRIVATE "-DESP32") - #idf_component_register(SRCS "${srcs}" - # INCLUDE_DIRS "." "./hal" ) + idf_component_register(SRCS "WiFiMulti-idf.c" + INCLUDE_DIRS "./include" ) diff --git a/components/WiFiMulti-idf/WiFiMulti-idf.c b/components/WiFiMulti-idf/WiFiMulti-idf.c index 217b597..f91aa75 100644 --- a/components/WiFiMulti-idf/WiFiMulti-idf.c +++ b/components/WiFiMulti-idf/WiFiMulti-idf.c @@ -26,7 +26,7 @@ #include "esp_timer.h" #include "esp_wifi.h" #include "esp_log.h" -#include "nvs_flash.h" +#include "esp_err.h" #include "esp_idf_version.h" // several bits of code depend on version :-( #include "lwip/err.h" @@ -425,9 +425,9 @@ wifi_multi_find(const uint8_t *ssid) esp_err_t wifi_multi_ap_add(const char* ssid, const char *password) { if (ssid == NULL) return(-1); - if (strlen(ssid) + 1 > SSID_LEN) return(ESP_INVALID_ARG); + if (strlen(ssid) + 1 > SSID_LEN) return(ESP_ERR_INVALID_ARG); // password allowed to be null for open APs - if (password && ( strlen(password) + 1 > PASSWORD_LEN ) ) return(ESP_INVALID_ARG); + if (password && ( strlen(password) + 1 > PASSWORD_LEN ) ) return(ESP_ERR_INVALID_ARG); wifi_ap_info_t *ap_info = malloc(sizeof(wifi_ap_info_t)); if (ap_info == 0) return(ESP_ERR_NO_MEM); @@ -720,7 +720,6 @@ void wifi_multi_loglevel_set(esp_log_level_t level) { esp_log_level_set(TAG, level); - ESP_LOGI(TAG, "ESP_WIFI_MODE_INIT_STA"); } diff --git a/components/WiFiMulti-idf/include/WiFiMulti-idf.h b/components/WiFiMulti-idf/include/WiFiMulti-idf.h index 9711279..1dc410c 100644 --- a/components/WiFiMulti-idf/include/WiFiMulti-idf.h +++ b/components/WiFiMulti-idf/include/WiFiMulti-idf.h @@ -21,24 +21,23 @@ #include "freertos/semphr.h" #include "esp_system.h" -#include "esp_event.h" -#include "esp_timer.h" #include "esp_wifi.h" #include "esp_log.h" -#include "nvs_flash.h" +#include "esp_err.h" +extern "C" { /* ** NOT EXISTING! Please see the readme and do some coding if you want this supported! */ -int wifi_multi_ap_remove(const char *ssid) +int wifi_multi_ap_remove(const char *ssid); /* ** Add an AP. If there is no password ( it's open ) you can pass nothing. ** Both values are put into an internal datastructure and are not consumed. */ -int wifi_multi_ap_add(const char* ssid, const char *password) +int wifi_multi_ap_add(const char* ssid, const char *password); /* ** it's very useful to set the log levels programmatically so you can @@ -49,11 +48,14 @@ int wifi_multi_ap_add(const char* ssid, const char *password) ** VERBOSE shows even more info about the choices being made */ -void wifi_multi_set_loglevel(int loglevel); +void wifi_multi_loglevel_set(esp_log_level_t loglevel); /* -** call this function after you add aps to have the background tasks maintain +** call this function BEFORE you add aps to have the background tasks maintain ** the network connection */ void wifi_multi_start(); + +} /* extern C */ + diff --git a/main/WiFiMulti-main.cpp b/main/WiFiMulti-main.cpp index b6b0ea4..27ac1f7 100644 --- a/main/WiFiMulti-main.cpp +++ b/main/WiFiMulti-main.cpp @@ -8,17 +8,28 @@ */ #include #include + #include "freertos/FreeRTOS.h" #include "freertos/task.h" + +#include "esp_system.h" #include "esp_system.h" -#include "esp_spi_flash.h" +#include "esp_wifi.h" +#include "esp_log.h" +#include "esp_err.h" +#include "nvs_flash.h" #include "WiFiMulti-idf.h" +extern "C" { + void app_main(); +} + void app_main() { //Initialize NVS --- // NOTE! Does this clear NVS? Or just init access? Looks like gives access because it clears it if there are problems + // this honestly seems like boilerplate that shouldn't really be here esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); @@ -27,17 +38,16 @@ void app_main() ESP_ERROR_CHECK(ret); // Since this seems to be working, set the log level to warning instead of info - wifi_multi_loglevel_set(TAG, ESP_LOG_INFO); - ESP_LOGI(TAG, "ESP_WIFI_MODE_INIT_STA"); + wifi_multi_loglevel_set(ESP_LOG_INFO); // in ESP-IDF is seems there are about 8 tasks uint16_t initial_tasks = uxTaskGetNumberOfTasks(); wifi_multi_start(); - wifi_multi_ap_add("sisyphus", "!medea4u"); - wifi_multi_ap_add("bb-ap-x", "landshark"); - wifi_multi_ap_add("laertes", "!medea4u"); + wifi_multi_ap_add("sisyphus", "X"); + wifi_multi_ap_add("bb-ap-x", "Y"); + wifi_multi_ap_add("laertes", "Z"); // put this back, it's a good idea, just right now it's also the above one //wifi_multi_ap_add(EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS); @@ -51,7 +61,7 @@ void app_main() // the interesting bit about this talks about the 'idle task' which will // reap deleted tasks... it it out there? Did I need to configure // something to start it? - ESP_LOGD(TAG,"tasks remaining: %u waiting for %u\n",n_tasks,initial_tasks); + printf("tasks remaining: %u waiting for %u\n",n_tasks,initial_tasks); if (n_tasks == initial_tasks) { printf("my tasks must have died --- let's restart!\n"); diff --git a/sdkconfig b/sdkconfig index 19e3f65..94f188c 100644 --- a/sdkconfig +++ b/sdkconfig @@ -974,6 +974,12 @@ CONFIG_WPA_MBEDTLS_CRYPTO=y # CONFIG_WPA_TESTING_OPTIONS is not set CONFIG_WPA_TLS_V12=y # end of Supplicant + +# +# WiFiMulti +# +# CONFIG_WIFI_MULTI_TEST is not set +# end of WiFiMulti # end of Component config #