Hi,
I have some custom scripts using “ubus call modbus_client.rpc tcp.test” with RUT956.
In latest FW release (07.13.1) it seams to execute the commands but the results returns just an incremented number for each attempt.
I see in the FW change log that there are several modification to the Modbus Client.
Can you provide instructions on how to use the commands with the new firmware?
Example command below working in previous FW-release (up to 07.13):
ubus call modbus_client.rpc tcp.test ‘{“id”:1,“timeout”:10,“function”:3,“first_reg”:127,“reg_count”:“1”,“data_type”:“16bit_int_hi_first”,“no_brackets”:1,“ip”:“192.168.1.2”,“port”:“502”,“delay”:0}’
On the new firmware, the ubus call command from previous versions can now only be used internally, and its syntax has been modified across firmware releases.
This is quite significant change which limits the functionality and response time.
As a test i made the below script to collect two values from the Modbus TCP Slave of the RUT956 to the Modbus TCP Client definition. Collecting the network connectivity and Ruter name…
It takes 11 seconds for login/retrieving token and thereafter between 4 to 12 seconds retrieving updated values.
Of course it could be due to bad programming on my side but the direct “ubus call modbus_client” is much faster (below seconds and consistent).
Are there any suggestion/possibilities to get somehow same performance as earlier?
Keep in mind this is internal request in the rut956 running the scripts so the extra security layer does not make much added value
Thanks you
Output:
Elapsed time: 0 s
Token expired, refreshing…
nettype=“No service”
rutname=“RUT956”
Elapsed time: 11 s
nettype=“No service”
rutname=“RUT956”
Elapsed time: 14 s
nettype=“No service”
rutname=“RUT956”
Elapsed time: 22 s
nettype=“No service”
rutname=“RUT956”
Elapsed time: 34 s
get_new_token() {
TOKEN=$(curl -s -k -X POST “$LOGIN_URL”
-H “Content-Type: application/json”
-d “{"username": "$USERNAME", "password": "$PASSWORD"}” | jsonfilter -e ‘@.data.token’)
# Update expiration based on the typical token lifespan, e.g., 1 hour
TOKEN_EXPIRATION=$(($(date +%s) + 3600)) # Current time + 1 hour
}
Main loop to continuously check status
start_time=$(date +%s)
while true;
do
looptime=$(date +%s)
elapsed_time=$((looptime - start_time))
echo Elapsed time: $elapsed_time s
# Check if token is expired
if [ "$(date +%s)" -ge "$TOKEN_EXPIRATION" ]; then
echo "Token expired, refreshing..."
get_new_token
if [ -z "$TOKEN" ]; then
echo "Failed to retrieve token. Will retry..."
sleep 60 # Wait a minute before retrying
continue
fi
fi
# Use token to make the next API request
RESPONSE=$(curl -s -k -X GET "$API_URL" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN")
# Parse the response to get the required variables using jsonfilter
nettype=$(echo "$RESPONSE" | jsonfilter -e '@.data.nettype.data')
rutname=$(echo "$RESPONSE" | jsonfilter -e '@.data.rutname.data')
# Clean the values by removing extra quotes
nettype="${nettype//\\\"/}"
rutname="${rutname//\\\"/}"
# Output the variables to verify
echo "nettype=$nettype"
echo "rutname=$rutname"
# Sleep for some time before making the next request
sleep 0 # Example: sleep for 5 minutes
I understand now that the API request may be used internally without requesting tokens.
But still i think the response is much slower than using ubus call function
Eg to get all values defined within a Mobus_Client:
/sbin/api GET /modbus/client/tcp/1/requests/status/