Serial Commands

Reference for the commands you can send to the OpenShock firmware over a serial (USB) connection.

The firmware has a small command console on its serial port. You can use it to view or change settings, troubleshoot the hub, or recover it when the web UI can't be reached.

Firmware version

This page describes firmware 1.6.0. Commands can differ in other versions. Type help on your hub to see exactly which commands it supports.

Connecting

  1. Connect the hub to your computer with a USB data cable.
  2. Open a serial terminal, for example the PlatformIO serial monitor, the Arduino IDE serial monitor, PuTTY, or screen.
  3. Use these settings: 115200 baud, 8 data bits, no parity, 1 stop bit (8N1).
  4. End each command with Enter. The firmware accepts both CR and LF line endings.

When the hub boots, it prints a welcome banner with version information. Type help to list all commands.

============== OPENSHOCK ==============
  Contribute @ github.com/OpenShock
  Discuss    @ discord.gg/OpenShock
  Type 'help' for available commands
=======================================

On boards with native USB (for example ESP32-S2/S3), the console runs on both the USB port and the UART pins, and responses are sent to both.

Syntax

<command> [subcommand] [argument]
  • Command names are case-insensitive (SysInfo works the same as sysinfo). Subcommands such as estop pin and help itself must be written in lowercase.
  • Most settings use one command for reading and writing. Without an argument, the command prints the current value. With an argument, it saves the new value.
  • Boolean arguments must be true or false (case-insensitive).
  • A line can be up to about 4 KB long.
  • help <command> shows the arguments and an example for one command.

Response format

Command results are printed on lines that start with $SYS$, so tools can tell them apart from regular log output:

$SYS$|Response|<Key>|<Value>    a value you asked for
$SYS$|Success|<Message>          a change was applied
$SYS$|Error|<Message>            the command failed

For example:

> rftxpin
$SYS$|Response|RmtPin|15
> rftxpin 4
$SYS$|Success|Saved config
> foo
$SYS$|Error|Command "foo" not found

Automated mode

If a line starts with $, the firmware runs it in automated mode. The $ is removed and the rest is run as a normal command, but the input is not echoed back. This is meant for scripts and tools that talk to the hub. For example, $sysinfo runs sysinfo.

Command reference

General

CommandDescription
helpList all commands.
help <cmd>Show the arguments and an example for one command.
versionPrint the firmware version, build mode, commit, board and chip.
sysinfoPrint free heap, uptime, and Wi-Fi status (SSID, BSSID, IPv4 and IPv6 when connected).
validgpiosList the GPIO pins that can be used on this board, for example ValidGPIOs|4,5,12,13.
ledtestRun every status LED pattern in turn (takes about 24 seconds).
restartRestart the hub.
factoryresetErase all settings, including Wi-Fi networks and the account link, then restart.

Console

CommandDescription
echoShow whether the console echoes what you type (SerialEcho|true).
echo <bool>Turn echo on or off. Saved to the config.

Network

CommandDescription
networksPrint all saved Wi-Fi networks as JSON, including passwords.
networks <json>Replace all saved Wi-Fi networks with the given list.
hostnamePrint the hub's network hostname.
hostname <name>Set the hostname and restart.

networks takes a JSON array. Each entry needs ssid and password, and can include a numeric id. If you leave out id, one is assigned automatically. The hub applies the new list right away. Any network not in the list is deleted.

networks [{"ssid":"HomeWiFi","password":"hunter2"},{"ssid":"Phone","password":"abc12345"}]

Backend

CommandDescription
domainPrint the backend API domain (default api.openshock.app).
domain <domain>Set the backend domain and restart. Used for self-hosting.
authtokenPrint the hub's backend auth token.
authtoken <token>Set the hub's backend auth token.
  • domain: before saving, the hub contacts https://<domain>/1 to check that an OpenShock backend is running there. If the check fails, the domain is not saved. This means the hub must already be connected to Wi-Fi. Enter only the hostname, without https:// or a path.
  • authtoken: if the backend rejects the token (HTTP 401), it is not saved. If the backend can't be reached (for example, there is no Wi-Fi yet), the token is saved anyway.

Keep your token private

The auth token lets anyone control the hub through the backend. Don't share output from authtoken, networks, or jsonconfig without removing it first.

Radio and shockers

CommandDescription
rftxpinPrint the GPIO pin used for the 433 MHz transmitter.
rftxpin <pin>Set the transmitter GPIO pin. Use validgpios to see which pins are allowed.
keepaliveShow whether shocker keep-alive is enabled.
keepalive <bool>Turn keep-alive on or off. Keep-alive periodically signals recently used shockers so they don't go to sleep.
rftransmit <json>Send one command directly over the radio. Useful for testing the transmitter.

rftransmit takes a JSON object with these fields:

FieldTypeValues
modelstringcaixianlin, petrainer, petrainer998dr, wellturnt330, d80
idnumberShocker RF ID, 0–65535
typestringshock, vibrate, sound, light, stop
intensitynumber0–255
durationMsnumberDuration in milliseconds, 0–65535
rftransmit {"model":"caixianlin","id":12345,"type":"vibrate","intensity":50,"durationMs":500}

No limits are applied

rftransmit sends directly to the radio. It skips the share limits and other safety checks in the OpenShock app. Test with vibrate or sound first, and read the safety rules.

Emergency stop

CommandDescription
estop enabledShow whether the E-Stop is enabled.
estop enabled <bool>Enable or disable the E-Stop.
estop pinPrint the GPIO pin used for the E-Stop button.
estop pin <pin>Set the E-Stop GPIO pin.

Configuration backup

CommandDescription
jsonconfigPrint the whole configuration as JSON, including secrets.
jsonconfig <json>Replace the whole configuration with the given JSON, then restart.
rawconfigPrint the raw binary configuration, Base64-encoded.
rawconfig <base64>Replace the configuration with a Base64-encoded binary config, then restart.

You can use these to back up a hub's settings and restore them later, or to copy settings to another hub. jsonconfig is easier to read and edit. rawconfig copies the exact stored bytes.

Last updated on

On this page