PlantCtrl/esp32/host/upload-settings.sh

42 lines
1.1 KiB
Bash
Raw Normal View History

2021-06-29 23:49:30 +02:00
#!//bin/bash
if [ $# -ne 3 ]; then
echo "Homie prefex and device index must be specified:"
echo "$0 <mqtt host> <prefix> <device index>"
echo "e.g."
echo "$0 192.168.0.2 test/ MyDeviceId"
exit 1
fi
mqttHost=$1
mqttPrefix=$2
homieId=$3
2022-06-25 17:20:11 +02:00
maxSteps=6
settingsFile=settings.json
if [ ! -f $settingsFile ]; then
echo "$settingsFile missing"
echo "check $settingsFile.example"
exit 1
fi
2021-06-29 23:49:30 +02:00
mosquitto_pub -h $mqttHost -t "${mqttPrefix}${homieId}/stay/alive/set" -m "1" -r
2022-06-25 17:20:11 +02:00
echo "(1 / $maxSteps) Waiting ..."
2021-06-29 23:49:30 +02:00
mosquitto_sub -h $mqttHost -t "${mqttPrefix}${homieId}/#" -R -C 1
set -e
2022-06-25 17:20:11 +02:00
echo "(2 / $maxSteps) Waiting 30 seconds ..."
2021-07-01 20:40:51 +02:00
sleep 30
mosquitto_pub -h $mqttHost -t "${mqttPrefix}${homieId}/\$implementation/config/set" -f $settingsFile
2022-06-25 17:20:11 +02:00
echo "(3 / $maxSteps) Waiting for reboot ..."
2021-06-29 23:49:30 +02:00
sleep 1
mosquitto_sub -h $mqttHost -t "${mqttPrefix}${homieId}/#" -R -C 1
2022-06-25 17:20:11 +02:00
echo "(4 / $maxSteps) Alive"
2021-07-01 20:40:51 +02:00
sleep 20
2022-06-25 17:20:11 +02:00
echo "(5 / $maxSteps) Create Backup ..."
2021-06-29 23:49:30 +02:00
mosquitto_pub -h $mqttHost -t "${mqttPrefix}${homieId}/config/backup/set" -m "true" -r
2021-07-01 20:40:51 +02:00
sleep 5
2022-06-25 17:20:11 +02:00
echo "(6 / $maxSteps) Shutdown ..."
2021-06-29 23:49:30 +02:00
mosquitto_pub -h $mqttHost -t "${mqttPrefix}${homieId}/stay/alive/set" -m "0" -r
exit 0