Skip to content

Commit bfe5cd5

Browse files
authored
Merge pull request wled#4748 from wled/aOTA
Revert disable OTA logic & optional Arduino OTA
2 parents b76ef23 + 6a5dcb3 commit bfe5cd5

File tree

9 files changed

+48
-40
lines changed

9 files changed

+48
-40
lines changed

wled00/data/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function isN(n) { return !isNaN(parseFloat(n)) && isFinite(n); } // isNumber
1313
// https://stackoverflow.com/questions/3885817/how-do-i-check-that-a-number-is-float-or-integer
1414
function isF(n) { return n === +n && n !== (n|0); } // isFloat
1515
function isI(n) { return n === +n && n === (n|0); } // isInteger
16-
function toggle(el) { gId(el).classList.toggle("hide"); gId('No'+el).classList.toggle("hide"); }
16+
function toggle(el) { gId(el).classList.toggle("hide"); let n = gId('No'+el); if (n) n.classList.toggle("hide"); }
1717
function tooltip(cont=null) {
1818
d.querySelectorAll((cont?cont+" ":"")+"[title]").forEach((element)=>{
1919
element.addEventListener("pointerover", ()=>{

wled00/data/index.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329
<div>
330330
<button class="btn ibtn" onclick="requestJson()">Refresh</button>
331331
<button class="btn ibtn" onclick="toggleNodes()">Instance List</button>
332-
<button class="btn ibtn" onclick="window.open(getURL('/update'),'_self');">Update WLED</button>
332+
<button class="btn ibtn" onclick="window.open(getURL('/update'),'_self');" id="updBt">Update WLED</button>
333333
<button class="btn ibtn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button>
334334
</div>
335335
<br>

wled00/data/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ function parseInfo(i) {
685685
gId("filter2D").classList.remove('hide');
686686
gId('bs').querySelectorAll('option[data-type="2D"]').forEach((o,i)=>{o.style.display='';});
687687
}
688+
gId("updBt").style.display = (i.opt & 1) ? '':'none';
688689
// if (i.noaudio) {
689690
// gId("filterVol").classList.add("hide");
690691
// gId("filterFreq").classList.add("hide");

wled00/data/settings_sec.htm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ <h2>Security & Update setup</h2>
5353
Factory reset: <input type="checkbox" name="RS"><br>
5454
All settings and presets will be erased.<br><br>
5555
<div class="warn">&#9888; Unencrypted transmission. An attacker on the same network can intercept form data!</div>
56-
<hr>
56+
<span id="OTA"><hr>
5757
<h3>Software Update</h3>
5858
<button type="button" onclick="U()">Manual OTA Update</button><br>
5959
<div id="aOTA">Enable ArduinoOTA: <input type="checkbox" name="AO"></div>
6060
Only allow update from same network/WiFi: <input type="checkbox" name="SU"><br>
6161
<i class="warn">&#9888; If you are using multiple VLANs (i.e. IoT or guest network) either set PIN or disable this option.<br>
62-
Disabling this option will make your device less secure.</i><br>
62+
Disabling this option will make your device less secure.</i><br></span>
6363
<hr id="backup">
6464
<h3>Backup & Restore</h3>
6565
<div class="warn">&#9888; Restoring presets/configuration will OVERWRITE your current presets/configuration.<br>

wled00/src/dependencies/network/Network.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,13 @@ void NetworkClass::localMAC(uint8_t* MAC)
7373

7474
bool NetworkClass::isConnected()
7575
{
76-
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
77-
return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED) || ETH.localIP()[0] != 0;
78-
#else
79-
return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED);
80-
#endif
76+
return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED) || isEthernet();
8177
}
8278

8379
bool NetworkClass::isEthernet()
8480
{
8581
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
86-
return (ETH.localIP()[0] != 0);
82+
return (ETH.localIP()[0] != 0) && ETH.linkUp();
8783
#endif
8884
return false;
8985
}

wled00/wled.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#define WLED_DEFINE_GLOBAL_VARS //only in one source file, wled.cpp!
22
#include "wled.h"
33
#include "wled_ethernet.h"
4-
#include <Arduino.h>
4+
#ifdef WLED_ENABLE_AOTA
5+
#define NO_OTA_PORT
6+
#include <ArduinoOTA.h>
7+
#endif
58

69
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET)
710
#include "soc/soc.h"
@@ -105,8 +108,8 @@ void WLED::loop()
105108
if (!realtimeMode || realtimeOverride || (realtimeMode && useMainSegmentOnly)) // block stuff if WARLS/Adalight is enabled
106109
{
107110
if (apActive) dnsServer.processNextRequest();
108-
#ifndef WLED_DISABLE_OTA
109-
if (WLED_CONNECTED && aOtaEnabled && !otaLock && correctPIN) ArduinoOTA.handle();
111+
#ifdef WLED_ENABLE_AOTA
112+
if (Network.isConnected() && aOtaEnabled && !otaLock && correctPIN) ArduinoOTA.handle();
110113
#endif
111114
handleNightlight();
112115
yield();
@@ -471,7 +474,7 @@ void WLED::setup()
471474
if (mqttClientID[0] == 0) sprintf_P(mqttClientID, PSTR("WLED-%*s"), 6, escapedMac.c_str() + 6);
472475
#endif
473476

474-
#ifndef WLED_DISABLE_OTA
477+
#ifdef WLED_ENABLE_AOTA
475478
if (aOtaEnabled) {
476479
ArduinoOTA.onStart([]() {
477480
#ifdef ESP8266
@@ -711,9 +714,8 @@ void WLED::initInterfaces()
711714
alexaInit();
712715
#endif
713716

714-
#ifndef WLED_DISABLE_OTA
715-
if (aOtaEnabled)
716-
ArduinoOTA.begin();
717+
#ifdef WLED_ENABLE_AOTA
718+
if (aOtaEnabled) ArduinoOTA.begin();
717719
#endif
718720

719721
// Set up mDNS responder:
@@ -784,7 +786,7 @@ void WLED::handleConnection()
784786
if (stac != stacO) {
785787
stacO = stac;
786788
DEBUG_PRINTF_P(PSTR("Connected AP clients: %d\n"), (int)stac);
787-
if (!WLED_CONNECTED && wifiConfigured) { // trying to connect, but not connected
789+
if (!Network.isConnected() && wifiConfigured) { // trying to connect, but not connected
788790
if (stac)
789791
WiFi.disconnect(); // disable search so that AP can work
790792
else
@@ -859,7 +861,7 @@ void WLED::handleConnection()
859861
}
860862

861863
// If status LED pin is allocated for other uses, does nothing
862-
// else blink at 1Hz when WLED_CONNECTED is false (no WiFi, ?? no Ethernet ??)
864+
// else blink at 1Hz when Network.isConnected() is false (no WiFi, ?? no Ethernet ??)
863865
// else blink at 2Hz when MQTT is enabled but not connected
864866
// else turn the status LED off
865867
#if defined(STATUSLED)
@@ -873,7 +875,7 @@ void WLED::handleStatusLED()
873875
}
874876
#endif
875877

876-
if (WLED_CONNECTED) {
878+
if (Network.isConnected()) {
877879
c = RGBW32(0,255,0,0);
878880
ledStatusType = 2;
879881
} else if (WLED_MQTT_CONNECTED) {

wled00/wled.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121

2222
// You are required to disable over-the-air updates:
2323
//#define WLED_DISABLE_OTA // saves 14kb
24+
#ifdef WLED_ENABLE_AOTA
25+
#if defined(WLED_DISABLE_OTA)
26+
#warning WLED_DISABLE_OTA was defined but it will be ignored due to WLED_ENABLE_AOTA.
27+
#endif
28+
#undef WLED_DISABLE_OTA
29+
#endif
2430

2531
// You can choose some of these features to disable:
2632
//#define WLED_DISABLE_ALEXA // saves 11kb
@@ -121,10 +127,6 @@
121127
#endif
122128
#include <WiFiUdp.h>
123129
#include <DNSServer.h>
124-
#ifndef WLED_DISABLE_OTA
125-
#define NO_OTA_PORT
126-
#include <ArduinoOTA.h>
127-
#endif
128130
#include <SPIFFSEditor.h>
129131
#include "src/dependencies/time/TimeLib.h"
130132
#include "src/dependencies/timezone/Timezone.h"
@@ -588,7 +590,7 @@ WLED_GLOBAL bool otaLock _INIT(true); // prevents OTA firmware update
588590
WLED_GLOBAL bool otaLock _INIT(false); // prevents OTA firmware updates without password. ALWAYS enable if system exposed to any public networks
589591
#endif
590592
WLED_GLOBAL bool wifiLock _INIT(false); // prevents access to WiFi settings when OTA lock is enabled
591-
#ifndef WLED_DISABLE_OTA
593+
#ifdef WLED_ENABLE_AOTA
592594
WLED_GLOBAL bool aOtaEnabled _INIT(true); // ArduinoOTA allows easy updates directly from the IDE. Careful, it does not auto-disable when OTA lock is on
593595
#else
594596
WLED_GLOBAL bool aOtaEnabled _INIT(false); // ArduinoOTA allows easy updates directly from the IDE. Careful, it does not auto-disable when OTA lock is on
@@ -1024,11 +1026,7 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
10241026
WLED_GLOBAL unsigned loops _INIT(0);
10251027
#endif
10261028

1027-
#ifdef ARDUINO_ARCH_ESP32
1028-
#define WLED_CONNECTED (WiFi.status() == WL_CONNECTED || ETH.localIP()[0] != 0)
1029-
#else
1030-
#define WLED_CONNECTED (WiFi.status() == WL_CONNECTED)
1031-
#endif
1029+
#define WLED_CONNECTED (Network.isConnected())
10321030

10331031
#ifndef WLED_AP_SSID_UNIQUE
10341032
#define WLED_SET_AP_SSID() do { \

wled00/wled_server.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "wled.h"
22

3-
#ifdef ESP8266
4-
#include <Updater.h>
5-
#else
6-
#include <Update.h>
3+
#ifndef WLED_DISABLE_OTA
4+
#ifdef ESP8266
5+
#include <Updater.h>
6+
#else
7+
#include <Update.h>
8+
#endif
79
#endif
810
#include "html_ui.h"
911
#include "html_settings.h"
@@ -387,6 +389,7 @@ void initServer()
387389
createEditHandler(correctPIN);
388390

389391
static const char _update[] PROGMEM = "/update";
392+
#ifndef WLED_DISABLE_OTA
390393
//init ota page
391394
server.on(_update, HTTP_GET, [](AsyncWebServerRequest *request){
392395
if (otaLock) {
@@ -446,14 +449,17 @@ void initServer()
446449
}
447450
}
448451
});
452+
#else
453+
const auto notSupported = [](AsyncWebServerRequest *request){
454+
serveMessage(request, 501, FPSTR(s_notimplemented), F("This build does not support OTA update."), 254);
455+
};
456+
server.on(_update, HTTP_GET, notSupported);
457+
server.on(_update, HTTP_POST, notSupported, [](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool isFinal){});
458+
#endif
449459

450460
#ifdef WLED_ENABLE_DMX
451461
server.on(F("/dmxmap"), HTTP_GET, [](AsyncWebServerRequest *request){
452-
request->send_P(200, FPSTR(CONTENT_TYPE_HTML), PAGE_dmxmap , dmxProcessor);
453-
});
454-
#else
455-
server.on(F("/dmxmap"), HTTP_GET, [](AsyncWebServerRequest *request){
456-
serveMessage(request, 501, FPSTR(s_notimplemented), F("DMX support is not enabled in this build."), 254);
462+
request->send_P(200, FPSTR(CONTENT_TYPE_HTML), PAGE_dmxmap, dmxProcessor);
457463
});
458464
#endif
459465

@@ -657,6 +663,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) {
657663
case SUBPAGE_DMX : content = PAGE_settings_dmx; len = PAGE_settings_dmx_length; break;
658664
#endif
659665
case SUBPAGE_UM : content = PAGE_settings_um; len = PAGE_settings_um_length; break;
666+
#ifndef WLED_DISABLE_OTA
660667
case SUBPAGE_UPDATE : content = PAGE_update; len = PAGE_update_length;
661668
#ifdef ARDUINO_ARCH_ESP32
662669
if (request->hasArg(F("revert")) && inLocalSubnet(request->client()->remoteIP()) && Update.canRollBack()) {
@@ -670,6 +677,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) {
670677
}
671678
#endif
672679
break;
680+
#endif
673681
#ifndef WLED_DISABLE_2D
674682
case SUBPAGE_2D : content = PAGE_settings_2D; len = PAGE_settings_2D_length; break;
675683
#endif

wled00/xml.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,11 @@ void getSettingsJS(byte subPage, Print& settingsScript)
596596
snprintf_P(tmp_buf,sizeof(tmp_buf),PSTR("WLED %s (build %d)"),versionString,VERSION);
597597
printSetClassElementHTML(settingsScript,PSTR("sip"),0,tmp_buf);
598598
settingsScript.printf_P(PSTR("sd=\"%s\";"), serverDescription);
599-
#ifdef WLED_DISABLE_OTA
600599
//hide settings if not compiled
600+
#ifdef WLED_DISABLE_OTA
601+
settingsScript.print(F("toggle('OTA');")); // hide update section
602+
#endif
603+
#ifndef WLED_ENABLE_AOTA
601604
settingsScript.print(F("toggle('aOTA');")); // hide ArduinoOTA checkbox
602605
#endif
603606
}

0 commit comments

Comments
 (0)