-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
USB serial input #681
Comments
Please include your nodered service definition here (copy it from your |
The Node Red section is this: nodered:
container_name: nodered
build:
context: ./services/nodered/.
args:
- DOCKERHUB_TAG=latest
- EXTRA_PACKAGES=
restart: unless-stopped
user: "0"
environment:
- TZ=Etc/UTC
ports:
- "1880:1880"
volumes:
- ./volumes/nodered/data:/data
- ./volumes/nodered/ssh:/root/.ssh
- /var/run/docker.sock:/var/run/docker.sock
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
devices:
- "/dev/ttyAMA0:/dev/ttyAMA0"
- "/dev/vcio:/dev/vcio"
- "/dev/gpiomem:/dev/gpiomem"
I have tried adding - "/dev/ttyUSB0:/dev/ttyUSB0" but it doesn't run - file not found even if the USB is plugged in
|
Try changing the service definition to:
The To implement:
A lot of things seem to be a bit wonky in NodeJS 16 which is why I'm sticking with NodeJS 14 and "awaiting developments". A lot of people report privilege conflicts when they try to upgrade Node-RED. We (IOTstack) tend not to see those because of the A few weeks/months back I did a simple test with an ESP32 development board (which shows up as a CP2102 on ttyUSB0). The sketch just wrote millis() to the serial port every couple of seconds. A Node-RED flow was able to display what was being received. It's not exactly a conclusive test but it didn't crash under Bullseye and Give it a whirl and see what happens. |
Version 14 makes no difference and neither does 12. I looked at the syslog and I get this, suggesting the device isn't recognised, but Minicom is receiving the data perfectly.
Also the NRed flow gives this:
|
Ah. Is the serial node add-on defined in your Dockerfile?
The above is mine. The first part is the same as comes out of the IOTstack template but I do the last part as a single command spread over continuation lines - so that I only get a single layer added to the local image, irrespective of the number of add-on nodes. Either method will work but you will need You might also want to run:
in case any duplicates show up. |
Yes I do have node-red-node-serialport in my Dockerfile. I ran the dups check and did remove one for serialport. |
OK. Figured it out.
I ignored the "rebuild from source" and other nonsense. Life's too short for that kind of thing on a Raspberry Pi. The magic incantation is to pin the version in the Dockerfile: I didn't find this written anywhere so it's pure speculation but, reading between the lines, I'd say the latest version of My test vehicle was an ESP32 development board. A simple sketch that bungs out millis() every five seconds, along with anything received on the serial port in the meantime. Mounts on the Pi as
So, the serial-in node is just dumping whatever it receives, which is the millis() output every 5 seconds. Clicking the Inject node sends the current time out the door and that comes back the next time the ESP32 speaks (an example is the 3rd row of debug output). For the record:
Hope this solves your problem. |
Pins `node-red-node-serialport` to version `0.15.0`. This seems to be the only version that works with current Node-RED (3.0.2). Test case showing version `0.15.0` working included with SensorsIot#681. Also includes links to related issues on other repositories which led to this solution. Fixes SensorsIot#681. Signed-off-by: Phill Kelley <[email protected]>
Pins `node-red-node-serialport` to version `0.15.0`. This seems to be the only version that works with current Node-RED (3.0.2). Test case showing version `0.15.0` working included with SensorsIot#681. Also includes links to related issues on other repositories which led to this solution. Signed-off-by: Phill Kelley <[email protected]>
Pins `node-red-node-serialport` to version `0.15.0`. This seems to be the only version that works with current Node-RED (3.0.2). Test case showing version `0.15.0` working included with SensorsIot#681. Also includes links to related issues on other repositories which led to this solution. Signed-off-by: Phill Kelley <[email protected]>
Thanks Phill, provided I keep the USB connected that all works now. I am still running Serial version 0.11.1 on the old 'live' version, and that works too with Bullseye/NR3.0. |
The problem of what happens when a device disconnects or, worse, device enumeration changes the "n" in "/dev/ttyUSBn" is pretty common. I'll give you two more pointers which you may or may not find helpful: The first deals with the problem of devices coming and going. Basically:
Printer connects. UDEV rule gives it a name (eg Printer goes away and the inverse happens to tear it all down. The Octoprint container stays up 24x7 to accept queued jobs etc, and doesn't crash every time the printer is switched on or off. You might be able to adapt some of the techniques to Node-RED. However, my first thought would be that restarting the Octoprint container as the printer comes and goes might be OK. Waiting a little while for Octoprint to become ready doesn't amount to much. But Node-RED is a different kettle of fish because you probably have a lot of flows doing a lot of things. Interrupting those just because a device went through a power-cycle would never be my first choice.
So that brings us to the second link above which is less about the mechanics of recording Pi temperatures and more an example of working with MING (Mosquitto, Influx, Node-RED, Grafana). The key idea is keeping Node-RED the heck away from the hardware (USB ports, GPIO pin headers, or trying to read the CPU temperature any differently on this machine just because it also happens to be the machine where Node-RED is running). It's about using MQTT (first choice) or HTTP (second choice), and only resorting to Node-RED (third choice) if the first two options are not viable. In my case, I have a Hiking DDS238-2 ZN/S Class 1 electricity meter. It speaks RS485. I built a project consisting of an ESP32 and a serial-to-RS485 adapter. The ESP32 polls the meter and sends updates via MQTT at 10-second intervals:
Anyway, the Node-RED flow subscribes to that topic and formats the JSON payload into an InfluxDB insert. Let's suppose I have all this running on Buster and a fairly ancient version of Node-RED. Now suppose I build a Bullseye system and bring my flows across. I haven't had to go near the Hiking meter and ESP32 system. That's gone right on sending. If I'm building Bullseye on a separate Pi, I can have my new instance of Node-RED subscribe to my old MQTT broker on the Buster machine. If I really want to test the new MQTT broker, I can either change the code on the ESP32 to send two MQTT updates, or set up a flow on the Buster machine to relay that topic to the new machine. By keeping Node-RED away from the hardware, I gain flexibility and testability before I need to commit to any changes. And I never ever have to worry about whether Buster or Bullseye or Bookend, or a Node-RED update, or a NodeJS version breaks something at the hardware level. Just sayin' … |
Hi Phill, What I do find curious though is my serial input still works without any config changes to Dockerfile/Docker-compose.yml/ or even adding Node-red-Serial to the add-ons list. This is Buster and NR 2.2 and Serial 0.11.0. And it's not fussy about the USB being present or not. I do know that it broke with NR3.0 and Serial 1.03 but I didn't try them separately. Loading the new Bullseye/NR 3.02 system with the old backup data so as to retain the history isn't quite straightforward as it need several goes to get right Serial version installed. I suspect the Serial add-on 1.03 is the culprit despite being only 2 month old. |
I have an EON energy monitor with a USB output, form which I collect my electrical usage data. It has worked fine on Buster/Node Red 2.03. I wanted to upgrade the OS to Bullseye and the latest Node Red (3.02) so I built a new SSD, I now cannot access the Serial In node (1.03) - it reports No Connection, rather than Not connected. I can see the data stream in Minicom. It also crashes Node Red quite easily with a segment fault.
Any thoughts?
The text was updated successfully, but these errors were encountered: