Skip to content

Commit 7973fd8

Browse files
committed
Revert disable OTA & optional Arduino OTA
- new compile flag WLED_ENABLE_AOTA - modify WLED_CONNECTED macro - bugfix in Network isConnected() when static IP is set
1 parent 66869f8 commit 7973fd8

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

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();
@@ -469,7 +472,7 @@ void WLED::setup()
469472
if (mqttClientID[0] == 0) sprintf_P(mqttClientID, PSTR("WLED-%*s"), 6, escapedMac.c_str() + 6);
470473
#endif
471474

472-
#ifndef WLED_DISABLE_OTA
475+
#ifdef WLED_ENABLE_AOTA
473476
if (aOtaEnabled) {
474477
ArduinoOTA.onStart([]() {
475478
#ifdef ESP8266
@@ -709,9 +712,8 @@ void WLED::initInterfaces()
709712
alexaInit();
710713
#endif
711714

712-
#ifndef WLED_DISABLE_OTA
713-
if (aOtaEnabled)
714-
ArduinoOTA.begin();
715+
#ifdef WLED_ENABLE_AOTA
716+
if (aOtaEnabled) ArduinoOTA.begin();
715717
#endif
716718

717719
// Set up mDNS responder:
@@ -782,7 +784,7 @@ void WLED::handleConnection()
782784
if (stac != stacO) {
783785
stacO = stac;
784786
DEBUG_PRINTF_P(PSTR("Connected AP clients: %d\n"), (int)stac);
785-
if (!WLED_CONNECTED && wifiConfigured) { // trying to connect, but not connected
787+
if (!Network.isConnected() && wifiConfigured) { // trying to connect, but not connected
786788
if (stac)
787789
WiFi.disconnect(); // disable search so that AP can work
788790
else
@@ -857,7 +859,7 @@ void WLED::handleConnection()
857859
}
858860

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

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

wled00/wled.h

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

2222
// You are required to disable over-the-air updates:
2323
//#define WLED_DISABLE_OTA // saves 14kb
24+
#ifdef WLED_ENABLE_AOTA
25+
#undef WLED_DISABLE_OTA
26+
#endif
2427

2528
// You can choose some of these features to disable:
2629
//#define WLED_DISABLE_ALEXA // saves 11kb
@@ -121,10 +124,6 @@
121124
#endif
122125
#include <WiFiUdp.h>
123126
#include <DNSServer.h>
124-
#ifndef WLED_DISABLE_OTA
125-
#define NO_OTA_PORT
126-
#include <ArduinoOTA.h>
127-
#endif
128127
#include <SPIFFSEditor.h>
129128
#include "src/dependencies/time/TimeLib.h"
130129
#include "src/dependencies/timezone/Timezone.h"
@@ -588,7 +587,7 @@ WLED_GLOBAL bool otaLock _INIT(true); // prevents OTA firmware update
588587
WLED_GLOBAL bool otaLock _INIT(false); // prevents OTA firmware updates without password. ALWAYS enable if system exposed to any public networks
589588
#endif
590589
WLED_GLOBAL bool wifiLock _INIT(false); // prevents access to WiFi settings when OTA lock is enabled
591-
#ifndef WLED_DISABLE_OTA
590+
#ifdef WLED_ENABLE_AOTA
592591
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
593592
#else
594593
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 +1023,7 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
10241023
WLED_GLOBAL unsigned loops _INIT(0);
10251024
#endif
10261025

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
1026+
#define WLED_CONNECTED (Network.isConnected())
10321027

10331028
#ifndef WLED_AP_SSID_UNIQUE
10341029
#define WLED_SET_AP_SSID() do { \

wled00/wled_server.cpp

Lines changed: 16 additions & 4 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,6 +449,13 @@ 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);
458+
#endif
449459

450460
#ifdef WLED_ENABLE_DMX
451461
server.on(F("/dmxmap"), HTTP_GET, [](AsyncWebServerRequest *request){
@@ -657,6 +667,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) {
657667
case SUBPAGE_DMX : content = PAGE_settings_dmx; len = PAGE_settings_dmx_length; break;
658668
#endif
659669
case SUBPAGE_UM : content = PAGE_settings_um; len = PAGE_settings_um_length; break;
670+
#ifndef WLED_DISABLE_OTA
660671
case SUBPAGE_UPDATE : content = PAGE_update; len = PAGE_update_length;
661672
#ifdef ARDUINO_ARCH_ESP32
662673
if (request->hasArg(F("revert")) && inLocalSubnet(request->client()->remoteIP()) && Update.canRollBack()) {
@@ -670,6 +681,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) {
670681
}
671682
#endif
672683
break;
684+
#endif
673685
#ifndef WLED_DISABLE_2D
674686
case SUBPAGE_2D : content = PAGE_settings_2D; len = PAGE_settings_2D_length; break;
675687
#endif

wled00/xml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ 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
599+
#ifndef WLED_ENABLE_AOTA
600600
//hide settings if not compiled
601601
settingsScript.print(F("toggle('aOTA');")); // hide ArduinoOTA checkbox
602602
#endif

0 commit comments

Comments
 (0)