Skip to main content

REST API Reference

Base URL: http://<device-ip>/api/wifi (configurable via api_base_path)

Authentication

If enable_auth = true in the HTTP config, all endpoints require HTTP Basic Auth:

curl -u admin:password http://192.168.4.1/api/wifi/status

Endpoints

MethodEndpointDescription
GET/statusGet connection status
GET/scanScan available networks
GET/networksList saved networks
POST/networksAdd new network
PUT/networks/:ssidUpdate network
DELETE/networks/:ssidRemove network
POST/connectConnect (auto or specific SSID)
POST/disconnectDisconnect
GET/ap/statusGet AP status
GET/ap/configGet AP configuration
PUT/ap/configUpdate AP configuration
POST/ap/startStart SoftAP
POST/ap/stopStop SoftAP
GET/varsList custom variables
PUT/vars/:keySet variable
DELETE/vars/:keyDelete variable
POST/factory_resetFactory reset

Example Requests

Get Status

curl http://192.168.4.1/api/wifi/status

Response:

{
"state": "connected",
"ssid": "MyWiFi",
"ip": "192.168.1.100",
"gateway": "192.168.1.1",
"netmask": "255.255.255.0",
"dns": "192.168.1.1",
"rssi": -65,
"quality": 70,
"channel": 6,
"mac": "AA:BB:CC:DD:EE:FF",
"hostname": "esp32-aabbcc",
"uptime_ms": 123456,
"ap_active": false
}

Scan Networks

curl http://192.168.4.1/api/wifi/scan

Response:

{
"networks": [
{"ssid": "MyWiFi", "rssi": -65, "auth": "WPA2"},
{"ssid": "Neighbor", "rssi": -80, "auth": "WPA/WPA2"},
{"ssid": "OpenNet", "rssi": -70, "auth": "OPEN"}
]
}

Add Network

curl -X POST http://192.168.4.1/api/wifi/networks \
-H "Content-Type: application/json" \
-d '{"ssid": "MyWiFi", "password": "secret123", "priority": 10}'

Connect

# Connect to a specific network
curl -X POST http://192.168.4.1/api/wifi/connect \
-H "Content-Type: application/json" \
-d '{"ssid": "MyWiFi"}'

# Auto-connect (highest priority saved network)
curl -X POST http://192.168.4.1/api/wifi/connect

Delete Network

curl -X DELETE http://192.168.4.1/api/wifi/networks/MyWiFi

AP Status

curl http://192.168.4.1/api/wifi/ap/status

Response:

{
"active": true,
"ssid": "ESP32-AABBCC",
"ip": "192.168.4.1",
"channel": 1,
"sta_count": 2,
"clients": [
{"mac": "AA:BB:CC:DD:EE:01", "ip": "192.168.4.2"},
{"mac": "AA:BB:CC:DD:EE:02", "ip": "192.168.4.3"}
]
}

Custom Variables

# List all variables
curl http://192.168.4.1/api/wifi/vars

# Set a variable
curl -X PUT http://192.168.4.1/api/wifi/vars/device_name \
-H "Content-Type: application/json" \
-d '{"value": "Living Room"}'

# Delete a variable
curl -X DELETE http://192.168.4.1/api/wifi/vars/device_name

Variables list response:

{
"vars": [
{"key": "server_url", "value": "https://api.example.com"},
{"key": "device_name", "value": "My ESP32"}
]
}

Factory Reset

curl -X POST http://192.168.4.1/api/wifi/factory_reset

Error Responses

All errors return a JSON object with an error field:

{"error": "Error message"}
HTTP CodeDescription
400Bad Request — Invalid JSON, missing required field
401Unauthorized — Authentication required
404Not Found — Network or variable does not exist
500Internal Error — Operation failed

CORS

The REST API includes CORS headers, allowing browser-based clients to access the endpoints directly.