Using RS485 port on CC100 with NodeRED

Steps to use the serial port on the CC100 with NodeRED in Docker.

  1. Disable the PLC Runtime

  2. The serial port on the CC100 is called /dev/ttySTM1 and has the correct permissions by default.

image

  1. Install Node-RED and attach the serial port in privileged mode.

docker run -d --name wago-node-red -d --privileged=true --user=root --network=host --device=/dev/ttySTM1:/dev/ttySTM1:rw -v node_red_user_data:/data nodered/node-red

  1. Open NodeRED GUI in browser at port 1880
    https://:1880

5.Install the Modbus palette (node-red-contrib-modbus) in the palette manager

  1. Wire up your modbus slave device to the RS485 port on the CC100.

For example with the WAGO Modbus RTU coupler you would wire pin 3 and 8 to the D+/D- on the CC100 connector X11 as shown below.

  1. Now configure the Modbus Read serial connection as shown below using /dev/ttySTM1 as the com port.

On my device, I am reading an RTD module at address 0.

Run this to a debug node, and the temp sensor is publishing its readings as you would expect.

Here is the example flow.
CC100 Serial Port Example MB Read.json (1.9 KB)

5 Likes

Hi there Kurt,

Thank you for the informative post. I was wondering if this is the same situation for the Wago PFC200 controllers?

If so, how does one read up on the devices and there names? For example here the serial port is “/dev/ttySTM1”. Is this information freely available somewhere?

Additionally, I am busy working with a PFC22-8216 controller that has a built-in serial port, however we have added a serial card 750-652 on the kbus. Is there any way to access the serial comms on the card via the kbus for NodeRED or would you suggest using the built-in port for NodeRED?

Any advice would be greatly appreciated!

Kind Regards,
Devlin

Just for a bit more information, here is a copy of the email I sent to Wago’s support for some more context of the issue.

I have a pfc200, 8216 controller.

I have been able to successfully run Modbus tcp/ip communication with a power meter in Node-RED. I’m now trying to do the same but with Modbus rtu.

I am using the node-red-contrib-modbus package and am interfacing with an inverter. The controller has a built-in RS-485 port (I think it is /dev/ttyO1 on the controller’s Linux system), we also have a 750-652 serial card connected to the controller.

What I want to please know is how do I use Node-RED to perform the Modbus rtu comms. In docker I believe I have to set the port permission when starting the Node-RED container? I assume that this will be related to the serial port (/dev/tty…). I’m not sure whether it will be easier to setup the onboard serial port or the 750-652. If you could please advise what I should try.

Here is the docker command I ran to run Node-RED:

docker run --restart=always -d --privileged=true --device=/dev/ttyO1:/dev/ttyO1:rw -p 1880:1880 --name ems nodered/node-red

I have also included a screenshot of the Modbus rtu configuration and a link to a Wago community forum post I was using for assistance.

Any assistance would be greatly appreciated.

Please see this post;

2 Likes

@WagoKurt thank you very much for the response, it has helped my understanding a lot. I have since set port ttyO1 to rs485 by using the command line tool (/etc/config-tools ./set_serial_mode_rs485). I also ensured that the necessary r+w permissions were allowed to ttyO1 for read and write access to the port using the chmod command.

To get the modbus rtu communication working tried using the node-red-node-serial port palette for modbus rtu but to no avail. I’m not sure if the functions in that palette are capable of performing modbus rtu read and write operations? In the example guide you attached I see it is used for ASCII.

I would just like to please confirm that modbus rtu can be achieved with the pfc200 8216 controller in Node-RED? And that it is most commonly done by using the node-red-contrib-modbus package, with the built-in RS485 port (X3)?

The reason I ask is because I have tried to perform a modbus RTU read but each time the docker container keeps restarting, even if I use the (–security-opt seccomp:unconfined) command when running the container. I’m not sure if this is a common issue? I also cannot assign port 1880 when --network=host is applied in the command, this may also be what is causing the problem.

For more context, the modbus read block in Node-RED just says “waiting” and the container restarts which causes it to lose connection. I then have to stop and remove the container and repeat the process.

Do you perhaps have some ideas as to where I could be going wrong? Sorry for all the information but I just want to provide as much context as possible. Any advice would be greatly appreciated.

Kind Regards,
Devlin

Can you verify what containers are running with the command;

docker container ls

