Skip to content

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.


Saves Wi-Fi credentials to flash memory. A device restart is required for the changes to take effect.

Parameters:

ParameterTypeDescription
ssidstringThe network SSID.
passwordstringThe network password.

Command Example:

{"action":"set_wifi", "ssid":"YourNetworkSSID", "password":"YourNetworkPassword"}

Success Response:

{"status":"success","message":"WiFi credentials saved. Restart to reconnect."}

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."}

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)


Requests the ESP32 wifi status.

Command Example:

{"action":"get_status"}

Success Response:

{"status":"success","connected": true,"message": "Connected to WiFi"}

Requests the ESP32 info.

Command Example:

{"action":"get_device_info"}

Success Response:

{"status":"success","hostname": "esp32-xxxxxx","mac_address": "AABBCCDDEEFF"}

Enables (1) or disables (0) detailed serial debug output. The setting is saved to flash.

Parameters:

ParameterTypeDescription
modeint1 to enable, 0 to disable.

Command Example:

{"action":"set_debug", "mode":1}

Success Response:

{"status":"success","message":"Debug mode changed to 1"}

Enables continuous monitoring for a specific sensor type on a specific pin.

Parameters:

ParameterTypeDescription
pinintThe GPIO pin number.
typestringThe 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"}

Disables continuous monitoring for a specific sensor type on a specific pin.

Parameters:

ParameterTypeDescription
pinintThe GPIO pin number.
typestringThe 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"}

Controls an LED connected to a specific pin.

Parameters:

ParameterTypeDescription
pinintThe GPIO pin number.
statestring"on" or "off".

Command Example (Turn On):

{"action":"led", "pin":2, "state":"on"}

Success Response:

{"status":"success","message":"LED turned on at pin 2"}

Reads the analog value from a specific pin.

Parameters:

ParameterTypeDescription
pinintThe 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:

ParameterTypeDescription
pinintThe PWM GPIO pin number.
positionintThe 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"}