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

Commit d01a89e

Browse files
authored
v2.0.0 for ESP32 + LwIP W6100
### 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 W6100 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 7d01d8a commit d01a89e

23 files changed

+3428
-0
lines changed

.codespellrc

Lines changed: 7 additions & 0 deletions
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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
## Contributing to AsyncUDP_ESP32_W6100
2+
3+
### Reporting Bugs
4+
5+
Please report bugs in AsyncUDP_ESP32_W6100 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_W6100/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_W6100/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+
* Board Core Version (e.g. ESP32 core v2.0.6)
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+
Please be educated, civilized and constructive as you've always been. Disrespective posts against [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-event-code-of-conduct) will be ignored and deleted.
27+
28+
---
29+
30+
### Example
31+
32+
```
33+
Arduino IDE version: 1.8.19
34+
ESP32_DEV board
35+
ESP32 core v2.0.6
36+
OS: Ubuntu 20.04 LTS
37+
Linux xy-Inspiron-3593 5.15.0-57-generic #63~20.04.1-Ubuntu SMP Wed Nov 30 13:40:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
38+
39+
Context:
40+
I encountered a crash while using this library
41+
Steps to reproduce:
42+
1. ...
43+
2. ...
44+
3. ...
45+
4. ...
46+
```
47+
48+
---
49+
50+
### Additional context
51+
52+
Add any other context about the problem here.
53+
54+
---
55+
56+
### Sending Feature Requests
57+
58+
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
59+
60+
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncUDP_ESP32_W6100/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
61+
62+
---
63+
64+
### Sending Pull Requests
65+
66+
Pull Requests with changes and fixes are also welcome!
67+
68+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
69+
70+
1. Change directory to the library GitHub
71+
72+
```
73+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncUDP_ESP32_W6100_GitHub/
74+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncUDP_ESP32_W6100_GitHub$
75+
```
76+
77+
2. Issue astyle command
78+
79+
```
80+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncUDP_ESP32_W6100_GitHub$ bash utils/restyle.sh
81+
```
82+
Lines changed: 35 additions & 0 deletions
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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# AsyncUDP_ESP32_W6100
2+
3+
4+
[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncUDP_ESP32_W6100.svg?)](https://www.ardu-badge.com/AsyncUDP_ESP32_W6100)
5+
[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncUDP_ESP32_W6100.svg)](https://github.com/khoih-prog/AsyncUDP_ESP32_W6100/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_W6100.svg)](http://github.com/khoih-prog/AsyncUDP_ESP32_W6100/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+
13+
---
14+
---
15+
16+
## Table of Contents
17+
18+
* [Changelog](#changelog)
19+
* [Initial Releases v2.0.0](#initial-releases-v200)
20+
21+
---
22+
---
23+
24+
## Changelog
25+
26+
### Initial Releases v2.0.0
27+
28+
1. Initial coding to port [AsyncUDP](https://github.com/espressif/arduino-esp32/tree/master/libraries/AsyncUDP) to ESP32 boards using `LwIP W6100 Ethernet`
29+
2. Add more examples.
30+
3. Add debugging features.
31+
4. Bump up to v2.0.0 to sync with [AsyncUDP v2.0.0](https://github.com/espressif/arduino-esp32/tree/master/libraries/AsyncUDP).
32+
33+
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/****************************************************************************************************************************
2+
Async_UdpClient.ino
3+
4+
AsyncUDP_ESP32_W6100 is a Async UDP library for the ESP32_W6100 (ESP32 + LwIP W6100)
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_W6100
8+
Licensed under GPLv3 license
9+
*****************************************************************************************************************************/
10+
11+
#if !( defined(ESP32) )
12+
#error This code is designed for (ESP32 + W6100) to run on ESP32 platform! Please check your Tools->Board setting.
13+
#endif
14+
15+
#include <Arduino.h>
16+
17+
#define ASYNC_UDP_ESP32_W6100_DEBUG_PORT Serial
18+
19+
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
20+
#define _ASYNC_UDP_ESP32_W6100_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_W6100.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_W6100_VERSION);
118+
Serial.println(ASYNC_UDP_ESP32_W6100_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_W6100_onEvent();
136+
137+
// start the ethernet connection and the server:
138+
// Use DHCP dynamic IP and random mac
139+
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
140+
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
141+
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
142+
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
143+
144+
// Static IP, leave without this line to get IP via DHCP
145+
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
146+
//ETH.config(myIP, myGW, mySN, myDNS);
147+
148+
ESP32_W6100_waitForConnect();
149+
150+
///////////////////////////////////
151+
152+
// Client address
153+
Serial.print("Async_UDPClient started @ IP address: ");
154+
Serial.println(ETH.localIP());
155+
156+
if (udp.connect(remoteIPAddress, UDP_REMOTE_PORT))
157+
{
158+
Serial.println("UDP connected");
159+
160+
udp.onPacket([](AsyncUDPPacket packet)
161+
{
162+
parsePacket( packet);
163+
});
164+
165+
//Send unicast
166+
udp.print("Hello Server!");
167+
}
168+
}
169+
170+
void loop()
171+
{
172+
delay(10000);
173+
//Send broadcast on port UDP_REMOTE_PORT = 1234
174+
udp.broadcastTo("Anyone here?", UDP_REMOTE_PORT);
175+
}

0 commit comments

Comments
 (0)