I would ensure only one container is running for the initial testing of the serial port. And also can you confirm that the Codesys runtime is disabled.

@Devlin_Hugo @WagoKurt
I am experiencing a similar issue on my wago CC100 running node red in docker. I’ve spent the last couple of days trying to solve this but with no positive outcome. Even with only one modbus serial read node and a debugger, after configuring the modbus read node, node red immidiately crash and goes into infinite boot-loop. I finally managed to find the flows.json via FTP and remove the modbus node from the flow and node red started back up on its own, as it should.

Same thing happens (serial only, TCP works fine) with node-red-contrib-serialport and node-red-contrib-modbus.

I’ve found some older info about this being an issue in the past as well, but on raspberry pi. In this case I would assume this is either a firmware or a node issue :confused:

I don’t have any logs available just now. FYI, I have two Wago CC100 installed docker and node-red exactly the same way, both are acting the same way.

Any tips and tricks to solve this?

Maybe something is helpful here with udev/symlinks:

Thank you for responding @WagoKurt and @StefSoma.

I can confirm that the runtime on the controller has been disabled. Each time Node-RED has crashed I have stopped and removed the container using the “docker stop containerID” and “docker rm containerID”. I would then run the “docker container ls” command to confirm that it was removed successfully.

Subsequently, I have been trying to run a container which doesn’t keep restarting by playing around with the docker run command, but each time the serial port ttyO1 is required the issue arises. For a bit more context, I was using a similar approach to that of @StefSoma by making use of a single modbus read node and a debugger when Node-RED kept rebooting.

I would also just like to please confirm that the PFC200 controllers have been used to achieve serial communication (modbus RTU) using Node-RED? Not sure if there are better ways to test if the port is working?

Kind Regards,
Devlin

@WagoGrim Thank you for the guidance. Unfortunately it made no difference. I modified the 99-serial.rules file, but still, the minute I add a modbus and a debugger (in a fresh clean flows, not other flows what so ever) and deploy. Node-RED immidiately goes into infinate boot-loop :frowning:

root@CC100-568AF0:~ ls -l /dev/ttySTM1
crw-rw-rw- 1 root dialout 247, 1 Jun 19 11:09 /dev/ttySTM1

I used this command to create the node-red container initially, as far as I can see. It worked fine. Node red “finds” the serial port in the “search” field in the config window of modbus-client node.

docker run -d --restart unless-stopped --name wago-node-red -d --privileged=true --user=root -p 1880:1880 --device=/dev/ttySTM1:/dev/ttySTM1:rw -v node_red_user_data:/data nodered/node-red

At this point I am lost, and officially out of ideas to try out.

My only trick is to try something different docker container like Telegraf in the repo I linked to then we know if its only Node-RED or not in your setup… Recipe something like:

docker pull arm32v7/telegraf

You can modify this conf-file, you only need the serial driver app inside here…

mv telegraf.conf /home/admin
chmod +x /home/admin/telegraf.conf
chmod ugo+rw /dev/serial

Run and see if its working or not…
docker run -d --name mytelegraf --device=/dev/serial:/dev/serial:rw -v /home/admin/telegraf.conf:/etc/telegraf/telegraf.conf:ro arm32v7/telegraf:latest

Run docker logs telegraf to output…

You can also try this Modbus/TCP to RTU gateway.
It also requires to associate the host serial device to the container.
You can adjust the verbosity if needed.

After a couple of trails and errors (not realizing the telegraf.conf file code above were truncked.)

