Browse Source

Wifi-toggle immediately effective

master
Torsten Stauder 5 years ago
parent
commit
7d1ba361c2
  1. 4
      README.md
  2. 4
      src/logmessages.h
  3. 4
      src/logmessages_EN.h
  4. 49
      src/main.cpp

4
README.md

@ -143,7 +143,7 @@ Please note: hostname can be used to call webgui or FTP-server. I tested it with
WiFi is mandatory for webgui, FTP and MQTT. However, WiFi can be temporarily or permanently disabled. There are two ways to do that: WiFi is mandatory for webgui, FTP and MQTT. However, WiFi can be temporarily or permanently disabled. There are two ways to do that:
* Use a special modification-card that can be configured via webgui * Use a special modification-card that can be configured via webgui
* Press previous + next-button in parallel shortly * Press previous + next-button in parallel shortly
This toggles the current WiFi-status which means: if it's currently enabled, it will be disabled and vice versa. Please note: change is *not effective until the next reboot* but will remain until you change it again. Having Wifi enabled is indicated in idle-mode (no playlist active) with four white slow rotating LEDs whereas disabled WiFi is represented by those ones colored blue.
This toggles the current WiFi-status which means: if it's currently enabled, it will be disabled and vice versa. Please note: This status will remain until you change it again. Having Wifi enabled is indicated in idle-mode (no playlist active) with four white slow rotating LEDs whereas disabled WiFi is represented by those ones colored blue.
## After Tonuino-ESP32 is connected to your WiFi ## After Tonuino-ESP32 is connected to your WiFi
After getting Tonuino part of your LAN/WiFi, the 'regular' webgui is available at the IP assigned by your router. Using this GUI, you can configure: After getting Tonuino part of your LAN/WiFi, the 'regular' webgui is available at the IP assigned by your router. Using this GUI, you can configure:
* WiFi * WiFi
@ -200,7 +200,7 @@ There are special RFID-tags, that don't start music by themself but can modify t
* current track in loop-mode (is "stronger" than playlist-loop but doesn't overwrite it!) * current track in loop-mode (is "stronger" than playlist-loop but doesn't overwrite it!)
* playlist in loop-mode * playlist in loop-mode
* track und playlist loop-mode can both be activated at the same time, but unless track-loop isn't deactivated, playlist-loop won't be effective * track und playlist loop-mode can both be activated at the same time, but unless track-loop isn't deactivated, playlist-loop won't be effective
* Toggle WiFi (enable/disable; effective after reboot)
* Toggle WiFi (enable/disable)
### Neopixel-ring (optional) ### Neopixel-ring (optional)
Indicates different things. Don't forget configuration of number of LEDs via #define NUM_LEDS Indicates different things. Don't forget configuration of number of LEDs via #define NUM_LEDS

4
src/logmessages.h

@ -143,5 +143,5 @@ static const char restoredHostnameFromNvs[] PROGMEM = "Hostname aus NVS geladen"
static const char currentVoltageMsg[] PROGMEM = "Aktuelle Batteriespannung"; static const char currentVoltageMsg[] PROGMEM = "Aktuelle Batteriespannung";
static const char voltageTooLow[] PROGMEM = "Batteriespannung niedrig"; static const char voltageTooLow[] PROGMEM = "Batteriespannung niedrig";
static const char sdBootFailedDeepsleep[] PROGMEM = "Bootgang wegen SD fehlgeschlagen. Gehe in Deepsleep..."; static const char sdBootFailedDeepsleep[] PROGMEM = "Bootgang wegen SD fehlgeschlagen. Gehe in Deepsleep...";
static const char wifiEnabledAfterRestart[] PROGMEM = "WLAN wird ab dem nächsten Neustart aktiviert.";
static const char wifiDisabledAfterRestart[] PROGMEM = "WLAN wird ab dem nächsten Neustart deaktiviert.";
static const char wifiEnabledAfterRestart[] PROGMEM = "WLAN wird aktiviert.";
static const char wifiDisabledAfterRestart[] PROGMEM = "WLAN wird deaktiviert.";

