Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 24d88d4

Browse files
authored
v1.4.2 to fix bugs
### Releases v1.4.2 1. Fix bug in UDP length check and in WiFi example. Check [UDP Length check discards correct responses when resolving names - On Nano RP2040 Connect #13](#13) 2. Fix bug in example [WiFiDiscoveringServices](https://github.com/khoih-prog/MDNS_Generic/tree/master/examples/WiFi/WiFiDiscoveringServices) 3. Update `Packages' Patches`
1 parent 0026e04 commit 24d88d4

21 files changed

+350
-231
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP32 core v2.0.2, ESP8266 core v3.0.2, ArduinoCore-mbed v3.0.1, etc.)
18+
* `RP2040` Core Version (e.g. RP2040 core v2.6.0)
19+
* `RP2040W` Board type (e.g. RASPBERRY_PI_PICO_W)
1920
* Contextual information (e.g. what you were trying to achieve)
2021
* Simplest possible steps to reproduce
2122
* Anything that might be relevant in your opinion, such as:
@@ -27,13 +28,13 @@ Please ensure to specify the following:
2728

2829
```
2930
Arduino IDE version: 1.8.19
30-
RASPBERRY_PI_PICO board
31-
ArduinoCore-mbed v3.0.1
31+
RP2040 core v2.6.0
32+
RASPBERRY_PI_PICO_W Module
3233
OS: Ubuntu 20.04 LTS
33-
Linux xy-Inspiron-3593 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
34+
Linux xy-Inspiron-3593 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3435
3536
Context:
36-
The board couldn't autoreconnect to Local Blynk Server after router power recycling.
37+
I encountered a crash while using this library
3738
3839
Steps to reproduce:
3940
1. ...

README.md

Lines changed: 59 additions & 54 deletions
Large diffs are not rendered by default.

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
## Table of Contents
1414

1515
* [Changelog](#changelog)
16+
* [Releases v1.4.2](#releases-v142)
1617
* [Releases v1.4.1](#releases-v141)
1718
* [Releases v1.4.0](#releases-v140)
1819
* [Releases v1.3.1](#releases-v131)
@@ -29,6 +30,12 @@
2930

3031
## Changelog
3132

33+
### Releases v1.4.2
34+
35+
1. Fix bug in UDP length check and in WiFi example. Check [UDP Length check discards correct responses when resolving names - On Nano RP2040 Connect #13](https://github.com/khoih-prog/MDNS_Generic/issues/13)
36+
2. Fix bug in example [WiFiDiscoveringServices](https://github.com/khoih-prog/MDNS_Generic/tree/master/examples/WiFi/WiFiDiscoveringServices)
37+
3. Update `Packages' Patches`
38+
3239
### Releases v1.4.1
3340

3441
1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00.

examples/Ethernet/DiscoveringServices/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define MDNS_DEBUG_PORT Serial
2727

2828
// Debug Level from 0 to 4
29-
#define _MDNS_LOGLEVEL_ 2
29+
#define _MDNS_LOGLEVEL_ 1
3030

3131
#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \
3232
|| defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \

examples/Ethernet/ResolvingHostNames/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define MDNS_DEBUG_PORT Serial
2727

2828
// Debug Level from 0 to 4
29-
#define _MDNS_LOGLEVEL_ 2
29+
#define _MDNS_LOGLEVEL_ 1
3030

3131
#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \
3232
|| defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \

examples/WiFi/WiFiDiscoveringServices/WiFiDiscoveringServices.ino

