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

Commit e11b91e

Browse files
authored
v1.6.2 for ESP32 + ENC28J60
#### Releases v1.6.2 1. Initial coding to port [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) to ESP32 boards using ENC28J60 Ethernet. 2. Bump up to `v1.6.2` to sync with [AsyncWebServer_ESP32_ENC v1.6.2](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC). 3. Use `allman astyle`
1 parent 3e00bad commit e11b91e

File tree

65 files changed

+22009
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+22009
-4
lines changed

CONTRIBUTING.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
## Contributing to AsyncWebServer_ESP32_ENC
2+
3+
### Reporting Bugs
4+
5+
Please report bugs in AsyncWebServer_ESP32_ENC 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/AsyncWebServer_ESP32_ENC/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/AsyncWebServer_ESP32_ENC/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.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_DEV board
31+
ESP32 core v2.0.5
32+
OS: Ubuntu 20.04 LTS
33+
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
34+
35+
Context:
36+
I encountered a crash while using this library
37+
Steps to reproduce:
38+
1. ...
39+
2. ...
40+
3. ...
41+
4. ...
42+
```
43+
44+
### Additional context
45+
46+
Add any other context about the problem here.
47+
48+
---
49+
50+
### Sending Feature Requests
51+
52+
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
53+
54+
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
55+
56+
---
57+
58+
### Sending Pull Requests
59+
60+
Pull Requests with changes and fixes are also welcome!
61+
62+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
63+
64+
1. Change directory to the library GitHub
65+
66+
```
67+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncWebServer_ESP32_ENC_GitHub/
68+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncWebServer_ESP32_ENC_GitHub$
69+
```
70+
71+
2. Issue astyle command
72+
73+
```
74+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncWebServer_ESP32_ENC_GitHub$ bash utils/restyle.sh
75+
```
76+

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>.

README.md

+1,840
Large diffs are not rendered by default.

changelog.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# AsyncWebServer_ESP32_ENC
2+
3+
[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncWebServer_ESP32_ENC.svg?)](https://www.ardu-badge.com/AsyncWebServer_ESP32_ENC)
4+
[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncWebServer_ESP32_ENC.svg)](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC/releases)
5+
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
6+
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncWebServer_ESP32_ENC.svg)](http://github.com/khoih-prog/AsyncWebServer_ESP32_ENC/issues)
7+
8+
<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>
9+
<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>
10+
<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>
11+
<a href="https://profile-counter.glitch.me/khoih-prog-AsyncWebServer_ESP32_ENC/count.svg" title="Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-AsyncWebServer_ESP32_ENC/count.svg" style="height: 30px;width: 200px;"></a>
12+
13+
---
14+
---
15+
16+
## Table of contents
17+
18+
* [Changelog](#changelog)
19+
* [Releases v1.6.2](#releases-v162)
20+
21+
22+
23+
---
24+
---
25+
26+
## Changelog
27+
28+
#### Releases v1.6.2
29+
30+
1. Initial coding to port [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) to ESP32 boards using ENC28J60 Ethernet.
31+
2. Bump up to `v1.6.2` to sync with [AsyncWebServer_ESP32_ENC v1.6.2](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC).
32+
3. Use `allman astyle`
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
/****************************************************************************************************************************
2+
AsyncMultiWebServer_ESP32_ENC.ino
3+
4+
For ENC28J60 Ethernet in ESP32 (ESP32 + ENC28J60)
5+
6+
AsyncWebServer_ESP32_ENC is a library for the Ethernet ENC28J60 in ESSP32 to run AsyncWebServer
7+
8+
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
9+
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC
10+
Licensed under GPLv3 license
11+
*****************************************************************************************************************************/
12+
13+
#if !( defined(ESP32) )
14+
#error This code is designed for (ESP32 + ENC28J60) to run on ESP32 platform! Please check your Tools->Board setting.
15+
#endif
16+
17+
#include <Arduino.h>
18+
19+
#define _ASYNC_WEBSERVER_LOGLEVEL_ 2
20+
21+
// Enter a MAC address and IP address for your controller below.
22+
#define NUMBER_OF_MAC 20
23+
24+
byte mac[][NUMBER_OF_MAC] =
25+
{
26+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
27+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
28+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
29+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
30+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
31+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
32+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
33+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
34+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
35+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
36+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
37+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
38+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
39+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
40+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
41+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
42+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
43+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
44+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
45+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
46+
};
47+
48+
// Select the IP address according to your local network
49+
IPAddress myIP(192, 168, 2, 232);
50+
IPAddress myGW(192, 168, 2, 1);
51+
IPAddress mySN(255, 255, 255, 0);
52+
53+
// Google DNS Server IP
54+
IPAddress myDNS(8, 8, 8, 8);
55+
56+
#include <AsyncTCP.h>
57+
58+
#include <AsyncWebServer_ESP32_ENC.h>
59+
60+
// Optional values to override default settings
61+
//#define SPI_HOST 1
62+
//#define SPI_CLOCK_MHZ 8
63+
64+
// Must connect INT to GPIOxx or not working
65+
//#define INT_GPIO 4
66+
67+
//#define MISO_GPIO 19
68+
//#define MOSI_GPIO 23
69+
//#define SCK_GPIO 18
70+
//#define CS_GPIO 5
71+
// Optional values to override default settings
72+
73+
unsigned int analogReadPin [] = { 12, 13, 14 };
74+
75+
#define BUFFER_SIZE 500
76+
77+
#define HTTP_PORT1 8080
78+
#define HTTP_PORT2 8081
79+
#define HTTP_PORT3 8082
80+
81+
AsyncWebServer* server1;
82+
AsyncWebServer* server2;
83+
AsyncWebServer* server3;
84+
85+
AsyncWebServer* multiServer [] = { server1, server2, server3 };
86+
uint16_t http_port [] = { HTTP_PORT1, HTTP_PORT2, HTTP_PORT3 };
87+
88+
#define NUM_SERVERS ( sizeof(multiServer) / sizeof(AsyncWebServer*) )
89+
90+
unsigned int serverIndex;
91+
92+
String createBuffer()
93+
{
94+
char temp[BUFFER_SIZE];
95+
96+
memset(temp, 0, sizeof(temp));
97+
98+
int sec = millis() / 1000;
99+
int min = sec / 60;
100+
int hr = min / 60;
101+
int day = hr / 24;
102+
103+
snprintf(temp, BUFFER_SIZE - 1,
104+
"<html>\
105+
<head>\
106+
<meta http-equiv='refresh' content='5'/>\
107+
<title>%s</title>\
108+
<style>\
109+
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
110+
</style>\
111+
</head>\
112+
<body>\
113+
<h1>Hello from %s</h1>\
114+
<h2>running AsyncMultiWebServer_ESP32_ENC</h2>\
115+
<h3>on %s</h3>\
116+
<h3>Uptime: %d d %02d:%02d:%02d</h3>\
117+
</body>\
118+
</html>", BOARD_NAME, BOARD_NAME, SHIELD_TYPE, day, hr, min % 60, sec % 60);
119+
120+
return temp;
121+
}
122+
123+
124+
void handleRoot(AsyncWebServerRequest * request)
125+
{
126+
String message = createBuffer();
127+
request->send(200, F("text/html"), message);
128+
}
129+
130+
String createNotFoundBuffer(AsyncWebServerRequest * request)
131+
{
132+
String message;
133+
134+
message.reserve(500);
135+
136+
message = F("File Not Found\n\n");
137+
138+
message += F("URI: ");
139+
message += request->url();
140+
message += F("\nMethod: ");
141+
message += (request->method() == HTTP_GET) ? F("GET") : F("POST");
142+
message += F("\nArguments: ");
143+
message += request->args();
144+
message += F("\n");
145+
146+
for (uint8_t i = 0; i < request->args(); i++)
147+
{
148+
message += " " + request->argName(i) + ": " + request->arg(i) + "\n";
149+
}
150+
151+
return message;
152+
}
153+
154+
void handleNotFound(AsyncWebServerRequest * request)
155+
{
156+
String message = createNotFoundBuffer(request);
157+
request->send(404, F("text/plain"), message);
158+
}
159+
160+
void setup()
161+
{
162+
Serial.begin(115200);
163+
164+
while (!Serial && millis() < 5000);
165+
166+
delay(200);
167+
168+
Serial.print(F("\nStart AsyncMultiWebServer_ESP32_ENC on "));
169+
Serial.print(BOARD_NAME);
170+
Serial.print(F(" with "));
171+
Serial.println(SHIELD_TYPE);
172+
Serial.println(ASYNC_WEBSERVER_ESP32_ENC_VERSION);
173+
174+
AWS_LOGWARN(F("Default SPI pinout:"));
175+
AWS_LOGWARN1(F("MOSI:"), MOSI_GPIO);
176+
AWS_LOGWARN1(F("MISO:"), MISO_GPIO);
177+
AWS_LOGWARN1(F("SCK:"), SCK_GPIO);
178+
AWS_LOGWARN1(F("CS:"), CS_GPIO);
179+
AWS_LOGWARN1(F("INT:"), INT_GPIO);
180+
AWS_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
181+
AWS_LOGWARN(F("========================="));
182+
183+
///////////////////////////////////
184+
185+
// To be called before ETH.begin()
186+
ESP32_ENC_onEvent();
187+
188+
// start the ethernet connection and the server:
189+
// Use DHCP dynamic IP and random mac
190+
uint16_t index = millis() % NUMBER_OF_MAC;
191+
192+
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
193+
// int SPI_HOST, uint8_t *ENC28J60_Mac = ENC28J60_Default_Mac);
194+
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, SPI_HOST );
195+
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, SPI_HOST, mac[index] );
196+
197+
// Static IP, leave without this line to get IP via DHCP
198+
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
199+
ETH.config(myIP, myGW, mySN, myDNS);
200+
201+
ESP32_ENC_waitForConnect();
202+
203+
///////////////////////////////////
204+
205+
206+
Serial.print("\nConnected to network. IP = ");
207+
Serial.println(ETH.localIP());
208+
209+
for (serverIndex = 0; serverIndex < NUM_SERVERS; serverIndex++)
210+
{
211+
multiServer[serverIndex] = new AsyncWebServer(http_port[serverIndex]);
212+
213+
if (multiServer[serverIndex])
214+
{
215+
Serial.printf("Initialize multiServer OK, serverIndex = %d, port = %d\n", serverIndex, http_port[serverIndex]);
216+
}
217+
else
218+
{
219+
Serial.printf("Error initialize multiServer, serverIndex = %d\n", serverIndex);
220+
221+
while (1);
222+
}
223+
224+
multiServer[serverIndex]->on("/", HTTP_GET, [](AsyncWebServerRequest * request)
225+
{
226+
handleRoot(request);
227+
});
228+
229+
multiServer[serverIndex]->on("/hello", HTTP_GET, [](AsyncWebServerRequest * request)
230+
{
231+
String message = F("Hello from AsyncMultiWebServer_ESP32_ENC using ENC28J60 Ethernet, running on ");
232+
message += BOARD_NAME;
233+
234+
request->send(200, "text/plain", message);
235+
});
236+
237+
multiServer[serverIndex]->onNotFound([](AsyncWebServerRequest * request)
238+
{
239+
handleNotFound(request);
240+
});
241+
242+
multiServer[serverIndex]->begin();
243+
244+
Serial.printf("HTTP server started at ports %d\n", http_port[serverIndex]);
245+
}
246+
}
247+
248+
void loop()
249+
{
250+
}

0 commit comments

Comments
 (0)