node-red-node-serialport provides a set of nodes for Node-RED, enabling communication with hardware serial ports (e.g., RS232, RS485, USB-to-serial adapters). It integrates the widely used `serialport` library to offer Input, Output, Request, and Control nodes directly within the Node-RED visual programming environment. The current stable version is 2.0.3, released in late 2023. This package is actively maintained, with significant updates in major versions to align with Node.js and underlying `serialport` library advancements. Its primary differentiator is seamless integration into Node-RED flows, allowing developers to manage serial communications visually and programmatically without writing custom boilerplate code for port management.
npm install node-red-node-serialportVerified import paths — ran on the pinned version, not inferred.
Illustrates how to install the Node-RED package and provides a JavaScript object representing a message payload to programmatically configure and control a serial port using the 'Serial Control' node in a Node-RED flow.
Verify successful installation by checking the Node-RED palette for the serial nodes. If they appear, the 'failures' were likely benign compilation warnings. If problems persist, ensure you have necessary build tools installed (e.g., `build-essential` on Linux, Visual Studio build tools on Windows).
For existing flows, review 'Serial In' nodes and explicitly set the 'Split char' to an empty string if streaming single characters is the desired behavior. For new flows, be aware of the new default split behavior.
Migrate parsing configurations (timeout, delimiter, length) from the shared serialport configuration node to the individual 'Serial In' nodes where they are used. Review and update all 'Serial In' nodes after upgrading.
If your flows relied on `msg.port` from 'Serial In' nodes, you will need to manually add this information (e.g., using a 'Change' node) or refactor to use 'Serial Request' nodes if applicable, or retrieve the port name from the node configuration directly if needed downstream.
Upgrade your Node.js installation to version 16.0.0 or newer. Check your Node-RED environment's Node.js version (`node -v`) and update if necessary.
Ensure your Node.js version meets the package requirements (>=16.0.0 for `node-red-node-serialport` v2.x). If Node.js was recently updated or downgraded, reinstall `node-red-node-serialport` to recompile its native dependencies for the current Node.js version: `npm rebuild node-red-node-serialport` or `npm install node-red-node-serialport` in your Node-RED user directory.
On Linux, add the Node-RED user to the `dialout` or `uucp` group: `sudo usermod -a -G dialout $USER` (replace `$USER` with the user running Node-RED, or `pi` if on Raspberry Pi). A reboot or logging out and back in may be required for group changes to take effect. Ensure the device path is correct.
Ensure that the `Serial In` node's output type is configured correctly (e.g., 'UTF8 string' if you expect string data for `.split()`). Use a 'Change' or 'Function' node upstream to convert `msg.payload` to a string using `msg.payload.toString()` if it might be a Buffer, or add checks like `if (typeof msg.payload === 'string') { ... }`.