Modbus: read 1 register on 2 serial RTU devices

Hi everybody,
I'm trying to do a small project to read some sensors with serial modbus rtu and store in a DB. I've a basic understanding of programming and I'm new to Node-Red.
Now I read correctly a modbus device (a power meter) and add a temperature/humidity sensor (i2c) on a pi3 and store the data on influxdb . It's time to add a new device but I'm stuck how to read the 2° modbus sensor and store the data in the flow. Because the modbus is time sensistive, I need to read the first sensor, wait the response and the read the second sensor and wait for response and repeat the loop. Searching on the forum/web a solution , but I don't understand how to , at the moment is not clear how to concatenate the node to read corretlly the bus with correct sequence.

This is my flow that work with 1 modbus sensor and 1 i2c sensor on raspberry.

Thanks
Regards
Stefano

Something like

thank Steve, now I'll try and I'll post the result.

ciao

Hi Steve, thanks!.
I've got both device data and put in result1 and result2, but for me seems to be separated messages.

now, I need to add together the resultX with a node (ex. join node) and then send to db?

A question about timing. I set the inject every .5 sec. How can I calculate the round trip between the first and last devices? if the round trip on the bus exceed the inject time , the request overlap and go in timeout? if yes, there is any way to bypass it?

I hope my questions are clear.
thanks
regards
Stefano

No, not if you followed my screenshot.

Look closely at the words I wrote e.g. "set Output Property to msg.result1" and "show complete message (look at msg.result1 and msg.result2)"

In short, if you successfully followed my cues, there is no need to join messages since both values will already be inside the same msg.

NOTE: If you are NOT seeing both properties in the msg, you may not have enabled "keep message properties"

image


There are lots of ways to prevent this. A simple method is to check a flow.busy flag is NOT true before requesting. (set flow.busy true just before 1st read and reset it just after the last read). There are also "simple gate" and "semaphore" nodes in the "manage palette".

As for timing - there is a handy subflow you can place in-line to measure timing: flow-timer. A simple subflow to measure time taken in parts of your flows. (flow) - Node-RED

I see your detailed image and set the same, but i saw only the last result2 and not result1. I'll try to enable "keep message" (now disabled) and retest everything.
Now I'll check and test your note about the flow.
I'm continue to gain knowledge in this powerfull platform but I still lack of esperience, sorry.
Thanks for your patience!!!!
regards
Stefano
ciao

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.