Lines changed: 68 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/****************************************************************************************************************************
22
WiFiDiscoveringServices.ino
3-
3+
44
mDNS library to support mDNS (registering services) and DNS-SD (service discovery).
5-
5+
66
Based on and modified from https://github.com/arduino-libraries/ArduinoMDNS
77
Built by Khoi Hoang https://github.com/khoih-prog/MDNS_Generic
88
Licensed under MIT license
9-
9+
1010
Original Author: Georg Kaindl (http://gkaindl.com)
11-
11+
1212
This file is part of Arduino EthernetBonjour.
13-
13+
1414
EthernetBonjour is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
1515
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
16-
16+
1717
EthernetBonjour is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
1818
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
19-
20-
You should have received a copy of the GNU Lesser General Public License along with EthernetBonjour.
19+
20+
You should have received a copy of the GNU Lesser General Public License along with EthernetBonjour.
2121
If not, see <http://www.gnu.org/licenses/>.
2222
*****************************************************************************************************************************/
2323

@@ -32,22 +32,22 @@
3232

3333
#else
3434
#if !defined(WIFI_NETWORK_TYPE)
35-
// Select one, but WIFI_NETWORK_ESP
36-
#warning You have to select a WiFi Network here, or default will be used => possibly creating error.
37-
38-
#define WIFI_NETWORK_TYPE NETWORK_WIFI_DEFAULT
39-
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFININA
40-
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFI101
41-
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_ESPAT
42-
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_ESP
43-
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_PORTENTA_H7
35+
// Select one, but WIFI_NETWORK_ESP
36+
#warning You have to select a WiFi Network here, or default will be used => possibly creating error.
37+
38+
#define WIFI_NETWORK_TYPE NETWORK_WIFI_DEFAULT
39+
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFININA
40+
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFI101
41+
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_ESPAT
42+
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_ESP
43+
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_PORTENTA_H7
4444
#endif
45-
45+
4646
String hostname = BOARD_TYPE;
47-
4847
#endif
4948

5049
#if (WIFI_NETWORK_TYPE == WIFI_NETWORK_WIFININA)
50+
5151
#include <SPI.h>
5252
#include <WiFiNINA_Generic.h>
5353
#include <WiFiUdp_Generic.h>
@@ -56,6 +56,7 @@
5656
WiFiServer server(80);
5757

5858
#elif (WIFI_NETWORK_TYPE == WIFI_NETWORK_WIFI101)
59+
5960
#include <SPI.h>
6061
#include <WiFi101.h>
6162
#include <WiFiUdp.h>
@@ -98,7 +99,7 @@
9899
#else
99100

100101
#error You have to select an appropriate WiFi network type from the list
101-
102+
102103
#endif
103104

104105
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
@@ -134,57 +135,45 @@ void printWifiStatus()
134135
Serial.println(" dBm");
135136
}
136137

