Modbus RTU transparent over LoRa to LoRa, Raspberry Pi 3B+ Node-RED

I have a Raspberry Pi 3B+ Buster (RPi) set up with a Modbus device working fine through Nodered read and write. The system is hard wired like this RPi—USBxRS485---ModbusRTU device slave (MDS). RPi works as Master and MDS as slave.
Now I want to go a step further to split the hard wired connection into and remotely read write over LoRa Node to LoRa node in this manner.
RPi1 + LoRa1 HAT Serial ttyS0 (Master Nodered) @@@@@wireless@@@@@@ LoRa2 HAT Serial ttyS0 (Slave Nodered)+RPi2—USBxRS485---MDS.
I have the serial enabled on raspi-config on both RPis and the LoRa HATs 1 & 2 communicate transparently and perfectly well. I am just not able to get the Nodered Red Flows right on the Master and Slave RPi to be able to interchange Modbus Read and Write Commands wirelessly over LoRa.
Have been trying to do work on it for many days now but just not able to get it right. RPI1 sends Modbus Read Hex Data to RPI2 (Slave address1, FC3, holding register 256) to RPi2 and I can see the Hex data come in perfectly on the RPi2 terminal. I do not have any idea of how to further fetch this incoming Hex data, send it to the MDS over serial, read and send msg.payload back to the Master RPI1 over LoRa (as if they are working perfectly hard wired mentioned in para1). I do not intend to use LoRaWAN Gateway, my aim is to use only LoRa node to LoRa node transparent communication. Any one has suggestion or example flow of how to achieve this?

I can see RPi2 this object coming in on the terminal sudo cat /dev/ttyS0:-{"fc":3,"unitid":1,"address":256,"quantity":1}

But when I use the "serial in" node set to /dev/ttyS0 on Node-RED. It shows green, serial port connected but do not see anything coming out of the debug node. Not sure why?


What LoRa Hat are you using ? link to product would help

Assume your are using AT commands ?
If so what is your "Split input" setting
\n = Line Feed
\r\n = Carriage Return Line Feed

@iiLaw . Using Waveshare LoRa HAT on each Raspberry Pi 3B+ (Master RPi1 and Slave RPi2).

'''SX1262 LoRa HAT for Raspberry Pi, Spread Spectrum Modulation, 868MHz Frequency Band'''

Managed to send and receive over LoRa based on your suggestion but there is an issue at the end:

  1. RPi1- Master Send to slave Modbus instruction fc=3, unitid=1, holding register address=256, qty=1 over ttyS0, 9600,8N1 is fine


  1. RPi2 - Slave Receive over ttyS0 then reads from device using Modbus Flex Read from ttyUSB0 is fine, reads 302 (30.2degC)


  1. RPi2 - Slave Send back value 302 to Master over ttyS0 is fine


  1. RPi1 - Master Receive Reply is NOT FINE, received message but shows as split message separated character by character on the debug window (see debug window on the picture)


How do I resolve this? Tried many options but could'nt get it right.

Ok you need to play with the split options as you NOT set any Master Receive Reply input node
If you always have a fixed number of characters coming back you can use
"into a fixed length of"
Or you can set
"after a timeout of" try 10 ms e.g. 10ms after first character arriving
"after a silence of" try 10 ms
You are nearly there just keep testing the options on Master Receive

Finally got it. Used "Join" + "Change" node from String to Number and it worked. Thank you.

1 Like