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

Commit

Permalink
v1.4.2 to fix bugs
Browse files Browse the repository at this point in the history
### 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`
  • Loading branch information
khoih-prog committed Oct 13, 2022
1 parent 0026e04 commit 24d88d4
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 231 deletions.
11 changes: 6 additions & 5 deletions CONTRIBUTING.md
Expand Up @@ -15,7 +15,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* 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.)
* `RP2040` Core Version (e.g. RP2040 core v2.6.0)
* `RP2040W` Board type (e.g. RASPBERRY_PI_PICO_W)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
Expand All @@ -27,13 +28,13 @@ Please ensure to specify the following:

```
Arduino IDE version: 1.8.19
RASPBERRY_PI_PICO board
ArduinoCore-mbed v3.0.1
RP2040 core v2.6.0
RASPBERRY_PI_PICO_W Module
OS: Ubuntu 20.04 LTS
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
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
Context:
The board couldn't autoreconnect to Local Blynk Server after router power recycling.
I encountered a crash while using this library
Steps to reproduce:
1. ...
Expand Down
113 changes: 59 additions & 54 deletions README.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions changelog.md
Expand Up @@ -13,6 +13,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v1.4.2](#releases-v142)
* [Releases v1.4.1](#releases-v141)
* [Releases v1.4.0](#releases-v140)
* [Releases v1.3.1](#releases-v131)
Expand All @@ -29,6 +30,12 @@

## Changelog

### 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](https://github.com/khoih-prog/MDNS_Generic/issues/13)
2. Fix bug in example [WiFiDiscoveringServices](https://github.com/khoih-prog/MDNS_Generic/tree/master/examples/WiFi/WiFiDiscoveringServices)
3. Update `Packages' Patches`

### Releases v1.4.1

1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00.
Expand Down
2 changes: 1 addition & 1 deletion examples/Ethernet/DiscoveringServices/defines.h
Expand Up @@ -26,7 +26,7 @@
#define MDNS_DEBUG_PORT Serial

// Debug Level from 0 to 4
#define _MDNS_LOGLEVEL_ 2
#define _MDNS_LOGLEVEL_ 1

#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \
|| defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \
Expand Down
2 changes: 1 addition & 1 deletion examples/Ethernet/ResolvingHostNames/defines.h
Expand Up @@ -26,7 +26,7 @@
#define MDNS_DEBUG_PORT Serial

// Debug Level from 0 to 4
#define _MDNS_LOGLEVEL_ 2
#define _MDNS_LOGLEVEL_ 1

#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \
|| defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \
Expand Down
153 changes: 68 additions & 85 deletions examples/WiFi/WiFiDiscoveringServices/WiFiDiscoveringServices.ino
@@ -1,23 +1,23 @@
/****************************************************************************************************************************
WiFiDiscoveringServices.ino
mDNS library to support mDNS (registering services) and DNS-SD (service discovery).
Based on and modified from https://github.com/arduino-libraries/ArduinoMDNS
Built by Khoi Hoang https://github.com/khoih-prog/MDNS_Generic
Licensed under MIT license
Original Author: Georg Kaindl (http://gkaindl.com)
This file is part of Arduino EthernetBonjour.
EthernetBonjour is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
EthernetBonjour is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with EthernetBonjour.
You should have received a copy of the GNU Lesser General Public License along with EthernetBonjour.
If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************************************************************/

Expand All @@ -32,22 +32,22 @@

#else
#if !defined(WIFI_NETWORK_TYPE)
// Select one, but WIFI_NETWORK_ESP
#warning You have to select a WiFi Network here, or default will be used => possibly creating error.
#define WIFI_NETWORK_TYPE NETWORK_WIFI_DEFAULT
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFININA
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFI101
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_ESPAT
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_ESP
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_PORTENTA_H7
// Select one, but WIFI_NETWORK_ESP
#warning You have to select a WiFi Network here, or default will be used => possibly creating error.

#define WIFI_NETWORK_TYPE NETWORK_WIFI_DEFAULT
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFININA
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFI101
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_ESPAT
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_ESP
//#define WIFI_NETWORK_TYPE WIFI_NETWORK_PORTENTA_H7
#endif

String hostname = BOARD_TYPE;

#endif

#if (WIFI_NETWORK_TYPE == WIFI_NETWORK_WIFININA)

#include <SPI.h>
#include <WiFiNINA_Generic.h>
#include <WiFiUdp_Generic.h>
Expand All @@ -56,6 +56,7 @@
WiFiServer server(80);

#elif (WIFI_NETWORK_TYPE == WIFI_NETWORK_WIFI101)

#include <SPI.h>
#include <WiFi101.h>
#include <WiFiUdp.h>
Expand Down Expand Up @@ -98,7 +99,7 @@
#else

#error You have to select an appropriate WiFi network type from the list

#endif

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

