Browse Source

More Wifi functions

main
Hendrik Langer 8 years ago
parent
commit
d603c85df7
  1. 37
      src/wifi.cpp
  2. 6
      src/wifi.h

37
src/wifi.cpp

@ -9,8 +9,10 @@
#include <WiFiMulti.h> #include <WiFiMulti.h>
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include <WiFiClient.h> #include <WiFiClient.h>
#include <Preferences.h>
// ToDo: check if https://github.com/me-no-dev/ESPAsyncWebServer/ becomes available // ToDo: check if https://github.com/me-no-dev/ESPAsyncWebServer/ becomes available
// libwebsockets got ESP32 support in v2.2 !
#include "hardware.h" #include "hardware.h"
#include "sound.h" #include "sound.h"
@ -62,6 +64,41 @@ void Wifi::init() {
MDNS.addService("http", "tcp", 80); 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() { void Wifi::loop() {
// Check if a client has connected // Check if a client has connected
WiFiClient client = server.available(); WiFiClient client = server.available();

6
src/wifi.h

@ -17,8 +17,10 @@ class Wifi {
void end(); void end();
void loop(); void loop();
// esp_err_t event_handler(void *ctx, system_event_t *event); // esp_err_t event_handler(void *ctx, system_event_t *event);
// void wifi_init_sta(); // void init_sta();
// void wifi_init_softap(); void init_softap();
size_t getStoredPassword(const char* ssid, char* value);
size_t setStoredPassword(const char* ssid, char* value);
private: private:
WiFiServer server; WiFiServer server;
}; };

Loading…
Cancel
Save