-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresence_detection.sh
106 lines (47 loc) · 2.21 KB
/
presence_detection.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
#!/bin/sh
###############################################################
# Proximity detection
###############################################################
IPAddr="192.168.1.3"
port="8080"
macdevice1="00:00:00:00:00:00" #Device 1
macdevice2="00:01:91:9f:00:49" #Device 2
# OpenHAB switch items to be updated for each tracked MAC
item1="Device_1"
item2="Device_2"
device=""
# see http://wiki.openwrt.org/doc/devel/debugging to enable additional logging
logread -f | while read input
do
if `echo $input | grep -q AP-STA-DISCONNECTED`
then
mac=`echo $input | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'`
if `echo $mac | grep -q $macdevice1`
then
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://$IPAddr:$port/rest/items/$item1"
elif `echo $mac | grep -q $macdevice2`
then
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://$IPAddr:$port/rest/items/$item2"
fi
elif `echo $input | grep -q deauthenticated`
then
mac=`echo $input | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'`
if `echo $mac | grep -q $macdevice1`
then
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://$IPAddr:$port/rest/items/$item1"
elif `echo $mac | grep -q $macdevice2`
then
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://$IPAddr:$port/rest/items/$item2"
fi
elif `echo $input | grep -q authenticated`
then
mac=`echo $input | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'`
if `echo $mac | grep -q $macdevice1`
then
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "ON" "http://$IPAddr:$port/rest/items/$item1"
elif `echo $mac | grep -q $macdevice2`
then
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "ON" "http://$IPAddr:$port/rest/items/$item2"
fi
fi
done