Web API¶
The device hosts a simple web server that allows you to check status and switch modes.
Insecure Protocol
HTTP is an inherently insecure protocol that transmits data, including credentials, in plain text. Only use this feature on a trusted, private network.
Web Server Credentials¶
The web server can be protected by basic authentication. You can set the username and password in the WiFiManager setup page.
- Connect with
curl
:- Use the
-u
or--user
flag to provide credentials. - If you omit the password,
curl
will prompt for it securely.
- Use the
Tip
To make the web server unauthenticated, make the user
and password
blank in the WiFiManager setup page.
Error Handling¶
This API uses standard HTTP status codes to indicate the success or failure of a request. Common status codes include:
- 200 OK: The request was successful.
- 400 Bad Request: The request was malformed or invalid (e.g., incorrect parameters, invalid data format).
- 401 Unauthorized: Authentication failed. Ensure you are providing valid credentials.
- 403 Forbidden: You are authenticated but do not have permission to perform the requested action.
- 404 Not Found: The requested resource or endpoint does not exist.
- 500 Internal Server Error: An unexpected error occurred on the server.
Specific endpoints may return additional details in the JSON response body to further clarify the error.
Web Server Commands¶
Tip
Run the test-api.sh
script to automate API tests to verify the device's web API functionality.
GET /
: Returns the current mode, display status, and SD card information.
Example Response
{
"mode": "USB MSC",
"display": {
"status": "on",
"orientation": 1
},
"sd_card": {
"total_size": 9876543210,
"used_size": 1234567890,
"free_size": 8641975320,
"file_count": 42
},
"mqtt": {
"enabled": true,
"state": 0,
"connected": true
},
"led": {
"color": "green",
"state": "on",
"brightness": 13
}
}
MQTT Icon
On the device's display, a small circle icon indicates the MQTT connection status:
Green: The MQTT client is connected to the broker.
Red: The MQTT client is disconnected from the broker.
- Missing: The MQTT client is disabled.
MQTT State
State | Description | State | Description |
---|---|---|---|
-4 | MQTT_CONNECTION_TIMEOUT | 1 | MQTT_CONNECT_BAD_PROTOCOL |
-3 | MQTT_CONNECTION_LOST | 2 | MQTT_CONNECT_BAD_CLIENT_ID |
-2 | MQTT_CONNECT_FAILED | 3 | MQTT_CONNECT_UNAVAILABLE |
-1 | MQTT_DISCONNECTED | 4 | MQTT_CONNECT_BAD_CREDENTIALS |
0 | MQTT_CONNECTED | 5 | MQTT_CONNECT_UNAUTHORIZED |
GET /mode/msc
: Returns the current mode (USB Mass Storage or FTP).
POST /mode/msc
: Switches the device to USB Mass Storage (MSC) mode.
Example Responses
GET /mode/ftp
: Returns the current mode (USB Mass Storage or FTP).
POST /mode/ftp
: Switches the device to FTP mode.
Example Responses
POST /device/restart
: Restarts the device.
GET /display/status
: Returns the current display status.
POST /display/toggle
: Toggles the display on and off.
Example Responses
POST /display/on
: Turns the display on.
POST /display/off
: Turns the display off.
POST /wifi/reset
: Resets the Wi-Fi settings and restarts the device.
Device Unreachable After Reset
After resetting the Wi-Fi settings, the device will restart and will no longer be connected to your Wi-Fi network. It will become unreachable at its previous IP address. You must reconnect to its Access Point (AP) to configure the new Wi-Fi credentials. See the Modes of Operation section for details on connecting to the AP.
GET /mqtt/status
: Returns the current MQTT client status.
Example Response
POST /mqtt/enable
: Enables the MQTT client.
POST /mqtt/disable
: Disables the MQTT client.
POST /mqtt/toggle
: Toggles the MQTT client on and off.
Example Responses
GET /led/status
: Returns the current LED color and state.
POST /led/on
: Turns the LED on.
POST /led/off
: Turns the LED off.
POST /led/toggle
: Toggles the LED on and off.
Example Responses
GET /led/brightness
: Returns the current LED brightness.
POST /led/brightness
: Sets the LED brightness. The body of the request should be a plain text integer between 0 and 255.
Example Responses
POST /upload
: Uploads a file to the device's SD card using multipart/form-data
.
Cannot Upload in MSC Mode
File uploads are only supported when the device is in FTP Server Mode. Attempts to upload in USB Mass Storage (MSC) mode will result in an error.
Example Responses