Hi @Vilius, still working on integrating an MQTT-based reboot listener into my TRB245 setup and could use some further assistance.
The goal is to have the device subscribe to an external MQTT broker topic and execute a system reboot when a message is received on that topic. I have a shell script configured to run at startup via /etc/rc.local, and have confirmed the broker hostname and topic are correct.
When running the script manually via CLI I receive the following error:
/etc/rc.local: line 41: mosquitto_sub: not found
Running find / -name "mosquitto*" shows that only the broker binary is present at /usr/sbin/mosquitto — the client tools (mosquitto_sub / mosquitto_pub) do not appear to be installed. The installed package appears to be mosquitto-ssl.
I attempted to install the client tools via:
opkg update
opkg install mosquitto-client-ssl
Could you confirm:
- Whether mosquitto-client-ssl is the correct package for client tools on TRB245 firmware 07.14.5?
- Whether mosquitto_sub is supported on this firmware for custom shell script use?
- If there is an alternative recommended approach for subscribing to an external MQTT topic and triggering a shell action on the TRB245?
For reference, here is the script (identifying information removed):
#!/bin/sh
#============================================================
kaa_reboot_listener.sh
Listens on an external MQTT broker topic for a reboot command.
Any message received on the topic triggers a router reboot.
NOTE: The command will remain in “Pending” status on the
platform side since the device reboots before it can
publish a result back. This is expected behaviour.
Place at: /etc/kaa_reboot_listener.sh
Make exec: chmod +x /etc/kaa_reboot_listener.sh
#============================================================
── Configuration ───────────────────────────────────────────
BROKER=“<BROKER_HOSTNAME>”
BROKER_PORT=“1883”
APP_VERSION=“<APP_VERSION>”
ENDPOINT_TOKEN=“<ENDPOINT_TOKEN>”
USERNAME=“”
PASSWORD=“”
CLIENT_ID=“reboot-listener-$$”
LOG_TAG=“reboot_listener”
────────────────────────────────────────────────────────────
TOPIC_SUB=“kp1/${APP_VERSION}/cex/${ENDPOINT_TOKEN}/command/reboot/status”
log() {
logger -t “$LOG_TAG” “$1”
echo “$(date ‘+%Y-%m-%d %H:%M:%S’) [$LOG_TAG] $1”
}
if [ -z “$APP_VERSION” ] || [ -z “$ENDPOINT_TOKEN” ]; then
log “ERROR: APP_VERSION and ENDPOINT_TOKEN must be set. Exiting.”
exit 1
fi
AUTH_ARGS=“”
if [ -n “$USERNAME” ]; then
AUTH_ARGS=“-u $USERNAME -P $PASSWORD”
fi
log “Starting reboot listener.”
log “Subscribing to: $TOPIC_SUB on $BROKER:$BROKER_PORT”
mosquitto_sub
-h “$BROKER”
-p “$BROKER_PORT”
-i “$CLIENT_ID”
$AUTH_ARGS
-t “$TOPIC_SUB”
-v | while IFS= read -r line; do
payload="${line#"$TOPIC_SUB "}"
log "Received message on reboot topic. Payload: '$payload'"
if [ -n "$payload" ]; then
log "Reboot command received. Syncing and rebooting..."
sync
sleep 1
reboot
exit 0
fi
done
log “mosquitto_sub exited unexpectedly. Listener stopped.”
Device: TRB245
Firmware: 00.07.14.5
Any guidance appreciated. Thanks