This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
leaf2mqtt.sh
59 lines (47 loc) · 1.62 KB
/
leaf2mqtt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
echo "Starting up..."
echo "Setting timezone..."
echo $TZ > /etc/timezone
rm -f /etc/localtime
cd /root
if [ -z "$MQTTUSER" ]
then
./leaf2mqtt.exe --username=$USERNAME --password=$PASSWORD --mqtthost=$MQTTHOST --mqtttopic=$MQTTTOPIC > cmd.sh
else
./leaf2mqtt.exe --username=$USERNAME --password=$PASSWORD --mqtthost=$MQTTHOST --mqtttopic=$MQTTTOPIC --mqttuser=$MQTTUSER --mqttpass=$MQTTPASS > cmd.sh
fi
chmod +x cmd.sh
echo "Publishing responses..."
./cmd.sh
echo "Starting up MQTT loop..."
VIN=`head -n 1 vin.txt`
if [ -z "$MQTTUSER" ]
then
EXTRAS=""
else
EXTRAS="-u \"$MQTTUSER\" -P \"$MQTTPASS\""
fi
while true
do
mosquitto_sub -h "$MQTTHOST" -t "$MQTTTOPIC/$VIN/set/#" $EXTRAS -v | while read -r topic payload
do
echo "Rx: ${topic}: ${payload}"
if [[ "$topic" == "$MQTTTOPIC/$VIN/set/climate" ]]
then
./leaf_climate.exe --username=$USERNAME --password=$PASSWORD --temperature "${payload}"
# elif [[ "$topic" == "$MQTTTOPIC/$VIN/set/charge" ]]
# then
# ./leaf_charge.exe --username=$USERNAME --password=$PASSWORD --operation "${payload}"
fi
echo "Refreshing..."
if [ -z "$MQTTUSER" ]
then
./leaf2mqtt.exe --username=$USERNAME --password=$PASSWORD --mqtthost=$MQTTHOST --mqtttopic=$MQTTTOPIC > cmd.sh
else
./leaf2mqtt.exe --username=$USERNAME --password=$PASSWORD --mqtthost=$MQTTHOST --mqtttopic=$MQTTTOPIC --mqttuser=$MQTTUSER --mqttpass=$MQTTPASS > cmd.sh
fi
chmod +x cmd.sh
echo "Publishing responses after command..."
./cmd.sh
done
done