@@ -33,6 +33,7 @@ ArduinoOTAClass::ArduinoOTAClass()
33
33
, _udp_ota(0 )
34
34
, _initialized(false )
35
35
, _rebootOnSuccess(true )
36
+ , _useMDNS(true )
36
37
, _state(OTA_IDLE)
37
38
, _size(0 )
38
39
, _cmd(0 )
@@ -103,10 +104,12 @@ void ArduinoOTAClass::setRebootOnSuccess(bool reboot){
103
104
_rebootOnSuccess = reboot ;
104
105
}
105
106
106
- void ArduinoOTAClass::begin () {
107
+ void ArduinoOTAClass::begin (bool useMDNS ) {
107
108
if (_initialized)
108
109
return ;
109
110
111
+ _useMDNS = useMDNS;
112
+
110
113
if (!_hostname.length ()) {
111
114
char tmp[15 ];
112
115
sprintf (tmp, " esp8266-%06x" , ESP.getChipId ());
@@ -127,12 +130,15 @@ void ArduinoOTAClass::begin() {
127
130
if (!_udp_ota->listen (IP_ADDR_ANY, _port))
128
131
return ;
129
132
_udp_ota->onRx (std::bind (&ArduinoOTAClass::_onRx, this ));
130
- MDNS.begin (_hostname.c_str ());
131
133
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
+ }
136
142
}
137
143
_initialized = true ;
138
144
_state = OTA_IDLE;
@@ -348,11 +354,15 @@ void ArduinoOTAClass::_runUpdate() {
348
354
}
349
355
}
350
356
357
+ // this needs to be called in the loop()
351
358
void ArduinoOTAClass::handle () {
352
359
if (_state == OTA_RUNUPDATE) {
353
360
_runUpdate ();
354
361
_state = OTA_IDLE;
355
362
}
363
+
364
+ if (_useMDNS)
365
+ MDNS.update (); // handle MDNS update as well, given that ArduinoOTA relies on it anyways
356
366
}
357
367
358
368
int ArduinoOTAClass::getCommand () {
0 commit comments