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
| Field | Default | Description |
|---|---|---|
| Serial Port | none (required) | The port to open, chosen from the ports that the engine finds on its host: see The port list |
| Baud Rate | 57600 | One of the listed rates, from 230400 to 300, or other to type any number |
| Data Bits | 8 | 8, 7, 6 or 5 |
| Parity | None | None, Even, Mark, Odd or Space |
| Stop Bits | 1 | 2 or 1 |
| DTR, RTS, CTS, DSR | auto | auto, 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 foundand 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.
| Field | Default | Description |
|---|---|---|
| Optionally wait for a start character of | empty | When 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 input | on the character \n | When a message ends: see the table below |
| and deliver | ASCII strings | ASCII strings: msg.payload is a string. binary buffers: msg.payload is a Buffer |
| Split input | Value | A message is emitted |
|---|---|---|
| on the character | A character | When 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 of | Milliseconds | That long after the first character of the message was received, with everything received until then |
| after a silence of | Milliseconds | When no data has arrived for that long. The time starts again with every chunk of data |
| into fixed lengths of | Number of characters | Every 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
| Field | Default | Description |
|---|---|---|
| Add character to output messages | empty | Appended 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
| Field | Default | Description |
|---|---|---|
| Default response timeout | 10000 ms | Sent 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
| Field | Default | Description |
|---|---|---|
| NATS URL | nats://localhost:4222 | The NATS server that carries the traffic of this port |
| Subject root | empty | Root 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-inorrosepetal-serial-outnode uses it. If the server cannot be reached it logs the errorUnable to connect to NATS atfollowed 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 periodicconfigure, 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
configuremessage 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 detectedand the nodes showserial 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.
| Button | Action |
|---|---|
| Pull Image | Pulls the engine image when it is not present locally. A pull is stopped after 5 minutes |
| Reload Docker | Stops 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:
- If Docker is not available it logs a warning and stops here.
- If the engine image is not present locally it pulls it. A failed pull is logged as a warning and the steps continue.
- If a container named
rosepetal-serial-engineis running, nothing else is done. - If the container exists but is stopped, it is started.
- 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 itsNATS_URLandSUBJECT_ROOTvariables.
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:
| Variable | Default | Purpose |
|---|---|---|
ROSEPETAL_ENGINE_AUTOSTART | enabled | false disables the automatic start. The buttons of the editor still work |
ROSEPETAL_ENGINE_CONTAINER | rosepetal-serial-engine | Name of the engine container |
ROSEPETAL_ENGINE_IMAGE | An image reference built into the package, tagged with the package version | Image that is pulled and run. Set it to the tag of an image built from engine/, for example rosepetal-serial-engine |
STATUS_HEARTBEAT_MS | 5000 | Heartbeat 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.
| Endpoint | Permission | Purpose |
|---|---|---|
GET /rosepetal-serialport/v1/ports | serial.read | The 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 /serialports | serial.read | Same as /rosepetal-serialport/v1/ports |
GET /rosepetal-serialport/v1/docker/status | serial.read | The Docker state shown in the dialog: version, image, container, dockerAvailable, containerRunning, containerExists, imageAvailableLocally, pulling |
POST /rosepetal-serialport/v1/docker/pull | serial.write | Pull Image. Answers success, version, image, pulled (false when the image was already present) and message |
POST /rosepetal-serialport/v1/docker/reload | serial.write | Reload 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.