JSON Commands
This documentation details the JSON commands that can be sent to the ESP32 via WebSocket or the Serial Monitor for device configuration and hardware control.
Device Configuration Commands
Section titled “Device Configuration Commands”set_wifi
Section titled “set_wifi”Saves Wi-Fi credentials to flash memory. A device restart is required for the changes to take effect.
Parameters:
Parameter | Type | Description |
---|---|---|
ssid | string | The network SSID. |
password | string | The network password. |
Command Example:
{"action":"set_wifi", "ssid":"YourNetworkSSID", "password":"YourNetworkPassword"}
Success Response:
{"status":"success","message":"WiFi credentials saved. Restart to reconnect."}
reboot_wifi
Section titled “reboot_wifi”Disconnects from the current network and attempts to reconnect using saved credentials. If none are found, it switches to AP mode.
Command Example:
{"action":"reboot_wifi"}
Success Response:
{"status":"success","message":"Attempting to restart WiFi connection."}
get_mac
Section titled “get_mac”Requests the unique MAC address of the ESP32.
Command Example:
{"action":"get_mac"}
Success Response:
{"status":"success","mac_address":"AABBCCDDEEFF"}
(The format is without colons)
get_status
Section titled “get_status”Requests the ESP32 wifi status.
Command Example:
{"action":"get_status"}
Success Response:
{"status":"success","connected": true,"message": "Connected to WiFi"}
get_device_info
Section titled “get_device_info”Requests the ESP32 info.
Command Example:
{"action":"get_device_info"}
Success Response:
{"status":"success","hostname": "esp32-xxxxxx","mac_address": "AABBCCDDEEFF"}
set_debug
Section titled “set_debug”Enables (
1
) or disables (0
) detailed serial debug output. The setting is saved to flash.
Parameters:
Parameter | Type | Description |
---|---|---|
mode | int | 1 to enable, 0 to disable. |
Command Example:
{"action":"set_debug", "mode":1}
Success Response:
{"status":"success","message":"Debug mode changed to 1"}
enable_monitor
Section titled “enable_monitor”Enables continuous monitoring for a specific sensor type on a specific pin.
Parameters:
Parameter | Type | Description |
---|---|---|
pin | int | The GPIO pin number. |
type | string | The sensor type: "button" , "potentiometer" , or "touch" . |
Command Example:
{"action":"enable_monitor", "pin":14, "type":"button"}
Success Response:
{"status":"success","message":"Enabled monitoring for button on pin 14"}
disable_monitor
Section titled “disable_monitor”Disables continuous monitoring for a specific sensor type on a specific pin.
Parameters:
Parameter | Type | Description |
---|---|---|
pin | int | The GPIO pin number. |
type | string | The sensor type: "button" , "potentiometer" , or "touch" . |
Command Example:
{"action":"disable_monitor", "pin":14, "type":"button"}
Success Response:
{"status":"success","message":"Disabled monitoring for button on pin 14"}
Hardware Control Commands
Section titled “Hardware Control Commands”Controls an LED connected to a specific pin.
Parameters:
Parameter | Type | Description |
---|---|---|
pin | int | The GPIO pin number. |
state | string | "on" or "off" . |
Command Example (Turn On):
{"action":"led", "pin":2, "state":"on"}
Success Response:
{"status":"success","message":"LED turned on at pin 2"}
read_analog
Section titled “read_analog”Reads the analog value from a specific pin.
Parameters:
Parameter | Type | Description |
---|---|---|
pin | int | The analog GPIO pin number. |
Command Example:
{"action":"read_analog", "pin":34}
Success Response:
{"status":"success","message":"Analog value read at pin 34"}
(The actual value is sent as a sensor_update
event)
Moves a servo motor connected to a PWM pin to a specified position in degrees.
Parameters:
Parameter | Type | Description |
---|---|---|
pin | int | The PWM GPIO pin number. |
position | int | The position in degrees (0-180). |
Command Example:
{"action":"servo", "pin":13, "position":90}
Success Response:
{"status":"success","message":"Servo moved to 90 degrees at pin 13"}