Thank you so much Chrish, this is working perfectly nice and are almost as responsive as earlier.
You saved my use case with quite many RUT956 devices interfacing Modbus-devices and the ability to keep the firmware updated!
Since you pointed out that catching ubus could create an issue, maybe with memory?, i made a test script for tcp.test, doing the job continuously and flawlessly.
After running 90k+ calls i cannot see any significant changes in memory use(terminal → top). But maybe you have observed something ?
Earlier i had problems that “modbus_client” service seams to fill the memory (easily solved by crontab and a reset eg. 05 */3 * * * /etc/init.d/modbus_client restart ) but now it seams fine.
And again thanks Chrish!
Output:
Retrieved ID: 90251
Status Response:
{
“finished”: true,
“error”: 0,
“result”: “0.000000”
}
Retrieved ID: 90252
Status Response:
{
“finished”: true,
“error”: 0,
“result”: “0.000000”
}
Script:
#!/bin/bash
IP=“192.168.2.10”
while true
do
RESPONSE=$(ubus call modbus_client.rpc tcp.test
‘{“ip”:"’“$IP”‘",“port”:“502”,“id”:1,“timeout”:5,“function”:3,“first_reg”:1125,“reg_count”:“2”,“data_type”:“32bit_float3412”,“no_brackets”:1,“garbage”:1}’)
ID=$(echo “$RESPONSE” | jsonfilter -e ‘@.result’)
if [ -z “$ID” ]; then
echo “Failed to extract ID.”
exit 1
fi
echo “Retrieved ID: $ID”
STATUS_RESPONSE=$(ubus call modbus_client.rpc request_status ‘{“id”:’“$ID”‘}’)
echo “Status Response:”
echo “$STATUS_RESPONSE”
sleep 0
done
exit 0