🔌 Xiao ESP32C6 - API Reference

Complete API documentation for LED control via HTTP endpoints

Base URL: http://<ESP32_IP>/ (Replace <ESP32_IP> with your device's IP address)

1️⃣ Status Endpoint

GET /status

Description

Get the current status of all LEDs and device information

Example Request

GET http://192.168.1.100/status

Response (200 OK)

{ "leds": [false, true, false, true], "ip": "192.168.1.100", "rssi": -45, "uptime": 3600, "device": "Xiao ESP32C3" }

Response Fields

Field Type Description
leds Array[bool] LED states [LED1, LED2, LED3, LED4]
ip String Device IP address
rssi Integer WiFi signal strength (dBm)
uptime Integer Device uptime in seconds
device String Device model name

2️⃣ LED Control Endpoints

GET /led[1-4]/on

Description

Turn a specific LED ON

Example Requests

GET http://192.168.1.100/led1/on GET http://192.168.1.100/led2/on GET http://192.168.1.100/led3/on GET http://192.168.1.100/led4/on

Response (200 OK)

{ "led": 1, "state": "on", "status": "success", "timestamp": 45250 }
GET /led[1-4]/off

Description

Turn a specific LED OFF

Example Requests

GET http://192.168.1.100/led1/off GET http://192.168.1.100/led2/off GET http://192.168.1.100/led3/off GET http://192.168.1.100/led4/off

Response (200 OK)

{ "led": 2, "state": "off", "status": "success", "timestamp": 45300 }
GET /led[1-4]

Description

Toggle LED state (ON → OFF or OFF → ON)

Example Requests

GET http://192.168.1.100/led1 GET http://192.168.1.100/led2 GET http://192.168.1.100/led3 GET http://192.168.1.100/led4

Response (200 OK)

{ "led": 3, "state": "on", "status": "success", "timestamp": 45350 }

3️⃣ Device Information Endpoint

GET /info

Description

Get detailed device information including hardware specs and current LED states

Example Request

GET http://192.168.1.100/info

Response (200 OK)

{ "device": "Xiao ESP32C3", "version": "1.0", "chip": "ESP32-C3", "cores": 1, "ram": 262144, "flash": 4194304, "ip": "192.168.1.100", "ssid": "MyWiFi", "rssi": -45, "uptime": 3600, "leds": [false, true, false, true] }

Response Fields

Field Type Description
device String Device model
version String Firmware version
chip String Chip model
cores Integer Number of CPU cores
ram Integer Available RAM in bytes
flash Integer Flash memory size in bytes
ip String Device IP address
ssid String Connected WiFi SSID
rssi Integer WiFi signal strength (dBm)
uptime Integer Device uptime in seconds
leds Array[bool] LED states [LED1, LED2, LED3, LED4]

4️⃣ Reset Endpoint

GET /reset

Description

Turn OFF all LEDs and reset device state

Example Request

GET http://192.168.1.100/reset

Response (200 OK)

{ "status": "reset", "all_leds": "off" }

5️⃣ Error Handling

404 Not Found

When requesting an invalid endpoint:

Request: GET http://192.168.1.100/invalid Response: 404 Not Found
{ "error": "Not Found", "message": "Endpoint does not exist" }

📝 Usage Examples

JavaScript/Fetch API

// Get status fetch('http://192.168.1.100/status') .then(r => r.json()) .then(data => console.log(data.leds)); // Turn LED 1 ON fetch('http://192.168.1.100/led1/on') .then(r => r.json()) .then(data => console.log(data.state)); // Toggle LED 2 fetch('http://192.168.1.100/led2') .then(r => r.json()) .then(data => console.log(data));

Python

import requests # Get status response = requests.get('http://192.168.1.100/status') data = response.json() print(data['leds']) # Control LED response = requests.get('http://192.168.1.100/led1/on') print(response.json())

cURL Command Line

# Get device info curl http://192.168.1.100/info # Turn LED 1 ON curl http://192.168.1.100/led1/on # Get status curl http://192.168.1.100/status

⚠️ Important Notes

1. CORS Enabled: All endpoints have CORS headers, allowing requests from any origin
2. JSON Format: All responses are in JSON format with Content-Type: application/json
3. LED Indexing: LEDs are numbered 1-4 in API but 0-3 internally
4. Response Time: Typical response time < 50ms over local WiFi
5. No Authentication: Current version has no authentication. Secure your network!

📊 Technical Specifications

Parameter Value
Protocol HTTP/1.1
Port 80 (configurable)
Response Format JSON
Max Concurrent Connections 4
WiFi Standard 802.11 b/g/n (2.4GHz only)
Number of LEDs 4
GPIO Pins Used 0, 1, 2, 3

Version: 1.0 | Device: Xiao ESP32C6 | Last Updated: 2026-05-04