Skip to content

Node rosepetal-serial-config ​

Configuration node shared by rosepetal-serial-in and rosepetal-serial-out. It describes one serial port, holds the NATS connection of the nodes that use it and sends the port settings to the engine, which is the process that opens the device.

Properties ​

Port ​

FieldDefaultDescription
Serial Portnone (required)The port to open, chosen from the ports that the engine finds on its host: see The port list
Baud Rate57600One of the listed rates, from 230400 to 300, or other to type any number
Data Bits88, 7, 6 or 5
ParityNoneNone, Even, Mark, Odd or Space
Stop Bits12 or 1
DTR, RTS, CTS, DSRautoauto, High or Low. The engine sets the lines that are not on auto when it opens the port. A change of these fields alone does not reopen a port that is already open, so it applies the next time the engine opens the port

The port list ​

While the dialog is open, Node-RED asks the engine for its ports through NATS, with the NATS URL and Subject root of the dialog, at once and then every 5 seconds. When the engine knows a stable /dev/serial/by-id/... path for a port, the list offers that path. The field only offers the ports of the list, so the engine has to be running to choose one.

  • If the saved port is not in the list that comes back, the field switches to the first port of the list.
  • If no list comes back (no engine, or no NATS server at that URL), the field shows No ports found and is left empty.

In both cases Done saves the new value: click Cancel to keep the saved port.

Input ​

These rules turn the bytes that arrive from the engine into the messages of rosepetal-serial-in. The configuration node applies them in Node-RED, so every rosepetal-serial-in node that uses it emits the same messages.

FieldDefaultDescription
Optionally wait for a start character ofemptyWhen set, incoming data is discarded until this character arrives. The start character is not part of the message, and after each message the node waits for it again
Split inputon the character \nWhen a message ends: see the table below
and deliverASCII stringsASCII strings: msg.payload is a string. binary buffers: msg.payload is a Buffer
Split inputValueA message is emitted
on the characterA characterWhen the character arrives. It stays at the end of the payload. Only the first character of the value is used; empty means \n, and 0 emits every byte as a message of its own
after a timeout ofMillisecondsThat long after the first character of the message was received, with everything received until then
after a silence ofMillisecondsWhen no data has arrived for that long. The time starts again with every chunk of data
into fixed lengths ofNumber of charactersEvery time that many bytes have been received

In every mode a message is also emitted when 32768 bytes have accumulated.

The start character, the split character and the character added to the output accept a plain character ($), an escape code (\n, \r, \t, \e, \f, \0) or a hexadecimal code (0x03).

Output ​

FieldDefaultDescription
Add character to output messagesemptyAppended to every payload that rosepetal-serial-out sends, Buffers included, often \r or \n. It can be more than one character, for example \r\n

Request ​

FieldDefaultDescription
Default response timeout10000 msSent to the engine with the rest of the settings, as responseTimeout. The package has no request node and the engine in engine/ does not use the value

Advanced settings ​

FieldDefaultDescription
NATS URLnats://localhost:4222The NATS server that carries the traffic of this port
Subject rootemptyRoot of the NATS subjects. Empty means rosepetal.serial. Change it only to run several engines on one NATS server, and give the same value to the SUBJECT_ROOT of the engine. In each segment between dots, every run of characters other than letters, digits, _ and - becomes one _, and a _ at the start or end of a segment is removed

The NATS connection is always enabled. The same block shows the state of the Docker engine and two buttons: see Docker engine.

NATS connection ​

  • The node connects to the NATS server when it starts (at the latest a second later), whether or not a rosepetal-serial-in or rosepetal-serial-out node uses it. If the server cannot be reached it logs the error Unable to connect to NATS at followed by the URL and the reason. While a node uses it, it tries again after 1 second and then with waits that double up to 15 seconds; otherwise it tries again with the next periodic configure, 30 seconds later. Once connected, the NATS client reconnects by itself for as long as it takes.
  • It sends the settings to the engine in a configure message when it connects, after a reconnection and every 30 seconds, so an engine that was restarted receives them again. A deploy that changes the configuration node restarts it, which sends the new settings.
  • It subscribes to the data and control subjects only while a node uses it, and discards the messages of other ports.
  • It keeps the last state that the engine reported for the port. When no state has arrived for 15 seconds it logs the warning Heartbeat timeout detected and the nodes show serial heartbeat lost.

The subjects and payloads are described in NATS channels.

Docker engine ​

The Docker engine block of the advanced settings shows the version of the package and what Docker reports on the Node-RED host: whether Docker is available, whether the engine container is running, stopped or missing, and whether the engine image is present locally.

ButtonAction
Pull ImagePulls the engine image when it is not present locally. A pull is stopped after 5 minutes
Reload DockerStops and removes the engine container, pulls the image if it is missing and starts a new container with the NATS URL and Subject root of the dialog

The node also starts the engine without being asked. The first time a configuration node starts after Node-RED does, the package runs the Docker command line on the Node-RED host:

  1. If Docker is not available it logs a warning and stops here.
  2. If the engine image is not present locally it pulls it. A failed pull is logged as a warning and the steps continue.
  3. If a container named rosepetal-serial-engine is running, nothing else is done.
  4. If the container exists but is stopped, it is started.
  5. Otherwise a new container is launched with docker run -d --name rosepetal-serial-engine --network host --privileged --restart unless-stopped, with the NATS URL and the subject root of the configuration node in its NATS_URL and SUBJECT_ROOT variables.

A container that already exists keeps the values it was created with; Reload Docker creates it again. If Docker is not available or the container cannot be started, the sequence runs again the next time a configuration node starts.

These environment variables of the Node-RED process change the behaviour:

VariableDefaultPurpose
ROSEPETAL_ENGINE_AUTOSTARTenabledfalse disables the automatic start. The buttons of the editor still work
ROSEPETAL_ENGINE_CONTAINERrosepetal-serial-engineName of the engine container
ROSEPETAL_ENGINE_IMAGEAn image reference built into the package, tagged with the package versionImage that is pulled and run. Set it to the tag of an image built from engine/, for example rosepetal-serial-engine
STATUS_HEARTBEAT_MS5000Heartbeat interval given to a container that Node-RED launches

To build the image and run the engine by hand, see Serial engine.

Admin endpoints ​

The package adds these HTTP endpoints to the Node-RED admin API (under httpAdminRoot); the dialog uses all of them except /serialports. With adminAuth enabled, they need the permission shown.

EndpointPermissionPurpose
GET /rosepetal-serialport/v1/portsserial.readThe ports of the engine, as the ports array of the discovery reply. Query parameters natsUrl and subjectRoot, by default nats://localhost:4222 and rosepetal.serial
GET /serialportsserial.readSame as /rosepetal-serialport/v1/ports
GET /rosepetal-serialport/v1/docker/statusserial.readThe Docker state shown in the dialog: version, image, container, dockerAvailable, containerRunning, containerExists, imageAvailableLocally, pulling
POST /rosepetal-serialport/v1/docker/pullserial.writePull Image. Answers success, version, image, pulled (false when the image was already present) and message
POST /rosepetal-serialport/v1/docker/reloadserial.writeReload Docker. JSON body with natsUrl and subjectRoot; answers success, container, image and version

Errors are answered with status 500 and { "error": "..." }. The port list answers Serial discovery service not available - is the engine running? when nothing answers on the discovery subject, and Serial discovery request timed out - is the engine running? after 5 seconds without a reply. The pull and reload endpoints answer Docker is not available when docker info fails on the Node-RED host; the status endpoint reports it as dockerAvailable: false.