-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgpio_monitor
executable file
·118 lines (108 loc) · 3.55 KB
/
rgpio_monitor
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
#!/bin/sh
### BEGIN INIT INFO
# Short-Description: Monitors RemoteGPIO dbus Service
# Description: Allow stoping and starting RemoteGPIO service from victron GUI
# Description: It also manage the reboot of the Dingtian devices
# Description: Also keep units.conf up to date so it creates the gpio at boot time
## END INIT INFO
exec 2>&1
get_setting()
{
dbus-send --print-reply=literal --system --type=method_call --dest=com.victronenergy.settings $1 com.victronenergy.BusItem.GetValue | awk '/int32/ { print $3 }'
}
set_setting()
{
dbus-send --print-reply=literal --system --type=method_call --dest=com.victronenergy.settings $1 com.victronenergy.BusItem.SetValue $2
}
get_IP()
{
dbus-send --print-reply=literal --system --type=method_call --dest=com.victronenergy.settings $1 com.victronenergy.BusItem.GetValue | awk '/variant/ { print $2 }'
}
latch=0
timer=$(date +%s)
while true
do
service=$(get_setting /Settings/Services/RemoteGPIO)
case $service in
0)
##
## Stop Service
###################
if [ $service != $latch ]
then
echo "Uninstalling remote relay pins" >> /var/log/RemoteGPIOv2/current
/etc/rcS.d/S90rgpio_pins.sh
fi
latch=$((service))
;;
1)
##
## Start Service
###########################
if [ $service != $latch ]
then
echo "Installing remote relay pins" >> /var/log/RemoteGPIOv2/current
/etc/rcS.d/S90rgpio_pins.sh
fi
latch=$((service))
;;
2)
##
## Reboot device
###########################
if [ $service != $latch ]
then
Reboot_Unit1=$(get_setting /Settings/RemoteGPIO/Unit1/Reboot)
Reboot_Unit2=$(get_setting /Settings/RemoteGPIO/Unit2/Reboot)
Reboot_Unit3=$(get_setting /Settings/RemoteGPIO/Unit3/Reboot)
if [ $Reboot_Unit1 = 1 ]
##
## Reboot Unit1
#####################
then
IP_Unit1=$(get_IP /Settings/RemoteGPIO/Unit1/IP)
wget http://$IP_Unit1/reboot.cgi
# Clear reboot flag and put RemoteGPIO service to 1
set_setting /Settings/RemoteGPIO/Unit1/Reboot variant:int32:0
set_setting /Settings/Services/RemoteGPIO variant:int32:1
fi
if [ $Reboot_Unit2 =1 ]
##
## Reboot Unit 2
####################
then
IP_Unit2=$(get_IP /Settings/RemoteGPIO/Unit2/IP)
wget http://$IP_Unit2/reboot.cgi
# Clear reboot flag and put RemoteGPIO service to 1
set_setting /Settings/RemoteGPIO/Unit2/Reboot variant:int32:0
set_setting /Settings/Services/RemoteGPIO variant:int32:1
fi
if [ $Reboot_Unit3 = 1 ]
##
## Reboot Unit 3
####################
then
IP_Unit3=$(get_IP /Settings/RemoteGPIO/Unit3/IP)
wget http://$IP_Unit3/reboot.cgi
# Clear reboot flag and put RemoteGPIO service to 1
set_setting /Settings/RemoteGPIO/Unit3/Reboot variant:int32:0
set_setting /Settings/Services/RemoteGPIO variant:int32:1
fi
fi
;;
3)
##
## Restart Service
###########################
if [ $service != $latch ]
then
echo "Re-installing remote relay pins" >> /var/log/RemoteGPIOv2/current
/etc/rcS.d/S90rgpio_pins.sh
set_setting /Settings/Services/RemoteGPIO variant:int32:1
set_setting /Settings/RemoteGPIO/Restart variant:int32:0
fi
;;
esac
#Reduce CPU load
sleep 2
done