-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_bluetooth.sh
More file actions
47 lines (40 loc) · 1.57 KB
/
check_bluetooth.sh
File metadata and controls
47 lines (40 loc) · 1.57 KB
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
#!/bin/sh
#this script monitor into the db the number of beacon received
#each beacon is sent every 15min (4 per hour)
#if we don't receive during the last 2h more than 4 beacon
#it means bluetooth is stuck and then we restart bleutooth
# error logged into the file error.log
#create a variable for collecting the nb of beacon
val=0
#curl command to retrieve the count value in json and parse it using jq
#we retrieve the nb of beacons received during last 2 hours
val=`curl -s -G http://localhost:8086/query --data-urlencode "u=username" --data-urlencode "p=password" --data-urlencode "db=Sensors" --data-urlencode "q=SELECT count(*) FROM \"Temperature\" WHERE (\"Sensor Type\" = '1' AND \"Sensor Number\" = '1' AND time > now() -2h)" | jq -r '.results[0].series[0].values[0][1] | tonumber'`
wait
# compare the value with 4 be
if [ $val -lt 4 ]
then
echo "$(date) Bluetooth error => restart Bluetooth and WiFi" >> /home/pi/RaspLogger/error.log
#stop wifi
ip link set wlan down
wait
#start wifi
ip link set wlan up
wait
#echo "bluetooth is stuck: Count = $val"
#echo "kill python"
killall -9 python3 > /dev/null 2>&1
wait
#echo "stop bluetooth"
systemctl stop bluetooth.service > /dev/null 2>&1
wait
#echo "enable bluetooth"
systemctl enable bluetooth.service > /dev/null 2>&1
wait
#echo "restart bluetooth"
systemctl restart bluetooth.service > /dev/null 2>&1
wait
#echo "restart ibeacon scanner"
python3 /home/pi/RaspLogger/ibeacon_scanner.py& > /dev/null 2>&1
else
#echo "$(date) : Bluetooth is alive"
fi