web_board_uploader_v

This commit is contained in:
e2002
2023-03-05 00:25:26 +03:00
parent 96aa10bc6d
commit c4b7e646b7
5 changed files with 53 additions and 16 deletions

Binary file not shown.

View File

@@ -38,6 +38,7 @@
<input type="range" id="slsoftap" class="slider" data-slaveid="slsoftapinfo" name="softap" min="0" max="20" value="0"> <input type="range" id="slsoftap" class="slider" data-slaveid="slsoftapinfo" name="softap" min="0" max="20" value="0">
</div> </div>
</div> </div>
<div class="row-title"><span>update</span></div>
<div class="flex-row last"> <div class="flex-row last">
<div class="button apply" data-name="fwupdate" id="fwupdate">Firmware</div> <div class="button apply" data-name="fwupdate" id="fwupdate">Firmware</div>
<div class="button apply" data-name="webboard" id="webboard">Board</div> <div class="button apply" data-name="webboard" id="webboard">Board</div>

View File

@@ -56,7 +56,18 @@ bool NetServer::begin() {
while(nsQueue==NULL){;} while(nsQueue==NULL){;}
if(config.emptyFS){ if(config.emptyFS){
webserver.on("/", HTTP_GET, [](AsyncWebServerRequest * request) { request->send_P(200, "text/html", emptyfs_html, processor); }); webserver.on("/", HTTP_GET, [](AsyncWebServerRequest * request) { request->send_P(200, "text/html", emptyfs_html, processor); });
webserver.on("/", HTTP_POST, [](AsyncWebServerRequest *request) { request->redirect("/"); ESP.restart(); }, handleUploadWeb); webserver.on("/", HTTP_POST, [](AsyncWebServerRequest *request) {
if(request->arg("ssid")!="" && request->arg("pass")!=""){
char buf[BUFLEN];
memset(buf, 0, BUFLEN);
snprintf(buf, BUFLEN, "%s\t%s", request->arg("ssid"), request->arg("pass"));
request->redirect("/");
config.saveWifiFromNextion(buf);
return;
}
request->redirect("/");
ESP.restart();
}, handleUploadWeb);
}else{ }else{
webserver.on("/", HTTP_ANY, handleHTTPArgs); webserver.on("/", HTTP_ANY, handleHTTPArgs);
webserver.on("/webboard", HTTP_GET, [](AsyncWebServerRequest * request) { request->send_P(200, "text/html", emptyfs_html, processor); }); webserver.on("/webboard", HTTP_GET, [](AsyncWebServerRequest * request) { request->send_P(200, "text/html", emptyfs_html, processor); });
@@ -650,7 +661,8 @@ void NetServer::requestOnChange(requestType_e request, uint8_t clientId) {
} }
String processor(const String& var) { // %Templates% String processor(const String& var) { // %Templates%
if (var == "ACTION") return network.status == CONNECTED?"webboard":""; if (var == "ACTION") return (network.status == CONNECTED && !config.emptyFS)?"webboard":"";
if (var == "UPLOADWIFI") return (network.status == CONNECTED || SPIFFS.exists("/data/wifi.csv"))?" hidden":"";
if (var == "VERSION") return YOVERSION; if (var == "VERSION") return YOVERSION;
if (var == "MODE") { if (var == "MODE") {
if(config.store.play_mode==PM_SDCARD) { if(config.store.play_mode==PM_SDCARD) {
@@ -690,6 +702,7 @@ void handleUploadWeb(AsyncWebServerRequest *request, String filename, size_t ind
} }
if (final) { if (final) {
request->_tempFile.close(); request->_tempFile.close();
if(filename=="playlist.csv") config.indexPlaylist();
} }
} }

View File

@@ -8,23 +8,35 @@
enum requestType_e : uint8_t { PLAYLIST=1, STATION=2, STATIONNAME=3, ITEM=4, TITLE=5, VOLUME=6, NRSSI=7, BITRATE=8, MODE=9, EQUALIZER=10, BALANCE=11, PLAYLISTSAVED=12, GETMODE=13, GETINDEX=14, GETACTIVE=15, GETSYSTEM=16, GETSCREEN=17, GETTIMEZONE=18, GETWEATHER=19, GETCONTROLS=20, DSPON=21, SDPOS=22, SDLEN=23, SDSNUFFLE=24 }; enum requestType_e : uint8_t { PLAYLIST=1, STATION=2, STATIONNAME=3, ITEM=4, TITLE=5, VOLUME=6, NRSSI=7, BITRATE=8, MODE=9, EQUALIZER=10, BALANCE=11, PLAYLISTSAVED=12, GETMODE=13, GETINDEX=14, GETACTIVE=15, GETSYSTEM=16, GETSCREEN=17, GETTIMEZONE=18, GETWEATHER=19, GETCONTROLS=20, DSPON=21, SDPOS=22, SDLEN=23, SDSNUFFLE=24 };
enum import_e : uint8_t { IMDONE=0, IMPL=1, IMWIFI=2 }; enum import_e : uint8_t { IMDONE=0, IMPL=1, IMWIFI=2 };
const char emptyfs_html[] PROGMEM = R"( const char emptyfs_html[] PROGMEM = R"(
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>ёRadio - WEB Board Uploader</title><style>body {background-color: #000; color: #e3d25f; font-size: 20px;} <!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, minimum-scale=0.25"><meta charset="UTF-8"><link rel="icon" href="data:;base64,iVBORw0KGgo="><title>ёRadio - WEB Board Uploader</title><style>body{background-color:#000;color:#e3d25f;font-size:20px;}
hr {margin: 20px 0; border: 0; border-top: #555 1px solid;} p {text-align: center;margin-bottom: 10px;} section {max-width: 500px; text-align: center;margin:0 auto;} hr{margin:20px 0;border:0; border-top:#555 1px solid;} p{text-align:center;margin-bottom:10px;} section{max-width:500px; text-align:center;margin:0 auto;}
input[type=file] {color: #ccc;} input[type=file]::file-selector-button, input[type=submit] {border: 2px solid #e3d25f;color: #ccc;padding: 6px 16px;border-radius: 15px;background-color: #000;margin: 0 6px;} input[type=file]{color:#ccc;} input[type=file]::file-selector-button, input[type=submit]{border:2px solid #e3d25f;color:#000;padding:6px 16px;border-radius:25px;background-color:#e3d25f;margin:0 6px;cursor:pointer;}
span{color:#ccc}</style></head><body> input[type=submit]{font-size:18px;text-transform:uppercase;padding:8px 26px;margin-top:10px;font-family:Times;} span{color:#ccc} .flex{display:flex;justify-content: space-around;margin-top:10px;}
input[type=text]{width:170px;background:#272727;color:#e3d25f;padding:6px 12px;font-size:20px;border:#2d2d2d 1px solid;margin:4px 0 0 4px;border-radius:4px;}input[type=text]{outline:none;}
</style></head><body>
<section> <section>
<h2>ёRadio - WEB Board Uploader</h2> <h2>ёRadio - WEB Board Uploader</h2>
<hr /> <hr />
<span>Please select <u>ALL</u> files from <i>yoRadio/data/www/</i> and upload them using the form below</span> <span>Select <u>ALL</u> files from <i>yoRadio/data/www/</i><br />and upload them using the form below</span>
<hr /> <hr />
<form action="/%ACTION%" method="post" enctype="multipart/form-data"> <form action="/%ACTION%" method="post" enctype="multipart/form-data">
<p><label for="www">www:</label> <input type="file" name="www" id="www" multiple></p> <p><label for="www">www:</label> <input type="file" name="www" id="www" multiple></p>
<hr /> <hr />
<span>Optional, you can also upload <i>playlist.csv</i> and <i>wifi.csv files</i> from backup</span> <span>-= OPTIONAL =-<br />You can also upload <i>playlist.csv</i><br />and <i>wifi.csv files</i> from your backup</span>
<p><label for="data">wifi:</label><input type="file" name="data" id="data" multiple></p> <p><label for="data">wifi:</label><input type="file" name="data" id="data" multiple></p>
<hr /> <hr />
<p><input type="submit" name="submit" value="Upload"></p> <p><input type="submit" name="submit" value="Upload Files"></p>
</form> </form>
<div style="padding:10px 0 0;"%UPLOADWIFI%>
<hr />
<form action="/%ACTION%" method="post" enctype="multipart/form-data">
<span>-= OPTIONAL =-<br />If you can't connect from PC to 192.168.4.1 address<br />setup WiFi connection first</span>
<div class="flex"><div><label for="ssid">ssid:</label><input type="text" id="ssid" name="ssid" value="" maxlength="30" autocomplete="off"></div>
<div><label for="pass">pass:</label><input type="text" id="pass" name="pass" value="" maxlength="40" autocomplete="off"></div>
</div>
<p><input type="submit" name="submit" value="Save Credentials"></p>
</form>
</div>
</section> </section>
</body></html> </body></html>
)"; )";

View File

@@ -261,6 +261,15 @@ bool getWeather(char *wstr) {
cursor = tmpe + 2; cursor = tmpe + 2;
float tempfl = atof(temp); (void)tempfl; float tempfl = atof(temp); (void)tempfl;
tmps = strstr(cursor, "\"pressure\":");
if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: pressure not found !"); return false;}
tmps += 11;
tmpe = strstr(tmps, ",\"");
if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: pressure not found !"); return false;}
strlcpy(press, tmps, tmpe - tmps + 1);
cursor = tmpe + 2;
int pressi = (float)atoi(press) / 1.333;
tmps = strstr(cursor, "humidity\":"); tmps = strstr(cursor, "humidity\":");
if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: humidity not found !"); return false;} if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: humidity not found !"); return false;}
tmps += 10; tmps += 10;
@@ -270,13 +279,15 @@ bool getWeather(char *wstr) {
strlcpy(hum, tmps, tmpe - tmps + (tmpc>tmpe?1:0)); strlcpy(hum, tmps, tmpe - tmps + (tmpc>tmpe?1:0));
tmps = strstr(cursor, "\"grnd_level\":"); tmps = strstr(cursor, "\"grnd_level\":");
if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: pressure not found !"); return false;} bool grnd_level_pr = (tmps != NULL);
if(grnd_level_pr){
tmps += 13; tmps += 13;
tmpe = strstr(tmps, ",\""); tmpe = strstr(tmps, ",\"");
if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: pressure not found !"); return false;} if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: grnd_level not found !"); return false;}
strlcpy(press, tmps, tmpe - tmps + 1); strlcpy(press, tmps, tmpe - tmps + 1);
cursor = tmpe + 2; cursor = tmpe + 2;
int pressi = (float)atoi(press) / 1.333; pressi = (float)atoi(press) / 1.333;
}
tmps = strstr(cursor, "\"speed\":"); tmps = strstr(cursor, "\"speed\":");
if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: wind speed not found !"); return false;} if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: wind speed not found !"); return false;}