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

Commit 77b6bf4

Browse files
authored
v1.4.1 for Teensy41 and QNEthernet
## Changelog ### Releases v1.4.1 1. Initial porting and coding for **Teensy 4.1 using built-in QNEthernet** 2. Bump up version to v1.4.1 to sync with [AsyncWebServer_STM32](https://github.com/khoih-prog/AsyncWebServer_STM32) v1.4.1
1 parent d09281a commit 77b6bf4

File tree

2 files changed

+7
-326
lines changed

2 files changed

+7
-326
lines changed

README.md

+6-325
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
77
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncWebServer_Teensy41.svg)](http://github.com/khoih-prog/AsyncWebServer_Teensy41/issues)
88

9+
<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>
10+
<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>
11+
912
---
1013
---
1114

@@ -1117,132 +1120,9 @@ server.reset();
11171120

11181121
## Setting up the server
11191122

1120-
```cpp
1121-
#define USING_DHCP true
1122-
//#define USING_DHCP false
1123-
1124-
#if !USING_DHCP
1125-
// Set the static IP address to use if the DHCP fails to assign
1126-
IPAddress myIP(192, 168, 2, 222);
1127-
IPAddress myNetmask(255, 255, 255, 0);
1128-
IPAddress myGW(192, 168, 2, 1);
1129-
//IPAddress mydnsServer(192, 168, 2, 1);
1130-
IPAddress mydnsServer(8, 8, 8, 8);
1131-
#endif
1132-
1133-
#include "QNEthernet.h" // https://github.com/ssilverman/QNEthernet
1134-
using namespace qindesign::network;
1135-
1136-
#include <AsyncWebServer_Teensy41.h>
1137-
1138-
AsyncWebServer server(80);
1139-
1140-
const int led = 13;
1141-
1142-
void handleRoot(AsyncWebServerRequest *request)
1143-
{
1144-
digitalWrite(led, 1);
1145-
request->send(200, "text/plain", String("Hello from AsyncWebServer_Teensy41 on ") + BOARD_NAME );
1146-
digitalWrite(led, 0);
1147-
}
1123+
https://github.com/khoih-prog/AsyncWebServer_Teensy41/blob/d09281ae572db571fa5e53e624ca19f16462f892/examples/Async_HelloServer/Async_HelloServer.ino#L13-L150
11481124

1149-
void handleNotFound(AsyncWebServerRequest *request)
1150-
{
1151-
digitalWrite(led, 1);
1152-
String message = "File Not Found\n\n";
1153-
1154-
message += "URI: ";
1155-
//message += server.uri();
1156-
message += request->url();
1157-
message += "\nMethod: ";
1158-
message += (request->method() == HTTP_GET) ? "GET" : "POST";
1159-
message += "\nArguments: ";
1160-
message += request->args();
1161-
message += "\n";
1162-
1163-
for (uint8_t i = 0; i < request->args(); i++)
1164-
{
1165-
message += " " + request->argName(i) + ": " + request->arg(i) + "\n";
1166-
}
11671125

1168-
request->send(404, "text/plain", message);
1169-
digitalWrite(led, 0);
1170-
}
1171-
1172-
void setup(void)
1173-
{
1174-
pinMode(led, OUTPUT);
1175-
digitalWrite(led, 0);
1176-
1177-
Serial.begin(115200);
1178-
while (!Serial);
1179-
1180-
delay(200);
1181-
1182-
Serial.print("\nStart Async_HelloServer on "); Serial.print(BOARD_NAME);
1183-
Serial.print(" with "); Serial.println(SHIELD_TYPE);
1184-
Serial.println(ASYNC_WEBSERVER_TEENSY41_VERSION);
1185-
1186-
delay(500);
1187-
1188-
#if USING_DHCP
1189-
// Start the Ethernet connection, using DHCP
1190-
Serial.print("Initialize Ethernet using DHCP => ");
1191-
Ethernet.begin();
1192-
#else
1193-
// Start the Ethernet connection, using static IP
1194-
Serial.print("Initialize Ethernet using static IP => ");
1195-
Ethernet.begin(myIP, myNetmask, myGW);
1196-
Ethernet.setDNSServerIP(mydnsServer);
1197-
#endif
1198-
1199-
if (!Ethernet.waitForLocalIP(5000))
1200-
{
1201-
Serial.println(F("Failed to configure Ethernet"));
1202-
1203-
if (!Ethernet.linkStatus())
1204-
{
1205-
Serial.println(F("Ethernet cable is not connected."));
1206-
}
1207-
1208-
// Stay here forever
1209-
while (true)
1210-
{
1211-
delay(1);
1212-
}
1213-
}
1214-
else
1215-
{
1216-
Serial.print(F("Connected! IP address:")); Serial.println(Ethernet.localIP());
1217-
}
1218-
1219-
#if USING_DHCP
1220-
delay(1000);
1221-
#else
1222-
delay(2000);
1223-
#endif
1224-
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request)
1225-
{
1226-
handleRoot(request);
1227-
});
1228-
1229-
server.on("/inline", [](AsyncWebServerRequest * request)
1230-
{
1231-
request->send(200, "text/plain", "This works as well");
1232-
});
1233-
1234-
server.onNotFound(handleNotFound);
1235-
1236-
server.begin();
1237-
1238-
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
1239-
Serial.println(Ethernet.localIP());
1240-
}
1241-
1242-
void loop(void)
1243-
{
1244-
}
1245-
```
12461126
---
12471127

12481128
### Setup global and class functions as request handlers
@@ -1398,207 +1278,8 @@ build_flags =
13981278

13991279
### Example [Async_AdvancedWebServer](examples/Async_AdvancedWebServer)
14001280

1281+
https://github.com/khoih-prog/AsyncWebServer_Teensy41/blob/d09281ae572db571fa5e53e624ca19f16462f892/examples/Async_AdvancedWebServer/Async_AdvancedWebServer.ino#L41-L237
14011282

1402-
```cpp
1403-
1404-
#if !( defined(CORE_TEENSY) && defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41) )
1405-
#error Only Teensy 4.1 supported
1406-
#endif
1407-
1408-
// Debug Level from 0 to 4
1409-
#define _TEENSY41_ASYNC_TCP_LOGLEVEL_ 1
1410-
#define _AWS_TEENSY41_LOGLEVEL_ 1
1411-
1412-
#define SHIELD_TYPE "Teensy4.1 QNEthernet"
1413-
1414-
#if (_AWS_TEENSY41_LOGLEVEL_ > 3)
1415-
#warning Using QNEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error
1416-
#endif
1417-
1418-
#define USING_DHCP true
1419-
//#define USING_DHCP false
1420-
1421-
#if !USING_DHCP
1422-
// Set the static IP address to use if the DHCP fails to assign
1423-
IPAddress myIP(192, 168, 2, 222);
1424-
IPAddress myNetmask(255, 255, 255, 0);
1425-
IPAddress myGW(192, 168, 2, 1);
1426-
//IPAddress mydnsServer(192, 168, 2, 1);
1427-
IPAddress mydnsServer(8, 8, 8, 8);
1428-
#endif
1429-
1430-
#include "QNEthernet.h" // https://github.com/ssilverman/QNEthernet
1431-
using namespace qindesign::network;
1432-
1433-
#include <AsyncWebServer_Teensy41.h>
1434-
1435-
AsyncWebServer server(80);
1436-
1437-
int reqCount = 0; // number of requests received
1438-
1439-
const int led = 13;
1440-
1441-
void handleRoot(AsyncWebServerRequest *request)
1442-
{
1443-
digitalWrite(led, 1);
1444-
1445-
#define BUFFER_SIZE 400
1446-
1447-
char temp[BUFFER_SIZE];
1448-
int sec = millis() / 1000;
1449-
int min = sec / 60;
1450-
int hr = min / 60;
1451-
int day = hr / 24;
1452-
1453-
snprintf(temp, BUFFER_SIZE - 1,
1454-
"<html>\
1455-
<head>\
1456-
<meta http-equiv='refresh' content='5'/>\
1457-
<title>AsyncWebServer-%s</title>\
1458-
<style>\
1459-
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
1460-
</style>\
1461-
</head>\
1462-
<body>\
1463-
<h2>AsyncWebServer_Teensy41!</h2>\
1464-
<h3>running on %s</h3>\
1465-
<p>Uptime: %d d %02d:%02d:%02d</p>\
1466-
<img src=\"/test.svg\" />\
1467-
</body>\
1468-
</html>", BOARD_NAME, BOARD_NAME, day, hr % 24, min % 60, sec % 60);
1469-
1470-
request->send(200, "text/html", temp);
1471-
1472-
digitalWrite(led, 0);
1473-
}
1474-
1475-
void handleNotFound(AsyncWebServerRequest *request)
1476-
{
1477-
digitalWrite(led, 1);
1478-
String message = "File Not Found\n\n";
1479-
1480-
message += "URI: ";
1481-
message += request->url();
1482-
message += "\nMethod: ";
1483-
message += (request->method() == HTTP_GET) ? "GET" : "POST";
1484-
message += "\nArguments: ";
1485-
message += request->args();
1486-
message += "\n";
1487-
1488-
for (uint8_t i = 0; i < request->args(); i++)
1489-
{
1490-
message += " " + request->argName(i) + ": " + request->arg(i) + "\n";
1491-
}
1492-
1493-
request->send(404, "text/plain", message);
1494-
digitalWrite(led, 0);
1495-
}
1496-
1497-
void drawGraph(AsyncWebServerRequest *request)
1498-
{
1499-
String out;
1500-
1501-
out.reserve(3000);
1502-
char temp[70];
1503-
1504-
out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n";
1505-
out += "<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"2\" stroke=\"rgb(0, 0, 0)\" />\n";
1506-
out += "<g stroke=\"blue\">\n";
1507-
int y = rand() % 130;
1508-
1509-
for (int x = 10; x < 300; x += 10)
1510-
{
1511-
int y2 = rand() % 130;
1512-
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"2\" />\n", x, 140 - y, x + 10, 140 - y2);
1513-
out += temp;
1514-
y = y2;
1515-
}
1516-
out += "</g>\n</svg>\n";
1517-
1518-
request->send(200, "image/svg+xml", out);
1519-
}
1520-
1521-
1522-
void setup(void)
1523-
{
1524-
pinMode(led, OUTPUT);
1525-
digitalWrite(led, 0);
1526-
1527-
Serial.begin(115200);
1528-
while (!Serial);
1529-
1530-
delay(200);
1531-
1532-
Serial.print("\nStart Async_AdvancedWebServer on "); Serial.print(BOARD_NAME);
1533-
Serial.print(" with "); Serial.println(SHIELD_TYPE);
1534-
Serial.println(ASYNC_WEBSERVER_TEENSY41_VERSION);
1535-
1536-
delay(500);
1537-
1538-
#if USING_DHCP
1539-
// Start the Ethernet connection, using DHCP
1540-
Serial.print("Initialize Ethernet using DHCP => ");
1541-
Ethernet.begin();
1542-
#else
1543-
// Start the Ethernet connection, using static IP
1544-
Serial.print("Initialize Ethernet using static IP => ");
1545-
Ethernet.begin(myIP, myNetmask, myGW);
1546-
Ethernet.setDNSServerIP(mydnsServer);
1547-
#endif
1548-
1549-
if (!Ethernet.waitForLocalIP(5000))
1550-
{
1551-
Serial.println(F("Failed to configure Ethernet"));
1552-
1553-
if (!Ethernet.linkStatus())
1554-
{
1555-
Serial.println(F("Ethernet cable is not connected."));
1556-
}
1557-
1558-
// Stay here forever
1559-
while (true)
1560-
{
1561-
delay(1);
1562-
}
1563-
}
1564-
else
1565-
{
1566-
Serial.print(F("Connected! IP address:")); Serial.println(Ethernet.localIP());
1567-
}
1568-
1569-
#if USING_DHCP
1570-
delay(1000);
1571-
#else
1572-
delay(2000);
1573-
#endif
1574-
1575-
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request)
1576-
{
1577-
handleRoot(request);
1578-
});
1579-
1580-
server.on("/test.svg", HTTP_GET, [](AsyncWebServerRequest * request)
1581-
{
1582-
drawGraph(request);
1583-
});
1584-
1585-
server.on("/inline", [](AsyncWebServerRequest * request)
1586-
{
1587-
request->send(200, "text/plain", "This works as well");
1588-
});
1589-
1590-
server.onNotFound(handleNotFound);
1591-
1592-
server.begin();
1593-
1594-
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
1595-
Serial.println(Ethernet.localIP());
1596-
}
1597-
1598-
void loop(void)
1599-
{
1600-
}
1601-
```
16021283

16031284
You can access the Async Advanced WebServer @ the server IP
16041285

@@ -1853,7 +1534,7 @@ If you want to contribute to this project:
18531534

18541535
### License
18551536

1856-
- The library is licensed under [LGPLv3](https://github.com/khoih-prog/AsyncWebServer_Teensy41/blob/main/LICENSE)
1537+
- The library is licensed under [GPLv3](https://github.com/khoih-prog/AsyncWebServer_Teensy41/blob/main/LICENSE)
18571538

18581539
---
18591540

changelog.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
### Releases v1.4.1
2424

25-
1. Initial coding for **Teensy 4.1 using built-in QNEthernet**
25+
1. Initial porting and coding for **Teensy 4.1 using built-in QNEthernet**
2626
2. Bump up version to v1.4.1 to sync with [AsyncWebServer_STM32](https://github.com/khoih-prog/AsyncWebServer_STM32) v1.4.1
2727

2828

0 commit comments

Comments
 (0)