Skip to content

Rosepetal Serial NATS Channels ​

The serial nodes and the Docker engine exchange every byte over the same four subjects. The root is rosepetal.serial by default and should only be overridden when you intentionally run multiple bridges; every write, frame and control payload includes the port field so the engine can map traffic to the correct device.

SubjectDirectionPurpose
rosepetal.serial.outNode-RED ➜ engineSerial writes
rosepetal.serial.inengine ➜ Node-REDSerial reads
rosepetal.serial.controlbidirectionalConfiguration, baud updates, statuses
rosepetal.serial.discoveryrequest/replySerial port enumeration

You can override the root (for example, myproject.serial) by changing both the Node-RED config node and the engine's SUBJECT_ROOT environment variable, but the .out, .in, .control, and .discovery suffixes are fixed. All payloads are UTF-8 JSON strings encoded with the StringCodec helper from the nats client.

rosepetal.serial.out ​

Node-RED publishes one message per write. The engine decodes the base64 payload and writes it to the serial device.

jsonc
{
  "type": "write",
  "timestamp": "2024-01-01T12:00:00.000Z",
  "port": "/dev/ttyUSB0",
  "encoding": "base64",
  "data": "SGVsbG8gV29ybGQh",
  "meta": {
    "msgId": "6d3f2a4f.9a70dc",
    "nodeId": "b27d3c90.6d65b",
    "timeout": 10000
  }
}
  • type is always write.
  • data contains the base64-encoded payload after terminators are applied by Node-RED.
  • meta carries tracing fields only (msgId, nodeId, and timeout when the message had a msg.timeout); the engine ignores it. msg.meta is intentionally not forwarded — upstream nodes use it for their own state (sometimes large buffers), and frames must stay under the NATS 1 MB payload limit.

rosepetal.serial.in ​

The engine publishes frames read from the serial device on the inbound subject. Node-RED applies its usual splitting rules to these chunks before emitting msg.payload downstream.

jsonc
{
  "type": "frame",
  "timestamp": "2024-01-01T12:00:01.000Z",
  "port": "/dev/ttyUSB0",
  "encoding": "base64",
  "data": "UkVBRFkK",
  "meta": {
    "source": "engine"
  }
}
  • encoding defaults to base64; hex and utf8 are also supported.
  • timestamp becomes msg.timestamp of the serial in node.
  • meta is free-form: the serial in node exposes it as msg.nats. The engine in engine/ sets it to { "source": "engine" }.
  • A status message (see below) is also accepted on this subject.

rosepetal.serial.control ​

Control messages keep both sides synchronised. Commands are expressed via the type field.

Node-RED ➜ engine ​

  • configure: emitted when the config node connects to NATS (on Node-RED start, and on the deploy that follows an update of the config node), after a NATS reconnection, and every 30 seconds so that an engine that was restarted receives the settings again. body.reason tells which: startup, nats-reconnect or periodic.
  • baudrate: emitted when a flow sends msg.baudrate to the serial out node.
  • node-status: emitted by each serial in/out node when it starts or stops so the bridge can log which Node-RED components reference a given port.
jsonc
{
  "type": "configure",
  "timestamp": "2024-01-01T12:00:00.000Z",
  "port": "/dev/ttyUSB0",
  "settings": {
    "port": "/dev/ttyUSB0",
    "baudRate": 57600,
    "dataBits": 8,
    "parity": "none",
    "stopBits": 1,
    "dtr": "none",
    "rts": "none",
    "cts": "none",
    "dsr": "none",
    "waitFor": "",
    "splitMode": "char",
    "newline": "\\n",
    "binary": false,
    "addChar": "",
    "responseTimeout": 10000
  },
  "body": {
    "reason": "startup"
  }
}
jsonc
{
  "type": "baudrate",
  "timestamp": "2024-01-01T12:05:00.000Z",
  "port": "/dev/ttyUSB0",
  "settings": { /* latest snapshot */ },
  "body": {
    "baudRate": 115200,
    "requestId": "6d3f2a4f.9a70dc"
  }
}
jsonc
{
  "type": "node-status",
  "timestamp": "2024-01-01T12:00:01.000Z",
  "port": "/dev/ttyUSB0",
  "settings": { /* latest snapshot */ },
  "body": {
    "nodeId": "b27d3c90.6d65b",
    "role": "serial-out",
    "state": "online"
  }
}

Engine ➜ Node-RED ​

The engine publishes status events on the same subject to indicate lifecycle changes and emits a heartbeat per port every STATUS_HEARTBEAT_MS (five seconds by default). Nodes consider the link healthy when the latest status is "opened", and report the heartbeat as lost when no status has arrived for 15 seconds.

jsonc
{
  "type": "status",
  "timestamp": "2024-01-01T12:00:02.000Z",
  "port": "/dev/ttyUSB0",
  "status": "opened",
  "details": "Port ready @ 57600 baud"
}

status is one of connecting, opened, reconnecting, closed or error. The engine in engine/ also adds a settings field with the settings it applied to the port, or null; the nodes do not read it.

Unknown type values should be ignored by both sides, which keeps the protocol extensible.

rosepetal.serial.discovery ​

Request/reply subject for discovering available serial ports. The configuration UI fills its port list through the Node-RED admin endpoint /rosepetal-serialport/v1/ports, which sends this request; /serialports does the same (see Admin endpoints).

Request (Node-RED ➜ engine) ​

jsonc
{
  "type": "discovery",
  "timestamp": "2025-11-18T12:00:00.000Z",
  "requestId": "discovery-1731934800000"
}

Response (engine ➜ Node-RED) ​

jsonc
{
  "type": "discovery-response",
  "timestamp": "2025-11-18T12:00:00.100Z",
  "requestId": "discovery-1731934800000",
  "ports": [
    {
      "path": "/dev/ttyUSB0",
      "manufacturer": "FTDI",
      "serialNumber": "A12345",
      "vendorId": "0403",
      "productId": "6001",
      "byId": "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A12345-if00-port0"
    },
    {
      "path": "/dev/ttyACM0",
      "manufacturer": "Arduino LLC",
      "serialNumber": "0123456789ABCDEF0123",
      "byId": null
    }
  ],
  "error": null
}

The engine calls SerialPort.list() and returns the results. If enumeration fails, error contains the error message and ports is an empty array. Requests timeout after 5 seconds if the engine doesn't respond. The ports array contains port information objects with at minimum a path field, and optionally manufacturer, serialNumber, vendorId, and productId when available from the system. The engine in engine/ adds a byId field to every port: its /dev/serial/by-id/... path when the host has one, otherwise null. The configuration UI offers that path instead of path when it is present.