TRB245 Modbus RTU registers

Hello,

Currently, it is not possible to trigger alarms on specific bits within a single register.

However, you should be able to achieve this via some additional scripting. This would involve writing a script that periodically requests data from your Modbus slave using crontab. It would then extract the 7th bit from the received data and compare its value. Depending on the outcome of this comparison, the script can then send an SMS message.

Here’s an example:

#!/bin/sh

# Read modbus register and get 7th bit

modbus_output=$(ubus call modbus_master tcp.test '{"ip":"127.0.0.1","port":502,"id":1,"timeout":1,"function":3,"first_reg":8,"reg_count":"1","data_type":"16bit_int_hi_first","no_brackets":1}' | jq -r .result)

bit_val=$(echo "$modbus_output 64" | awk '{ printf ("%d", and($1,$2)) }')

# If 7th bit is 1

if [ $bit_val -eq 64 ]; then

# Send SMS if 7th bit is 1

logger $bit_val

logger "sending SMS!"

gsmctl -S -s "0037000000 Modbus triggered!"

fi

Note: jq is used in this script. To install jq, exucute:

  • opkg update
  • opkg install jq

Then, you can add this script to crontab to execute periodically. If you are unfamiliar with crontab, you can take a look at an example here.

EDIT:

Did not notice that you are using Modbus RTU. You may want to use the ‘serial.test’ ubus command instead of ‘tcp.test’. Just fill in the required values.:

"serial.test":{"id":"Integer","timeout":"Integer","function":"Integer","first_reg":"Integer","reg_count":"String","data_type":"String","no_brackets":"Integer","serial_type":"String","baudrate":"Integer","databits":"Integer","stopbits":"Integer","parity":"String","flowctrl":"String"}

Kind Regards,