Add Human Activity Sensor
This commit is contained in:
parent
4208bc54c7
commit
059d555463
112
README.md
112
README.md
@ -3,6 +3,7 @@
|
||||
Linux box with a loudspeaker and an emergency light to be used for announcements and notifications.
|
||||
|
||||
## Hardware
|
||||
### Overview
|
||||
* SBC with GPIOs and sound output :: OrangePi Zero with an expansion board
|
||||
* PA system
|
||||
* speaker :: 30W, 4 Ohms horn loudspeaker
|
||||
@ -11,12 +12,30 @@ Linux box with a loudspeaker and an emergency light to be used for announcements
|
||||
* Warning Light system
|
||||
* warning light :: 12V 10W rotary orange warning light
|
||||
* relay module :: 12V low trigger relay
|
||||
|
||||
* System Activity Light system
|
||||
* indicator LED
|
||||
* Human Activity Sensor system
|
||||
* PIR module
|
||||
|
||||
### Building
|
||||
TBD
|
||||
|
||||
## Software
|
||||
### Overview
|
||||
* Operating System - Linux :: Armbian Bullseye for the OrangePi Zero
|
||||
* PA System
|
||||
* Voice Synthesizer :: Festival / ESpeak
|
||||
|
||||
### Installation
|
||||
Run as root:
|
||||
```bash
|
||||
cp toolkit/* /usr/local/bin/
|
||||
|
||||
cp etc/systemd/system /etc/systemd/system
|
||||
systemctl enable --now system-activity-light.service
|
||||
systemctl enable --now human-activity-sensor.service
|
||||
```
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
### Armbian + OrangePi Zero Installation
|
||||
@ -44,21 +63,6 @@ cd wiringOP
|
||||
./build
|
||||
```
|
||||
|
||||
#### Initialize GPIOs
|
||||
```bash
|
||||
# System Activity Indicator
|
||||
PIN_SALIGHT=11
|
||||
gpio mode $PIN_SALIGHT output
|
||||
|
||||
# Emergency Light system
|
||||
PIN_ELIGHT=7
|
||||
gpio mode $PIN_ELIGHT output
|
||||
|
||||
# PA system
|
||||
PIN_PASOUND=5
|
||||
gpio mode $PIN_PASOUND output
|
||||
```
|
||||
|
||||
### PA System
|
||||
#### Enabling mixed sound output
|
||||
```bash
|
||||
@ -90,78 +94,10 @@ espeak -f ssml.txt -m
|
||||
sox infile.wav outfile.wav downsample echo 0.5 1 1 1
|
||||
```
|
||||
|
||||
#### Playing a sound file
|
||||
### Human Activity Sensor
|
||||
|
||||
#### Reading File Timestamp
|
||||
```bash
|
||||
aplay file.wav
|
||||
mplayer file.mp3
|
||||
```
|
||||
|
||||
### Emergency Light
|
||||
#### Control Script
|
||||
```bash
|
||||
cat /usr/local/bin/emergency-light
|
||||
#!/bin/bash
|
||||
|
||||
PIN_ELIGHT=7
|
||||
|
||||
# init
|
||||
gpio mode $PIN_ELIGHT output
|
||||
|
||||
# command
|
||||
if [[ "$1" == "on" ]]; then
|
||||
gpio write $PIN_ELIGHT 1
|
||||
elif [[ "$1" == "off" ]]; then
|
||||
gpio write $PIN_ELIGHT 0
|
||||
elif [[ "$1" == "read" ]]; then
|
||||
gpio read $PIN_ELIGHT
|
||||
else
|
||||
gpio toggle $PIN_ELIGHT
|
||||
fi
|
||||
```
|
||||
|
||||
### System Activity Light
|
||||
#### System Usage
|
||||
```bash
|
||||
uptime | head -n 1 | cut -f3 -d, | cut -f2 -d:
|
||||
```
|
||||
|
||||
#### Daemon
|
||||
```bash
|
||||
cat /etc/systemd/system/system-activity-light.service
|
||||
[Unit]
|
||||
Description=System Activity Light Daemon
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/sbin/system-activity-light-daemon
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
```bash
|
||||
cat /usr/sbin/system-activity-light-daemon
|
||||
#!/bin/bash
|
||||
|
||||
DELAY=10000
|
||||
|
||||
while [[ true ]]; do
|
||||
ACTIVITY=2000
|
||||
TOP=`system-usage`
|
||||
if (( $(echo "$TOP > 1.0" | bc -l) )); then
|
||||
ACTIVITY=50
|
||||
elif (( $(echo "$TOP > 0.75" | bc -l) )); then
|
||||
ACTIVITY=100
|
||||
elif (( $(echo "$TOP > 0.5" | bc -l) )); then
|
||||
ACTIVITY=500
|
||||
elif (( $(echo "$TOP > 0.2" | bc -l) )); then
|
||||
ACTIVITY=1000
|
||||
fi
|
||||
echo $TOP
|
||||
system-activity-light blink $ACTIVITY $DELAY
|
||||
done
|
||||
```
|
||||
|
||||
```bash
|
||||
sudo systemctl enable --now system-activity-light.service
|
||||
stat /var/tmp/human_last_seen --format=%Y
|
||||
```
|
||||
|
||||
|
@ -4,20 +4,18 @@ source pa-lib
|
||||
|
||||
pa-preheat
|
||||
|
||||
pa-volume-loud
|
||||
pa-announcement-quickest
|
||||
pa-volume-loud-if-inactive
|
||||
|
||||
emergency-light on
|
||||
pa-alarm-start
|
||||
|
||||
sleep 1
|
||||
sleep 5
|
||||
|
||||
pa-say "$@"
|
||||
|
||||
sleep 1
|
||||
sleep 5
|
||||
|
||||
emergency-light off
|
||||
|
||||
pa-announcement-quick
|
||||
|
||||
pa-shutdown
|
||||
|
||||
|
12
bin/pa-lib
12
bin/pa-lib
@ -29,6 +29,17 @@ function pa-volume-loud() {
|
||||
pa-volume 25
|
||||
}
|
||||
|
||||
function pa-volume-loud-if-inactive() {
|
||||
LAST_ACTIVE=`human-activity-ago`
|
||||
if [[ $LAST_ACTIVE > 200 ]]; then
|
||||
info "Human is inactive. Last activity: $LAST_ACTIVE seconds ago."
|
||||
pa-volume-loud
|
||||
else
|
||||
info "Human is active. Setting only normal volume."
|
||||
pa-volume-normal
|
||||
fi
|
||||
}
|
||||
|
||||
function pa-volume-quiet() {
|
||||
info "Volume set to low"
|
||||
pa-volume 8
|
||||
@ -47,6 +58,7 @@ function pa-shutdown() {
|
||||
info "PA Shutdown"
|
||||
pa-power off
|
||||
pa-volume-normal
|
||||
killall $PLAYER
|
||||
}
|
||||
|
||||
function pa-announcement() {
|
||||
|
9
etc/systemd/system/human-activity-sensor.service
Normal file
9
etc/systemd/system/human-activity-sensor.service
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Human Activity Sensor Daemon
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/human-activity-daemon
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
9
etc/systemd/system/system-activity-light.service
Normal file
9
etc/systemd/system/system-activity-light.service
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=System Activity Light Daemon
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/sbin/system-activity-light-daemon
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
11
toolkit/human-activity-ago
Executable file
11
toolkit/human-activity-ago
Executable 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
toolkit/human-activity-daemon
Executable file
27
toolkit/human-activity-daemon
Executable 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
toolkit/human-activity-sensor
Executable file
10
toolkit/human-activity-sensor
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
PIN_PIR=3
|
||||
|
||||
# init
|
||||
gpio mode $PIN_PIR input
|
||||
|
||||
# read
|
||||
gpio read $PIN_PIR
|
||||
|
Loading…
Reference in New Issue
Block a user