forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgoecheck.sh
executable file
·177 lines (169 loc) · 7.69 KB
/
goecheck.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
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
171
172
173
174
175
176
177
#!/bin/bash
goecheck(){
#######################################
#goe mobility check
digit='^[0-9]$'
if [[ $evsecon == "goe" ]]; then
output=$(curl --connect-timeout 1 -s http://$goeiplp1/status)
if [[ $? == "0" ]] ; then
#check whether goe has 1to3phase switch capability => new HWV3 and new API V2
fsp=$(echo $output | jq -r '.fsp')
if [[ ! $fsp =~ $digit ]] ; then
state=$(echo $output | jq -r '.alw')
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatus"; then
lp1enabled=$(</var/www/html/openWB/ramdisk/lp1enabled)
if ((state == "0")) && (( lp1enabled == "1" )) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=alw=1 > /dev/null
fi
fi
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatus"; then
if ((state == "1")) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=alw=0 > /dev/null
fi
fi
version=$(echo $output | jq -r '.fwv') # get firmware version
majorVersion=${version%.*} # remove everything after a "."
majorVersion=${majorVersion%-*} # remove everything after a "-"
majorVersion=${majorVersion#0} # remove leading "0"
oldcurrent=$(echo $output | jq -r '.amp')
current=$(</var/www/html/openWB/ramdisk/llsoll)
if (( oldcurrent != $current )) && (( $current != 0 )); then
if (($majorVersion >= 40)) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=amx=$current > /dev/null
else
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=amp=$current > /dev/null
fi
fi
else
output=$(curl --connect-timeout 1 -s http://$goeiplp1/api/status)
state=$(echo $output | jq -r '.frc')
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatus"; then
lp1enabled=$(</var/www/html/openWB/ramdisk/lp1enabled)
if ((state == "1")) && (( lp1enabled == "1" )) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/api/set?frc=0 > /dev/null
fi
fi
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatus"; then
if (( state == "0" )) || (( state == "2" )) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/api/set?frc=1 > /dev/null
fi
fi
oldcurrent=$(echo $output | jq -r '.amp')
current=$(</var/www/html/openWB/ramdisk/llsoll)
if (( oldcurrent != $current )) && (( $current != 0 )) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/api/set?amp=$current > /dev/null
fi
fi
fi
fi
if [[ $lastmanagement == "1" ]]; then
if [[ $evsecons1 == "goe" ]]; then
output=$(curl --connect-timeout 1 -s http://$goeiplp2/status)
if [[ $? == "0" ]] ; then
#check whether goe has 1to3phase switch capability => new HWV3 and new API V2
fsp=$(echo $output | jq -r '.fsp')
if [[ ! $fsp =~ $digit ]] ; then
state=$(echo $output | jq -r '.alw')
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
lp2enabled=$(</var/www/html/openWB/ramdisk/lp2enabled)
if ((state == "0")) && (( lp2enabled == "1" )) ; then
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/mqtt?payload=alw=1 > /dev/null
fi
fi
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
if ((state == "1")) ; then
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/mqtt?payload=alw=0 > /dev/null
fi
fi
version=$(echo $output | jq -r '.fwv') # get firmware version
majorVersion=${version%.*} # remove everything after a "."
majorVersion=${majorVersion%-*} # remove everything after a "-"
majorVersion=${majorVersion#0} # remove leading "0"
oldcurrent=$(echo $output | jq -r '.amp')
current=$(</var/www/html/openWB/ramdisk/llsolls1)
if (( oldcurrent != $current )) && (( $current != 0 )); then
if (($majorVersion >= 40)) ; then
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/mqtt?payload=amx=$current > /dev/null
else
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/mqtt?payload=amp=$current > /dev/null
fi
fi
else
output=$(curl --connect-timeout 1 -s http://$goeiplp2/api/status)
state=$(echo $output | jq -r '.frc')
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
lp2enabled=$(</var/www/html/openWB/ramdisk/lp2enabled)
if ((state == "1")) && (( lp2enabled == "1" )) ; then
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/api/set?frc=0 > /dev/null
fi
fi
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
if (( state == "0" )) || (( state == "2" )) ; then
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/api/set?frc=1 > /dev/null
fi
fi
oldcurrent=$(echo $output | jq -r '.amp')
current=$(</var/www/html/openWB/ramdisk/llsolls1)
if (( oldcurrent != $current )) && (( $current != 0 )) ; then
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/api/set?amp=$current > /dev/null
fi
fi
fi
fi
if [[ $lastmanagements2 == "1" ]]; then
if [[ $evsecons2 == "goe" ]]; then
output=$(curl --connect-timeout 1 -s http://$goeiplp3/status)
if [[ $? == "0" ]] ; then
#check whether goe has 1to3phase switch capability => new HWV3 and new API V2
fsp=$(echo $output | jq -r '.fsp')
if [[ ! $fsp =~ $digit ]] ; then
state=$(echo $output | jq -r '.alw')
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuss2"; then
lp3enabled=$(</var/www/html/openWB/ramdisk/lp3enabled)
if ((state == "0")) && (( lp3enabled == "1" )) ; then
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/mqtt?payload=alw=1 > /dev/null
fi
fi
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatuss2"; then
if ((state == "1")) ; then
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/mqtt?payload=alw=0 > /dev/null
fi
fi
version=$(echo $output | jq -r '.fwv') # get firmware version
majorVersion=${version%.*} # remove everything after a "."
majorVersion=${majorVersion%-*} # remove everything after a "-"
majorVersion=${majorVersion#0} # remove leading "0"
oldcurrent=$(echo $output | jq -r '.amp')
current=$(</var/www/html/openWB/ramdisk/llsolls2)
if (( oldcurrent != $current )) ; then
if (($majorVersion >= 40)) ; then
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/mqtt?payload=amx=$current > /dev/null
else
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/mqtt?payload=amp=$current > /dev/null
fi
fi
else
output=$(curl --connect-timeout 1 -s http://$goeiplp3/api/status)
state=$(echo $output | jq -r '.frc')
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuss2"; then
lp3enabled=$(</var/www/html/openWB/ramdisk/lp3enabled)
if (( state == "1" )) && (( lp3enabled == "1" )) ; then
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/api/set?frc=0 > /dev/null
fi
fi
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatuss2"; then
if (( state == "0" )) || (( state == "2" )) ; then
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/api/set?frc=1 > /dev/null
fi
fi
oldcurrent=$(echo $output | jq -r '.amp')
current=$(</var/www/html/openWB/ramdisk/llsolls2)
if (( oldcurrent != $current && $current != 0 )) ; then
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/api/set?amp=$current > /dev/null
fi
fi
fi
fi
fi
fi
}