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

Commit 65644f2

Browse files
authored
v2.0.0 for (ESP32 + LwIP W5500)
### Initial Releases v2.0.0 1. Initial coding to port [AsyncUDP](https://github.com/espressif/arduino-esp32/tree/master/libraries/AsyncUDP) to ESP32 boards using `LwIP W5500 Ethernet` 2. Add more examples. 3. Add debugging features. 4. Bump up to v2.0.0 to sync with [AsyncUDP v2.0.0](https://github.com/espressif/arduino-esp32/tree/master/libraries/AsyncUDP)
1 parent b7324ec commit 65644f2

23 files changed

+3393
-4
lines changed

.codespellrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# See: https://github.com/codespell-project/codespell#using-a-config-file
2+
[codespell]
3+
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
4+
ignore-words-list = ,
5+
check-filenames =
6+
check-hidden =
7+
skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches

CONTRIBUTING.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
## Contributing to AsyncUDP_ESP32_W5500
2+
3+
### Reporting Bugs
4+
5+
Please report bugs in AsyncUDP_ESP32_W5500 if you find them.
6+
7+
However, before reporting a bug please check through the following:
8+
9+
* [Existing Open Issues](https://github.com/khoih-prog/AsyncUDP_ESP32_W5500/issues) - someone might have already encountered this.
10+
11+
If you don't find anything, please [open a new issue](https://github.com/khoih-prog/AsyncUDP_ESP32_W5500/issues/new).
12+
13+
### How to submit a bug report
14+
15+
Please ensure to specify the following:
16+
17+
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18+
* `ESP32` Core Version (e.g. ESP32 v2.0.5)
19+
* Contextual information (e.g. what you were trying to achieve)
20+
* Simplest possible steps to reproduce
21+
* Anything that might be relevant in your opinion, such as:
22+
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
23+
* Network configuration
24+
25+
26+
### Example
27+
28+
```
29+
Arduino IDE version: 1.8.19
30+
ESP32 Core Version 2.0.5
31+
OS: Ubuntu 20.04 LTS
32+
Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
33+
34+
Context:
35+
I encountered a crash while using this library
36+
Steps to reproduce:
37+
1. ...
38+
2. ...
39+
3. ...
40+
4. ...
41+
```
42+
43+
### Additional context
44+
45+
Add any other context about the problem here.
46+
47+
---
48+
49+
### Sending Feature Requests
50+
51+
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
52+
53+
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncUDP_ESP32_W5500/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
54+
55+
---
56+
57+
### Sending Pull Requests
58+
59+
Pull Requests with changes and fixes are also welcome!
60+
61+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
62+
63+
1. Change directory to the library GitHub
64+
65+
```
66+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncUDP_ESP32_W5500_GitHub/
67+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncUDP_ESP32_W5500_GitHub$
68+
```
69+
70+
2. Issue astyle command
71+
72+
```
73+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncUDP_ESP32_W5500_GitHub$ bash utils/restyle.sh
74+
```
75+

LICENSE

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GNU GENERAL PUBLIC LICENSE
22
Version 3, 29 June 2007
33

4-
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
4+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
55
Everyone is permitted to copy and distribute verbatim copies
66
of this license document, but changing it is not allowed.
77

@@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
645645
GNU General Public License for more details.
646646

647647
You should have received a copy of the GNU General Public License
648-
along with this program. If not, see <https://www.gnu.org/licenses/>.
648+
along with this program. If not, see <http://www.gnu.org/licenses/>.
649649

650650
Also add information on how to contact you by electronic and paper mail.
651651

@@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
664664
You should also get your employer (if you work as a programmer) or school,
665665
if any, to sign a "copyright disclaimer" for the program, if necessary.
666666
For more information on this, and how to apply and follow the GNU GPL, see
667-
<https://www.gnu.org/licenses/>.
667+
<http://www.gnu.org/licenses/>.
668668

669669
The GNU General Public License does not permit incorporating your program
670670
into proprietary programs. If your program is a subroutine library, you
671671
may consider it more useful to permit linking proprietary applications with
672672
the library. If this is what you want to do, use the GNU Lesser General
673673
Public License instead of this License. But first, please read
674-
<https://www.gnu.org/licenses/why-not-lgpl.html>.
674+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Server.h - Base class that provides Server
3+
Copyright (c) 2011 Adrian McEwen. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef server_h
21+
#define server_h
22+
23+
#include "Print.h"
24+
25+
class Server: public Print
26+
{
27+
public:
28+
// KH, change to fix compiler error for EthernetWebServer
29+
// error: cannot declare field 'EthernetWebServer::_server' to be of abstract type 'EthernetServer'
30+
// virtual void begin(uint16_t port=0) =0;
31+
//virtual void begin() = 0;
32+
void begin() {};
33+
};
34+
35+
#endif

changelog.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# AsyncUDP_ESP32_W5500
2+
3+
4+
[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncUDP_ESP32_W5500.svg?)](https://www.ardu-badge.com/AsyncUDP_ESP32_W5500)
5+
[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncUDP_ESP32_W5500.svg)](https://github.com/khoih-prog/AsyncUDP_ESP32_W5500/releases)
6+
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
7+
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncUDP_ESP32_W5500.svg)](http://github.com/khoih-prog/AsyncUDP_ESP32_W5500/issues)
8+
9+
10+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
11+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
12+
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
13+
<a href="https://profile-counter.glitch.me/khoih-prog-AsyncUDP_ESP32_W5500/count.svg" title="Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-AsyncUDP_ESP32_W5500/count.svg" style="height: 30px;width: 200px;"></a>
14+
15+
---
16+
---
17+
18+
## Table of Contents
19+
20+
* [Changelog](#changelog)
21+
* [Initial Releases v2.0.0](#initial-releases-v200)
22+
23+
---
24+
---
25+
26+
## Changelog
27+
28+
### Initial Releases v2.0.0
29+
30+
1. Initial coding to port [AsyncUDP](https://github.com/espressif/arduino-esp32/tree/master/libraries/AsyncUDP) to ESP32 boards using `LwIP W5500 Ethernet`
31+
2. Add more examples.
32+
3. Add debugging features.
33+
4. Bump up to v2.0.0 to sync with [AsyncUDP v2.0.0](https://github.com/espressif/arduino-esp32/tree/master/libraries/AsyncUDP).
34+
35+
+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/****************************************************************************************************************************
2+
Async_UdpClient.ino
3+
4+
AsyncUDP_ESP32_W5500 is a Async UDP library for the ESP32_W5500 (ESP32 + LwIP W5500)
5+
6+
Based on and modified from ESPAsyncUDP Library (https://github.com/me-no-dev/ESPAsyncUDP)
7+
Built by Khoi Hoang https://github.com/khoih-prog/AsyncUDP_ESP32_W5500
8+
Licensed under GPLv3 license
9+
*****************************************************************************************************************************/
10+
11+
#if !( defined(ESP32) )
12+
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
13+
#endif
14+
15+
#include <Arduino.h>
16+
17+
#define ASYNC_UDP_ESP32_W5500_DEBUG_PORT Serial
18+
19+
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
20+
#define _ASYNC_UDP_ESP32_W5500_LOGLEVEL_ 1
21+
22+
//////////////////////////////////////////////////////////
23+
24+
// Optional values to override default settings
25+
// Don't change unless you know what you're doing
26+
//#define ETH_SPI_HOST SPI3_HOST
27+
//#define SPI_CLOCK_MHZ 25
28+
29+
// Must connect INT to GPIOxx or not working
30+
//#define INT_GPIO 4
31+
32+
//#define MISO_GPIO 19
33+
//#define MOSI_GPIO 23
34+
//#define SCK_GPIO 18
35+
//#define CS_GPIO 5
36+
37+
//////////////////////////////////////////////////////////
38+
39+
#include <AsyncUDP_ESP32_W5500.h>
40+
41+
IPAddress remoteIPAddress = IPAddress(192, 168, 2, 112);
42+
43+
#define UDP_REMOTE_PORT 5698
44+
45+
/////////////////////////////////////////////
46+
47+
// Enter a MAC address and IP address for your controller below.
48+
#define NUMBER_OF_MAC 20
49+
50+
byte mac[][NUMBER_OF_MAC] =
51+
{
52+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
53+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
54+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
55+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
56+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
57+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
58+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
59+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
60+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
61+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
62+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
63+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
64+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
65+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
66+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
67+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
68+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
69+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
70+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
71+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
72+
};
73+
74+
// Select the IP address according to your local network
75+
IPAddress myIP(192, 168, 2, 232);
76+
IPAddress myGW(192, 168, 2, 1);
77+
IPAddress mySN(255, 255, 255, 0);
78+
79+
// Google DNS Server IP
80+
IPAddress myDNS(8, 8, 8, 8);
81+
82+
/////////////////////////////////////////////
83+
84+
AsyncUDP udp;
85+
86+
void parsePacket(AsyncUDPPacket packet)
87+
{
88+
Serial.print("UDP Packet Type: ");
89+
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
90+
Serial.print(", From: ");
91+
Serial.print(packet.remoteIP());
92+
Serial.print(":");
93+
Serial.print(packet.remotePort());
94+
Serial.print(", To: ");
95+
Serial.print(packet.localIP());
96+
Serial.print(":");
97+
Serial.print(packet.localPort());
98+
Serial.print(", Length: ");
99+
Serial.print(packet.length());
100+
Serial.print(", Data: ");
101+
Serial.write(packet.data(), packet.length());
102+
Serial.println();
103+
//reply to the client
104+
packet.printf("Got %u bytes of data", packet.length());
105+
}
106+
107+
void setup()
108+
{
109+
Serial.begin(115200);
110+
111+
while (!Serial && (millis() < 5000));
112+
113+
Serial.print(F("\nStart Async_UDPClient on "));
114+
Serial.print(ARDUINO_BOARD);
115+
Serial.print(F(" with "));
116+
Serial.println(SHIELD_TYPE);
117+
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
118+
Serial.println(ASYNC_UDP_ESP32_W5500_VERSION);
119+
120+
Serial.setDebugOutput(true);
121+
122+
UDP_LOGWARN(F("Default SPI pinout:"));
123+
UDP_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
124+
UDP_LOGWARN1(F("MOSI:"), MOSI_GPIO);
125+
UDP_LOGWARN1(F("MISO:"), MISO_GPIO);
126+
UDP_LOGWARN1(F("SCK:"), SCK_GPIO);
127+
UDP_LOGWARN1(F("CS:"), CS_GPIO);
128+
UDP_LOGWARN1(F("INT:"), INT_GPIO);
129+
UDP_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
130+
UDP_LOGWARN(F("========================="));
131+
132+
///////////////////////////////////
133+
134+
// To be called before ETH.begin()
135+
ESP32_W5500_onEvent();
136+
137+
// start the ethernet connection and the server:
138+
// Use DHCP dynamic IP and random mac
139+
uint16_t index = millis() % NUMBER_OF_MAC;
140+
141+
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
142+
// int SPI_HOST, uint8_t *W5500_Mac = W5500_Default_Mac);
143+
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
144+
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[index] );
145+
146+
// Static IP, leave without this line to get IP via DHCP
147+
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
148+
//ETH.config(myIP, myGW, mySN, myDNS);
149+
150+
ESP32_W5500_waitForConnect();
151+
152+
///////////////////////////////////
153+
154+
// Client address
155+
Serial.print("Async_UDPClient started @ IP address: ");
156+
Serial.println(ETH.localIP());
157+
158+
if (udp.connect(remoteIPAddress, UDP_REMOTE_PORT))
159+
{
160+
Serial.println("UDP connected");
161+
162+
udp.onPacket([](AsyncUDPPacket packet)
163+
{
164+
parsePacket( packet);
165+
});
166+
167+
//Send unicast
168+
udp.print("Hello Server!");
169+
}
170+
}
171+
172+
void loop()
173+
{
174+
delay(10000);
175+
//Send broadcast on port UDP_REMOTE_PORT = 1234
176+
udp.broadcastTo("Anyone here?", UDP_REMOTE_PORT);
177+
}

0 commit comments

Comments
 (0)