// This function is called when a name is resolved via mMDNS/Bonjour. We set
// this up in the setup() function above. The name you give to this callback
// 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) 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.
void serviceFound(const char* type, MDNSServiceProtocol /*proto*/,
const char* name, IPAddress ip,
unsigned short port,
const char* txtContent)
// 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
// 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)
// 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.
void serviceFound(const char* type, MDNSServiceProtocol /*proto*/, const char* name, IPAddress ip,
unsigned short port, const char* txtContent)
{
if (NULL == name)
if (NULL == name)
{
Serial.print("Finished discovering services of type ");
Serial.println(type);
}
else
}
else
{
Serial.print("Found: '");
Serial.print(name);
Serial.print("' at ");
Serial.print(ip);
Serial.print(", port ");
Serial.print(port);
Serial.println(" (TCP)");

// Check out http://www.zeroconf.org/Rendezvous/txtrecords.html for a
// primer on the structure of TXT records. Note that the Bonjour
// library will always return the txt content as a zero-terminated
// string, even if the specification does not require this.
if (txtContent)
Serial.print("Found: '"); Serial.print(name);
Serial.print("' at "); Serial.print(ip);
Serial.print(", port "); Serial.print(port); Serial.println(" (TCP)");

// Check out http://www.zeroconf.org/Rendezvous/txtrecords.html for a primer on the structure of TXT records. Note that the Bonjour
// library will always return the txt content as a zero-terminated string, even if the specification does not require this.
if (txtContent)
{
Serial.print("\ttxt record: ");

char buf[256];
char len = *txtContent++;
int i = 0;

while (len)
int i=0;
while (len)
{
i = 0;

while (len--)
buf[i++] = *txtContent++;

buf[i] = '\0';

Serial.print(buf);
len = *txtContent++;

if (len)
Serial.print(", ");
else
Expand All @@ -198,7 +187,7 @@ void setup()
{
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial);
while (!Serial && millis() < 5000);

Serial.print("\nStart WiFiDiscoveringServices on "); Serial.println(BOARD_NAME);
Serial.println(MDNS_GENERIC_VERSION);
Expand Down Expand Up @@ -238,18 +227,14 @@ void setup()
#endif

Serial.print("Attempting to connect to SSID: "); Serial.println(ssid);

WiFi.begin(ssid, pass);

delay(1000);

// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.status();

delay(1000);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}

printWifiStatus();
Expand Down Expand Up @@ -280,45 +265,43 @@ void setup()
}

void loop()
{
{
char serviceName[256];
int length = 0;

uint8_t length = 0;
// read in a service name from the Arduino IDE's serial monitor.
while (Serial.available())
while (Serial.available())
{
serviceName[length] = Serial.read();
length = (length + 1) % 256;
length = (length+1) % 256;
delay(5);
}

// Terminal adds "\r\n", need to remove
if (length > 1)
length = (length - 2) % 256;

serviceName[length] = '\0';

// You can use the "isDiscoveringService()" function to find out whether the
// mDNS library is currently discovering service instances.

// You can use the "isDiscoveringService()" function to find out whether the Bonjour library is currently discovering service instances.
// If so, we skip this input, since we want our previous request to continue.
if (!mdns.isDiscoveringService())
if (!mdns.isDiscoveringService())
{
if (length > 0)
if (length > 0)
{
Serial.print("Discovering services of type '");
Serial.print(serviceName);
Serial.println("' via Multi-Cast DNS (Bonjour)...");

// 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.
// The last argument is a duration (in milliseconds) for which we will
// search (specify 0 to run the discovery indefinitely).
// Note that the library will resend the discovery message every 10
// seconds, so if you search for longer than that, you will receive
// duplicate instances.
// 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.
// The last argument is a duration (in milliseconds) for which we will search (specify 0 to run the discovery indefinitely). Note that the library
// will resend the discovery message every 10 seconds, so if you search for longer than that, you will receive duplicate instances.

mdns.startDiscoveringService(serviceName, MDNSServiceTCP, 5000);
}
}
}

// This actually runs the mDNS module. YOU HAVE TO CALL THIS PERIODICALLY,
// This actually runs the Bonjour module. YOU HAVE TO CALL THIS PERIODICALLY,
// OR NOTHING WILL WORK!
// Preferably, call it once per loop().
mdns.run();
Expand Down
Expand Up @@ -179,13 +179,9 @@ void setup()

delay(1000);

// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.status();

delay(1000);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}

printWifiStatus();
Expand Down
Expand Up @@ -179,13 +179,9 @@ void setup()

delay(1000);

// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.status();

delay(1000);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}

printWifiStatus();
Expand Down
14 changes: 5 additions & 9 deletions examples/WiFi/WiFiResolvingHostNames/WiFiResolvingHostNames.ino
Expand Up @@ -140,8 +140,8 @@ void printWifiStatus()
// the name resolution timed out).
void nameFound(const char* name, IPAddress ip)
{
//if ( (ip[0] != 0) && (ip[1] != 0) && (ip[2] != 0) && (ip[3] != 0) )
if ( (ip[0] != 0) || (ip[1] != 0) || (ip[2] != 0) || (ip[3] != 0) )
if ( (ip[0] != 0) && (ip[1] != 0) && (ip[2] != 0) && (ip[3] != 0) )
//if ( (ip[0] != 0) || (ip[1] != 0) || (ip[2] != 0) || (ip[3] != 0) )
{
Serial.print("The IP address for '");
Serial.print(name);
Expand Down Expand Up @@ -216,13 +216,9 @@ void setup()

delay(1000);

// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.status();

delay(1000);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}

printWifiStatus();
Expand Down
2 changes: 1 addition & 1 deletion examples/WiFi/WiFiResolvingHostNames/defines.h
Expand Up @@ -26,7 +26,7 @@
#define SYSTEM_ENDIAN _ENDIAN_BIG_

#define MDNS_DEBUG_PORT Serial
#define _MDNS_LOGLEVEL_ 4
#define _MDNS_LOGLEVEL_ 1

#define DEBUG_WIFININA_PORT Serial
// Debug Level from 0 to 4
Expand Down

0 comments on commit 24d88d4

Please sign in to comment.