root@CC100-568AF0:~ docker logs mytelegraf
2023-06-19T13:22:19Z I! Loading config: /etc/telegraf/telegraf.conf
2023-06-19T13:22:19Z E! Unable to open /var/log/telegraf.log (open /var/log/telegraf.log: permission denied), using stderr
2023-06-19T13:22:19Z I! Starting Telegraf 1.27.0
2023-06-19T13:22:19Z I! Available plugins: 237 inputs, 9 aggregators, 28 processors, 23 parsers, 59 outputs, 4 secret-stores
2023-06-19T13:22:19Z I! Loaded inputs: modbus
2023-06-19T13:22:19Z I! Loaded aggregators:
2023-06-19T13:22:19Z I! Loaded processors:
2023-06-19T13:22:19Z I! Loaded secretstores:
2023-06-19T13:22:19Z I! Loaded outputs: influxdb websocket
2023-06-19T13:22:19Z I! Tags enabled: host=ad2b92dd2e75
2023-06-19T13:22:19Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:“ad2b92dd2e75”, Flush Interval:10s
2023-06-19T13:22:19Z D! [agent] Initializing plugins
2023-06-19T13:22:19Z I! [inputs.modbus::MID] Got 6 request(s) touching 56 holding registers for 29 fields (slave 1)
2023-06-19T13:22:19Z I! [inputs.modbus::MID] Got 0 request(s) touching 0 inputs registers for 0 fields (slave 1)
2023-06-19T13:22:19Z I! [inputs.modbus::MID] Got 0 request(s) touching 0 discrete registers for 0 fields (slave 1)
2023-06-19T13:22:19Z I! [inputs.modbus::MID] Got 0 request(s) touching 0 coil registers for 0 fields (slave 1)
2023-06-19T13:22:19Z D! [agent] Connecting outputs
2023-06-19T13:22:19Z D! [agent] Attempting connection to [outputs.influxdb]
2023-06-19T13:22:24Z W! [outputs.influxdb] When writing to [http://192.168.3.236:8086]: database “wagodb” creation failed: Post “http://192.168.3.236:8086/query”: context deadline exceeded (Client.Timeout exceeded while awaiting headers)
2023-06-19T13:22:24Z D! [agent] Successfully connected to outputs.influxdb
2023-06-19T13:22:24Z D! [agent] Attempting connection to [outputs.websocket]

I have no clue what this tells me. Good or bad news? :rofl:

@Devlin_Hugo did you find a fix to get the serial communication working without node-red crashing?

Edit: See here if this solves your issue. https://www.wago.community/t/how-to-using-pfc200-onboard-serial-port-with-node-red/68/5?u=stefsoma

Hi there @StefSoma,

Sorry for taking a while to respond, quite a lot going on at the moment.

I have managed to create a container with modbus rtu that does not crash. However the actual reads are not successful which is perhaps a configuration error on my side. I don’t believe so though as I have been very thorough in checking the communication parameters as well as the registers I’m reading from.

I keep getting a “Error: Client Not Ready To Read At State reconnecting” error in the debug channel as indicated in the provided screenshot. Not sure if this is something you have dealt with before? Or if perhaps @WagoKurt and @WagoGrim have any possible suggestions.

Instead of using a debug node directly after the Modbus Read node, I used a Modbus Response node which seems to be effective in preventing the crashing. I also ran @WagoGrim’s chmod command (thanks @WagoGrim ) chmod ugo+rw /dev/serial. I believe that the permissions for the port were already granted before the command though, as I mentioned in my previous posts.

I then connected the debug node to the Modbus Read node where it connects to the Modbus Response node. Still no luck reading any actual registers unfortunately but at least the container seems stable.

Kind Regards,
Devlin

One thing you might check are the docker logs. If you open a terminal and after the NR container is created, type;
docker logs [container-id] --follow

Then configure the serial port in Node-RED and after the container crashes, there might be a clue posted to the log.

Thanks for the suggestion @WagoKurt,

When I run the command and check file this is the message which appears each time I “inject” the modbus read node:

21 Jun 13:05:47 - [error] [modbus-read:65d2b5d11c21941e] Error: Client Not Ready To Read At State reconnecting

I’m going to try using the advice in the post @StefSoma provided a link to and try to rebuild the serial node. Will post an update here if I have any success.

Kind Regards,
Devlin

A further update, if I remove the connection timeout in the Modbus Read node, the node in idles the green “active” state. I then trigger the modbus rtu read in Node-RED and now I get an error which says “Error: Port Not Open”.

This seems to point to the fact that there’s some type of configuration issue with the serial port.

I can confirm the container stops when using modbus read with the serial port STM1 on CC100/FW25.

@WagoKurt I’m trying my exact same setup /config as for another wago C100 that’s working with both TCP and serial node-red-contrib-modbus. Last time I ran npm rebuild --build-from-source. After that (and making sure the modbus wiring and EOL resistor were in place it worked). However, the npm rebuild did not work on my new cc100.

This time I also tried this to no avail.
npm cache clean -f
rm -rf node_modules/
npm install

TCP works perfectly fine using node-red-modbus, only serial not working.

Any suggestions? Any permanent fix for this?

Please help :innocent: