I had some time to play around with the mosquitto_pub in the latest dev. Had some issues with rc.local running before WIFI was up (and thinking it was an issue with rc.local but it wasnt) so I made this script. Maybe it will help someone.
start_mosquitto_pub.sh:
Seems to work the few times I have rebooted the HeaterMeter. Id like to add something to have it try to reconnect if there's an error in mosquitto_pub or it disconnects. May be best to make an init.d script but I dont know how to do this yet.
If I get anywhere with NodeRed flow I'll post it here if anyone is interested.
EDIT: Added '/root/start_mosquitto_pub.sh' to /etc/rc.local before the 'exit 0' BTW...
start_mosquitto_pub.sh:
Code:
#!/bin/sh
MQTT_HOST=192.168.0.123
MQTT_PORT=1883
MQTT_USER="somemosquittouser"
MQTT_PWD="somemosquittopassword"
MQTT_CLIENT="heatermeter"
MQTT_TOPIC="heatermeter/hmstatus"
#TESTING...
#echo "HOST: " $MQTT_HOST
#echo "PORT: " $MQTT_PORT
#echo "USER: " $MQTT_USER
#echo "PASSWORD: " $MQTT_PWD
#echo "CLIENT: " $MQTT_CLIENT
#echo "TOPIC: " $MQTT_TOPIC
#Wait for ping return of the MQTT server before trying to connect
while ! ping -c 1 -W 1 $MQTT_HOST; do
sleep 1
done
#Connect to MQTT and publish HeaterMeter data...
/usr/bin/lmclient @LMSS,1 | /usr/bin/mosquitto_pub -h $MQTT_HOST -p $MQTT_PORT -u $MQTT_USER -P $MQTT_PWD -i $MQTT_CLIENT -t $MQTT_TOPIC -l
Seems to work the few times I have rebooted the HeaterMeter. Id like to add something to have it try to reconnect if there's an error in mosquitto_pub or it disconnects. May be best to make an init.d script but I dont know how to do this yet.
If I get anywhere with NodeRed flow I'll post it here if anyone is interested.
EDIT: Added '/root/start_mosquitto_pub.sh' to /etc/rc.local before the 'exit 0' BTW...
Last edited: