Skip to main content

๐Ÿ“‹ 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 a device field for filtering

Actions

pin โ€” Digital Output

Toggle a digital GPIO pin on or off.

{
  "action": "pin",
  "payload": { "pin": 8, "state": 1 }
}
FieldTypeDescription
pinnumberGPIO pin number (must match device config)
statenumber1 = 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 }
}
FieldTypeDescription
servonumberPCA9685 channel (0โ€“15)
valuenumberTarget angle in degrees
currentnumberCurrent angle (Arduino only โ€” used for smooth transition)

turnout โ€” Turnout Control

Throw or close a configured turnout.

{
  "action": "turnout",
  "payload": { "turnout": 0, "state": true }
}
FieldTypeDescription
turnoutnumberTurnout index (matches device config array position)
statebooleantrue = 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 }
}
FieldTypeDescription
stripnumberLED strip index
patternnumberAnimation pattern ID
r, g, bnumberRGB 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.