Skip to content

Commit e9d052c

Browse files
authored
WIP - Update ArduinoOTA and examples with MDNS.update() calls (esp8266#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

+16-6
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

+3-2
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

+3
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

+4
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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
}

libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino

+1
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ void setup(void) {
7575

7676
void loop(void) {
7777
server.handleClient();
78+
MDNS.update();
7879
}

libraries/ESP8266WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino

+1
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,5 @@ void setup(void){
144144

145145
void loop(void){
146146
server.handleClient();
147+
MDNS.update();
147148
}

libraries/ESP8266WebServer/examples/HelloServerSecure/HelloServerSecure.ino

+1
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,5 @@ void setup(void) {
181181

182182
void loop(void) {
183183
server.handleClient();
184+
MDNS.update();
184185
}

libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino

+1
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,5 @@ void setup(void) {
315315

316316
void loop(void) {
317317
server.handleClient();
318+
MDNS.update();
318319
}

libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ void setup(void) {
7070

7171
void loop(void) {
7272
server.handleClient();
73-
delay(1);
73+
MDNS.update();
7474
}

libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino

-1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,5 @@ void setup() {
238238
void loop() {
239239
// Handle OTA server.
240240
ArduinoOTA.handle();
241-
yield();
242241
}
243242

libraries/ESP8266mDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ void setup() {
7676

7777
void loop() {
7878
// put your main code here, to run repeatedly:
79-
79+
MDNS.update();
8080
}

libraries/ESP8266mDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ void setup(void) {
7272
}
7373

7474
void loop(void) {
75+
76+
MDNS.update();
77+
7578
// Check if a client has connected
7679
WiFiClient client = server.available();
7780
if (!client) {

0 commit comments

Comments
 (0)