@@ -142,26 +142,39 @@ MDNSResponder::~MDNSResponder() {
142
142
_answers = 0 ;
143
143
}
144
144
145
- bool MDNSResponder::begin (const char * hostname){
146
- size_t n = strlen (hostname);
145
+ bool MDNSResponder::begin (const char * hostName){
146
+ return _begin (hostName, 0 , 120 );
147
+ }
148
+
149
+ bool MDNSResponder::begin (const char * hostName, IPAddress ip, uint32_t ttl){
150
+ return _begin (hostName, ip, ttl);
151
+ }
152
+
153
+ bool MDNSResponder::_begin (const char *hostName, uint32_t ip, uint32_t ttl){
154
+ size_t n = strlen (hostName);
147
155
if (n > 63 ) { // max size for a single label.
148
156
return false ;
149
157
}
150
158
159
+ _ip = ip;
160
+
151
161
// Copy in hostname characters as lowercase
152
- _hostName = hostname ;
162
+ _hostName = hostName ;
153
163
_hostName.toLowerCase ();
154
164
155
165
// If instance name is not already set copy hostname to instance name
156
- if (_instanceName.equals (" " ) ) _instanceName=hostname ;
166
+ if (_instanceName.equals (" " ) ) _instanceName=hostName ;
157
167
158
- _gotIPHandler = WiFi.onStationModeGotIP ([this ](const WiFiEventStationModeGotIP& event){
159
- _restart ();
160
- });
168
+ // only if the IP hasn't been set manually, use the events
169
+ if (ip == 0 ) {
170
+ _gotIPHandler = WiFi.onStationModeGotIP ([this ](const WiFiEventStationModeGotIP& event){
171
+ _restart ();
172
+ });
161
173
162
- _disconnectedHandler = WiFi.onStationModeDisconnected ([this ](const WiFiEventStationModeDisconnected& event) {
163
- _restart ();
164
- });
174
+ _disconnectedHandler = WiFi.onStationModeDisconnected ([this ](const WiFiEventStationModeDisconnected& event) {
175
+ _restart ();
176
+ });
177
+ }
165
178
166
179
return _listen ();
167
180
}
@@ -442,7 +455,11 @@ uint16_t MDNSResponder::_getServicePort(char *name, char *proto){
442
455
443
456
uint32_t MDNSResponder::_getOurIp (){
444
457
int mode = wifi_get_opmode ();
445
- if (mode & STATION_MODE){
458
+
459
+ // if has a manually set IP use this
460
+ if (_ip){
461
+ return _ip;
462
+ } else if (mode & STATION_MODE){
446
463
struct ip_info staIpInfo;
447
464
wifi_get_ip_info (STATION_IF, &staIpInfo);
448
465
return staIpInfo.ip .addr ;
0 commit comments