forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron5min.sh
executable file
·267 lines (251 loc) · 10.9 KB
/
cron5min.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/bin/bash
. /var/www/html/openWB/loadconfig.sh
dailyfile="/var/www/html/openWB/web/logging/data/daily/$(date +%Y%m%d)"
monthlyladelogfile="/var/www/html/openWB/web/logging/data/ladelog/$(date +%Y%m).csv"
linesladelog=$(cat $monthlyladelogfile | wc -l)
if [[ "$linesladelog" == 0 ]]; then
echo > $monthlyladelogfile
fi
bezug=$(</var/www/html/openWB/ramdisk/bezugkwh)
einspeisung=$(</var/www/html/openWB/ramdisk/einspeisungkwh)
if [[ $pv2wattmodul != "none" ]]; then
pv=$(</var/www/html/openWB/ramdisk/pvallwh)
else
pv=$(</var/www/html/openWB/ramdisk/pvkwh)
fi
ll1=$(</var/www/html/openWB/ramdisk/llkwh)
ll2=$(</var/www/html/openWB/ramdisk/llkwhs1)
ll3=$(</var/www/html/openWB/ramdisk/llkwhs2)
llg=$(</var/www/html/openWB/ramdisk/llkwhges)
soc=$(</var/www/html/openWB/ramdisk/soc)
soc1=$(</var/www/html/openWB/ramdisk/soc1)
speicheri=$(</var/www/html/openWB/ramdisk/speicherikwh)
speichere=$(</var/www/html/openWB/ramdisk/speicherekwh)
speichersoc=$(</var/www/html/openWB/ramdisk/speichersoc)
ll1=$(echo "$ll1 * 1000" | bc)
ll2=$(echo "$ll2 * 1000" | bc)
ll3=$(echo "$ll3 * 1000" | bc)
llg=$(echo "$llg * 1000" | bc)
verbraucher1=$(</var/www/html/openWB/ramdisk/verbraucher1_wh)
verbraucher2=$(</var/www/html/openWB/ramdisk/verbraucher2_wh)
verbraucher3=$(</var/www/html/openWB/ramdisk/verbraucher3_wh)
verbrauchere1=$(</var/www/html/openWB/ramdisk/verbraucher1_whe)
verbrauchere2=$(</var/www/html/openWB/ramdisk/verbraucher2_whe)
ll4=$(</var/www/html/openWB/ramdisk/llkwhlp4)
ll5=$(</var/www/html/openWB/ramdisk/llkwhlp5)
ll6=$(</var/www/html/openWB/ramdisk/llkwhlp6)
ll7=$(</var/www/html/openWB/ramdisk/llkwhlp7)
ll8=$(</var/www/html/openWB/ramdisk/llkwhlp8)
ll4=$(echo "$ll4 * 1000" | bc)
ll5=$(echo "$ll5 * 1000" | bc)
ll6=$(echo "$ll6 * 1000" | bc)
ll7=$(echo "$ll7 * 1000" | bc)
ll8=$(echo "$ll8 * 1000" | bc)
temp1=$(</var/www/html/openWB/ramdisk/device1_temp0)
temp2=$(</var/www/html/openWB/ramdisk/device1_temp1)
temp3=$(</var/www/html/openWB/ramdisk/device1_temp2)
temp4=$(</var/www/html/openWB/ramdisk/device2_temp0)
temp5=$(</var/www/html/openWB/ramdisk/device2_temp1)
temp6=$(</var/www/html/openWB/ramdisk/device2_temp2)
d1=$(</var/www/html/openWB/ramdisk/device1_wh)
d2=$(</var/www/html/openWB/ramdisk/device2_wh)
d3=$(</var/www/html/openWB/ramdisk/device3_wh)
d4=$(</var/www/html/openWB/ramdisk/device4_wh)
d5=$(</var/www/html/openWB/ramdisk/device5_wh)
d6=$(</var/www/html/openWB/ramdisk/device6_wh)
d7=$(</var/www/html/openWB/ramdisk/device7_wh)
d8=$(</var/www/html/openWB/ramdisk/device8_wh)
d9=$(</var/www/html/openWB/ramdisk/device9_wh)
d10=$(</var/www/html/openWB/ramdisk/device10_wh)
echo $(date +%H%M),$bezug,$einspeisung,$pv,$ll1,$ll2,$ll3,$llg,$speicheri,$speichere,$verbraucher1,$verbrauchere1,$verbraucher2,$verbrauchere2,$verbraucher3,$ll4,$ll5,$ll6,$ll7,$ll8,$speichersoc,$soc,$soc1,$temp1,$temp2,$temp3,$d1,$d2,$d3,$d4,$d5,$d6,$d7,$d8,$d9,$d10,$temp4,$temp5,$temp6 >> $dailyfile.csv
netzabschaltunghz=0
if (( netzabschaltunghz == 1 )); then
hz=$(</var/www/html/openWB/ramdisk/llhz)
hz=$(echo "$hz * 100" | bc | sed 's/\..*$//')
netzschutz=$(</var/www/html/openWB/ramdisk/netzschutz)
if (( netzschutz == 0 )); then
if (( hz > 4500 )) && (( $hz < 5300 )); then
if (( $hz > 5180 )); then
lademodus=$(</var/www/html/openWB/ramdisk/lademodus)
echo $lademodus > /var/www/html/openWB/ramdisk/templademodus
echo 3 > /var/www/html/openWB/ramdisk/lademodus
echo 1 > /var/www/html/openWB/ramdisk/netzschutz
fi
if (( hz < 4920 )); then
lademodus=$(</var/www/html/openWB/ramdisk/lademodus)
echo $lademodus > /var/www/html/openWB/ramdisk/templademodus
echo 1 > /var/www/html/openWB/ramdisk/netzschutz
(sleep $(shuf -i1-90 -n1) && echo 3 > /var/www/html/openWB/ramdisk/lademodus) &
fi
fi
else
if (( hz > 4500 )) && (( $hz < 5300 )); then
if (( $hz < 5100 )); then
templademodus=$(</var/www/html/openWB/ramdisk/templademodus)
echo $templademodus > /var/www/html/openWB/ramdisk/lademodus
echo 0 > /var/www/html/openWB/ramdisk/netzschutz
fi
if (( $hz > 4960 )); then
templademodus=$(</var/www/html/openWB/ramdisk/templademodus)
echo $templademodus > /var/www/html/openWB/ramdisk/lademodus
echo 0 > /var/www/html/openWB/ramdisk/netzschutz
fi
fi
fi
fi
if (( awattaraktiv == 1 )); then
/var/www/html/openWB/runs/awattargetprices.sh
fi
pvkwh=$pv
pvdailyyieldstart=$(head -n 1 /var/www/html/openWB/web/logging/data/daily/$(date +%Y%m%d).csv)
pvyieldcount=0
for i in ${pvdailyyieldstart//,/ }
do
pvyieldcount=$((pvyieldcount + 1 ))
if (( pvyieldcount == 2 )); then
bezugdailyyield=$(echo "scale=2;($bezug - $i) / 1000" |bc)
echo $bezugdailyyield > /var/www/html/openWB/ramdisk/daily_bezugkwh
fi
if (( pvyieldcount == 3 )); then
einspeisungdailyyield=$(echo "scale=2;($einspeisung - $i) / 1000" |bc)
echo $einspeisungdailyyield > /var/www/html/openWB/ramdisk/daily_einspeisungkwh
fi
if (( pvyieldcount == 4 )); then
pvdailyyield=$(echo "scale=2;($pvkwh - $i) / 1000" |bc)
echo $pvdailyyield > /var/www/html/openWB/ramdisk/daily_pvkwhk
fi
if (( pvyieldcount == 8 )); then
lladailyyield=$(echo "scale=2;($llg - $i) / 1000" |bc)
echo $lladailyyield > /var/www/html/openWB/ramdisk/daily_llakwh
fi
if (( pvyieldcount == 9 )); then
sidailyyield=$(echo "scale=2;($speicheri - $i) / 1000" |bc)
echo $sidailyyield > /var/www/html/openWB/ramdisk/daily_sikwh
fi
if (( pvyieldcount == 10 )); then
sedailyyield=$(echo "scale=2;($speichere - $i) / 1000" |bc)
echo $sedailyyield > /var/www/html/openWB/ramdisk/daily_sekwh
fi
if (( pvyieldcount == 11 )); then
verbraucher1dailyyield=$(echo "scale=2;($verbraucher1 - $i) / 1000" |bc)
echo $verbraucher1dailyyield > /var/www/html/openWB/ramdisk/daily_verbraucher1ikwh
fi
if (( pvyieldcount == 12 )); then
verbrauchere1dailyyield=$(echo "scale=2;($verbrauchere1 - $i) / 1000" |bc)
echo $verbrauchere1dailyyield > /var/www/html/openWB/ramdisk/daily_verbraucher1ekwh
fi
if (( pvyieldcount == 13 )); then
verbraucher2dailyyield=$(echo "scale=2;($verbraucher2 - $i) / 1000" |bc)
echo $verbraucher2dailyyield > /var/www/html/openWB/ramdisk/daily_verbraucher2ikwh
fi
if (( pvyieldcount == 14 )); then
verbrauchere2dailyyield=$(echo "scale=2;($verbrauchere2 - $i) / 1000" |bc)
echo $verbrauchere2dailyyield > /var/www/html/openWB/ramdisk/daily_verbraucher2ekwh
fi
if (( pvyieldcount == 15 )); then
verbraucher3dailyyield=$(echo "scale=2;($verbraucher3 - $i) / 1000" |bc)
echo $verbraucher3dailyyield > /var/www/html/openWB/ramdisk/daily_verbraucher3ikwh
fi
if (( pvyieldcount == 27 )); then
d1dailyyield=$(echo "scale=2;($d1 - $i) / 1000" |bc)
echo $d1dailyyield > /var/www/html/openWB/ramdisk/daily_d1kwh
fi
if (( pvyieldcount == 28 )); then
d2dailyyield=$(echo "scale=2;($d2 - $i) / 1000" |bc)
echo $d2dailyyield > /var/www/html/openWB/ramdisk/daily_d2kwh
fi
if (( pvyieldcount == 29 )); then
d3dailyyield=$(echo "scale=2;($d3 - $i) / 1000" |bc)
echo $d3dailyyield > /var/www/html/openWB/ramdisk/daily_d3kwh
fi
if (( pvyieldcount == 30 )); then
d4dailyyield=$(echo "scale=2;($d4 - $i) / 1000" |bc)
echo $d4dailyyield > /var/www/html/openWB/ramdisk/daily_d4kwh
fi
if (( pvyieldcount == 31 )); then
d5dailyyield=$(echo "scale=2;($d5 - $i) / 1000" |bc)
echo $d5dailyyield > /var/www/html/openWB/ramdisk/daily_d5kwh
fi
if (( pvyieldcount == 32 )); then
d6dailyyield=$(echo "scale=2;($d6 - $i) / 1000" |bc)
echo $d6dailyyield > /var/www/html/openWB/ramdisk/daily_d6kwh
fi
if (( pvyieldcount == 33 )); then
d7dailyyield=$(echo "scale=2;($d7 - $i) / 1000" |bc)
echo $d7dailyyield > /var/www/html/openWB/ramdisk/daily_d7kwh
fi
if (( pvyieldcount == 34 )); then
d8dailyyield=$(echo "scale=2;($d8 - $i) / 1000" |bc)
echo $d8dailyyield > /var/www/html/openWB/ramdisk/daily_d8kwh
fi
if (( pvyieldcount == 35 )); then
d9dailyyield=$(echo "scale=2;($d9 - $i) / 1000" |bc)
echo $d9dailyyield > /var/www/html/openWB/ramdisk/daily_d9kwh
fi
done
hausdailyyield=$(echo "scale=2;$bezugdailyyield + $pvdailyyield - $lladailyyield + $sedailyyield - $sidailyyield - $einspeisungdailyyield - $d1dailyyield - $d2dailyyield - $d3dailyyield - $d4dailyyield - $d5dailyyield - $d6dailyyield - $d7dailyyield - $d8dailyyield - $d9dailyyield - $verbraucher1dailyyield + $verbrauchere1dailyyield - $verbraucher2dailyyield + $verbrauchere2dailyyield - $verbraucher3dailyyield" | bc)
echo $hausdailyyield > /var/www/html/openWB/ramdisk/daily_hausverbrauchkwh
ip route get 1 | awk '{print $NF;exit}' > /var/www/html/openWB/ramdisk/ipaddress
#echo "$(tail -500 /var/www/html/openWB/ramdisk/smarthome.log)" > /var/www/html/openWB/ramdisk/smarthome.log
#echo "$(tail -500 /var/www/html/openWB/ramdisk/mqtt.log)" > /var/www/html/openWB/ramdisk/mqtt.log
#echo "$(tail -500 /var/www/html/openWB/ramdisk/nurpv.log)" > /var/www/html/openWB/ramdisk/nurpv.log
#echo "$(tail -5000 /var/www/html/openWB/ramdisk/nurpv.log)" > /var/www/html/openWB/ramdisk/isss.log
#echo "$(tail -5000 /var/www/html/openWB/ramdisk/nurpv.log)" > /var/www/html/openWB/ramdisk/rfid.log
if ps ax |grep -v grep |grep "python3 /var/www/html/openWB/runs/mqttsub.py" > /dev/null
then
echo "test" > /dev/null
else
python3 /var/www/html/openWB/runs/mqttsub.py &
fi
if ps ax |grep -v grep |grep "python3 /var/www/html/openWB/runs/smarthomehandler.py" > /dev/null
then
echo "test" > /dev/null
else
python3 /var/www/html/openWB/runs/smarthomehandler.py >> /var/www/html/openWB/ramdisk/smarthomehandler.log 2>&1 &
fi
if (( isss == 1 )); then
if ps ax |grep -v grep |grep "python3 /var/www/html/openWB/runs/isss.py" > /dev/null
then
echo "test" > /dev/null
else
python3 /var/www/html/openWB/runs/isss.py &
fi
else
ethstate=$(</sys/class/net/eth0/carrier)
if (( ethstate == 1 )); then
sudo ifconfig eth0:0 192.168.193.5 netmask 255.255.255.0 up
sudo ifconfig wlan0:0 192.168.193.6 netmask 255.255.255.0 down
else
sudo ifconfig wlan0:0 192.168.193.6 netmask 255.255.255.0 up
sudo ifconfig eth0:0 192.168.193.5 netmask 255.255.255.0 down
fi
fi
if [[ "$evsecon" == "buchse" ]]; then
if ps ax |grep -v grep |grep "python3 /var/www/html/openWB/runs/buchse.py" > /dev/null
then
echo "test" > /dev/null
else
python3 /var/www/html/openWB/runs/buchse.py &
fi
fi
if [[ "$rfidakt" == "2" ]]; then
echo $rfidlist > /var/www/html/openWB/ramdisk/rfidlist
if ps ax |grep -v grep |grep "python3 /var/www/html/openWB/runs/rfid.py" > /dev/null
then
echo "test" > /dev/null
else
python3 /var/www/html/openWB/runs/rfid.py &
fi
else
if ps ax |grep -v grep |grep "python3 /var/www/html/openWB/runs/rfid.py" > /dev/null
then
sudo kill $(ps aux |grep 'runs/[r]fid.py' | awk '{print $2}')
fi
fi
if ps ax |grep -v grep |grep "sudo python3 /var/www/html/openWB/runs/modbusserver/modbusserver.py" > /dev/null
then
echo "test" > /dev/null
else
sudo python3 /var/www/html/openWB/runs/modbusserver/modbusserver.py &
fi
/var/www/html/openWB/runs/cleanup.sh >> /var/www/html/openWB/ramdisk/cleanup.log 2>&1