forked from dst6se/aquatemp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heatpump
executable file
·171 lines (140 loc) · 5.07 KB
/
heatpump
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
#Get setting etc
path=`dirname "$0":`
username=`cat $path/settings | grep username | cut -f2`
password=`cat $path/settings | grep password | cut -f2`
mqtt=`cat $path/settings | grep mqttserver | cut -f2`
mqttuser=`cat $path/settings | grep mqttuser | cut -f2`
mqttpass=`cat $path/settings | grep mqttpass | cut -f2`
mqttport=`cat $path/settings | grep mqttport | cut -f2`
devicecode=`cat $path/settings | grep devicecode | cut -f2`
cloudurl="https://cloud.linked-go.com/cloudservice/api"
name=`cat $path/settings | grep openhabname | cut -f2`
mkdir -p $path/tmp
update()
{
token=`curl -s -H "Content-Type: application/json; charset=utf-8" -X POST \
-d '{"user_name":"'$username'",
"password":"'$password'",
"type":"2"}' $cloudurl/app/user/login.json |
jq -r '.object_result."x-token"'`
echo $token > $path/tmp/token
}
#update
check=`find $path/tmp/token -newermt '-86400 seconds' | wc -l`
if [[ $check -lt "1" ]]; then
update
fi
token=`cat $path/tmp/token`
power()
{
curl -s -H "Content-Type: application/json; charset=utf-8" \
-H "x-token: $token" \
-d '{"param":[{"device_code":"'$devicecode'","protocol_code":"Power","value":"'$1'"}]}' \
-X POST $cloudurl/app/device/control.json
}
if [[ $1 = "status" ]]; then
curl -s -H "Content-Type: application/json; charset=utf-8" \
-H "x-token: $token" \
-d '{"device_code":"'$devicecode'"}' \
-X POST $cloudurl/app/device/getDeviceStatus.json > $path/tmp/status
online=`cat $path/tmp/status | jq -r '.object_result."status"'`
is_fault=`cat $path/tmp/status | jq -r '.object_result."is_fault"'`
if [[ $is_fault = "true" ]];then
curl -s -H "Content-Type: application/json; charset=utf-8" \
-H "x-token: $token" \
-d '{"device_code":"'$devicecode'"}' \
-X POST $cloudurl/app/device/getFaultDataByDeviceCode.json > $path/tmp/fault
error_msg=`cat $path/tmp/fault | jq -r '.object_result[]."description"'`
mosquitto_pub -r -h $mqtt -p $mqttport -u $mqttuser -P $mqttpass \
-m "${error_msg}" \
-t "evoheat/$name/error_msg/state"
elif [[ $is_fault = "false" ]];then
error_msg="No Error"
mosquitto_pub -r -h $mqtt -p $mqttport -u $mqttuser -P $mqttpass \
-m "${error_msg}" \
-t "evoheat/$name/error_msg/state"
fi
status()
{
mosquitto_pub -r -h $mqtt -p $mqttport -u $mqttuser -P $mqttpass \
-m "${1}" \
-t "evoheat/$name/$2/state"
}
status $online status
status $is_fault is_fault
elif [[ $1 = "test" ]]; then
curl -s -H "Content-Type: application/json; charset=utf-8" \
-H "x-token: $token" \
-d '{"device_code":"'$devicecode'","protocal_codes":["'$2'"]}' \
-X POST $cloudurl/app/device/getDataByCode.json > $path/tmp/test
elif [[ $1 = "info" ]]; then
echo info
curl -s -H "Content-Type: application/json; charset=utf-8" \
-H "x-token: $token" \
-d '{"device_code":"'$devicecode'","protocal_codes":["Power","mode","T02","T10","R01","M06","M17","H07","H98","1129","1133","2050","mode_real"]}' \
-X POST $cloudurl/app/device/getDataByCode.json > $path/tmp/info
power=`cat $path/tmp/info | jq '.object_result[] | select(.code=="Power")' | jq -r '.value'`
mode=`cat $path/tmp/info | jq '.object_result[] | select(.code=="mode")' | jq -r '.value'`
toptemp=`cat $path/tmp/info | jq '.object_result[] | select(.code=="T10")' | jq -r '.value'`
bottomtemp=`cat $path/tmp/info | jq '.object_result[] | select(.code=="T02")' | jq -r '.value'`
modereal=`cat $path/tmp/info | jq '.object_result[] | select(.code=="mode_real")' | jq -r '.value'`
targettemp=`cat $path/tmp/info | jq '.object_result[] | select(.code=="R01")' | jq -r '.value'`
mosquitto_status()
{
mosquitto_pub -r -h $mqtt -p $mqttport -u $mqttuser -P $mqttpass \
-m "${1}" \
-t "evoheat/$name/$2/state"
}
mosquitto_status $mode mode
mosquitto_status $toptemp toptemp
mosquitto_status $bottomtemp bottomtemp
mosquitto_status $modereal modereal
mosquitto_status $targettemp targettemp
if [[ $power = "0" ]];then
mosquitto_status OFF power
elif [[ $power = "1" ]];then
mosquitto_status ON power
if [[ $mode = "1" ]];then
mosquitto_status intelligent mode_state
elif [[ $mode = "2" ]];then
mosquitto_status eco mode_state
elif [[ $mode = "3" ]];then
mosquitto_status hybrid mode_state
elif [[ $mode = "4" ]];then
mosquitto_status fast mode_state
fi
fi
#control
elif [[ $1 = "on" ]]; then
power 1
elif [[ $1 = "off" ]]; then
power 0
elif [[ $1 = "temp" ]]; then
temp=$2
curl -s -H "Content-Type: application/json; charset=utf-8" \
-H "x-token: $token" \
-d '{"param": [{"device_code": "'$devicecode'","protocol_code": "R01","value": "'$temp'"}]}' \
-X POST $cloudurl/app/device/control.json
elif [[ $1 = "mode" ]]; then
mode()
{
curl -s -H "Content-Type: application/json; charset=utf-8" \
-H "x-token: $token" \
-d '{"param":[{"device_code":"'$devicecode'","protocol_code":"mode","value":"'$mode'"}]}' \
-X POST $cloudurl/app/device/control.json
}
if [[ $2 = "intelligent" ]];then
mode="1"
mode
elif [[ $2 = "eco" ]];then
mode="2"
mode
elif [[ $2 = "hybrid" ]];then
mode="3"
mode
elif [[ $2 = "fast" ]];then
mode="4"
mode
fi
fi