Added CFG to OLED WiFi icon when portal running. 5 sec press to reset WiFi creds, start portal

This commit is contained in:
rljonesau 2019-01-14 11:47:13 +11:00
parent de2cd12770
commit 320b7e8b6f
4 changed files with 65 additions and 10 deletions

View file

@ -128,7 +128,14 @@ CScreenHeader::showWifiIcon()
{
if(isWifiConnected() || isWifiAP()) {
_display.drawBitmap(X_WIFI_ICON, Y_WIFI_ICON, wifiIcon, W_WIFI_ICON, H_WIFI_ICON, WHITE);
if(isWifiAP()) {
if(isPortal()) {
_display.fillRect(X_WIFI_ICON + 8, Y_WIFI_ICON + 5, 15, 7, BLACK);
CTransientFont AF(_display, &MINIFONT); // temporarily use a mini font
_display.setCursor(X_WIFI_ICON+9, Y_WIFI_ICON+6);
// _display.print("PTL");
_display.print("CFG");
}
else if(isWifiAP()) {
_display.fillRect(X_WIFI_ICON + 8, Y_WIFI_ICON + 5, 10, 7, BLACK);
CTransientFont AF(_display, &MINIFONT); // temporarily use a mini font
_display.setCursor(X_WIFI_ICON+9, Y_WIFI_ICON+6);

View file

@ -119,6 +119,26 @@ const uint8_t miniFontBitmaps[] PROGMEM =
0x28, // # #
0x38, // ###
0x28, // # #
// @54 'L' (3 pixels wise)
0xf8, // #####
0x08, // #
0x08, // #
// @57 'T' (3 pixels wise)
0x80, // #
0xf8, // #####
0x80, // #
// @60 'F' (3 pixels wise)
0xf8, // #####
0xa0, // # #
0x80, // #
// @63 'T' (3 pixels wise)
0xf8, // #####
0x88, // # #
0x98, // # ##
};
// Character descriptors for a 3x5 font
@ -149,13 +169,13 @@ const FONT_CHAR_INFO miniFontDescriptors[] PROGMEM =
{3, 5, 36}, // 'C'
{0, 0, 0}, // 'D'
{0, 0, 0}, // 'E'
{0, 0, 0}, // 'F'
{0, 0, 0}, // 'G'
{3, 5, 60}, // 'F'
{3, 5, 63}, // 'G'
{3, 5, 39}, // 'H'
{0, 0, 0}, // 'I'
{0, 0, 0}, // 'J'
{0, 0, 0}, // 'K'
{0, 0, 0}, // 'L'
{3, 5, 54}, // 'L'
{0, 0, 0}, // 'M'
{0, 0, 0}, // 'N'
{0, 0, 0}, // 'O'
@ -163,7 +183,7 @@ const FONT_CHAR_INFO miniFontDescriptors[] PROGMEM =
{0, 0, 0}, // 'Q'
{0, 0, 0}, // 'R'
{0, 0, 0}, // 'S'
{0, 0, 0}, // 'T'
{3, 5, 57}, // 'T'
{0, 0, 0}, // 'U'
{3, 5, 45}, // 'V'
{3, 5, 48}, // 'W'

View file

@ -40,9 +40,11 @@ WiFiManager wm;
extern void stopWebServer();
extern void initWebServer();
void saveParamsCallback();
void APstartedCallback(WiFiManager*);
unsigned int timeout = 120; // seconds to run for
unsigned int startTime = millis();
bool isPortalAP = false;
bool isAP = false;
bool portalRunning = false;
bool startCP = true;//true; // start AP and webserver if true, else start only webserver
@ -87,6 +89,7 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
wm.setConfigPortalTimeout(20);
wm.setConfigPortalBlocking(false);
wm.setSaveParamsCallback(saveParamsCallback); // ensure our webserver gets awoken when IP config changes to STA
wm.setAPCallback(APstartedCallback);
wm.setEnableConfigPortal(shouldBootIntoConfigPortal());
wm.setAPStaticIPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255,255,255,0));
@ -94,20 +97,26 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
// bool res = false;
if(!res) {
// runs through here if we need to start our own soft AP to run THE web page
DebugPort.println("Failed to connect");
DebugPort.println("Setting up ESP as AP");
// We need to start the soft AP
// - wifimanger has done most of the work, but has been left us high and dry :-)
WiFi.softAPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255,255,255,0));
delay(100);
isAP = WiFi.softAP(failedssid, failedpassword);
DebugPort.print("IP address: ");
DebugPort.println(WiFi.softAPIP());
DebugPort.print("AP IP address: "); DebugPort.println(WiFi.softAPIP());
return false;
}
else {
// runs through here is STA or portal config AP mode
//if you get here you have connected to the WiFi
DebugPort.println("connected...yeey :)");
DebugPort.println("Ready");
DebugPort.print("IP address: ");
if(isPortal())
DebugPort.print("AP IP address: ");
else
DebugPort.print("STA IP address: ");
DebugPort.println(WiFi.localIP());
}
return true;
@ -137,7 +146,14 @@ void doWiFiManager(){
pinDown = false;
unsigned long tDelta = millis() - pinTime;
DebugPort.print("Wifi config button tDelta = "); DebugPort.println(tDelta);
if(tDelta > 1000) { // > 1 second press
if(tDelta > 5000) { // > 5 second press
prepBootIntoConfigPortal(true); // very long press - clear credentials, boot into portal
wm.resetSettings();
DebugPort.println("*** Clearing credentials and rebooting into portal ***");
delay(1000);
ESP.restart();
}
else if(tDelta > 1000) { // > 1 second press
prepBootIntoConfigPortal(false); // long press - boot into SoftAP
DebugPort.println("*** Rebooting into web server ***");
delay(1000);
@ -196,6 +212,12 @@ void doWiFiManager(){
void saveParamsCallback()
{
startServer = millis();
prepBootIntoConfigPortal(false); // ensure we fall back to SoftAP with our web page in future
}
void APstartedCallback(WiFiManager*)
{
isPortalAP = true;
}
const char* getWifiAddrStr()
@ -217,6 +239,11 @@ bool isWifiAP()
return isAP;
}
bool isPortal()
{
return isPortalAP;
}
void prepBootIntoConfigPortal(bool state)
{
@ -224,7 +251,7 @@ void prepBootIntoConfigPortal(bool state)
NV.begin("user");
NV.putBool("bootPortal", state);
NV.end();
DebugPort.print("Set boot config portal if WiFiManager not configured = "); DebugPort.println(state);
DebugPort.print("Setting boot config portal if WiFiManager not configured = "); DebugPort.println(state);
}
bool shouldBootIntoConfigPortal()

View file

@ -31,6 +31,7 @@
const char* getWifiAddrStr();
bool isWifiConnected();
bool isWifiAP();
bool isPortal();
bool isWebClientConnected();
bool hasWebClientSpoken(bool reset = false);
bool hasWebServerSpoken(bool reset = false);