This is simple yet complete WebServer library for AVR, Teensy, etc. boards running ESP8266 AT-command shields. The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32.
The library supports
WiFi Client, STA and AP mode
TCP Server and Client
UDP Server and Client
HTTP Server and Client
HTTP GET and POST requests, provides argument parsing, handles one client at a time.
The ESP8266_AT_Web_Server class found in ESP8266_AT_Web_Server.h header, is a simple web server that knows how to handle HTTP requests such as GET and POST and can only support one simultaneous client.
Sample Code
#define DEBUG_ESP8266_AT_WEBSERVER_PORT Serial
#include <ESP8266_AT_WebServer.h>
#ifdef CORE_TEENSY
// For Teensy 4.0
#define EspSerial Serial2 //Serial2, Pin RX2 : 7, TX2 : 8
#if defined(__IMXRT1062__)
#define BOARD_TYPE "TEENSY 4.0"
#elif ( defined(__MKL26Z64__) || defined(ARDUINO_ARCH_AVR) )
#define BOARD_TYPE "TEENSY LC or 2.0"
#else
#define BOARD_TYPE "TEENSY 3.X"
#endif
#else
// For Mega
#define EspSerial Serial3
#define BOARD_TYPE "AVR Mega"
#endif
char ssid[] = "****"; // your network SSID (name)
char pass[] = "****"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
int reqCount = 0; // number of requests received
ESP8266_AT_WebServer server(80);
const int led = 13;
void handleRoot()
{
server.send(200, "text/plain", "Hello from ESP8266_AT_WebServer!");
}
void handleNotFound()
{
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}
void setup(void)
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
// initialize serial for ESP module
EspSerial.begin(115200);
// initialize ESP module
WiFi.init(&EspSerial);
Serial.println("\nStarting HelloServer on " + String(BOARD_TYPE));
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD)
{
Serial.println(F("WiFi shield not present"));
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED)
{
Serial.print(F("Connecting to WPA SSID: "));
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
server.begin();
Serial.print("WebServer is @ ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.on("/inline", []()
{
server.send(200, "text/plain", "This works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.print(F("HTTP server started @ "));
Serial.println(WiFi.localIP());
}
void loop(void)
{
server.handleClient();
}
I just found out WiFiEsp lib at the time I needed a WebServer library having similar functions as ESP8266WiFi WebServer lib in order to write some AT-based WiFiManager for Arduino, Teensy boards.
I think the code can use any WiFi (AT) library with the same interfacing functions.
Just come across your WiFiEspAT lib today in this forum (which I'm very new to).
Have a quick look and it's very good. Hope we can work together.
I don't think there'll be any issue with SAMD (or any) boards, just because I have only Mega, Teensy 4.0 boards to test.
Can you clarify how and why the RingBuffer class creates issues with SAMD as I don't have SAMD to test and know now?
Just have a quick look at your server wrapper class, it's interesting and promising. Will try to wrap all networking libs into a super one. If you can proceed with this, please go ahead as you already had plenty experience on the issue. I'll just provide support when necessary.
khoih-prog:
Can you clarify how and why the RingBuffer class creates issues with SAMD as I don't have SAMD to test and know now?
Just have a quick look at your server wrapper class, it's interesting and promising. Will try to wrap all networking libs into a super one. If you can proceed with this, please go ahead as you already had plenty experience on the issue. I'll just provide support when necessary.
khoih-prog:
IMHO, this is just a small issue, and can be fixed quickly by modifying the lib.
How about your taking over the super Arduino WebServer lib?
I have already too many Arduino plans. this one was behind the horizon.
for example today I added to my todo list "improve ArduinoHttpClient library". it uses only int for contentLength and doesn't support F().
yesterday I finished OTA download examples.
It would be good to finish/make OTA for Nano 33 BLE, Nano every, STM32
Two projects are waiting...