Custom script blocking rms on reboot

Hello. I have a custom script running on my device and I have noticed that any device with a custom script wont automatically reconnect to rms when the device reboots. Every other device without a custom script connects just fine. I have added a 30 second sleep timer to my script but even that doesn’t help.

I have managed to find a temporary solution. So it seems that that script teltonika uses for rms gets stuck on reconnecting. To fix this simply add /etc/init.d/rms_mqtt restart at the start of your script after a sleep of about 20 seconds. The sleep is very important because your script will also hang if you don’t add it.

Hello,

Could you please share the script currently running on your device that is preventing RMS from automatically reconnecting?

Best regards,

Hello.
Here is the script im using:

#!/bin/bash

sleep 30

/etc/init.d/rms_mqtt restart

serial_Nr=$(cat /sys/mnf_info/serial)
BROKER=Ip_Address
PORT=1883
TOPIC=“/${serial_Nr}_WR”
RESPONSE_TOPIC=“/${serial_Nr}_WR/response”
USERNAME=“Username”
PASSWORD=“Password”
QOS=0
RETRY_INTERVAL=10
MAX_RETRIES=10

for i in $(seq 1 $MAX_RETRIES); do
echo “Attempting to connect to MQTT broker (Attempt $i)…”

mosquitto_pub -h $BROKER -p $PORT -t "$/test/connection" -u $USERNAME -P $PASSWORD -m "test" -q $QOS

if [ $? -eq 0 ]; then
    echo "Connected to MQTT broker successfully."

    mosquitto_sub -h $BROKER -p $PORT -t $TOPIC -u $USERNAME -P $PASSWORD -q $QOS | while IFS=',' read -r ID FUNCTION FIRST_REG VALUE DATA_TYPE
    do
        echo "Received command: ID=$ID, FUNCTION=$FUNCTION, FIRST_REG=$FIRST_REG, VALUE=$VALUE, DATA_TYPE=$DATA_TYPE"

        RESPONSE=$(ubus call modbus_client.rpc serial.test "{
            \"serial_type\": \"/dev/rs485\",
            \"baudrate\": 9600,
            \"databits\": 8,
            \"stopbits\": 1,
            \"parity\": \"none\",
            \"flowcontrol\": \"none\",
            \"timeout\": 5,
            \"id\": $ID,
            \"function\": $FUNCTION,
            \"first_reg\": $FIRST_REG,
            \"reg_count\": \"$VALUE\",
            \"data_type\": \"$DATA_TYPE\",
            \"no_brackets\": 1
        }")

        echo "Sent Modbus request"

        if [ $? -eq 0 ]; then
            echo "Command executed successfully. Response: $RESPONSE"
            timeout 4 mosquitto_pub -h $BROKER -p $PORT -t "$RESPONSE_TOPIC" -u $USERNAME -P $PASSWORD -m "$RESPONSE" -q $QOS 
        else
            echo "Failed to execute write command."
            echo "Response was: $RESPONSE"
        fi
    done
    break
else
    echo "Failed to connect to MQTT broker. Retrying in $RETRY_INTERVAL seconds..."
    sleep $RETRY_INTERVAL
fi

done

if [ $? -ne 0 ]; then
echo “Failed to connect to MQTT broker after $MAX_RETRIES attempts.”
exit 1
fi

The sleep 30 and /etc/init.d/rms_mqtt restart were added to fix the issue im having. I also suspect that custom scripts also affect mobile connections and gps services but im still testing that theory.