Skip to content

Commit 55d249e

Browse files
author
darkpoet78
committed
2025.08.20
1 parent 7380194 commit 55d249e

7 files changed

Lines changed: 95 additions & 75 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Documentation will be slowly improved.
1717

1818

1919
### 2025.08.20
20+
- Fixes to Online updater
2021
- WebUI fixed for mobile displays
2122
- MQTT added to WebUI options / defaults set by adding defines to `myoptions.h`
2223
- `#define MQTT_ENABLE` to enable (will not be available otherwise)

builds/trip5/platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ platform = espressif32
77
framework = arduino
88
monitor_speed = 115200
99
build_flags =
10-
-DCORE_DEBUG_LEVEL=1 ; Set to 0 for no debug; saves memory / 5 for full debug
10+
-DCORE_DEBUG_LEVEL=0 ; Set to 0 for no debug; saves memory / 5 for full debug
1111
; required libraries - universal libs here and build-dependent libs with the board definitions
1212
lib_deps =
1313
bblanchon/ArduinoJson@^6.21.3

data/www/script.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ function onMessage(event) {
9393
const status = getId('uploadstatus');
9494
if(status) status.innerHTML = "OTA Update: " + data.onlineupdateprogress + "%  downloaded  |  please wait...";
9595
if (data.onlineupdateprogress >= 100) {
96-
getId("uploadstatus").innerHTML = "OTA Update Complete. Radio will reboot, update files, and reboot again. Please be patient.";
97-
rebootingProgress(80);
96+
getId("uploadstatus").innerHTML = "OTA Update Complete. Radio will reboot, update files, and reboot again. This will take 1 or 2 minutes.";
97+
rebootingProgress(60);
9898
}
9999
}
100100
}
@@ -744,8 +744,7 @@ function rebootingProgress(waitSeconds) {
744744
if (elapsed < waitSeconds * 1000) {
745745
rebootTimer = setTimeout(update, 200);
746746
} else {
747-
location.href = `http://${hostname}/`;
748-
window.location.reload(true);
747+
window.location.replace(`http://${hostname}/`);
749748
}
750749
};
751750
update();

