BiancoRoyal/node-red-contrib-modbus

Modbus Nodes do not forward msg attributes

Closed this issue · 8 comments

Which node-red-contrib-modbus version are you using?

5.28.0

What happened?

I'm expecting the modbus nodes to forward all msg attributes from the input to the output when they are not overwritten by new values. Existing attributes should retain. Currently a complete new message object is created, only keeping the input topic.

Server

Other/External server

How can this be reproduced?

I'll provide an easy example:

image
flows.json

The inject node has an payload containing all necessary information for the modbus node. In addition I've set a topic and msg.Some and msg.Hello:

image

As a result the output from the modbus node is a new message object containing only the given topic of "ExampleTopic", but missing the attributes "Some" and "Hello":

image

What did you expect to happen?

I expect the output to contain everything given as an input as long as it's not overwritten (e.g. like "payload"). Why are the modbus nodes clearing up the attributes? Is there any reason for it? I'd like to use the modbus node combined with HTTP nodes. For this I need to forward the incoming HTTP attributes to the HTTP response, but with the modbus node eliminating the data this is not possible.

image

Other Information

No response

Modbus is only numeric, to pass ASCII data through a modbus register you first convert the ASCII character to a number. The number will be then held in the register to be read and then converted back to ASCII. So a modbus node does not need to process non numeric data.

Thank you for your reply. I don't know if we are misunderstanding each other. I don't want to send my example values of msg.Some and msg.Hello to the modbus device/modbus server. I just want Node Red and the modbus node to retain that information and pass it to the output. The value "TopicExample" of msg.topic is retained and passed to the output - why is the value "World" of msg.Hello not passed to the output?

I've set up a second example to make it clear. I've got two different inputs going into one Modbus Flex Getter and want to split them up again after the modbus node:

image

At my inject nodes I've set msg.startingNode = "FromTopInject" for the top one and "FromBottomInject" for the lower one:

image

Then I'd like the switch node to check this value and direct into the upper or lower way:

image

But this is not possible because msg.startingNode is no longer set. It is cleared by the modbus node and I don't understand why.

And before the suggestion comes up: Unfortunately, I cannot use msg.topic for my case.

There is no requirement for normal modbus usage in what you ask, so it may be added by the developers but for a single user I doubt it will happen but they will reply. While waiting I would instead have a pre and post node. The pre node strips out your HTTP and then passes it directly to the post node missing out the modbus node to be recombined, the modbus continues into the modbus node. For the pre node you could use switch or filter, post node use change or join.

I'm not that deep into NodeRed, but I thought it is normal behaviour to pass everything given from the input to the output, even it is not used by that single node. Until now every node I've used had exactly that behaviour, but the modbus nodes didn't.

I've had set up exactly your suggestion but I encountered some problems with splitting and rejoining, so I tried to work with a single line flow without splitting. If there will be no option to pass the values through I'll have to have a look at that solution again.

I'll wait for another response from the dev. Again, thank you :)

I am not an expert either, currently at 4 complete and functioning flows started from scratch. The best way I find to get a flow to do what you want is to search the flow examples on the Node-red site and then import them for unpicking and altering, the ones that do what you are looking for are not always the obvious ones so a bit of hunting is needed. So for my MQTT to modbus flows I use a Json Filter node to extract single values from a full MQTT message.

https://flows.nodered.org/flow/7db69e532e4c58eb8078724092c4308a

HI, the flex-getter sends out a new msg every time and has an option to "keepMsgProperties" - HTTP should work as we have it in the examples - did you test the Modbus HTTP example, which is delivered with the package?

image

Hi and thanks for your response. That's exactly what I need. To be honest I did not know that there are additional properties under that tab which would exactly solve my problem.

Sorry for wasting your time on this and thank you very much! :)

no worries 😎 feel free to help us to improve, how to find or learn better from our docs 😉