WebServer on ESP32-C5-WIFI6-KIT-N16R8, to control onboard RGB LED (Arduino Framework)
Exercises (Arduino Framework) run on Waveshare ESP32-C5-WIFI6-KIT-N16R8, act as WiFi Access Point, and setup simple WebServer to control onboard RGB LED.
ESP32C5_WiFi_AP_WebServer, act as Access Point and setup a simple WebServer.
ESP32C5_WiFi_AP_WebServer_LED, to toggle onboard RGB LED.
ESP32C5_WiFi_AP_WebServer_RGB, to control onboard RGB LED with a Color Picker.
ESP32C5_WiFi_AP_WebServer, act as Access Point and setup a simple WebServer.
/*
Exercise run on Waveshare ESP32-C5-WIFI6-KIT-N16R8
Setup WiFi AP, and a simple WebServer.
details:
https://coxxect.blogspot.com/2026/03/webserver-on-esp32-c5-wifi6-kit-n16r8.html
Ref:
Arduino ESP32 Wi-Fi API
https://docs.espressif.com/projects/arduino-esp32/en/latest/api/wifi.html
Github: espressif/arduino-esp32/libraries/WebServer/
https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer
*/
#include <WiFi.h>
#include <WebServer.h> // Built-in lightweight HTTP server
const char* ssid = "ESP32-C5_AP";
const char* password = "12345678";
// Create a web server on port 80
WebServer server(80);
void handleRoot() {
server.send(200, "text/html", "<h1>Hello from ESP32-C5 Web Server!</h1>");
}
void handleNotFound() {
server.send(404, "text/plain", "404: Not Found");
}
void setup() {
delay(2000);
Serial.begin(115200);
delay(1000);
// Start AP
WiFi.mode(WIFI_AP);
//WiFi.softAP(ssid, password); // Channel 0 → Auto
//WiFi.softAP(ssid, password, 2); // Channel 1 → 2.4 GHz
WiFi.softAP(ssid, password, 36); // Channel 36 → 5 GHz
Serial.println("Access Point started");
Serial.print("IP address: ");
Serial.println(WiFi.softAPIP());
// Read back channel
int ch = WiFi.channel();
Serial.print("AP is running on channel: ");
Serial.println(ch);
// Configure web server routes
server.on("/", handleRoot);
server.onNotFound(handleNotFound);
// Start server
server.begin();
Serial.println("Web server started");
}
void loop() {
// Handle incoming client requests
server.handleClient();
}
ESP32C5_WiFi_AP_WebServer_LED, to toggle onboard RGB LED.
/*
Exercise run on Waveshare ESP32-C5-WIFI6-KIT-N16R8
Setup WiFi AP, and a simple WebServer to toggle onboard LED.
details:
https://coxxect.blogspot.com/2026/03/webserver-on-esp32-c5-wifi6-kit-n16r8.html
Ref:
Arduino ESP32 Wi-Fi API
https://docs.espressif.com/projects/arduino-esp32/en/latest/api/wifi.html
Github: espressif/arduino-esp32/libraries/WebServer/
https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer
*/
#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "ESP32-C5_AP";
const char* password = "12345678";
WebServer server(80);
bool ledState = LOW; // Track LED state
void handleRoot() {
String html = "<!DOCTYPE html><html><head><title>ESP32-C5 LED Control</title></head><body>";
html += "<h1>ESP32-C5 Web Server</h1>";
html += "<p>LED is currently: ";
html += (ledState == HIGH) ? "ON" : "OFF";
html += "</p>";
html += "<form action=\"/toggle\" method=\"POST\">";
html += "<button type=\"submit\">Toggle LED</button>";
html += "</form>";
html += "</body></html>";
server.send(200, "text/html", html);
}
void handleToggle() {
ledState = !ledState; // Flip state
digitalWrite(LED_BUILTIN, ledState); // Apply to onboard LED
handleRoot(); // Refresh page
}
void handleNotFound() {
server.send(404, "text/plain", "404: Not Found");
}
void setup() {
delay(2000);
Serial.begin(115200);
delay(1000);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, ledState);
WiFi.mode(WIFI_AP);
//WiFi.softAP(ssid, password); // Channel 0 → Auto
//WiFi.softAP(ssid, password, 2); // Channel 1 → 2.4 GHz
WiFi.softAP(ssid, password, 36); // Channel 36 → 5 GHz
Serial.println("Access Point started");
Serial.print("IP address: ");
Serial.println(WiFi.softAPIP());
int ch = WiFi.channel();
Serial.print("AP is running on channel: ");
Serial.println(ch);
server.on("/", handleRoot);
server.on("/toggle", HTTP_POST, handleToggle);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("Web server started");
}
void loop() {
server.handleClient();
}
ESP32C5_WiFi_AP_WebServer_RGB, to control onboard RGB LED with a Color Picker.
/*
Exercise run on Waveshare ESP32-C5-WIFI6-KIT-N16R8
Setup WiFi AP, and a simple WebServer, with a color picker to control onboard RGB LED.
details:
https://coxxect.blogspot.com/2026/03/webserver-on-esp32-c5-wifi6-kit-n16r8.html
Ref:
Arduino ESP32 Wi-Fi API
https://docs.espressif.com/projects/arduino-esp32/en/latest/api/wifi.html
Github: espressif/arduino-esp32/libraries/WebServer/
https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer
*/
#include <WiFi.h>
#include <WebServer.h>
#include <Adafruit_NeoPixel.h>
const char* ssid = "ESP32-C5_AP";
const char* password = "12345678";
WebServer server(80);
// Adjust these to match your board’s RGB LED pin and count
#define RGB_PIN 27 // Example GPIO for onboard RGB LED
#define RGB_COUNT 1 // Only one LED onboard
Adafruit_NeoPixel rgb(RGB_COUNT, RGB_PIN, NEO_RGB + NEO_KHZ800);
uint8_t red = 0, green = 0, blue = 0;
void handleRoot() {
String html = "<!DOCTYPE html><html><head><title>ESP32-C5 RGB Control</title></head><body>";
html += "<h1>ESP32-C5 RGB LED Control</h1>";
html += "<form action=\"/setColor\" method=\"GET\">";
html += "<input type=\"color\" name=\"color\" value=\"#";
char buf[7];
sprintf(buf, "%02X%02X%02X", red, green, blue);
html += buf;
html += "\">";
html += "<input type=\"submit\" value=\"Set Color\">";
html += "</form>";
html += "</body></html>";
server.send(200, "text/html", html);
}
void handleSetColor() {
if (server.hasArg("color")) {
String color = server.arg("color"); // format: #RRGGBB
if (color.length() == 7 && color[0] == '#') {
long rgbVal = strtol(color.substring(1).c_str(), NULL, 16);
red = (rgbVal >> 16) & 0xFF;
green = (rgbVal >> 8) & 0xFF;
blue = rgbVal & 0xFF;
rgb.setPixelColor(0, rgb.Color(red, green, blue));
rgb.show();
}
}
handleRoot(); // Refresh page with updated color
}
void handleNotFound() {
server.send(404, "text/plain", "404: Not Found");
}
void setup() {
delay(2000);
Serial.begin(115200);
delay(1000);
rgb.begin();
rgb.setBrightness(50); // Adjust brightness
rgb.show();
WiFi.mode(WIFI_AP);
//WiFi.softAP(ssid, password); // Channel 0 → Auto
//WiFi.softAP(ssid, password, 2); // Channel 1 → 2.4 GHz
WiFi.softAP(ssid, password, 36); // Channel 36 → 5 GHz
Serial.println("Access Point started");
Serial.print("IP address: ");
Serial.println(WiFi.softAPIP());
int ch = WiFi.channel();
Serial.print("AP is running on channel: ");
Serial.println(ch);
server.on("/", handleRoot);
server.on("/setColor", handleSetColor);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("Web server started");
}
void loop() {
server.handleClient();
}
Comments
Post a Comment