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

Commit eee5626

Browse files
authored
v1.4.1 for ESP8266 using W5x00/ENC28J60 Ethernet
#### Releases v1.4.1 1. Initial coding to port [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) to ESP8266 boards using W5x00 / ENC28J60 Ethernet. 2. Add more examples. 3. Add debugging features. 4. Bump up to v1.4.1 to sync with [AsyncWebServer_WT32_ETH01 v1.4.1](https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01).
1 parent 6fcf679 commit eee5626

Some content is hidden

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

62 files changed

+15412
-5
lines changed

CONTRIBUTING.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Contributing to AsyncWebServer_Ethernet
2+
3+
### Reporting Bugs
4+
5+
Please report bugs in AsyncWebServer_Ethernet 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_Ethernet/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_Ethernet/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. ESP8266 core v3.0.2)
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+
ESP8266_NODEMCU_ESP12E using ESP8266_W5500 Ethernet
31+
ESP8266 core v3.0.2
32+
OS: Ubuntu 20.04 LTS
33+
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
34+
35+
Context:
36+
I encountered a crash while trying to use the Timer Interrupt.
37+
38+
Steps to reproduce:
39+
1. ...
40+
2. ...
41+
3. ...
42+
4. ...
43+
```
44+
45+
### Sending Feature Requests
46+
47+
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
48+
49+
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncWebServer_Ethernet/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
50+
51+
### Sending Pull Requests
52+
53+
Pull Requests with changes and fixes are also welcome!
54+

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,717-1
Large diffs are not rendered by default.

changelog.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# AsyncWebServer_Ethernet
2+
3+
[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncWebServer_Ethernet.svg?)](https://www.ardu-badge.com/AsyncWebServer_Ethernet)
4+
[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncWebServer_Ethernet.svg)](https://github.com/khoih-prog/AsyncWebServer_Ethernet/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_Ethernet.svg)](http://github.com/khoih-prog/AsyncWebServer_Ethernet/issues)
7+
8+
---
9+
---
10+
11+
## Table of contents
12+
13+
* [Changelog](#changelog)
14+
* [Releases v1.4.1](#releases-v141)
15+
16+
---
17+
---
18+
19+
## Changelog
20+
21+
#### Releases v1.4.1
22+
23+
1. Initial coding to port [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) to ESP8266 boards using W5x00 / ENC28J60 Ethernet.
24+
2. Add more examples.
25+
3. Add debugging features.
26+
4. Bump up to v1.4.1 to sync with [AsyncWebServer_WT32_ETH01 v1.4.1](https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01).
27+
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/****************************************************************************************************************************
2+
AsyncMultiWebServer.h
3+
4+
For ESP8266 using W5x00/ENC8266 Ethernet
5+
6+
AsyncWebServer_Ethernet is a library for the Ethernet with lwIP_5100, lwIP_5500 or lwIP_enc28j60 library
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_Ethernet
10+
Licensed under GPLv3 license
11+
*****************************************************************************************************************************/
12+
13+
#include "defines.h"
14+
15+
#include <AsyncWebServer_Ethernet.h>
16+
17+
unsigned int analogReadPin [] = { 12, 13, 14 };
18+
19+
#define BUFFER_SIZE 512
20+
21+
#define HTTP_PORT1 8080
22+
#define HTTP_PORT2 8081
23+
#define HTTP_PORT3 8082
24+
25+
AsyncWebServer* server1;
26+
AsyncWebServer* server2;
27+
AsyncWebServer* server3;
28+
29+
AsyncWebServer* multiServer [] = { server1, server2, server3 };
30+
uint16_t http_port [] = { HTTP_PORT1, HTTP_PORT2, HTTP_PORT3 };
31+
32+
#define NUM_SERVERS ( sizeof(multiServer) / sizeof(AsyncWebServer*) )
33+
34+
unsigned int serverIndex;
35+
36+
String createBuffer()
37+
{
38+
char temp[BUFFER_SIZE];
39+
40+
memset(temp, 0, sizeof(temp));
41+
42+
int sec = millis() / 1000;
43+
int min = sec / 60;
44+
int hr = min / 60;
45+
int day = hr / 24;
46+
47+
snprintf(temp, BUFFER_SIZE - 1,
48+
"<html>\
49+
<head>\
50+
<meta http-equiv='refresh' content='5'/>\
51+
<title>%s</title>\
52+
<style>\
53+
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
54+
</style>\
55+
</head>\
56+
<body>\
57+
<h1>Hello from %s</h1>\
58+
<h2>running AsyncWebServer_Ethernet</h2>\
59+
<h3>on %s</h3>\
60+
<h3>Uptime: %d d %02d:%02d:%02d</h3>\
61+
</body>\
62+
</html>", BOARD_NAME, BOARD_NAME, SHIELD_TYPE, day, hr, min % 60, sec % 60);
63+
64+
return temp;
65+
}
66+
67+
68+
void handleRoot(AsyncWebServerRequest * request)
69+
{
70+
String message = createBuffer();
71+
request->send(200, F("text/html"), message);
72+
}
73+
74+
String createNotFoundBuffer(AsyncWebServerRequest * request)
75+
{
76+
String message;
77+
78+
message.reserve(500);
79+
80+
message = F("File Not Found\n\n");
81+
82+
message += F("URI: ");
83+
message += request->url();
84+
message += F("\nMethod: ");
85+
message += (request->method() == HTTP_GET) ? F("GET") : F("POST");
86+
message += F("\nArguments: ");
87+
message += request->args();
88+
message += F("\n");
89+
90+
for (uint8_t i = 0; i < request->args(); i++)
91+
{
92+
message += " " + request->argName(i) + ": " + request->arg(i) + "\n";
93+
}
94+
95+
return message;
96+
}
97+
98+
void handleNotFound(AsyncWebServerRequest * request)
99+
{
100+
String message = createNotFoundBuffer(request);
101+
request->send(404, F("text/plain"), message);
102+
}
103+
104+
void initEthernet()
105+
{
106+
SPI.begin();
107+
SPI.setClockDivider(SPI_CLOCK_DIV4);
108+
SPI.setBitOrder(MSBFIRST);
109+
SPI.setDataMode(SPI_MODE0);
110+
111+
#if !USING_DHCP
112+
eth.config(localIP, gateway, netMask, gateway);
113+
#endif
114+
115+
eth.setDefault();
116+
117+
if (!eth.begin())
118+
{
119+
Serial.println("No Ethernet hardware ... Stop here");
120+
121+
while (true)
122+
{
123+
delay(1000);
124+
}
125+
}
126+
else
127+
{
128+
Serial.print("Connecting to network : ");
129+
130+
while (!eth.connected())
131+
{
132+
Serial.print(".");
133+
delay(1000);
134+
}
135+
}
136+
137+
Serial.println();
138+
139+
#if USING_DHCP
140+
Serial.print("Ethernet DHCP IP address: ");
141+
#else
142+
Serial.print("Ethernet Static IP address: ");
143+
#endif
144+
145+
Serial.println(eth.localIP());
146+
}
147+
148+
void setup()
149+
{
150+
Serial.begin(115200);
151+
while (!Serial && millis() < 5000);
152+
153+
delay(200);
154+
155+
Serial.print("\nStart AsyncMultiWebServer on "); Serial.print(BOARD_NAME);
156+
Serial.print(" with "); Serial.println(SHIELD_TYPE);
157+
Serial.println(ASYNC_WEBSERVER_ETHERNET_VERSION);
158+
159+
initEthernet();
160+
161+
for (serverIndex = 0; serverIndex < NUM_SERVERS; serverIndex++)
162+
{
163+
multiServer[serverIndex] = new AsyncWebServer(http_port[serverIndex]);
164+
165+
if (multiServer[serverIndex])
166+
{
167+
Serial.printf("Initialize multiServer OK, serverIndex = %d, port = %d\n", serverIndex, http_port[serverIndex]);
168+
}
169+
else
170+
{
171+
Serial.printf("Error initialize multiServer, serverIndex = %d\n", serverIndex);
172+
173+
while(1);
174+
}
175+
176+
multiServer[serverIndex]->on("/", HTTP_GET, [](AsyncWebServerRequest * request)
177+
{
178+
handleRoot(request);
179+
});
180+
181+
multiServer[serverIndex]->on("/hello", HTTP_GET, [](AsyncWebServerRequest * request)
182+
{
183+
String message = F("Hello from AsyncWebServer using built-in LAN8742A Ethernet, running on ");
184+
message += BOARD_NAME;
185+
186+
request->send(200, "text/plain", message);
187+
});
188+
189+
multiServer[serverIndex]->onNotFound([](AsyncWebServerRequest * request)
190+
{
191+
handleNotFound(request);
192+
});
193+
194+
multiServer[serverIndex]->begin();
195+
196+
Serial.printf("HTTP server started at ports %d\n", http_port[serverIndex]);
197+
}
198+
}
199+
200+
void loop()
201+
{
202+
}
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/****************************************************************************************************************************
2+
defines.h
3+
4+
For ESP8266 using W5x00/ENC8266 Ethernet
5+
6+
AsyncWebServer_Ethernet is a library for the Ethernet with lwIP_5100, lwIP_5500 or lwIP_enc28j60 library
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_Ethernet
10+
Licensed under GPLv3 license
11+
***************************************************************************************************************************************/
12+
13+
#ifndef defines_h
14+
#define defines_h
15+
16+
#if defined(ESP8266)
17+
#define LED_ON LOW
18+
#define LED_OFF HIGH
19+
#else
20+
#error Only ESP8266
21+
#endif
22+
23+
#define _AWS_ETHERNET_LOGLEVEL_ 1
24+
25+
//////////////////////////////////////////////////////////
26+
27+
#define USING_W5500 true
28+
#define USING_W5100 false
29+
#define USING_ENC28J60 false
30+
31+
#include <SPI.h>
32+
33+
#define CSPIN 16 // 5
34+
35+
#if USING_W5500
36+
#include "W5500lwIP.h"
37+
#define SHIELD_TYPE "ESP8266_W5500 Ethernet"
38+
39+
Wiznet5500lwIP eth(CSPIN);
40+
41+
#elif USING_W5100
42+
#include <W5100lwIP.h>
43+
#define SHIELD_TYPE "ESP8266_W5100 Ethernet"
44+
45+
Wiznet5100lwIP eth(CSPIN);
46+
47+
#elif USING_ENC28J60
48+
#include <ENC28J60lwIP.h>
49+
#define SHIELD_TYPE "ESP8266_ENC28J60 Ethernet"
50+
51+
ENC28J60lwIP eth(CSPIN);
52+
#else
53+
// default if none selected
54+
#include "W5500lwIP.h"
55+
56+
Wiznet5500lwIP eth(CSPIN);
57+
#endif
58+
59+
#include <WiFiClient.h> // WiFiClient (-> TCPClient)
60+
61+
using TCPClient = WiFiClient;
62+
63+
//////////////////////////////////////////////////////////
64+
65+
#define USING_DHCP true
66+
67+
#if !USING_DHCP
68+
IPAddress localIP(192, 168, 2, 222);
69+
IPAddress gateway(192, 168, 2, 1);
70+
IPAddress netMask(255, 255, 255, 0);
71+
#endif
72+
73+
#endif //defines_h

0 commit comments

Comments
 (0)