Occupancy Sensor: Difference between revisions
(Created page with "[http://www.unallocatedspace.org/status Is the space open?] The occupancy sensor bash script (detailed below) is run via cron every 5 minutes. The script pulls a static image f...") |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
=== <span style="color: red">''This Project is Deprecated''</span> === | |||
[http://www.unallocatedspace.org/status Is the space open?] | [http://www.unallocatedspace.org/status Is the space open?] | ||
Line 12: | Line 14: | ||
* Calling [[The Wall]] script when the flag changes from FALSE to TRUE. | * Calling [[The Wall]] script when the flag changes from FALSE to TRUE. | ||
* Switching in open.wav or closed.wav to status.wav for our [[Asterisk]] phone responder. (changes will be made regarding this function) | * Switching in open.wav or closed.wav to status.wav for our [[Asterisk]] phone responder. (changes will be made regarding this function) | ||
== Sensor Override== | == Sensor Override== | ||
Line 27: | Line 26: | ||
== Source Code for ocs.sh == | == Source Code for ocs.sh == | ||
<pre> | <pre> | ||
#!/bin/bash | #!/bin/bash | ||
override=`lsusb` | override=`lsusb` | ||
if [[ $override == *0781:5530* ]] | if [[ $override == *0781:5530* ]] | ||
then | then | ||
level=9999 | level=9999 #9999 | ||
echo "Override on" | echo "Override on" | ||
else | else | ||
curl "http:// | curl "http://-redacted-/axis-cgi/com/ptz.cgi?gotoserverpresetname=ocs2&camera=1" | ||
curl "http:// | sleep 2 | ||
curl "http://-redacted-/axis-cgi/com/ptz.cgi?camera=1&irisbar=185&alignment=horisontal&barcoord=80,0" | |||
sleep 8 | sleep 8 | ||
wget http:// | wget http://-redacted-/axis-cgi/jpg/image.cgi -q -O /tmp/ocs.jpg | ||
level=`convert /tmp/ocs.jpg -colorspace gray -format "%[fx:mean]" info:|cut -c3-5` | level=`convert /tmp/ocs.jpg -colorspace gray -format "%[fx:mean]" info:|cut -c3-5` | ||
vlevel=`convert /tmp/ocs.jpg -colorspace gray -format "%[fx:mean]" info:` | vlevel=`convert /tmp/ocs.jpg -colorspace gray -format "%[fx:mean]" info:` | ||
echo $level | |||
echo $vlevel | |||
fi | fi | ||
cs=`cat /tmp/status` | cs=`cat /tmp/status` | ||
#cs='false' #for testing | |||
cs=${cs:0:1} | cs=${cs:0:1} | ||
if [ $level -gt 690 ] | if [ $level -gt 690 ] #690 | ||
then | then | ||
nstatus="The space has been open since " | nstatus="The space has been open since " | ||
Line 65: | Line 67: | ||
echo -n " (override engaged)" >> /tmp/status | echo -n " (override engaged)" >> /tmp/status | ||
fi | fi | ||
echo "`date` [$ns]" >> / | echo "`date` [$ns]" >> /uas/ocs/log | ||
echo "Attempting to update webflag, this should work" | echo "Attempting to update webflag, this should work" | ||
echo "Pushing to IRC bot" | echo "Pushing to IRC bot" | ||
echo $nstatus ` date +"%T %F"` > / | echo $nstatus ` date +"%T %F"` > /uas/irc/irc | ||
python /uas/statustweet/statustweet.py "$ns$nstatus ` date `" | |||
ftp -n -redacted- <<END_SCRIPT | |||
quote -redacted- | |||
quote -redacted- | |||
ascii | |||
put /tmp/status -redacted- | |||
quit | |||
END_SCRIPT | |||
#exit 0 | |||
# | |||
if [ "$ns" == "+" ] | if [ "$ns" == "+" ] | ||
then | then | ||
#php /uas/asterisk/calladmin.php | |||
cp /etc/asterisk/uas/open.wav /etc/asterisk/uas/status.wav | |||
mplayer /uas/hal9001/nowopen.wav | |||
if [ $level -lt 9999 ] | |||
then | |||
echo "Updating the wall." | |||
/uas/ocs/thewall.sh | |||
fi | |||
else | |||
cp /etc/asterisk/uas/closed.wav /etc/asterisk/uas/status.wav | |||
echo -n "" > /uas/checkin/ciusers | |||
mplayer /uas/hal9001/nowclosed.wav | |||
fi | fi | ||
else | else | ||
Line 96: | Line 105: | ||
#debug | #debug | ||
vlevel2=`convert /tmp/ocs.jpg - | vlevel2=`convert /tmp/ocs.jpg -threshold 99% -format "%[fx:100*image.mean]" info:` | ||
vlevel3=`convert /tmp/ocs.jpg - | vlevel3=`convert /tmp/ocs.jpg -colors 3 -depth 8 -format %c histogram:info:-` | ||
echo "` date` [$ns] $vlevel - $vlevel2 -- $vlevel3 | echo "` date` [$ns] $vlevel - $vlevel2 -- $vlevel3" >> /uas/ocs/logv | ||
#debug | #debug | ||
exit 0 | |||
</pre> | </pre> | ||
[[Category:Project]] |
Latest revision as of 20:36, 5 January 2023
This Project is Deprecated
The occupancy sensor bash script (detailed below) is run via cron every 5 minutes.
The script pulls a static image from the Big Brother Axis IP camera, analyzes it for light levels, then determines if the space is open (TRUE) or closed (FALSE).
It compares the new status with the current status to determine if the state of the space has changed.
If the status has changed, it updates the website with a new TRUE/FALSE flag. If the status has not changed it does nothing.
The occupancy sensor is also responsible for:
- Calling The Wall script when the flag changes from FALSE to TRUE.
- Switching in open.wav or closed.wav to status.wav for our Asterisk phone responder. (changes will be made regarding this function)
Sensor Override
The Occupancy Sensor override is currently located hanging on the side of the gray cabinet. When enabled it will override the light level check, and report that the space is open. This is useful for parties, or watching movies, etc.
The switch is connected to the 5v line of a USB cable, when the circuit is complete, the override is on, and a USB dongle is connected to the computer running the occupancy sensor. The script then checks for the presence of this USB dongle with lsusb before checking the light levels.
Source Code for ocs.sh
#!/bin/bash override=`lsusb` if [[ $override == *0781:5530* ]] then level=9999 #9999 echo "Override on" else curl "http://-redacted-/axis-cgi/com/ptz.cgi?gotoserverpresetname=ocs2&camera=1" sleep 2 curl "http://-redacted-/axis-cgi/com/ptz.cgi?camera=1&irisbar=185&alignment=horisontal&barcoord=80,0" sleep 8 wget http://-redacted-/axis-cgi/jpg/image.cgi -q -O /tmp/ocs.jpg level=`convert /tmp/ocs.jpg -colorspace gray -format "%[fx:mean]" info:|cut -c3-5` vlevel=`convert /tmp/ocs.jpg -colorspace gray -format "%[fx:mean]" info:` echo $level echo $vlevel fi cs=`cat /tmp/status` #cs='false' #for testing cs=${cs:0:1} if [ $level -gt 690 ] #690 then nstatus="The space has been open since " ns="+" else nstatus="The space has been closed since " ns="-" fi if [ "$cs" != "$ns" ] then echo "The status has changed, The flag is now set to $ns" echo -n $ns$nstatus ` date +"%T %F"` > /tmp/status if [ $level -eq 9999 ] then echo -n " (override engaged)" >> /tmp/status fi echo "`date` [$ns]" >> /uas/ocs/log echo "Attempting to update webflag, this should work" echo "Pushing to IRC bot" echo $nstatus ` date +"%T %F"` > /uas/irc/irc python /uas/statustweet/statustweet.py "$ns$nstatus ` date `" ftp -n -redacted- <<END_SCRIPT quote -redacted- quote -redacted- ascii put /tmp/status -redacted- quit END_SCRIPT #exit 0 if [ "$ns" == "+" ] then #php /uas/asterisk/calladmin.php cp /etc/asterisk/uas/open.wav /etc/asterisk/uas/status.wav mplayer /uas/hal9001/nowopen.wav if [ $level -lt 9999 ] then echo "Updating the wall." /uas/ocs/thewall.sh fi else cp /etc/asterisk/uas/closed.wav /etc/asterisk/uas/status.wav echo -n "" > /uas/checkin/ciusers mplayer /uas/hal9001/nowclosed.wav fi else echo "The status has not changed, the flag is still set to $ns" fi #debug vlevel2=`convert /tmp/ocs.jpg -threshold 99% -format "%[fx:100*image.mean]" info:` vlevel3=`convert /tmp/ocs.jpg -colors 3 -depth 8 -format %c histogram:info:-` echo "` date` [$ns] $vlevel - $vlevel2 -- $vlevel3" >> /uas/ocs/logv #debug exit 0