Skip to content

Commit

Permalink
Compiles now! Might even work!
Browse files Browse the repository at this point in the history
  • Loading branch information
bbulkow committed May 26, 2020
1 parent ac4c46a commit fe804d7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions components/WiFiMulti-idf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
7 changes: 3 additions & 4 deletions components/WiFiMulti-idf/WiFiMulti-idf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");

}

16 changes: 9 additions & 7 deletions components/WiFiMulti-idf/include/WiFiMulti-idf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */

24 changes: 17 additions & 7 deletions main/WiFiMulti-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,28 @@
*/
#include <stdio.h>
#include <stdint.h>

#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());
Expand All @@ -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);

Expand All @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down

0 comments on commit fe804d7

Please sign in to comment.