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

Commit 1bf164e

Browse files
authored
Initial Releases v1.2.3
### Initial Releases 1.2.3 1. Initial coding to port ESPAsyncWebServer to STM32 boards using builtin LAN8742A Ethernet. More supports will be added gradually later, such as AsyncUDP, other Ethernet / WiFi shields. 2. Add more examples. 3. Add debugging features. 4. Bump up to v1.2.3 to sync with [ESPAsyncWebServer v1.2.3](https://github.com/me-no-dev/ESPAsyncWebServer).
0 parents  commit 1bf164e

Some content is hidden

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

50 files changed

+11972
-0
lines changed

CONTRIBUTING.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Contributing to ESP_WiFiManager
2+
3+
### Reporting Bugs
4+
5+
Please report bugs in ESP_WiFiManager 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/ESP_WiFiManager/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/ESP_WiFiManager/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.11) or Platform.io version
18+
* `ESP8266` or `ESP32` Core Version (e.g. ESP8266 core v2.6.3 or ESP32 v1.0.4)
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.11
30+
ESP8266 Core Version 2.6.3
31+
OS: Ubuntu 16.04 LTS
32+
Linux Inspiron 4.4.0-170-generic #199-Ubuntu SMP Thu Nov 14 01:45:04 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
33+
34+
Context:
35+
I encountered an endless loop while trying to connect to Local WiFi.
36+
37+
Steps to reproduce:
38+
1. ...
39+
2. ...
40+
3. ...
41+
4. ...
42+
```
43+
### Sending Feature Requests
44+
45+
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
46+
47+
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/ESP_WiFiManager/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
48+
49+
### Sending Pull Requests
50+
51+
Pull Requests with changes and fixes are also welcome!

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Khoi Hoang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1710 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
#include <LwIP.h>
2+
#include <STM32Ethernet.h>
3+
4+
#include <STM32AsyncTCP.h>
5+
#include <AsyncWebServer_STM32.h>
6+
7+
// Enter a MAC address and IP address for your controller below.
8+
#define NUMBER_OF_MAC 20
9+
10+
byte mac[][NUMBER_OF_MAC] =
11+
{
12+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
13+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
14+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
15+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
16+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
17+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
18+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
19+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
20+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
21+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
22+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
23+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
24+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
25+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
26+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
27+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
28+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
29+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
30+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
31+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
32+
};
33+
// Select the IP address according to your local network
34+
IPAddress ip(192, 168, 2, 232);
35+
36+
// SKETCH BEGIN
37+
AsyncWebServer server(80);
38+
AsyncWebSocket ws("/ws");
39+
AsyncEventSource events("/events");
40+
41+
void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len)
42+
{
43+
if (type == WS_EVT_CONNECT)
44+
{
45+
Serial.printf("ws[%s][%u] connect\n", server->url(), client->id());
46+
client->printf("Hello Client %u :)", client->id());
47+
client->ping();
48+
}
49+
else if (type == WS_EVT_DISCONNECT)
50+
{
51+
Serial.printf("ws[%s][%u] disconnect\n", server->url(), client->id());
52+
}
53+
else if (type == WS_EVT_ERROR)
54+
{
55+
Serial.printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t*)arg), (char*)data);
56+
}
57+
else if (type == WS_EVT_PONG)
58+
{
59+
Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len) ? (char*)data : "");
60+
}
61+
else if (type == WS_EVT_DATA)
62+
{
63+
AwsFrameInfo * info = (AwsFrameInfo*)arg;
64+
String msg = "";
65+
66+
if (info->final && info->index == 0 && info->len == len)
67+
{
68+
//the whole message is in a single frame and we got all of it's data
69+
Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT) ? "text" : "binary", info->len);
70+
71+
if (info->opcode == WS_TEXT)
72+
{
73+
for (size_t i = 0; i < info->len; i++)
74+
{
75+
msg += (char) data[i];
76+
}
77+
}
78+
else
79+
{
80+
char buff[3];
81+
82+
for (size_t i = 0; i < info->len; i++)
83+
{
84+
sprintf(buff, "%02x ", (uint8_t) data[i]);
85+
msg += buff ;
86+
}
87+
}
88+
89+
Serial.printf("%s\n", msg.c_str());
90+
91+
if (info->opcode == WS_TEXT)
92+
client->text("I got your text message");
93+
else
94+
client->binary("I got your binary message");
95+
}
96+
else
97+
{
98+
//message is comprised of multiple frames or the frame is split into multiple packets
99+
100+
if (info->index == 0)
101+
{
102+
if (info->num == 0)
103+
Serial.printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT) ? "text" : "binary");
104+
105+
Serial.printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len);
106+
}
107+
108+
Serial.printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT) ? "text" : "binary", info->index, info->index + len);
109+
110+
if (info->opcode == WS_TEXT)
111+
{
112+
for (size_t i = 0; i < len; i++)
113+
{
114+
msg += (char) data[i];
115+
}
116+
}
117+
else
118+
{
119+
char buff[3];
120+
121+
for (size_t i = 0; i < len; i++)
122+
{
123+
sprintf(buff, "%02x ", (uint8_t) data[i]);
124+
msg += buff ;
125+
}
126+
}
127+
128+
Serial.printf("%s\n", msg.c_str());
129+
130+
if ((info->index + len) == info->len)
131+
{
132+
Serial.printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len);
133+
134+
if (info->final)
135+
{
136+
Serial.printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT) ? "text" : "binary");
137+
138+
if (info->message_opcode == WS_TEXT)
139+
client->text("I got your text message");
140+
else
141+
client->binary("I got your binary message");
142+
}
143+
}
144+
}
145+
}
146+
}
147+
148+
149+
const char * hostName = "esp-async";
150+
const char* http_username = "admin";
151+
const char* http_password = "admin";
152+
153+
void setup()
154+
{
155+
Serial.begin(115200);
156+
while (!Serial);
157+
158+
Serial.println("\nStarting AsyncFSBrowser_STM32 on " + String(BOARD_NAME));
159+
160+
// start the ethernet connection and the server
161+
// Use random mac
162+
uint16_t index = millis() % NUMBER_OF_MAC;
163+
164+
// Use Static IP
165+
//Ethernet.begin(mac[index], ip);
166+
// Use DHCP dynamic IP and random mac
167+
Ethernet.begin(mac[index]);
168+
169+
ws.onEvent(onWsEvent);
170+
server.addHandler(&ws);
171+
172+
events.onConnect([](AsyncEventSourceClient * client)
173+
{
174+
client->send("hello!", NULL, millis(), 1000);
175+
});
176+
177+
server.addHandler(&events);
178+
179+
server.on("/board", HTTP_GET, [](AsyncWebServerRequest * request)
180+
{
181+
request->send(200, "text/plain", String(BOARD_NAME));
182+
});
183+
184+
server.onNotFound([](AsyncWebServerRequest * request)
185+
{
186+
Serial.printf("NOT_FOUND: ");
187+
if (request->method() == HTTP_GET)
188+
Serial.printf("GET");
189+
else if (request->method() == HTTP_POST)
190+
Serial.printf("POST");
191+
else if (request->method() == HTTP_DELETE)
192+
Serial.printf("DELETE");
193+
else if (request->method() == HTTP_PUT)
194+
Serial.printf("PUT");
195+
else if (request->method() == HTTP_PATCH)
196+
Serial.printf("PATCH");
197+
else if (request->method() == HTTP_HEAD)
198+
Serial.printf("HEAD");
199+
else if (request->method() == HTTP_OPTIONS)
200+
Serial.printf("OPTIONS");
201+
else
202+
Serial.printf("UNKNOWN");
203+
Serial.printf(" http://%s%s\n", request->host().c_str(), request->url().c_str());
204+
205+
if (request->contentLength())
206+
{
207+
Serial.printf("_CONTENT_TYPE: %s\n", request->contentType().c_str());
208+
Serial.printf("_CONTENT_LENGTH: %u\n", request->contentLength());
209+
}
210+
211+
int headers = request->headers();
212+
int i;
213+
214+
for (i = 0; i < headers; i++)
215+
{
216+
AsyncWebHeader* h = request->getHeader(i);
217+
Serial.printf("_HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str());
218+
}
219+
220+
int params = request->params();
221+
222+
for (i = 0; i < params; i++)
223+
{
224+
AsyncWebParameter* p = request->getParam(i);
225+
226+
if (p->isPost())
227+
{
228+
Serial.printf("_POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
229+
}
230+
else
231+
{
232+
Serial.printf("_GET[%s]: %s\n", p->name().c_str(), p->value().c_str());
233+
}
234+
}
235+
236+
request->send(404);
237+
});
238+
239+
server.onRequestBody([](AsyncWebServerRequest * request, uint8_t *data, size_t len, size_t index, size_t total)
240+
{
241+
if (!index)
242+
Serial.printf("BodyStart: %u\n", total);
243+
244+
Serial.printf("%s", (const char*)data);
245+
246+
if (index + len == total)
247+
Serial.printf("BodyEnd: %u\n", total);
248+
});
249+
250+
server.begin();
251+
252+
Serial.print("Server started @ ");
253+
Serial.println(Ethernet.localIP());
254+
}
255+
256+
void loop()
257+
{
258+
ws.cleanupClients();
259+
}
96.6 KB
Binary file not shown.
3.06 KB
Binary file not shown.
1.12 KB
Binary file not shown.

0 commit comments

Comments
 (0)