4
src/logmessages_EN.h

@ -143,5 +143,5 @@ static const char restoredHostnameFromNvs[] PROGMEM = "Restored hostname from NV
static const char currentVoltageMsg[] PROGMEM = "Current battery-voltage"; static const char currentVoltageMsg[] PROGMEM = "Current battery-voltage";
static const char voltageTooLow[] PROGMEM = "Low battery-voltage"; static const char voltageTooLow[] PROGMEM = "Low battery-voltage";
static const char sdBootFailedDeepsleep[] PROGMEM = "Failed to boot due to SD. Will go to deepsleep..."; static const char sdBootFailedDeepsleep[] PROGMEM = "Failed to boot due to SD. Will go to deepsleep...";
static const char wifiEnabledAfterRestart[] PROGMEM = "WiFi will be enabled (effective after next boot).";
static const char wifiDisabledAfterRestart[] PROGMEM = "WiFi will be disabled (effective after next boot).";
static const char wifiEnabledAfterRestart[] PROGMEM = "WiFi will be enabled.";
static const char wifiDisabledAfterRestart[] PROGMEM = "WiFi will be disabled .";

49
src/main.cpp

@ -261,6 +261,8 @@ static const char backupFile[] PROGMEM = "/backup.txt"; // File is written every
unsigned long wifiCheckLastTimestamp = 0; unsigned long wifiCheckLastTimestamp = 0;
bool wifiEnabled; // Current status if wifi is enabled bool wifiEnabled; // Current status if wifi is enabled
uint32_t wifiStatusToggledTimestamp = 0; uint32_t wifiStatusToggledTimestamp = 0;
bool webserverStarted = false;
bool wifiNeedsRestart = false;
// Neopixel // Neopixel
#ifdef NEOPIXEL_ENABLE #ifdef NEOPIXEL_ENABLE
bool showLedError = false; bool showLedError = false;
@ -412,6 +414,7 @@ bool fileValid(const char *_fileItem);
void freeMultiCharArray(char **arr, const uint32_t cnt); void freeMultiCharArray(char **arr, const uint32_t cnt);
uint8_t getRepeatMode(void); uint8_t getRepeatMode(void);
bool getWifiEnableStatusFromNVS(void); bool getWifiEnableStatusFromNVS(void);
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
void headphoneVolumeManager(void); void headphoneVolumeManager(void);
bool isNumber(const char *str); bool isNumber(const char *str);
void loggerNl(const char *str, const uint8_t logLevel); void loggerNl(const char *str, const uint8_t logLevel);
@ -1297,6 +1300,8 @@ void playAudio(void *parameter) {
trackCommand = 0; trackCommand = 0;
loggerNl((char *) FPSTR(cmndStop), LOGLEVEL_INFO); loggerNl((char *) FPSTR(cmndStop), LOGLEVEL_INFO);
playProperties.pausePlay = true; playProperties.pausePlay = true;
playProperties.playlistFinished = true;
playProperties.playMode = NO_PLAYLIST;
continue; continue;
case PAUSEPLAY: case PAUSEPLAY:
@ -2715,12 +2720,18 @@ bool writeWifiStatusToNVS(bool wifiStatus) {
if (!wifiStatus) { if (!wifiStatus) {
if (prefsSettings.putUInt("enableWifi", 0)) { // disable if (prefsSettings.putUInt("enableWifi", 0)) { // disable
loggerNl((char *) FPSTR(wifiDisabledAfterRestart), LOGLEVEL_NOTICE); loggerNl((char *) FPSTR(wifiDisabledAfterRestart), LOGLEVEL_NOTICE);
trackControlToQueueSender(STOP);
delay(300);
WiFi.mode(WIFI_OFF);
wifiEnabled = false;
return true; return true;
} }
} else { } else {
if (prefsSettings.putUInt("enableWifi", 1)) { // enable if (prefsSettings.putUInt("enableWifi", 1)) { // enable
loggerNl((char *) FPSTR(wifiEnabledAfterRestart), LOGLEVEL_NOTICE); loggerNl((char *) FPSTR(wifiEnabledAfterRestart), LOGLEVEL_NOTICE);
wifiNeedsRestart = true;
wifiEnabled = true;
return true; return true;
} }
} }
@ -2734,7 +2745,7 @@ wl_status_t wifiManager(void) {
return WiFi.status(); return WiFi.status();
} }
if (wifiCheckLastTimestamp == 0) {
if (!wifiCheckLastTimestamp || wifiNeedsRestart) {
// Get credentials from NVS // Get credentials from NVS
String strSSID = prefsSettings.getString("SSID", "-1"); String strSSID = prefsSettings.getString("SSID", "-1");
if (!strSSID.compareTo("-1")) { if (!strSSID.compareTo("-1")) {
@ -2781,6 +2792,7 @@ wl_status_t wifiManager(void) {
} else { // Starts AP if WiFi-connect wasn't successful } else { // Starts AP if WiFi-connect wasn't successful
accessPointStart((char *) FPSTR(accessPointNetworkSSID), apIP, apNetmask); accessPointStart((char *) FPSTR(accessPointNetworkSSID), apIP, apNetmask);
} }
wifiNeedsRestart = false;
} }
return WiFi.status(); return WiFi.status();
@ -3093,6 +3105,36 @@ bool isNumber(const char *str) {
} }
void webserverStart(void) {
if (wifiManager() == WL_CONNECTED && !webserverStarted) {
// attach AsyncWebSocket for Mgmt-Interface
ws.onEvent(onWebsocketEvent);
wServer.addHandler(&ws);
// attach AsyncEventSource
wServer.addHandler(&events);
wServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send_P(200, "text/html", mgtWebsite, templateProcessor);
});
wServer.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", backupRecoveryWebsite);
}, handleUpload);
wServer.on("/restart", HTTP_GET, [] (AsyncWebServerRequest *request) {
request->send_P(200, "text/html", restartWebsite);
Serial.flush();
ESP.restart();
});
wServer.onNotFound(notFound);
wServer.begin();
webserverStarted = true;
}
}
// Dumps all RFID-entries from NVS into a file on SD-card // Dumps all RFID-entries from NVS into a file on SD-card
bool dumpNvsToSd(char *_namespace, char *_destFile) { bool dumpNvsToSd(char *_namespace, char *_destFile) {
esp_partition_iterator_t pi; // Iterator for find esp_partition_iterator_t pi; // Iterator for find
@ -3515,7 +3557,7 @@ void setup() {
lastTimeActiveTimestamp = millis(); // initial set after boot lastTimeActiveTimestamp = millis(); // initial set after boot
if (wifiManager() == WL_CONNECTED) {
/*if (wifiManager() == WL_CONNECTED) {
// attach AsyncWebSocket for Mgmt-Interface // attach AsyncWebSocket for Mgmt-Interface
ws.onEvent(onWebsocketEvent); ws.onEvent(onWebsocketEvent);
wServer.addHandler(&ws); wServer.addHandler(&ws);
@ -3539,7 +3581,7 @@ void setup() {
wServer.onNotFound(notFound); wServer.onNotFound(notFound);
wServer.begin(); wServer.begin();
}
}*/
bootComplete = true; bootComplete = true;
Serial.print(F("Free heap: ")); Serial.print(F("Free heap: "));
@ -3548,6 +3590,7 @@ void setup() {
void loop() { void loop() {
webserverStart();
#ifdef HEADPHONE_ADJUST_ENABLE #ifdef HEADPHONE_ADJUST_ENABLE
headphoneVolumeManager(); headphoneVolumeManager();
#endif #endif

Loading…
Cancel
Save