SHARE
TWEET

Untitled

a guest Apr 21st, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. open="0"
  4. closed="1"
  5.  
  6. previousState="0"
  7. timeOfChange=`date +%s`
  8.  
  9. while true
  10. do
  11.   sleep 1
  12.   #state=$(gpio read 7)
  13.   state=$(cat doorstate)
  14.   if [ $state != $previousState  ]; then
  15.     now=`date +%s`
  16.     duration=$((now-timeOfChange))
  17.     previousState=$state
  18.     timeOfChange=$now
  19.     if [ $state = $open ]; then
  20.       echo "The door just opened after $duration seconds"
  21.     else
  22.       echo "The door just closed after $duration seconds"
  23.     fi
  24.   fi
  25. done
RAW Paste Data
Top