web_board_uploader_v1
This commit is contained in:
Binary file not shown.
@@ -39,7 +39,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-row last">
|
<div class="flex-row last">
|
||||||
<div class="button apply" data-name="fwupdate" id="fwupdate">Firmware update</div>
|
<div class="button apply" data-name="fwupdate" id="fwupdate">Firmware</div>
|
||||||
|
<div class="button apply" data-name="webboard" id="webboard">Board</div>
|
||||||
</div>
|
</div>
|
||||||
</section><a name="screen"></a>
|
</section><a name="screen"></a>
|
||||||
<section class="group group_display group_oled group_nextion hidden" id="group_display">
|
<section class="group group_display group_oled group_nextion hidden" id="group_display">
|
||||||
|
|||||||
@@ -15,8 +15,20 @@ void u8fix(char *src){
|
|||||||
if ((uint8_t)last >= 0xC2) src[strlen(src)-1]='\0';
|
if ((uint8_t)last >= 0xC2) src[strlen(src)-1]='\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Config::_isFSempty() {
|
||||||
|
const char* reqiredFiles[] = {"dragpl.js.gz","elogo.png","elogo84.png","index.html","ir.css.gz","ir.html","ir.js.gz","script.js.gz","settings.css.gz","settings.html","style.css.gz","update.html"};
|
||||||
|
const uint8_t reqiredFilesSize = 12;
|
||||||
|
char fullpath[28];
|
||||||
|
for (uint8_t i=0; i<reqiredFilesSize; i++){
|
||||||
|
sprintf(fullpath, "/www/%s", reqiredFiles[i]);
|
||||||
|
if(!SPIFFS.exists(fullpath)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Config::init() {
|
void Config::init() {
|
||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
|
emptyFS = true;
|
||||||
#if IR_PIN!=255
|
#if IR_PIN!=255
|
||||||
irindex=-1;
|
irindex=-1;
|
||||||
#endif
|
#endif
|
||||||
@@ -26,12 +38,16 @@ void Config::init() {
|
|||||||
if(store.play_mode==80) store.play_mode=0b100;
|
if(store.play_mode==80) store.play_mode=0b100;
|
||||||
sdSnuffle = bitRead(store.play_mode, 2);
|
sdSnuffle = bitRead(store.play_mode, 2);
|
||||||
store.play_mode = store.play_mode & 0b11;
|
store.play_mode = store.play_mode & 0b11;
|
||||||
|
_initHW();
|
||||||
//if (!SPIFFS.begin(false, "/spiffs", 30)) {
|
//if (!SPIFFS.begin(false, "/spiffs", 30)) {
|
||||||
if (!SPIFFS.begin(false)) {
|
if (!SPIFFS.begin(true)) {
|
||||||
|
Serial.println("##[ERROR]#\tSPIFFS Mount Failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BOOTLOG("SPIFFS mounted");
|
||||||
loadTheme();
|
//emptyFS = !SPIFFS.exists("/www/index.html");
|
||||||
|
emptyFS = _isFSempty();
|
||||||
|
if(emptyFS) BOOTLOG("SPIFFS is empty!");
|
||||||
ssidsCount = 0;
|
ssidsCount = 0;
|
||||||
sdResumePos = 0;
|
sdResumePos = 0;
|
||||||
if(SDC_CS!=255){
|
if(SDC_CS!=255){
|
||||||
@@ -42,7 +58,7 @@ void Config::init() {
|
|||||||
if(store.play_mode==PM_SDCARD) initSDPlaylist();
|
if(store.play_mode==PM_SDCARD) initSDPlaylist();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(store.play_mode==PM_WEB) initPlaylist();
|
if(store.play_mode==PM_WEB && !emptyFS) initPlaylist();
|
||||||
|
|
||||||
if (store.lastStation == 0 && store.countStation > 0) {
|
if (store.lastStation == 0 && store.countStation > 0) {
|
||||||
store.lastStation = 1;
|
store.lastStation = 1;
|
||||||
@@ -50,18 +66,23 @@ void Config::init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadStation(store.lastStation);
|
loadStation(store.lastStation);
|
||||||
#if IR_PIN!=255
|
|
||||||
|
bootInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::_initHW(){
|
||||||
|
loadTheme();
|
||||||
|
#if IR_PIN!=255
|
||||||
eepromRead(EEPROM_START_IR, ircodes);
|
eepromRead(EEPROM_START_IR, ircodes);
|
||||||
if(ircodes.ir_set!=4224){
|
if(ircodes.ir_set!=4224){
|
||||||
ircodes.ir_set=4224;
|
ircodes.ir_set=4224;
|
||||||
memset(ircodes.irVals, 0, sizeof(ircodes.irVals));
|
memset(ircodes.irVals, 0, sizeof(ircodes.irVals));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if BRIGHTNESS_PIN!=255
|
#if BRIGHTNESS_PIN!=255
|
||||||
pinMode(BRIGHTNESS_PIN, OUTPUT);
|
pinMode(BRIGHTNESS_PIN, OUTPUT);
|
||||||
setBrightness(false);
|
setBrightness(false);
|
||||||
#endif
|
#endif
|
||||||
bootInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Config::color565(uint8_t r, uint8_t g, uint8_t b)
|
uint16_t Config::color565(uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ class Config {
|
|||||||
uint32_t sdResumePos;
|
uint32_t sdResumePos;
|
||||||
uint16_t backupLastStation;
|
uint16_t backupLastStation;
|
||||||
bool sdSnuffle;
|
bool sdSnuffle;
|
||||||
|
bool emptyFS;
|
||||||
public:
|
public:
|
||||||
Config() {};
|
Config() {};
|
||||||
void save();
|
void save();
|
||||||
@@ -206,6 +207,8 @@ class Config {
|
|||||||
void initSDPlaylist();
|
void initSDPlaylist();
|
||||||
void indexSDPlaylist();
|
void indexSDPlaylist();
|
||||||
bool checkNoMedia(const char* path);
|
bool checkNoMedia(const char* path);
|
||||||
|
void _initHW();
|
||||||
|
bool _isFSempty();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Config config;
|
extern Config config;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ AsyncUDP udp;
|
|||||||
|
|
||||||
String processor(const String& var);
|
String processor(const String& var);
|
||||||
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||||
|
void handleUploadWeb(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||||
void handleUpdate(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
void handleUpdate(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||||
void handleHTTPArgs(AsyncWebServerRequest * request);
|
void handleHTTPArgs(AsyncWebServerRequest * request);
|
||||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len);
|
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len);
|
||||||
@@ -53,12 +54,21 @@ bool NetServer::begin() {
|
|||||||
irRecordEnable = false;
|
irRecordEnable = false;
|
||||||
nsQueue = xQueueCreate( 20, sizeof( nsRequestParams_t ) );
|
nsQueue = xQueueCreate( 20, sizeof( nsRequestParams_t ) );
|
||||||
while(nsQueue==NULL){;}
|
while(nsQueue==NULL){;}
|
||||||
webserver.on("/", HTTP_ANY, handleHTTPArgs);
|
if(config.emptyFS){
|
||||||
|
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);
|
||||||
|
}else{
|
||||||
|
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_POST, [](AsyncWebServerRequest *request) { request->redirect("/"); }, handleUploadWeb);
|
||||||
|
}
|
||||||
|
|
||||||
webserver.on(PLAYLIST_PATH, HTTP_GET, handleHTTPArgs);
|
webserver.on(PLAYLIST_PATH, HTTP_GET, handleHTTPArgs);
|
||||||
webserver.on(INDEX_PATH, HTTP_GET, handleHTTPArgs);
|
webserver.on(INDEX_PATH, HTTP_GET, handleHTTPArgs);
|
||||||
webserver.on(PLAYLIST_SD_PATH, HTTP_GET, handleHTTPArgs);
|
webserver.on(PLAYLIST_SD_PATH, HTTP_GET, handleHTTPArgs);
|
||||||
webserver.on(INDEX_SD_PATH, HTTP_GET, handleHTTPArgs);
|
webserver.on(INDEX_SD_PATH, HTTP_GET, handleHTTPArgs);
|
||||||
webserver.on(SSIDS_PATH, HTTP_GET, handleHTTPArgs);
|
webserver.on(SSIDS_PATH, HTTP_GET, handleHTTPArgs);
|
||||||
|
|
||||||
webserver.on("/upload", HTTP_POST, beginUpload, handleUpload);
|
webserver.on("/upload", HTTP_POST, beginUpload, handleUpload);
|
||||||
webserver.on("/update", HTTP_GET, handleHTTPArgs);
|
webserver.on("/update", HTTP_GET, handleHTTPArgs);
|
||||||
webserver.on("/update", HTTP_POST, beginUpdate, handleUpdate);
|
webserver.on("/update", HTTP_POST, beginUpdate, handleUpdate);
|
||||||
@@ -640,6 +650,7 @@ 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 == "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) {
|
||||||
@@ -653,6 +664,9 @@ String processor(const String& var) { // %Templates%
|
|||||||
|
|
||||||
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
|
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||||
if (!index) {
|
if (!index) {
|
||||||
|
//String spath = "/www/";
|
||||||
|
//if(filename=="playlist.csv" || filename=="wifi.csv") spath = "/data/";
|
||||||
|
//request->_tempFile = SPIFFS.open(config.emptyFS?spath + filename:TMP_PATH , "w");
|
||||||
request->_tempFile = SPIFFS.open(TMP_PATH , "w");
|
request->_tempFile = SPIFFS.open(TMP_PATH , "w");
|
||||||
}
|
}
|
||||||
if (len) {
|
if (len) {
|
||||||
@@ -664,6 +678,21 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleUploadWeb(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||||
|
DBGVB("File: %s, size:%u bytes, index: %u, final: %s\n", filename.c_str(), len, index, final?"true":"false");
|
||||||
|
if (!index) {
|
||||||
|
String spath = "/www/";
|
||||||
|
if(filename=="playlist.csv" || filename=="wifi.csv") spath = "/data/";
|
||||||
|
request->_tempFile = SPIFFS.open(spath + filename , "w");
|
||||||
|
}
|
||||||
|
if (len) {
|
||||||
|
request->_tempFile.write(data, len);
|
||||||
|
}
|
||||||
|
if (final) {
|
||||||
|
request->_tempFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WS_EVT_CONNECT: if (config.store.audioinfo) Serial.printf("[WEBSOCKET] client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str()); break;
|
case WS_EVT_CONNECT: if (config.store.audioinfo) Serial.printf("[WEBSOCKET] client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str()); break;
|
||||||
|
|||||||
@@ -7,6 +7,27 @@
|
|||||||
|
|
||||||
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"(
|
||||||
|
<!DOCTYPE html><html><head><meta charset="UTF-8"><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;}
|
||||||
|
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;}
|
||||||
|
span{color:#ccc}</style></head><body>
|
||||||
|
<section>
|
||||||
|
<h2>ёRadio - WEB Board Uploader</h2>
|
||||||
|
<hr />
|
||||||
|
<span>Please select <u>ALL</u> files from <i>yoRadio/data/www/</i> and upload them using the form below</span>
|
||||||
|
<hr />
|
||||||
|
<form action="/%ACTION%" method="post" enctype="multipart/form-data">
|
||||||
|
<p><label for="www">www:</label> <input type="file" name="www" id="www" multiple></p>
|
||||||
|
<hr />
|
||||||
|
<span>Optional, you can also upload <i>playlist.csv</i> and <i>wifi.csv files</i> from backup</span>
|
||||||
|
<p><label for="data">wifi:</label><input type="file" name="data" id="data" multiple></p>
|
||||||
|
<hr />
|
||||||
|
<p><input type="submit" name="submit" value="Upload"></p>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</body></html>
|
||||||
|
)";
|
||||||
|
|
||||||
struct nsRequestParams_t
|
struct nsRequestParams_t
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user