Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions docker/mqtt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,19 @@ for entity in $CLEANUP_ENTITIES; do
-t "$DISCOVERY_TOPIC" -n -r
done

# Periodic state updates
# mosquitto_pub -l keeps the connection open and publishes each line of input, outer loop
# reconnects on drop, use keep-alive larger than MQTT_PAUSE to avoid needless pings.
while true; do
# Replace this with your real data source
ORB_OUTPUT="$(/app/orb summary || echo '{}')"
#echo "ORB_OUTPUT: $ORB_OUTPUT"
while true; do
# sleep first to avoid publishing zeroes on first iteration
sleep "$MQTT_PAUSE"

# Publish Orb Summary to MQTT
mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
-t "$STATE_TOPIC" -m "$ORB_OUTPUT" -r
# output a single line to mosquitto_pub
(/app/orb summary || echo '{}') | jq -c .

done | mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
-t "$STATE_TOPIC" -l -r -k $((MQTT_PAUSE * 2))

sleep "$MQTT_PAUSE"
echo "mosquitto_pub disconnected, reconnecting..."
done