From d603c85df7b3d12c14e55e71f39d179d1c3efe5a Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Wed, 26 Apr 2017 10:51:57 +0200 Subject: [PATCH] More Wifi functions --- src/wifi.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/wifi.h | 6 ++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/wifi.cpp b/src/wifi.cpp index ebfe861..09881ae 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -9,8 +9,10 @@ #include #include #include +#include // ToDo: check if https://github.com/me-no-dev/ESPAsyncWebServer/ becomes available +// libwebsockets got ESP32 support in v2.2 ! #include "hardware.h" #include "sound.h" @@ -62,6 +64,41 @@ void Wifi::init() { MDNS.addService("http", "tcp", 80); } +void Wifi::init_softap() { +// WiFi wifi; +// wifi.softAP("soundboard"); +} + +/* never used */ /* +void Wifi::readPreferences() { + Preferences preferences; + preferences.begin("sb_wifi", false); // namespace limited to 15 chars! + for(uint8_t i=0; true; i++) { + char key[8]; + sprintf(key, "ssid%d", i); + String ssid = preferences.getString(key); // max 31 + sprintf(key, "pass%d", i); + String password = preferences.getString(key); // max 63 + } + preferences.end(); +} */ + +size_t Wifi::getStoredPassword(const char* ssid, char* value) { + Preferences preferences; + preferences.begin("sb_wifi-pwd", false); + size_t len = preferences.getString(ssid, value, 64); + preferences.end(); + return len; +} + +size_t Wifi::setStoredPassword(const char* ssid, char* value) { + Preferences preferences; + preferences.begin("sb_wifi-pwd", false); + size_t len = preferences.putString(ssid, value); + preferences.end(); + return len; +} + void Wifi::loop() { // Check if a client has connected WiFiClient client = server.available(); diff --git a/src/wifi.h b/src/wifi.h index 26d1db2..00dc701 100644 --- a/src/wifi.h +++ b/src/wifi.h @@ -17,8 +17,10 @@ class Wifi { void end(); void loop(); // esp_err_t event_handler(void *ctx, system_event_t *event); -// void wifi_init_sta(); -// void wifi_init_softap(); +// void init_sta(); + void init_softap(); + size_t getStoredPassword(const char* ssid, char* value); + size_t setStoredPassword(const char* ssid, char* value); private: WiFiServer server; };