Commit | Line | Data |
---|---|---|
890439ae TM |
1 | #!/bin/sh |
2 | # Simple sleep monitor (Harvie 2012) | |
3 | # | |
4 | # You probably have soundcard with one output and input | |
5 | # Take PIR motion sensor from security system | |
6 | # Use PIR to switch connection between left channels of output and input (tips of 3.5mm jacks) | |
7 | # Connect grounds of these two together (maybe you will not need it - depending on your soundcard) | |
8 | # Power up PIR | |
9 | # Launch this script | |
10 | # Use alsamixer and some GUI recorder (like audacity) to tune volume to some usable level | |
11 | # Place PIR facing to your bed and go sleep | |
12 | # Wake up | |
13 | # Enjoy your data | |
14 | ||
15 | out=/tmp/sleeplog-"$(date +%F_%r)".txt | |
16 | speaker-test -t sine &>/dev/null & | |
17 | tresh=10 | |
18 | lastdate=0 | |
19 | arecord | ./goertzel -i -q -a -t $tresh -s 2000 | while read line; do | |
20 | date="$(date +%s)" | |
21 | time="$(echo "$line" | cut -f 1)" | |
22 | level="$(echo "$line" | cut -f 2)" | |
23 | echo -ne "$time\t$date\t$(date '+%F%t%r')\t" | |
24 | test "$level" -gt "$tresh" && { | |
25 | echo -n "Nothing detected..."; | |
26 | } || { | |
27 | echo -n "Motion detected!!!!"; | |
28 | } | |
29 | test "$lastdate" != 0 && { | |
30 | after=$(( $date - $lastdate)) | |
31 | echo -ne "\t$level After $after secs"; | |
32 | } | |
33 | echo; | |
34 | lastdate="$date"; | |
35 | done | tee "$out" | |
36 | kill $! | |
37 | echo "Your file: $out" |