Add Human Activity Sensor

This commit is contained in:
Dejvino
2020-12-17 20:09:45 +01:00
parent 4208bc54c7
commit 059d555463
8 changed files with 106 additions and 94 deletions
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
LAST_SEEN_FILE=/var/tmp/human_last_seen
LAST_CHECKED_FILE=/var/tmp/human_last_checked
LAST_SEEN=`stat /var/tmp/human_last_seen --format=%Y`
TIME_NOW=`date +%s`
AGO=$(( $TIME_NOW - $LAST_SEEN ))
echo $AGO
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
READER=human-activity-sensor
LAST_SEEN_FILE=/var/tmp/human_last_seen
LAST_CHECKED_FILE=/var/tmp/human_last_checked
echo "Human Activity Daemon"
echo ""
echo "Last seen file: $LAST_SEEN_FILE"
echo "Last checked file: $LAST_CHECKED_FILE"
echo ""
echo "Values stream:"
LAST_VAL=-1
while [[ true ]]; do
VAL=`$READER`
touch $LAST_CHECKED_FILE
if [[ $VAL == "1" ]]; then
touch $LAST_SEEN_FILE
fi
if [[ $LAST_VAL != $VAL ]]; then
echo "[`date "+%F %T"`] $VAL"
LAST_VAL=$VAL
fi
sleep 1
done
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
PIN_PIR=3
# init
gpio mode $PIN_PIR input
# read
gpio read $PIN_PIR