Skip to content

Commit c142010

Browse files
Fixed Dashboard updates, added optional CORS, fixed ESP32 DRD
1 parent b6dc056 commit c142010

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
lines changed

led-matrix-dashboard/src/components/OTAUpdate.vue

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
</md-card-header>
77
<md-card-content>
88
<div class="inline-centered">
9-
<md-button class="md-accent md-raised" :disabled="progress >= 0" @click="checkForUpdate">Check for Update</md-button>
10-
<md-tooltip md-delay="1000" md-direction="bottom"> Check GitHub for updates </md-tooltip>
9+
<md-button class="md-accent md-raised" :disabled="progress >= 0" @click="checkForUpdate">Check for Update
10+
</md-button>
11+
<md-tooltip md-delay="1000" md-direction="bottom"> Check GitHub for updates</md-tooltip>
1112
</div>
1213
<div v-if="this.$store.state.latestVersion !== this.$store.state.stats.version">Display out of date</div>
1314
<div v-else-if="this.$store.state.latestVersion !== this.$dashboardVersion">Dashboard out of date</div>
@@ -16,24 +17,24 @@
1617
<form novalidate class="md-layout" @submit.prevent="updateDialog = true">
1718
<div class="inline-centered">
1819
<md-radio v-model="selected" value="firmware" :disabled="progress >= 0">Firmware</md-radio>
19-
<md-tooltip md-delay="1000" md-direction="bottom"> Firmware update mode </md-tooltip>
20+
<md-tooltip md-delay="1000" md-direction="bottom"> Firmware update mode</md-tooltip>
2021
</div>
2122
<div class="inline-centered">
2223
<md-radio v-model="selected" value="filesystem" :disabled="progress >= 0">Dashboard</md-radio>
23-
<md-tooltip md-delay="1000" md-direction="bottom"> Dashboard update mode </md-tooltip>
24+
<md-tooltip md-delay="1000" md-direction="bottom"> Dashboard update mode</md-tooltip>
2425
</div>
2526
<div class="inline-centered">
2627
<md-checkbox v-model="manual" :disabled="progress >= 0">Manual</md-checkbox>
27-
<md-tooltip md-delay="1000" md-direction="bottom"> Manually flash using a binary file </md-tooltip>
28+
<md-tooltip md-delay="1000" md-direction="bottom"> Manually flash using a binary file</md-tooltip>
2829
</div>
2930
<md-field v-if="manual">
3031
<label>Binary</label>
3132
<md-file accept=".bin,.bin.gz" @md-change="onSelect" :disabled="progress >= 0"/>
32-
<md-tooltip md-delay="1000" md-direction="bottom"> The binary file to flash </md-tooltip>
33+
<md-tooltip md-delay="1000" md-direction="bottom"> The binary file to flash</md-tooltip>
3334
</md-field>
3435
<div class="inline-centered">
3536
<md-button class="md-accent md-raised" type="submit" :disabled="progress >= 0">Update</md-button>
36-
<md-tooltip md-delay="1000" md-direction="bottom"> Perform software update </md-tooltip>
37+
<md-tooltip md-delay="1000" md-direction="bottom"> Perform software update</md-tooltip>
3738
</div>
3839
</form>
3940
</md-card-content>
@@ -42,7 +43,8 @@
4243
<md-dialog :md-active.sync="updateDialog">
4344
<md-dialog-title>Update Display</md-dialog-title>
4445
<md-dialog-content style="width: 300px">
45-
Are you sure you want to update the display? The display will be factory reset in the process, so make sure you have
46+
Are you sure you want to update the display? The display will be factory reset in the process, so make sure you
47+
have
4648
saved a backup of the configuration before updating. All custom images and settings will be lost.
4749
</md-dialog-content>
4850
<md-dialog-actions>
@@ -70,7 +72,7 @@ export default {
7072
methods: {
7173
onSelect(files) {
7274
// Todo: switch to normal file input if md-file blank file glitch isn't fixed
73-
if (files.length> 0)
75+
if (files.length > 0)
7476
this.binary = files[0]
7577
},
7678
async abortUpdate() {
@@ -106,7 +108,7 @@ export default {
106108
let assets = (await this.$axios.get(`https://api.github.com/repos/TheLogicMaster/ESP-LED-Matrix-Display/releases/latest`)).data.assets
107109
let url = ''
108110
for (let i in assets) {
109-
if (this.selected === 'firmware' && assets[i].name === `firmware-${this.$store.state.stats.platform}-${this.$store.state.stats.height}x${this.$store.state.stats.width}-v${this.$store.state.latestVersion}.bin` || this.selected !== 'firmware' && assets[i].name === `fs-4m-v${this.$store.state.latestVersion}.bin`)
111+
if (this.selected === 'firmware' && assets[i].name === `firmware-${this.$store.state.stats.platform}-${this.$store.state.stats.height}x${this.$store.state.stats.width}-v${this.$store.state.latestVersion}.bin` || this.selected !== 'firmware' && assets[i].name === `fs-${this.$store.state.stats.features & 1 ? 'esp32' : 'esp8266'}-v${this.$store.state.latestVersion}.bin`)
110112
url = assets[i].url
111113
}
112114
if (url === '') {
@@ -115,7 +117,10 @@ export default {
115117
}
116118
// Hack to bypass CORS for GitHub AWS servers
117119
url = 'https://cors-anywhere.herokuapp.com/' + url
118-
binary = (await this.$axios.get(url, {responseType: 'blob', headers: {accept: 'application/octet-stream'}})).data
120+
binary = (await this.$axios.get(url, {
121+
responseType: 'blob',
122+
headers: {accept: 'application/octet-stream'}
123+
})).data
119124
} catch (error) {
120125
this.error('error', 'Failed to update display')
121126
console.error(error)
@@ -139,8 +144,7 @@ export default {
139144
if (response.data.includes('OK')) {
140145
this.info('Success', 'Successfully updated display', true)
141146
this.waitForPromiseSuccess(this.getStats).then()
142-
}
143-
else {
147+
} else {
144148
this.error('Error', 'Failed to update display: ' + response.data)
145149
await this.waitForPromiseSuccess(this.abortUpdate)
146150
}

led-matrix-display/main.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
#ifndef CACHE_DASHBOARD
8080
#define CACHE_DASHBOARD true // Disable for dashboard development, I guess
8181
#endif
82+
#ifndef USE_CORS
83+
#define USE_CORS false // CORS header is not needed in production
84+
#endif
8285
#ifndef USE_SUNRISE
8386
#define USE_SUNRISE true // Disable to save space if Sunrise brightness mode isn't needed
8487
#endif
@@ -394,7 +397,7 @@ const uint16_t MAGENTA = display.color565(255, 0, 255);
394397
RunningAverage brightnessAverage(BRIGHTNESS_ROLLING_AVG_SIZE);
395398
#endif
396399

397-
DoubleResetDetector drd(10, 0);
400+
DoubleResetDetector* drd;
398401
AsyncWebServer server(80);
399402
DNSServer dnsServer;
400403

@@ -655,6 +658,7 @@ void closeConnection(AsyncWebServerRequest *request) {
655658

656659
void onStartAccessPoint(AsyncWiFiManager *wiFiManager) {
657660
Serial.println(F("Entering AP config mode"));
661+
display.fillScreen(BLUE);
658662
display.setCursor(0, 0);
659663
display.println(F("Wifi"));
660664
display.println(F("Config"));
@@ -1158,6 +1162,8 @@ void serveRecovery(AsyncWebServerRequest *request) {
11581162
}
11591163

11601164
void setupWebserver() {
1165+
if (USE_CORS)
1166+
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
11611167
server.on("/", serveRoot);
11621168
server.on("/index.html", serveRoot);
11631169
server.on("/config", HTTP_GET, serveConfig);
@@ -1964,14 +1970,16 @@ void updateTime() {
19641970
DEBUG("Set timezone\n");
19651971
else
19661972
DEBUG("Failed to set timezone\n");
1967-
}
19681973
needsTimezone = false;
1974+
}
19691975
if (!bootTime && timeStatus() == timeSet)
19701976
bootTime = timezone.tzTime(TIME_NOW, UTC_TIME);
19711977
events(); // Handle NTP events
1972-
theHour12 = hourFormat12();
1973-
theHour = hour();
1974-
theMinute = minute();
1978+
if (timeStatus() == timeSet) {
1979+
theHour12 = hourFormat12();
1980+
theHour = hour();
1981+
theMinute = minute();
1982+
}
19751983
#endif
19761984
}
19771985

@@ -2022,6 +2030,7 @@ void setup() {
20222030
Serial.begin(115200);
20232031
Serial.println();
20242032

2033+
drd = new DoubleResetDetector(10, 0);
20252034
display.begin(16);
20262035
#ifdef ESP8266
20272036
display_ticker.attach(0.002, display_updater);
@@ -2034,9 +2043,8 @@ void setup() {
20342043
timerAlarmEnable(timer);;
20352044
#endif
20362045
display.setPanelsWidth(DISPLAY_PANELS);
2037-
display.fillScreen(GREEN);
2046+
display.fillScreen(BLUE);
20382047
display.showBuffer();
2039-
display.fillScreen(GREEN);
20402048

20412049
if (!LittleFS.begin() && !LittleFS.begin()) {
20422050
display.fillScreen(BLUE);
@@ -2067,9 +2075,10 @@ void setup() {
20672075

20682076
AsyncWiFiManager wifiManager(&server, &dnsServer);
20692077
wifiManager.setAPCallback(onStartAccessPoint);
2070-
2071-
if (drd.detectDoubleReset()) {
2078+
2079+
if (drd->detectDoubleReset()) {
20722080
Serial.println(F("Double reset detected, entering config mode"));
2081+
wifiManager.setTryConnectDuringConfigPortal(false);
20732082
wifiManager.startConfigPortal("LED Matrix Display");
20742083
} else {
20752084
Serial.println(F("Attemping to connect to network..."));
@@ -2079,8 +2088,16 @@ void setup() {
20792088
display.showBuffer();
20802089
wifiManager.autoConnect("LED Matrix Display", NULL, 5);
20812090
}
2091+
2092+
display.fillScreen(BLUE);
2093+
display.setCursor(0, 0);
2094+
display.println(F("Reset to"));
2095+
display.println(F("configure"));
2096+
display.println(F("WiFi"));
2097+
display.showBuffer();
2098+
delay(2000); // Delay for DRD activation
20822099

2083-
drd.stop();
2100+
drd->stop();
20842101
server.reset();
20852102
Serial.print(F("Connected to network with IP: "));
20862103
Serial.println(WiFi.localIP());

platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ lib_deps =
2424
;upload_port = 10.0.0.62
2525
build_flags =
2626
-Wno-unknown-pragmas
27-
;-DDEBUG_ESP_SSL
2827
-DVERSION_CODE=0
28+
;-DDEBUG_ESP_SSL
29+
;-DUSE_CORS=true
2930
;-DDEBUGGING=true
3031
;-DCORE_DEBUG_LEVEL=5
3132
;-DDEBUG_ESP_HTTP_UPDATE

0 commit comments

Comments
 (0)