Skip to content

Commit e9d052c

Browse files
authored
WIP - Update ArduinoOTA and examples with MDNS.update() calls (#5494)
* ArduinoOTA: allow use without MDNS, add MDNS.update() in handle() * Update examples with MDNS.update() in loop * Update CaptivePortalAdvanced.ino Fix typo * Update CaptivePortalAdvanced.ino astyle * Update Arduino_Wifi_AVRISP.ino astyle
1 parent 8ede8f1 commit e9d052c

File tree

18 files changed

+41
-11
lines changed

18 files changed

+41
-11
lines changed

libraries/ArduinoOTA/ArduinoOTA.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ArduinoOTAClass::ArduinoOTAClass()
3333
, _udp_ota(0)
3434
, _initialized(false)
3535
, _rebootOnSuccess(true)
36+
, _useMDNS(true)
3637
, _state(OTA_IDLE)
3738
, _size(0)
3839
, _cmd(0)
@@ -103,10 +104,12 @@ void ArduinoOTAClass::setRebootOnSuccess(bool reboot){
103104
_rebootOnSuccess = reboot;
104105
}
105106

106-
void ArduinoOTAClass::begin() {
107+
void ArduinoOTAClass::begin(bool useMDNS) {
107108
if (_initialized)
108109
return;
109110

111+
_useMDNS = useMDNS;
112+
110113
if (!_hostname.length()) {
111114
char tmp[15];
112115
sprintf(tmp, "esp8266-%06x", ESP.getChipId());
@@ -127,12 +130,15 @@ void ArduinoOTAClass::begin() {
127130
if(!_udp_ota->listen(IP_ADDR_ANY, _port))
128131
return;
129132
_udp_ota->onRx(std::bind(&ArduinoOTAClass::_onRx, this));
130-
MDNS.begin(_hostname.c_str());
131133

132-
if (_password.length()) {
133-
MDNS.enableArduino(_port, true);
134-
} else {
135-
MDNS.enableArduino(_port);
134+
if(_useMDNS) {
135+
MDNS.begin(_hostname.c_str());
136+
137+
if (_password.length()) {
138+
MDNS.enableArduino(_port, true);
139+
} else {
140+
MDNS.enableArduino(_port);
141+
}
136142
}
137143
_initialized = true;
138144
_state = OTA_IDLE;
@@ -348,11 +354,15 @@ void ArduinoOTAClass::_runUpdate() {
348354
}
349355
}
350356

357+
//this needs to be called in the loop()
351358
void ArduinoOTAClass::handle() {
352359
if (_state == OTA_RUNUPDATE) {
353360
_runUpdate();
354361
_state = OTA_IDLE;
355362
}
363+
364+
if(_useMDNS)
365+
MDNS.update(); //handle MDNS update as well, given that ArduinoOTA relies on it anyways
356366
}
357367

358368
int ArduinoOTAClass::getCommand() {

libraries/ArduinoOTA/ArduinoOTA.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class ArduinoOTAClass
6060
void onProgress(THandlerFunction_Progress fn);
6161

6262
//Starts the ArduinoOTA service
63-
void begin();
63+
void begin(bool useMDNS = true);
6464

65-
//Call this in loop() to run the service
65+
//Call this in loop() to run the service. Also calls MDNS.update() when begin() or begin(true) is used.
6666
void handle();
6767

6868
//Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS
@@ -76,6 +76,7 @@ class ArduinoOTAClass
7676
UdpContext *_udp_ota;
7777
bool _initialized;
7878
bool _rebootOnSuccess;
79+
bool _useMDNS;
7980
ota_state_t _state;
8081
int _size;
8182
int _cmd;

libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ void loop() {
130130
WiFi.disconnect();
131131
}
132132
}
133+
if (s == WL_CONNECTED) {
134+
MDNS.update();
135+
}
133136
}
134137
// Do work:
135138
//DNS

libraries/ESP8266AVRISP/examples/Arduino_Wifi_AVRISP/Arduino_Wifi_AVRISP.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ void loop() {
7070
if (last_state != AVRISP_STATE_IDLE) {
7171
avrprog.serve();
7272
}
73+
74+
if (WiFi.status() == WL_CONNECTED) {
75+
MDNS.update();
76+
}
7377
}

libraries/ESP8266HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,5 @@ void setup()
119119
void loop()
120120
{
121121
httpServer.handleClient();
122+
MDNS.update();
122123
}

libraries/ESP8266HTTPUpdateServer/examples/SecureHTTPSUpdater/SecureHTTPSUpdater.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,5 @@ void setup() {
188188

189189
void loop() {
190190
httpServer.handleClient();
191+
MDNS.update();
191192
}

libraries/ESP8266HTTPUpdateServer/examples/SecureWebUpdater/SecureWebUpdater.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ void setup(void) {
4747

4848
void loop(void) {
4949
httpServer.handleClient();
50+
MDNS.update();
5051
}

libraries/ESP8266HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ void setup(void) {
4444

4545
void loop(void) {
4646
httpServer.handleClient();
47+
MDNS.update();
4748
}

libraries/ESP8266WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void setup(void) {
130130

131131
void loop(void) {
132132
server.handleClient();
133+
MDNS.update();
133134
}
134135

135136
void drawGraph() {

libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,5 @@ void setup(void) {
282282

283283
void loop(void) {
284284
server.handleClient();
285+
MDNS.update();
285286
}

0 commit comments

Comments
 (0)