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

Commit

Permalink
v2.0.0 for (ESP32 + LwIP ENC28J60)
Browse files Browse the repository at this point in the history
### 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 ENC28J60 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)
  • Loading branch information
khoih-prog authored Nov 28, 2022
1 parent a210cbf commit 6647e6a
Show file tree
Hide file tree
Showing 22 changed files with 3,375 additions and 4 deletions.
75 changes: 75 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
## Contributing to AsyncUdp_ESP32_ENC

### Reporting Bugs

Please report bugs in AsyncUdp_ESP32_ENC if you find them.

However, before reporting a bug please check through the following:

* [Existing Open Issues](https://github.com/khoih-prog/AsyncUdp_ESP32_ENC/issues) - someone might have already encountered this.

If you don't find anything, please [open a new issue](https://github.com/khoih-prog/AsyncUdp_ESP32_ENC/issues/new).

### How to submit a bug report

Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* `ESP32` Core Version (e.g. ESP32 v2.0.5)
* 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:
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
* Network configuration


### Example

```
Arduino IDE version: 1.8.19
ESP32 Core Version 2.0.5
OS: Ubuntu 20.04 LTS
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
Context:
I encountered a crash while using this library
Steps to reproduce:
1. ...
2. ...
3. ...
4. ...
```

### Additional context

Add any other context about the problem here.

---

### Sending Feature Requests

Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.

There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncUdp_ESP32_ENC/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.

---

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)

1. Change directory to the library GitHub

```
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncUdp_ESP32_ENC_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncUdp_ESP32_ENC_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncUdp_ESP32_ENC_GitHub$ bash utils/restyle.sh
```

8 changes: 4 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

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

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

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

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

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

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
35 changes: 35 additions & 0 deletions LibraryPatches/esp32/cores/esp32/Server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Server.h - Base class that provides Server
Copyright (c) 2011 Adrian McEwen. All right reserved.
This library 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 2.1 of the License, or (at your option) any later version.
This library 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 this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef server_h
#define server_h

#include "Print.h"

class Server: public Print
{
public:
// KH, change to fix compiler error for EthernetWebServer
// error: cannot declare field 'EthernetWebServer::_server' to be of abstract type 'EthernetServer'
// virtual void begin(uint16_t port=0) =0;
//virtual void begin() = 0;
void begin() {};
};

#endif
35 changes: 35 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# AsyncUdp_ESP32_ENC


[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncUdp_ESP32_ENC.svg?)](https://www.ardu-badge.com/AsyncUdp_ESP32_ENC)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncUdp_ESP32_ENC.svg)](https://github.com/khoih-prog/AsyncUdp_ESP32_ENC/releases)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncUdp_ESP32_ENC.svg)](http://github.com/khoih-prog/AsyncUdp_ESP32_ENC/issues)


<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>
<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>
<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>
<a href="https://profile-counter.glitch.me/khoih-prog-AsyncUdp_ESP32_ENC/count.svg" title="Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-AsyncUdp_ESP32_ENC/count.svg" style="height: 30px;width: 200px;"></a>

---
---

## Table of Contents

* [Changelog](#changelog)
* [Initial Releases v2.0.0](#initial-releases-v200)

---
---

## Changelog

### 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 ENC28J60 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).


175 changes: 175 additions & 0 deletions examples/AsyncUDPClient/AsyncUDPClient.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/****************************************************************************************************************************
Async_UdpClient.ino
AsyncUDP_ESP32_ENC is a Async UDP library for the the ESP32 with Ethernet ENC28J60
Based on and modified from ESPAsyncUDP Library (https://github.com/me-no-dev/ESPAsyncUDP)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncUDP_ESP32_ENC
Licensed under GPLv3 license
*****************************************************************************************************************************/

#if !( defined(ESP32) )
#error This code is designed for (ESP32 + ENC28J60) to run on ESP32 platform! Please check your Tools->Board setting.
#endif

#include <Arduino.h>

#define ASYNC_UDP_ESP32_ENC_DEBUG_PORT Serial

// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_UDP_ESP32_ENC_LOGLEVEL_ 1

//////////////////////////////////////////////////////////

// Optional values to override default settings
//#define SPI_HOST 1
//#define SPI_CLOCK_MHZ 8

// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4

//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5

//////////////////////////////////////////////////////////

#include <AsyncUDP_ESP32_ENC.h>

IPAddress remoteIPAddress = IPAddress(192, 168, 2, 112);

#define UDP_REMOTE_PORT 5698

/////////////////////////////////////////////

// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20

byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};

// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);

// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);

/////////////////////////////////////////////

AsyncUDP udp;

void parsePacket(AsyncUDPPacket packet)
{
Serial.print("UDP Packet Type: ");
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
Serial.print(", From: ");
Serial.print(packet.remoteIP());
Serial.print(":");
Serial.print(packet.remotePort());
Serial.print(", To: ");
Serial.print(packet.localIP());
Serial.print(":");
Serial.print(packet.localPort());
Serial.print(", Length: ");
Serial.print(packet.length());
Serial.print(", Data: ");
Serial.write(packet.data(), packet.length());
Serial.println();
//reply to the client
packet.printf("Got %u bytes of data", packet.length());
}

void setup()
{
Serial.begin(115200);

while (!Serial && (millis() < 5000));

Serial.print(F("\nStart Async_UDPClient on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_ENC_VERSION);
Serial.println(ASYNC_UDP_ESP32_ENC_VERSION);

Serial.setDebugOutput(true);

ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));

///////////////////////////////////

// To be called before ETH.begin()
ESP32_ENC_onEvent();

// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
uint16_t index = millis() % NUMBER_OF_MAC;

//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *ENC28J60_Mac = ENC28J60_Default_Mac);
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, SPI_HOST );
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, SPI_HOST, mac[index] );

// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
//ETH.config(myIP, myGW, mySN, myDNS);

ESP32_ENC_waitForConnect();

///////////////////////////////////

// Client address
Serial.print("Async_UDPClient started @ IP address: ");
Serial.println(ETH.localIP());

if (udp.connect(remoteIPAddress, UDP_REMOTE_PORT))
{
Serial.println("UDP connected");

udp.onPacket([](AsyncUDPPacket packet)
{
parsePacket( packet);
});

//Send unicast
udp.print("Hello Server!");
}
}

void loop()
{
delay(10000);
//Send broadcast on port UDP_REMOTE_PORT = 1234
udp.broadcastTo("Anyone here?", UDP_REMOTE_PORT);
}
Loading

0 comments on commit 6647e6a

Please sign in to comment.