All WifiManager reconfigs now conclude via wifiEnterConfigPortal which manages NV flag and OLED reboot alert
This commit is contained in:
parent
af0980a72b
commit
716827b399
6 changed files with 85 additions and 49 deletions
|
@ -79,11 +79,12 @@ CScreen4::show()
|
||||||
else {
|
else {
|
||||||
_printInverted(0, yPos, " WiFi Inactive ", true);
|
_printInverted(0, yPos, " WiFi Inactive ", true);
|
||||||
}
|
}
|
||||||
yPos += _display.textHeight() + 2;
|
|
||||||
|
/* yPos += _display.textHeight() + 2;
|
||||||
char msg[32];
|
char msg[32];
|
||||||
int mins = NVstore.getDimTime() / 60000;
|
int mins = NVstore.getDimTime() / 60000;
|
||||||
sprintf(msg, "Display Dim: %d min%c", mins, (mins > 1) ? 's' : ' ');
|
sprintf(msg, "Display Dim: %d min%c", mins, (mins > 1) ? 's' : ' ');
|
||||||
_printMenuText(0, yPos, msg);
|
_printMenuText(0, yPos, msg);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,15 +95,16 @@ CScreen4::keyHandler(uint8_t event)
|
||||||
_repeatCount = 0;
|
_repeatCount = 0;
|
||||||
// press CENTRE
|
// press CENTRE
|
||||||
if(event & key_Centre) {
|
if(event & key_Centre) {
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// press LEFT
|
// press LEFT
|
||||||
if(event & key_Left) {
|
if(event & key_Left) {
|
||||||
_ScreenManager.prevScreen();
|
_ScreenManager.prevScreen();
|
||||||
|
_rowSel = 0;
|
||||||
}
|
}
|
||||||
// press RIGHT
|
// press RIGHT
|
||||||
if(event & key_Right) {
|
if(event & key_Right) {
|
||||||
_ScreenManager.nextScreen();
|
_ScreenManager.nextScreen();
|
||||||
|
_rowSel = 0;
|
||||||
}
|
}
|
||||||
// press UP
|
// press UP
|
||||||
if(event & key_Up) {
|
if(event & key_Up) {
|
||||||
|
@ -116,6 +118,7 @@ CScreen4::keyHandler(uint8_t event)
|
||||||
// _rowSel--;
|
// _rowSel--;
|
||||||
// UPPERLIMIT(_rowSel, 0);
|
// UPPERLIMIT(_rowSel, 0);
|
||||||
}
|
}
|
||||||
|
_ScreenManager.reqUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event & keyRepeat) { // track key hold time
|
if(event & keyRepeat) { // track key hold time
|
||||||
|
@ -125,13 +128,17 @@ CScreen4::keyHandler(uint8_t event)
|
||||||
if(event & keyReleased) {
|
if(event & keyReleased) {
|
||||||
if(event & key_Centre) {
|
if(event & key_Centre) {
|
||||||
if(_rowSel) {
|
if(_rowSel) {
|
||||||
if(isWifiConfigPortal())
|
|
||||||
wifiEnterConfigPortal(false); // stop config portal, reboot
|
if(_repeatCount > STA_HOLD_TIME) {
|
||||||
|
wifiEnterConfigPortal(true, _repeatCount > STA_HOLD_TIME, 5000); // press - reboot into portal, long press - erase credentials
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if(_rowSel==1)
|
if(isWifiConfigPortal()) {
|
||||||
wifiEnterConfigPortal(true, _repeatCount > STA_HOLD_TIME); // press - reboot into portal, long press - erase credentials
|
wifiEnterConfigPortal(false, false, 5000); // stop config portal, reboot
|
||||||
else
|
}
|
||||||
wifiEnterConfigPortal(false); // stop config portal, reboot
|
else {
|
||||||
|
wifiEnterConfigPortal(true, false, 5000); // stop config portal, reboot
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "Screen6.h"
|
#include "Screen6.h"
|
||||||
#include "Screen7.h"
|
#include "Screen7.h"
|
||||||
#include "Screen8.h"
|
#include "Screen8.h"
|
||||||
|
#include "RebootScreen.h"
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include "../cfg/pins.h"
|
#include "../cfg/pins.h"
|
||||||
#include "../cfg/BTCConfig.h"
|
#include "../cfg/BTCConfig.h"
|
||||||
|
@ -96,6 +97,7 @@ CScreenManager::CScreenManager()
|
||||||
_currentScreen = -1;
|
_currentScreen = -1;
|
||||||
_bReqUpdate = false;
|
_bReqUpdate = false;
|
||||||
_DimTime = millis() + 60000;
|
_DimTime = millis() + 60000;
|
||||||
|
_pRebootScreen = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CScreenManager::~CScreenManager()
|
CScreenManager::~CScreenManager()
|
||||||
|
@ -167,10 +169,17 @@ CScreenManager::checkUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_bReqUpdate) {
|
if(_bReqUpdate) {
|
||||||
if(_currentScreen >= 0) {
|
if(_pRebootScreen) {
|
||||||
_Screens[_currentScreen]->show();
|
_pRebootScreen->show();
|
||||||
_bReqUpdate = false;
|
_bReqUpdate = false;
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(_currentScreen >= 0) {
|
||||||
|
_Screens[_currentScreen]->show();
|
||||||
|
_bReqUpdate = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -235,11 +244,18 @@ CScreenManager::keyHandler(uint8_t event)
|
||||||
|
|
||||||
if(_DimTime == 0)
|
if(_DimTime == 0)
|
||||||
_pDisplay->dim(false);
|
_pDisplay->dim(false);
|
||||||
// _DimTime = millis() + NVstore.getDimTime();
|
_DimTime = (millis() + NVstore.getDimTime()) | 1;
|
||||||
_DimTime = millis() + 60000;
|
// _DimTime = (millis() + 60000) | 1;
|
||||||
if(_DimTime == 0)
|
|
||||||
_DimTime = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CScreenManager::showRebootMsg(const char* content[2], long delayTime)
|
||||||
|
{
|
||||||
|
if(_pRebootScreen == NULL)
|
||||||
|
_pRebootScreen = new CRebootScreen(*_pDisplay, *this);
|
||||||
|
|
||||||
|
_pRebootScreen->setMessage(content, delayTime);
|
||||||
|
_bReqUpdate = true;
|
||||||
|
_pDisplay->dim(false);
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
class CProtocol;
|
class CProtocol;
|
||||||
class C128x64_OLED;
|
class C128x64_OLED;
|
||||||
class CScreen;
|
class CScreen;
|
||||||
|
class CRebootScreen;
|
||||||
|
|
||||||
class CScreenManager {
|
class CScreenManager {
|
||||||
std::vector<CScreen*> _Screens;
|
std::vector<CScreen*> _Screens;
|
||||||
|
@ -36,6 +37,7 @@ class CScreenManager {
|
||||||
unsigned long _DimTime;
|
unsigned long _DimTime;
|
||||||
bool _bReqUpdate;
|
bool _bReqUpdate;
|
||||||
void _switchScreen();
|
void _switchScreen();
|
||||||
|
CRebootScreen* _pRebootScreen;
|
||||||
public:
|
public:
|
||||||
CScreenManager();
|
CScreenManager();
|
||||||
~CScreenManager();
|
~CScreenManager();
|
||||||
|
@ -47,6 +49,7 @@ public:
|
||||||
void prevScreen();
|
void prevScreen();
|
||||||
void keyHandler(uint8_t event);
|
void keyHandler(uint8_t event);
|
||||||
void reqUpdate();
|
void reqUpdate();
|
||||||
|
void showRebootMsg(const char* content[2], long delayTime);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __SCREEN_MANAGER_H__
|
#endif // __SCREEN_MANAGER_H__
|
||||||
|
|
|
@ -47,24 +47,22 @@ void handleBTCRoot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleWMConfig() {
|
void handleWMConfig() {
|
||||||
|
server.send(200, "text/plain", "Start Config Portal - Retaining credential");
|
||||||
DebugPort.println("Starting web portal for wifi config");
|
DebugPort.println("Starting web portal for wifi config");
|
||||||
wm.startWebPortal();
|
delay(500);
|
||||||
|
// wm.startWebPortal();
|
||||||
|
wifiEnterConfigPortal(true, false, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleReset() {
|
void handleReset() {
|
||||||
server.send(200, "text/plain", "Resetting Wifi Settings!");
|
server.send(200, "text/plain", "Start Config Portal - Resetting Wifi credentials!");
|
||||||
DebugPort.println("diconnecting client and wifi, then rebooting");
|
DebugPort.println("diconnecting client and wifi, then rebooting");
|
||||||
|
delay(500);
|
||||||
//client.disconnect();
|
//client.disconnect();
|
||||||
// wifi_station_disconnect();
|
// wifi_station_disconnect();
|
||||||
wm.disconnect();
|
// wm.disconnect();
|
||||||
wm.resetSettings();
|
// wm.resetSettings();
|
||||||
|
wifiEnterConfigPortal(true, true, 3000);
|
||||||
delay(1000);
|
|
||||||
|
|
||||||
ESP.restart();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleBTCNotFound() {
|
void handleBTCNotFound() {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "BTCWifi.h"
|
#include "BTCWifi.h"
|
||||||
#include "../Utility/DebugPort.h"
|
#include "../Utility/DebugPort.h"
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
|
#include "../OLED/ScreenManager.h"
|
||||||
|
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
|
@ -45,6 +46,7 @@ bool isSTA = false; // true if connected to an access point
|
||||||
int TRIG_PIN; // pin that triggers the configuration portal when set to LOW
|
int TRIG_PIN; // pin that triggers the configuration portal when set to LOW
|
||||||
unsigned restartServer = 0; // set to time of portal reconfig - will cause reboot a while later
|
unsigned restartServer = 0; // set to time of portal reconfig - will cause reboot a while later
|
||||||
|
|
||||||
|
extern CScreenManager ScreenManager;
|
||||||
|
|
||||||
bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
|
bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
|
||||||
{
|
{
|
||||||
|
@ -134,17 +136,6 @@ void doWiFiManager()
|
||||||
{
|
{
|
||||||
wm.process();
|
wm.process();
|
||||||
|
|
||||||
// handle the tail end of new credentials being saved by WiFiManager
|
|
||||||
// whilst the new connection is established OK, the web server is detached
|
|
||||||
// Reboot the ESP so the config portal's root link is removed and our's becomes active
|
|
||||||
// reboot takes palce 7.5 seconds after the config portal params are saved
|
|
||||||
if(restartServer) {
|
|
||||||
long tDelta = millis() - restartServer;
|
|
||||||
if(tDelta > 7500) {
|
|
||||||
restartServer = 0;
|
|
||||||
ESP.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// manage handling of pin to enter WiFManager config portal
|
// manage handling of pin to enter WiFManager config portal
|
||||||
// we typically use the BOOT pin for this (pins.h)
|
// we typically use the BOOT pin for this (pins.h)
|
||||||
|
@ -154,15 +145,25 @@ void doWiFiManager()
|
||||||
// > 5 second press - erase credentials, enable config portal
|
// > 5 second press - erase credentials, enable config portal
|
||||||
static bool pinDown = false;
|
static bool pinDown = false;
|
||||||
static long pinTime = 0;
|
static long pinTime = 0;
|
||||||
|
unsigned long tDelta;
|
||||||
|
|
||||||
if(digitalRead(TRIG_PIN) == LOW) {
|
if(digitalRead(TRIG_PIN) == LOW) {
|
||||||
if(!pinDown)
|
if(!pinDown)
|
||||||
pinTime = millis();
|
pinTime = millis();
|
||||||
pinDown = true;
|
pinDown = true;
|
||||||
|
// track hold duration - change OLED Wifi annotation according to length of press
|
||||||
|
tDelta = millis() - pinTime;
|
||||||
|
if(tDelta > 5000)
|
||||||
|
isPortalAP = true; // we will start portal - show 'CFG' on OLED!
|
||||||
|
else if(tDelta > 1000)
|
||||||
|
isPortalAP = false; // we won't start portal - hide 'CFG' on OLED!
|
||||||
|
else
|
||||||
|
isPortalAP = true; // we will start portal - show 'CFG' on OLED!
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(pinDown) {
|
if(pinDown) {
|
||||||
pinDown = false;
|
pinDown = false;
|
||||||
unsigned long tDelta = millis() - pinTime;
|
tDelta = millis() - pinTime;
|
||||||
DebugPort.print("Wifi config button tDelta = "); DebugPort.println(tDelta);
|
DebugPort.print("Wifi config button tDelta = "); DebugPort.println(tDelta);
|
||||||
// > 5 second press?
|
// > 5 second press?
|
||||||
if(tDelta > 5000) {
|
if(tDelta > 5000) {
|
||||||
|
@ -181,30 +182,41 @@ void doWiFiManager()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wifiEnterConfigPortal(bool state, bool erase)
|
void wifiEnterConfigPortal(bool state, bool erase, long rebootDelay)
|
||||||
{
|
{
|
||||||
|
wm.disconnect();
|
||||||
prepBootIntoConfigPortal(state);
|
prepBootIntoConfigPortal(state);
|
||||||
|
|
||||||
|
const char* content[2];
|
||||||
|
|
||||||
|
if(isWifiSTA() && !erase)
|
||||||
|
content[0] = "WiFi Mode -> STA+AP";
|
||||||
|
else
|
||||||
|
content[0] = "WiFi Mode -> AP only";
|
||||||
|
|
||||||
if(erase) {
|
if(erase) {
|
||||||
wm.resetSettings();
|
wm.resetSettings();
|
||||||
DebugPort.println("*** Erased wifi credentials ***");
|
DebugPort.println("*** Erased wifi credentials ***");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state)
|
if(state) {
|
||||||
DebugPort.println("*** Rebooting into config portal ***");
|
DebugPort.println("*** Rebooting into config portal ***");
|
||||||
else
|
content[1] = "Web -> Config Portal";
|
||||||
|
}
|
||||||
|
else {
|
||||||
DebugPort.println("*** Rebooting into web server ***");
|
DebugPort.println("*** Rebooting into web server ***");
|
||||||
|
content[1] = "Web -> Heater control";
|
||||||
|
}
|
||||||
|
|
||||||
delay(1000);
|
restartServer = (millis() + rebootDelay) | 1; // prepare to reboot in the future - ensure non zero!
|
||||||
ESP.restart();
|
|
||||||
|
ScreenManager.showRebootMsg(content, rebootDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// callback is invoked by WiFiManager after new credentials are saved and verified
|
// callback is invoked by WiFiManager after new credentials are saved and verified
|
||||||
void saveParamsCallback()
|
void saveParamsCallback()
|
||||||
{
|
{
|
||||||
restartServer = millis() | 1; // prepare to reboot in the near future - ensure non zero!
|
wifiEnterConfigPortal(false); // stop config portal, reboot
|
||||||
prepBootIntoConfigPortal(false); // ensure we present our web page after reboot
|
|
||||||
isPortalAP = false; // clear CFG adornment from OLED WiFi icon
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// callback called if the WiFiManager started the config portal
|
// callback called if the WiFiManager started the config portal
|
||||||
|
|
|
@ -37,6 +37,6 @@
|
||||||
bool isWebClientConnected();
|
bool isWebClientConnected();
|
||||||
bool hasWebClientSpoken(bool reset = false);
|
bool hasWebClientSpoken(bool reset = false);
|
||||||
bool hasWebServerSpoken(bool reset = false);
|
bool hasWebServerSpoken(bool reset = false);
|
||||||
void wifiEnterConfigPortal(bool state, bool erase = false);
|
void wifiEnterConfigPortal(bool state, bool erase = false, long timeout = 7000);
|
||||||
|
|
||||||
#endif __BTCWIFI_H__
|
#endif __BTCWIFI_H__
|
||||||
|
|
Loading…
Reference in a new issue