Many people, me including, are using Arduino, Teensy, etc. boards with ESP8266 AT-Command shields. I haven’t seen a WebServer library, with similar features to ESP8266WebServer, to support this combination. That’s why we ,so far, still haven’t got a library similar to WiFiManager for Arduino, Teensy, etc.
This is the reason for me to finish this new ESP8266_AT_WebServer
Library. The AT_WiFiManager will be in the to-do list.
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.
Library is based on and modified from:
There currently are 14 examples:
- HelloServer
- HelloServer2
- AdvancedWebServer
- HttpBasicAuth
- PostServer
- SimpleAuthentication
- ConnectWPA
- ScanNetworks
- UdpNTPClient
- UdpSendReceive
- WebClient
- WebClientRepeating
- WebServer
- WebServerAP
This is the HelloServer
#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();
}
Update Feb 17th 2020
ESP8266_AT_WebServer libraries v1.0.0
just got included into Arduino Library Manager.
Now you can install this library directly from Arduino Library Manager.
Update Feb 17th 2020
Version v1.0.1
- Add support to server’s lambda function calls with dependency on
Functional-VLPP library
Update Feb 22th 2020
New Version v1.0.2
- Add support to SAMD (DUE, ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit CIRCUITPLAYGROUND_EXPRESS, etc.) boards