๐ Command Reference
All DEJA IO devices receive JSON commands with an action and payload. The same handlers run on every device type โ pin, servo, turnout, effects, and ialed work identically whether the message arrives over USB serial or MQTT. Only the wrapping format differs:
- ๐ข๐ USB serial (
deja-arduino,deja-esp32) โ JSON array of commands - ๐๐ MQTT (
deja-esp32-wifi,deja-mqtt) โ single JSON object with adevicefield for filtering
Actions
pin โ Digital Output
Toggle a digital GPIO pin on or off.
{
"action": "pin",
"payload": { "pin": 8, "state": 1 }
}
| Field | Type | Description |
|---|---|---|
pin | number | GPIO pin number (must match device config) |
state | number | 1 = on (HIGH), 0 = off (LOW) |
servo โ Servo Position
Set a PCA9685 servo channel to a specific angle.
{
"action": "servo",
"payload": { "servo": 0, "value": 90, "current": 45 }
}
| Field | Type | Description |
|---|---|---|
servo | number | PCA9685 channel (0โ15) |
value | number | Target angle in degrees |
current | number | Current angle (Arduino only โ used for smooth transition) |
turnout โ Turnout Control
Throw or close a configured turnout.
{
"action": "turnout",
"payload": { "turnout": 0, "state": true }
}
| Field | Type | Description |
|---|---|---|
turnout | number | Turnout index (matches device config array position) |
state | boolean | true = thrown, false = closed |
ialed โ Addressable LED Strip (Planned)
Control individually addressable LED strips.
{
"action": "ialed",
"payload": { "strip": 0, "pattern": 0, "r": 255, "g": 0, "b": 0 }
}
| Field | Type | Description |
|---|---|---|
strip | number | LED strip index |
pattern | number | Animation pattern ID |
r, g, b | number | RGB color values (0โ255) |
This action is defined in the Arduino firmware but not yet fully implemented.
๐ฆ Format Differences
๐ข๐ USB Serial (deja-arduino / deja-esp32)
Commands are sent as a JSON array over serial at 115200 baud. Both device types share the same io/src/deja-arduino/ sketch, so they accept the same wire format:
[
{ "action": "pin", "payload": { "pin": 8, "state": 1 } },
{ "action": "servo", "payload": { "servo": 0, "value": 90, "current": 45 } }
]
Multiple commands can be batched in a single array.
๐๐ MQTT (deja-esp32-wifi / deja-mqtt)
Commands are sent as a single JSON object with a device field for filtering. Both wireless device types share the same MQTT topology and accept the same format:
{
"action": "pin",
"payload": { "pin": 8, "state": 1 },
"device": "my-wifi-device"
}
The device field is required โ devices ignore messages that don't match their own DEVICE_ID. The deja-esp32-wifi firmware also accepts the JSON-array shape used by the deja-arduino sketch as a convenience, so the same handlers work for both transports.
๐ก Sensor Responses
USB-serial devices (deja-arduino, deja-esp32) send sensor state changes back over serial:
{ "sensor": 0, "state": 1 }
MQTT devices (deja-esp32-wifi, deja-mqtt) publish equivalent sensor events to their โฆ/messages topic. Either way, sensor data is debounced (500ms minimum between state changes) and routed through the same writeSensorState() helper on the DEJA Server.