How to send a simple string to a serial node

I'm quite new to Node-RED, and I might be missing a significant feature. I have a straightforward setup where I need to send a string to a serial device.

To provide some context, the device in question is a Mettler Toledo scale, which is set to have continuous output. I need to change this setting using a SICS command (this detail might not be relevant to my main question) every time the scale start (this is because every time this scale is shut down, it resets its parameters).

The string I need to send to the scale is a simple "S\r\n" (S and LFCR). I've successfully done this using PowerShell or the command prompt.

In Node-RED, I tried configuring an "Serial Out" Node and an "Inject" Node to send a string or a JSON (I tried "S\r\n" and S\r\n). However, despite not receiving any errors, the output of the scale does not change as expected.
b
a

Could someone please advise on how to properly send commands to the scale using Node-RED?
What I'm doing wrong?

that does look correct (as far as I can see) - the usual mistake is to set it to string mode and then try to send \r\n - which then sends all those characters - but you have set JSON mode so that should send the correct characters. Have you set the serial port to add extra characters to the output ?

Thanks for thw answer!

These are the settings of my serial node:

The settings are the same as those for the "serial IN" node, which correctly allows me to receive scale output (I can observe this in the debug). I am wondering if the presence of the "serial IN" node might be causing a problem. Could the two nodes (one IN and one OUT) potentially interfere with each other?

Maybe the inject node sends the message too early. Have you tried to manually send the message by pressing the button on the inject node?

No, that's the correct way of using it.

Try this:

I apologize, everyone. I'm not sure why, but without making any changes from my previous situation, now it seems to be working. Sorry for wasting your time.

Maybe every time I manually injected the JSON, it was the wrong string, I don't know.

The problem I'm facing now is that I don't know how to send the JSON when the scale starts. It seems that when I power off the scale, Node-RED still sees the serial connection as active.

I want to avoid sending the string every 10 seconds or so. Is there any way I can achieve this?

Again, thanks for all the answers!

I presume you mean sending messages to the scales. Why does it matter if you keep sending?

Due to this situation: the scale is continuously sending out the weight in grams without my intervention (and I can't change that permanently). I send two strings to the scale: one to stop the scale's output and one to start the output in both grams and carats. This could lead to a problem to my system when the output is briefly stopped after the first command. I can't remove the first command (the one that stops the output) because otherwise the result of the output is really messy (it's like the scale is trying to output two measurements at the same time, but this is another story).

OK, I understand now. Is the solution to send the string when you start receiving data from the scales after a period when there has been no data for a while?

If so then a Trigger node configured something like this should do it

Feed the data from the scales into that. When it first receives a message it will immediately send the S message. If data keeps coming in at least once every 30 seconds then the 'extend delay' option will prevent it timing out. If data stops for more that 30 seconds then the Trigger will send nothing, but will then reset and wait for the data from the scales to restart. The Trigger node is incredibly flexible and powerful and can solve a myriad of similar problems. Obviously you can adjust the 30 seconds to meet your requirements.

1 Like

Perfect. I was trying to use the "change" node, but I wasn't able to obtain the same result as with the trigger node... THANKS!