src/core/commandhandler.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,7 @@ bool CommandHandler::exec(const char *command, const char *value, uint8_t cid) {
100100
if (strEquals(command, "snuffle")) { config.setSnuffle(strcmp(value, "true") == 0); return true; }
101101
if (strEquals(command, "balance")) { config.setBalance(static_cast<uint8_t>(atoi(value))); return true; }
102102
if (strEquals(command, "reboot")) { ESP.restart(); return true; }
103-
if (strEquals(command, "format")) { player.sendCommand({PR_STOP, 0}); SPIFFS.format();
104-
#ifdef UPDATEURL
105-
delay(250);
106-
File markerFile = SPIFFS.open(ONLINEUPDATE_MARKERFILE, "w"); if (markerFile) markerFile.close();
107-
delay(250);
108-
#endif
109-
ESP.restart(); return true; }
103+
if (strEquals(command, "format")) { player.sendCommand({PR_STOP, 0}); SPIFFS.format(); ESP.restart(); return true; }
110104
if (strEquals(command, "submitplaylist")) { player.sendCommand({PR_STOP, 0}); return true; }
111105

112106
#if IR_PIN!=255

src/core/config.cpp

Lines changed: 84 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ void Config::init() {
8282
BOOTLOG("SPIFFS mounted");
8383
emptyFS = _isFSempty();
8484
if(emptyFS) {
85-
#ifndef FILESURL
85+
#ifndef UPDATEURL
8686
BOOTLOG("SPIFFS is empty!");
8787
#else
88-
BOOTLOG("SPIFFS is empty. Will attempt to get files from online...");
89-
File markerFile = SPIFFS.open(ONLINEUPDATE_MARKERFILE, "w");
90-
if (markerFile) markerFile.close();
91-
display.putRequest(NEWMODE, UPDATING);
88+
BOOTLOG("SPIFFS is missing files. Will attempt to get files from online...");
89+
config.deleteMainDatawwwFile();
90+
getRequiredFiles();
91+
delay(200);
92+
ESP.restart();
9293
#endif
9394
}
9495
ssidsCount = 0;
@@ -1169,6 +1170,23 @@ void Config::sleepForAfter(uint16_t sf, uint16_t sa){
11691170
else doSleep();
11701171
}
11711172

1173+
void Config::deleteMainDatawwwFile() {
1174+
if (requiredFilesCount > 0) {
1175+
const char* lastFile = requiredFiles[requiredFilesCount - 1];
1176+
char mainfile[64];
1177+
snprintf(mainfile, sizeof(mainfile), "www/%s", lastFile);
1178+
if (SPIFFS.exists(mainfile)) {
1179+
SPIFFS.remove(mainfile);
1180+
Serial.printf("[Config] Deleted main www file: %s\n", mainfile);
1181+
}
1182+
snprintf(mainfile, sizeof(mainfile), "www/%s.gz", lastFile);
1183+
if (SPIFFS.exists(mainfile)) {
1184+
SPIFFS.remove(mainfile);
1185+
Serial.printf("[Config] Deleted main www file: %s\n", mainfile);
1186+
}
1187+
}
1188+
}
1189+
11721190
void cleanStaleSearchResults() {
11731191
const char* metaPath = "/data/searchresults.json.meta";
11741192
if (SPIFFS.exists(metaPath)) {
@@ -1206,41 +1224,45 @@ void fixPlaylistFileEnding() {
12061224
playlistfile.close();
12071225
}
12081226

1209-
void updateFile(void* param, const char* localFile, const char* onlineFile, const char* updatePeriod, const char* simpleName) {
1210-
char startMsg[128];
1211-
snprintf(startMsg, sizeof(startMsg), "[ESPFileUpdater: %s] Started update.", simpleName);
1212-
Serial.println(startMsg);
1213-
ESPFileUpdater* updater = (ESPFileUpdater*)param;
1214-
ESPFileUpdater::UpdateStatus result = updater->checkAndUpdate(
1215-
localFile,
1216-
onlineFile,
1217-
updatePeriod,
1218-
ESPFILEUPDATER_VERBOSE
1219-
);
1220-
if (result == ESPFileUpdater::UPDATED) {
1221-
Serial.printf("[ESPFileUpdater: %s] Update completed.\n", simpleName);
1222-
} else if (result == ESPFileUpdater::NOT_MODIFIED||result == ESPFileUpdater::MAX_AGE_NOT_REACHED) {
1223-
Serial.printf("[ESPFileUpdater: %s] No update needed.\n", simpleName);
1224-
} else {
1225-
Serial.printf("[ESPFileUpdater: %s] Update failed.\n", simpleName);
1226-
}
1227-
}
1228-
12291227
#ifdef UPDATEURL
1230-
void getRequiredFiles(void* param) {
1228+
void Config::getRequiredFiles() {
1229+
player.sendCommand({PR_STOP, 0});
1230+
display.putRequest(NEWMODE, UPDATING);
1231+
char localFileGz[64];
1232+
char localFile[64];
1233+
char tryFile[64];
1234+
char tryUrl[128];
12311235
for (size_t i = 0; i < requiredFilesCount; i++) {
1232-
player.sendCommand({PR_STOP, 0});
1233-
display.putRequest(NEWMODE, UPDATING);
12341236
const char* fname = requiredFiles[i];
1235-
char localPath[64];
1236-
char remoteUrl[128];
1237-
snprintf(localPath, sizeof(localPath), "/www/%s", fname);
1238-
if (strlen(fname) > 3 && strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
1239-
snprintf(remoteUrl, sizeof(remoteUrl), "%s%s", UPDATEURL, fname);
1240-
} else {
1241-
snprintf(remoteUrl, sizeof(remoteUrl), "%s%s.gz", UPDATEURL, fname);
1237+
snprintf(localFileGz, sizeof(localFileGz), "/www/%s.gz", fname);
1238+
snprintf(localFile, sizeof(localFile), "/www/%s", fname);
1239+
if (SPIFFS.exists(localFileGz)) SPIFFS.remove(localFileGz);
1240+
if (SPIFFS.exists(localFile)) SPIFFS.remove(localFile);
1241+
for (size_t j = 0; j < 2; j++) {
1242+
if (j == 0) { // Try compressed first
1243+
snprintf(tryFile, sizeof(tryFile), "%s", localFileGz);
1244+
snprintf(tryUrl, sizeof(tryUrl), "%s%s.gz", UPDATEURL, fname);
1245+
} else { // Fallback to uncompressed
1246+
snprintf(tryFile, sizeof(tryFile), "%s", localFile);
1247+
snprintf(tryUrl, sizeof(tryUrl), "%s%s", UPDATEURL, fname);
1248+
}
1249+
Serial.printf("[ESPFileUpdater: %s] Updating required file.\n", tryFile);
1250+
ESPFileUpdater updater(SPIFFS);
1251+
updater.setTimeout(5000);
1252+
ESPFileUpdater::UpdateStatus result = updater.checkAndUpdate(
1253+
tryFile,
1254+
tryUrl,
1255+
"",
1256+
ESPFILEUPDATER_VERBOSE
1257+
);
1258+
if (result == ESPFileUpdater::UPDATED) {
1259+
Serial.printf("[ESPFileUpdater: %s] Download completed.\n", tryFile);
1260+
break; // Exit inner loop on success
1261+
} else {
1262+
if (j == 0) Serial.printf("[ESPFileUpdater: %s] Download failed. Will retry for uncompressed file.\n", tryFile);
1263+
if (j == 1) Serial.printf("[ESPFileUpdater: %s] Download failed. Moving onto next file anyways.\n", tryFile);
1264+
}
12421265
}
1243-
updateFile(param, localPath, remoteUrl, "", fname);
12441266
}
12451267
// Delete any files in /www that are not in the requiredFiles list
12461268
File root = SPIFFS.open("/www");
@@ -1254,7 +1276,10 @@ void updateFile(void* param, const char* localFile, const char* onlineFile, cons
12541276
if (slash) name = slash + 1;
12551277
bool found = false;
12561278
for (size_t j = 0; j < requiredFilesCount; j++) {
1257-
if (strcmp(name, requiredFiles[j]) == 0) {
1279+
// Check against both compressed and uncompressed names
1280+
char requiredNameGz[64];
1281+
snprintf(requiredNameGz, sizeof(requiredNameGz), "%s.gz", requiredFiles[j]);
1282+
if (strcmp(name, requiredFiles[j]) == 0 || strcmp(name, requiredNameGz) == 0) {
12581283
found = true;
12591284
break;
12601285
}
@@ -1269,19 +1294,30 @@ void updateFile(void* param, const char* localFile, const char* onlineFile, cons
12691294
}
12701295
#endif //#ifdef UPDATEURL
12711296

1297+
void Config::updateFile(void* param, const char* localFile, const char* onlineFile, const char* updatePeriod, const char* simpleName) {
1298+
char startMsg[128];
1299+
snprintf(startMsg, sizeof(startMsg), "[ESPFileUpdater: %s] Started update.", simpleName);
1300+
Serial.println(startMsg);
1301+
ESPFileUpdater* updater = (ESPFileUpdater*)param;
1302+
ESPFileUpdater::UpdateStatus result = updater->checkAndUpdate(
1303+
localFile,
1304+
onlineFile,
1305+
updatePeriod,
1306+
ESPFILEUPDATER_VERBOSE
1307+
);
1308+
if (result == ESPFileUpdater::UPDATED) {
1309+
Serial.printf("[ESPFileUpdater: %s] Update completed.\n", simpleName);
1310+
} else if (result == ESPFileUpdater::NOT_MODIFIED||result == ESPFileUpdater::MAX_AGE_NOT_REACHED) {
1311+
Serial.printf("[ESPFileUpdater: %s] No update needed.\n", simpleName);
1312+
} else {
1313+
Serial.printf("[ESPFileUpdater: %s] Update failed.\n", simpleName);
1314+
}
1315+
}
1316+
12721317
void startAsyncServices(void* param){
12731318
fixPlaylistFileEnding();
1274-
// if the OTA marker file exists, fetch all web assets immediately, clean up, restart
1275-
#ifdef UPDATEURL
1276-
if (SPIFFS.exists(ONLINEUPDATE_MARKERFILE)) {
1277-
getRequiredFiles(param);
1278-
SPIFFS.remove(ONLINEUPDATE_MARKERFILE);
1279-
delay(200);
1280-
ESP.restart();
1281-
}
1282-
#endif
1283-
updateFile(param, "/www/timezones.json.gz", TIMEZONES_JSON_URL, "1 week", "Timezones database file");
1284-
updateFile(param, "/www/rb_srvrs.json", RADIO_BROWSER_SERVERS_URL, "4 weeks", "Radio Browser Servers list");
1319+
config.updateFile(param, "/www/timezones.json.gz", TIMEZONES_JSON_URL, "1 week", "Timezones database file");
1320+
config.updateFile(param, "/www/rb_srvrs.json", RADIO_BROWSER_SERVERS_URL, "4 weeks", "Radio Browser Servers list");
12851321
cleanStaleSearchResults();
12861322
vTaskDelete(NULL);
12871323
}

src/core/config.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
#define ESPFILEUPDATER_VERBOSE false
2323
#endif
2424

25-
#ifdef UPDATEURL
26-
#define ONLINEUPDATE_MARKERFILE "/data/otaupdate.meta"
27-
#endif
28-
2925
#define PLAYLIST_PATH "/data/playlist.csv"
3026
#define SSIDS_PATH "/data/wifi.csv"
3127
#define TMP_PATH "/data/tmpfile.txt"
@@ -204,11 +200,6 @@ class Config {
204200
bool isScreensaver;
205201
int newConfigMode;
206202
public:
207-
Config() {};
208-
//void save();
209-
#if IR_PIN!=255
210-
void saveIR();
211-
#endif
212203
void init();
213204
void loadPreferences();
214205
void deleteOldKeys();
@@ -236,10 +227,10 @@ class Config {
236227
void setBitrateFormat(BitrateFormat fmt) { configFmt = fmt; }
237228
void initPlaylist();
238229
void indexPlaylist();
239-
void updateTZjson(void* param);
240-
void getRequiredFiles(void* param);
230+
void deleteMainDatawwwFile();
231+
void getRequiredFiles();
241232
void startAsyncServicesButWait();
242-
void updateRadioBrowserServersjson();
233+
void updateFile(void* param, const char* localFile, const char* onlineFile, const char* updatePeriod, const char* simpleName);
243234
#ifdef USE_SD
244235
void initSDPlaylist();
245236
void changeMode(int newmode=-1);
@@ -269,11 +260,11 @@ class Config {
269260
void setScreensaverPlayingEnabled(bool val);
270261
void setScreensaverPlayingTimeout(uint16_t val);
271262
void setScreensaverPlayingBlank(bool val);
272-
void setSntpOne(const char *val);
273263
void setShowweather(bool val);
274264
void setWeatherKey(const char *val);
275265
void setSDpos(uint32_t val);
276266
#if IR_PIN!=255
267+
void saveIR();
277268
void setIrBtn(int val);
278269
#endif
279270
void resetSystem(const char *val, uint8_t clientId);

src/core/netserver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,8 +1044,7 @@ void launchPlaybackTask(const String& url, const String& name) {
10441044
bool ended = Update.end();
10451045
Serial.printf("[Online Update] Written %u bytes, expected %d, end() returned %s\n", written, contentLength, ended?"true":"false");
10461046
if (written == contentLength && ended) {
1047-
File markerFile = SPIFFS.open(ONLINEUPDATE_MARKERFILE, "w");
1048-
if (markerFile) markerFile.close();
1047+
config.deleteMainDatawwwFile();
10491048
websocket.textAll("{\"onlineupdatestatus\": \"Update successful, rebooting...\"}");
10501049
delay(1000);
10511050
ESP.restart();

0 commit comments

Comments
 (0)