-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoor_Status
56 lines (40 loc) · 1.49 KB
/
Door_Status
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
#!/bin/bash
# Door Log process started - Write today's date to log files
# Using -printf \n - command to print line break to highlight reboot in log
# - instead, you can uncomment the following line to start new log on every reboot
# rm /usr/share/webiopi/htdocs/door.log
printf "\nDoorTracker started at " >> /usr/share/webiopi/htdocs/door.log
date >> /usr/share/webiopi/htdocs/door.log
# GPIO 18 is used as door1 sensor
# Must be changed in two places if different
# (Lines 16 & 27)
echo "18" > /sys/class/gpio/export
# Loop this whole script indefinitely
while true
do
# Start loop. Assign previous status (stored in file /usr/bin/door_state) &
# get current status of GPIO pin. Verify GPIO to your door sensor.
# If no change in state, pause (sleep) then restart loop
STATE1_PRV=$(</usr/bin/door1_state)
STATE1_CUR=$(</sys/class/gpio/gpio18/value)
# ====================================
if [ "$STATE1_PRV" = "$STATE1_CUR" ]
then
sleep 5
else
# 41: Create variable with current date & time in short format, &
# 43: update State_Text to current status, then
# 50: write date and current status text to log file.
# 52: Finally, write current status to previous status variable.
STR1=$(date +%F)" "$(date +%R)
if [ $STATE1_CUR = 1 ]
then
STATE1_TEXT='OPEN'
else
STATE1_TEXT='CLOSED'
fi
echo $STR1 ": DOOR 1 is" $STATE1_TEXT >> /usr/share/webiopi/htdocs/door.log
echo $STATE1_CUR > /usr/bin/door1_state
fi
# date
done