Fixed ESP32 resetting upon opening wifi settings

This commit is contained in:
cschwinne 2018-07-22 21:21:18 +02:00
parent 0462755922
commit b3dcb9fe6c
2 changed files with 40 additions and 33 deletions

View File

@ -38,7 +38,7 @@
#include "src/dependencies/blynk/BlynkSimpleEsp.h" #include "src/dependencies/blynk/BlynkSimpleEsp.h"
//version in format yymmddb (b = daily build) //version in format yymmddb (b = daily build)
#define VERSION 1807211 #define VERSION 1807221
char versionString[] = "0.7.1"; char versionString[] = "0.7.1";
//AP and OTA default passwords (change them!) //AP and OTA default passwords (change them!)

View File

@ -73,13 +73,6 @@ void sappend(char stype, char* key, int val) //append a setting to string buffer
oappendi(val); oappendi(val);
oappend(";"); oappend(";");
break; break;
case 's': //string (we can interpret val as char*)
oappend(ds);
oappend(key);
oappend(".value=\"");
oappend((char*)val);
oappend("\";");
break;
case 'i': //selectedIndex case 'i': //selectedIndex
oappend(ds); oappend(ds);
oappend(key); oappend(key);
@ -87,11 +80,25 @@ void sappend(char stype, char* key, int val) //append a setting to string buffer
oappendi(val); oappendi(val);
oappend(";"); oappend(";");
break; break;
}
}
void sappends(char stype, char* key, char* val) //append a string setting
{
switch(stype)
{
case 's': //string (we can interpret val as char*)
oappend("d.Sf.");
oappend(key);
oappend(".value=\"");
oappend(val);
oappend("\";");
break;
case 'm': //message case 'm': //message
oappend("d.getElementsByClassName"); oappend("d.getElementsByClassName");
oappend(key); oappend(key);
oappend(".innerHTML=\""); oappend(".innerHTML=\"");
oappend((char*)val); oappend(val);
oappend("\";"); oappend("\";");
break; break;
} }
@ -107,13 +114,13 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
if (subPage <1 || subPage >6) return; if (subPage <1 || subPage >6) return;
if (subPage == 1) { if (subPage == 1) {
sappend('s',"CS",(int)clientSSID); sappends('s',"CS",clientSSID);
byte l = strlen(clientPass); byte l = strlen(clientPass);
char fpass[l+1]; //fill password field with *** char fpass[l+1]; //fill password field with ***
fpass[l] = 0; fpass[l] = 0;
memset(fpass,'*',l); memset(fpass,'*',l);
sappend('s',"CP",(int)fpass); sappends('s',"CP",fpass);
char k[3]; k[2] = 0; //IP addresses char k[3]; k[2] = 0; //IP addresses
for (int i = 0; i<4; i++) for (int i = 0; i<4; i++)
@ -124,16 +131,16 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
k[0] = 'S'; sappend('v',k,staticSubnet[i]); k[0] = 'S'; sappend('v',k,staticSubnet[i]);
} }
sappend('s',"CM",(int)cmDNS); sappends('s',"CM",cmDNS);
sappend('v',"AT",apWaitTimeSecs); sappend('v',"AT",apWaitTimeSecs);
sappend('s',"AS",(int)apSSID); sappends('s',"AS",apSSID);
sappend('c',"AH",apHide); sappend('c',"AH",apHide);
l = strlen(apPass); l = strlen(apPass);
char fapass[l+1]; //fill password field with *** char fapass[l+1]; //fill password field with ***
fapass[l] = 0; fapass[l] = 0;
memset(fapass,'*',l); memset(fapass,'*',l);
sappend('s',"AP",(int)fapass); sappends('s',"AP",fapass);
sappend('v',"AC",apChannel); sappend('v',"AC",apChannel);
@ -142,10 +149,10 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
char s[16]; char s[16];
IPAddress localIP = WiFi.localIP(); IPAddress localIP = WiFi.localIP();
sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]); sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]);
sappend('m',"(\"sip\")[0]",(int)s); sappends('m',"(\"sip\")[0]",s);
} else } else
{ {
sappend('m',"(\"sip\")[0]",(int)"Not connected"); sappends('m',"(\"sip\")[0]","Not connected");
} }
if (WiFi.softAPIP()[0] != 0) //is active if (WiFi.softAPIP()[0] != 0) //is active
@ -153,10 +160,10 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
char s[16]; char s[16];
IPAddress apIP = WiFi.softAPIP(); IPAddress apIP = WiFi.softAPIP();
sprintf(s, "%d.%d.%d.%d", apIP[0], apIP[1], apIP[2], apIP[3]); sprintf(s, "%d.%d.%d.%d", apIP[0], apIP[1], apIP[2], apIP[3]);
sappend('m',"(\"sip\")[1]",(int)apIP); sappends('m',"(\"sip\")[1]",s);
} else } else
{ {
sappend('m',"(\"sip\")[1]",(int)"Not active"); sappends('m',"(\"sip\")[1]","Not active");
} }
} }
@ -198,16 +205,16 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
if (subPage == 3) if (subPage == 3)
{ {
sappend('i',"UI",uiConfiguration); sappend('i',"UI",uiConfiguration);
sappend('s',"DS",(int)serverDescription); sappends('s',"DS",serverDescription);
sappend('c',"MD",useHSBDefault); sappend('c',"MD",useHSBDefault);
sappend('i',"TH",currentTheme); sappend('i',"TH",currentTheme);
char k[3]; k[0] = 'C'; k[2] = 0; //keys char k[3]; k[0] = 'C'; k[2] = 0; //keys
for (int i=0; i<6; i++) for (int i=0; i<6; i++)
{ {
k[1] = 48+i; //ascii 0,1,2,3,4,5 k[1] = 48+i; //ascii 0,1,2,3,4,5
sappend('s',k,(int)cssCol[i]); sappends('s',k,cssCol[i]);
} }
sappend('s',"CF",(int)cssFont); sappends('s',"CF",cssFont);
} }
if (subPage == 4) if (subPage == 4)
@ -224,9 +231,9 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
sappend('c',"RD",receiveDirect); sappend('c',"RD",receiveDirect);
sappend('c',"RU",enableRealtimeUI); sappend('c',"RU",enableRealtimeUI);
sappend('c',"AL",alexaEnabled); sappend('c',"AL",alexaEnabled);
sappend('s',"AI",(int)alexaInvocationName); sappends('s',"AI",alexaInvocationName);
sappend('c',"SA",alexaNotify); sappend('c',"SA",alexaNotify);
sappend('s',"BK",(int)((blynkEnabled)?"Hidden":"")); sappends('s',"BK",(char*)((blynkEnabled)?"Hidden":""));
sappend('v',"H0",hueIP[0]); sappend('v',"H0",hueIP[0]);
sappend('v',"H1",hueIP[1]); sappend('v',"H1",hueIP[1]);
sappend('v',"H2",hueIP[2]); sappend('v',"H2",hueIP[2]);
@ -237,7 +244,7 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
sappend('c',"HO",hueApplyOnOff); sappend('c',"HO",hueApplyOnOff);
sappend('c',"HB",hueApplyBri); sappend('c',"HB",hueApplyBri);
sappend('c',"HC",hueApplyColor); sappend('c',"HC",hueApplyColor);
sappend('m',"(\"hms\")[0]",(int)hueError); sappends('m',"(\"hms\")[0]",hueError);
} }
if (subPage == 5) if (subPage == 5)
@ -246,14 +253,14 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
sappend('c',"CF",!useAMPM); sappend('c',"CF",!useAMPM);
sappend('i',"TZ",currentTimezone); sappend('i',"TZ",currentTimezone);
sappend('v',"UO",utcOffsetSecs); sappend('v',"UO",utcOffsetSecs);
sappend('m',"(\"times\")[0]",(int)getTimeString().c_str()); sappends('m',"(\"times\")[0]",(char*)getTimeString().c_str());
sappend('i',"OL",overlayCurrent); sappend('i',"OL",overlayCurrent);
sappend('v',"O1",overlayMin); sappend('v',"O1",overlayMin);
sappend('v',"O2",overlayMax); sappend('v',"O2",overlayMax);
sappend('v',"OM",analogClock12pixel); sappend('v',"OM",analogClock12pixel);
sappend('c',"OS",analogClockSecondsTrail); sappend('c',"OS",analogClockSecondsTrail);
sappend('c',"O5",analogClock5MinuteMarks); sappend('c',"O5",analogClock5MinuteMarks);
sappend('s',"CX",(int)cronixieDisplay); sappends('s',"CX",cronixieDisplay);
sappend('c',"CB",cronixieBacklight); sappend('c',"CB",cronixieBacklight);
sappend('c',"CE",countdownMode); sappend('c',"CE",countdownMode);
sappend('v',"CY",countdownYear); sappend('v',"CY",countdownYear);
@ -267,7 +274,7 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
for (int i=1;i<17;i++) for (int i=1;i<17;i++)
{ {
sprintf(k+1,"%i",i); sprintf(k+1,"%i",i);
sappend('s',k,(int)loadMacro(i).c_str()); sappends('s',k,(char*)loadMacro(i).c_str());
} }
sappend('v',"MB",macroBoot); sappend('v',"MB",macroBoot);
@ -285,7 +292,7 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript
sappend('c',"OW",wifiLock); sappend('c',"OW",wifiLock);
sappend('c',"AO",aOtaEnabled); sappend('c',"AO",aOtaEnabled);
sappend('c',"NA",recoveryAPDisabled); sappend('c',"NA",recoveryAPDisabled);
sappend('m',"(\"msg\")[0]",(int)"WLED "); sappends('m',"(\"msg\")[0]","WLED ");
olen -= 2; //delete "; olen -= 2; //delete ";
oappend(versionString); oappend(versionString);
oappend(" (build "); oappend(" (build ");