137-
// This function is called when a name is resolved via mMDNS/Bonjour. We set
138-
// this up in the setup() function above. The name you give to this callback
139-
// function does not matter at all, but it must take exactly these arguments
140-
// as below.
141-
// If a service is discovered, name, ipAddr, port and (if available) txtContent
142-
// will be set.
143-
// If your specified discovery timeout is reached, the function will be called
144-
// with name (and all successive arguments) being set to NULL.
145-
void serviceFound(const char* type, MDNSServiceProtocol /*proto*/,
146-
const char* name, IPAddress ip,
147-
unsigned short port,
148-
const char* txtContent)
138+
// This function is called when a name is resolved via MDNS/Bonjour. We set this up in the setup() function above. The name you give to this callback
139+
// function does not matter at all, but it must take exactly these arguments as below. If a service is discovered, name, ipAddr, port and (if available)
140+
// txtContent will be set. If your specified discovery timeout is reached, the function will be called with name (and all successive arguments) being set to NULL.
141+
void serviceFound(const char* type, MDNSServiceProtocol /*proto*/, const char* name, IPAddress ip,
142+
unsigned short port, const char* txtContent)
149143
{
150-
if (NULL == name)
144+
if (NULL == name)
151145
{
152146
Serial.print("Finished discovering services of type ");
153147
Serial.println(type);
154-
}
155-
else
148+
}
149+
else
156150
{
157-
Serial.print("Found: '");
158-
Serial.print(name);
159-
Serial.print("' at ");
160-
Serial.print(ip);
161-
Serial.print(", port ");
162-
Serial.print(port);
163-
Serial.println(" (TCP)");
164-
165-
// Check out http://www.zeroconf.org/Rendezvous/txtrecords.html for a
166-
// primer on the structure of TXT records. Note that the Bonjour
167-
// library will always return the txt content as a zero-terminated
168-
// string, even if the specification does not require this.
169-
if (txtContent)
151+
Serial.print("Found: '"); Serial.print(name);
152+
Serial.print("' at "); Serial.print(ip);
153+
Serial.print(", port "); Serial.print(port); Serial.println(" (TCP)");
154+
155+
// Check out http://www.zeroconf.org/Rendezvous/txtrecords.html for a primer on the structure of TXT records. Note that the Bonjour
156+
// library will always return the txt content as a zero-terminated string, even if the specification does not require this.
157+
if (txtContent)
170158
{
171159
Serial.print("\ttxt record: ");
172-
160+
173161
char buf[256];
174162
char len = *txtContent++;
175-
int i = 0;
176-
177-
while (len)
163+
int i=0;
164+
165+
while (len)
178166
{
179167
i = 0;
180-
168+
181169
while (len--)
182170
buf[i++] = *txtContent++;
183-
171+
184172
buf[i] = '\0';
173+
185174
Serial.print(buf);
186175
len = *txtContent++;
187-
176+
188177
if (len)
189178
Serial.print(", ");
190179
else
@@ -198,7 +187,7 @@ void setup()
198187
{
199188
//Initialize serial and wait for port to open:
200189
Serial.begin(115200);
201-
while (!Serial);
190+
while (!Serial && millis() < 5000);
202191

203192
Serial.print("\nStart WiFiDiscoveringServices on "); Serial.println(BOARD_NAME);
204193
Serial.println(MDNS_GENERIC_VERSION);
@@ -238,18 +227,14 @@ void setup()
238227
#endif
239228

240229
Serial.print("Attempting to connect to SSID: "); Serial.println(ssid);
241-
230+
242231
WiFi.begin(ssid, pass);
243-
232+
244233
delay(1000);
245-
246-
// attempt to connect to Wifi network:
247-
while (status != WL_CONNECTED)
248-
{
249-
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
250-
status = WiFi.status();
251234

252-
delay(1000);
235+
while (WiFi.status() != WL_CONNECTED)
236+
{
237+
delay(500);
253238
}
254239

255240
printWifiStatus();
@@ -280,45 +265,43 @@ void setup()
280265
}
281266

282267
void loop()
283-
{
268+
{
284269
char serviceName[256];
285-
int length = 0;
286-
270+
uint8_t length = 0;
271+
287272
// read in a service name from the Arduino IDE's serial monitor.
288-
while (Serial.available())
273+
while (Serial.available())
289274
{
290275
serviceName[length] = Serial.read();
291-
length = (length + 1) % 256;
276+
length = (length+1) % 256;
292277
delay(5);
293278
}
294279

280+
// Terminal adds "\r\n", need to remove
281+
if (length > 1)
282+
length = (length - 2) % 256;
283+
295284
serviceName[length] = '\0';
296-
297-
// You can use the "isDiscoveringService()" function to find out whether the
298-
// mDNS library is currently discovering service instances.
285+
286+
// You can use the "isDiscoveringService()" function to find out whether the Bonjour library is currently discovering service instances.
299287
// If so, we skip this input, since we want our previous request to continue.
300-
if (!mdns.isDiscoveringService())
288+
if (!mdns.isDiscoveringService())
301289
{
302-
if (length > 0)
290+
if (length > 0)
303291
{
304292
Serial.print("Discovering services of type '");
305293
Serial.print(serviceName);
306294
Serial.println("' via Multi-Cast DNS (Bonjour)...");
307295

308-
// Now we tell the mDNS library to discover the service. Below, I have
309-
// hardcoded the TCP protocol, but you can also specify to discover UDP
310-
// services.
311-
// The last argument is a duration (in milliseconds) for which we will
312-
// search (specify 0 to run the discovery indefinitely).
313-
// Note that the library will resend the discovery message every 10
314-
// seconds, so if you search for longer than that, you will receive
315-
// duplicate instances.
296+
// Now we tell the mDNS library to discover the service. Below, I have hardcoded the TCP protocol, but you can also specify to discover UDP services.
297+
// The last argument is a duration (in milliseconds) for which we will search (specify 0 to run the discovery indefinitely). Note that the library
298+
// will resend the discovery message every 10 seconds, so if you search for longer than that, you will receive duplicate instances.
316299

317300
mdns.startDiscoveringService(serviceName, MDNSServiceTCP, 5000);
318-
}
301+
}
319302
}
320303

321-
// This actually runs the mDNS module. YOU HAVE TO CALL THIS PERIODICALLY,
304+
// This actually runs the Bonjour module. YOU HAVE TO CALL THIS PERIODICALLY,
322305
// OR NOTHING WILL WORK!
323306
// Preferably, call it once per loop().
324307
mdns.run();

examples/WiFi/WiFiRegisteringServices/WiFiRegisteringServices.ino

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,9 @@ void setup()
179179

180180
delay(1000);
181181

182-
// attempt to connect to Wifi network:
183-
while (status != WL_CONNECTED)
184-
{
185-
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
186-
status = WiFi.status();
187-
188-
delay(1000);
182+
while (WiFi.status() != WL_CONNECTED)
183+
{
184+
delay(500);
189185
}
190186

191187
printWifiStatus();

examples/WiFi/WiFiRegisteringServicesWithTxtRecord/WiFiRegisteringServicesWithTxtRecord.ino

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,9 @@ void setup()
179179

180180
delay(1000);
181181

182-
// attempt to connect to Wifi network:
183-
while (status != WL_CONNECTED)
184-
{
185-
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
186-
status = WiFi.status();
187-
188-
delay(1000);
182+
while (WiFi.status() != WL_CONNECTED)
183+
{
184+
delay(500);
189185
}
190186

191187
printWifiStatus();

examples/WiFi/WiFiResolvingHostNames/WiFiResolvingHostNames.ino

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ void printWifiStatus()
140140
// the name resolution timed out).
141141
void nameFound(const char* name, IPAddress ip)
142142
{
143-
//if ( (ip[0] != 0) && (ip[1] != 0) && (ip[2] != 0) && (ip[3] != 0) )
144-
if ( (ip[0] != 0) || (ip[1] != 0) || (ip[2] != 0) || (ip[3] != 0) )
143+
if ( (ip[0] != 0) && (ip[1] != 0) && (ip[2] != 0) && (ip[3] != 0) )
144+
//if ( (ip[0] != 0) || (ip[1] != 0) || (ip[2] != 0) || (ip[3] != 0) )
145145
{
146146
Serial.print("The IP address for '");
147147
Serial.print(name);
@@ -216,13 +216,9 @@ void setup()
216216

217217
delay(1000);
218218

219-
// attempt to connect to Wifi network:
220-
while (status != WL_CONNECTED)
221-
{
222-
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
223-
status = WiFi.status();
224-
225-
delay(1000);
219+
while (WiFi.status() != WL_CONNECTED)
220+
{
221+
delay(500);
226222
}
227223

228224
printWifiStatus();

examples/WiFi/WiFiResolvingHostNames/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define SYSTEM_ENDIAN _ENDIAN_BIG_
2727

2828
#define MDNS_DEBUG_PORT Serial
29-
#define _MDNS_LOGLEVEL_ 4
29+
#define _MDNS_LOGLEVEL_ 1
3030

3131
#define DEBUG_WIFININA_PORT Serial
3232
// Debug Level from 0 to 4

0 commit comments

Comments
 (0)