Last active
October 8, 2021 08:07
-
-
Save mathieuthollet/b2f0e80211fe267035626bd4b8cf562c to your computer and use it in GitHub Desktop.
Revisions
-
mathieuthollet revised this gist
Oct 8, 2021 . No changes.There are no files selected for viewing
-
mathieuthollet revised this gist
Jul 4, 2021 . 1 changed file with 17 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,16 @@ #!/bin/bash # Time mobile offline before active detection (seconds) IDLE_TIME_TRIGGER_DETECTION=3600 # IPs to check for availability IP="192.168.1.89 192.168.1.92" # motion URL MOTION_URL="http://127.0.0.1:7999/1/detection" # displays date for logs date # get previous detection status if echo "`wget -qO- http://127.0.0.1:7999/1/detection/status`" | grep -q "ACTIVE"; then DETECTION_STATUS="active" @@ -33,9 +39,10 @@ function presence () { sudo arp -d $i if mobile_presence "$i"; then echo "$i is online" date +%s > /tmp/last_mobile_presence.txt if [ ! "$DETECTION_STATUS" = "pause" ]; then logger "device $i is online, pausing motion detection" motion_control pause fi return 0 else @@ -53,7 +60,13 @@ if ! presence; then fi echo "$IP is/are offline" if [ ! "$DETECTION_STATUS" = "active" ]; then echo "No device is online" typeset -i LAST_MOBILE_PRESENCE=$(cat /tmp/last_mobile_presence.txt) IDLE_TIME=$(($(date +%s)-$LAST_MOBILE_PRESENCE)) echo "Idle time : $IDLE_TIME (min idle time to trigger detection : $IDLE_TIME_TRIGGER_DETECTION)" if (($IDLE_TIME>=$IDLE_TIME_TRIGGER_DETECTION)); then echo "Starting motion detection" motion_control start fi fi fi -
mathieuthollet revised this gist
Jun 12, 2021 . 1 changed file with 11 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,24 @@ #!/bin/bash # IPs to check for availability IP="192.168.1.89 192.168.1.92" # motion URL MOTION_URL="http://127.0.0.1:7999/1/detection" # get previous detection status if echo "`wget -qO- http://127.0.0.1:7999/1/detection/status`" | grep -q "ACTIVE"; then DETECTION_STATUS="active" else DETECTION_STATUS="pause" fi echo "Detection status : $DETECTION_STATUS" # send control command to motion function motion_control () { wget -q -O - "$MOTION_URL/$1" | grep Camera | sed -e "s/<[^>]*>//g" -e "s/.*Camera/Camera/" } # check mobile presence on network function mobile_presence () { # ping mobile to wake/fill arp cache ping -c 1 "$1" &> /dev/null @@ -35,31 +27,33 @@ function mobile_presence () { return $? } # check each mobile presence and stop motion detection if online function presence () { for i in $IP; do sudo arp -d $i if mobile_presence "$i"; then echo "$i is online" if [ ! "$DETECTION_STATUS" = "pause" ]; then logger "device $i is online, pausing motion detection" motion_control pause fi return 0 else echo "$i is offline" fi done return 1 } # main script : if no mobile online, start motion detection if ! presence; then echo "$IP appear to be offline... retrying..." if presence; then exit 0 fi echo "$IP is/are offline" if [ ! "$DETECTION_STATUS" = "active" ]; then echo "No device is online, starting motion detection" motion_control start fi fi -
mathieuthollet created this gist
Jun 12, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ #!/bin/bash if [ ! -f `dirname "$0"`/includes.sh ]; then function debug () { echo $@ } else . `dirname "$0"`/includes.sh fi # IPs to check for availability IP="192.168.1.89 192.168.1.92" # motion URL MOTION_URL="http://127.0.0.1:7999/1/detection" #DEBUG=yes # get previous detection status if echo "`wget -qO- http://127.0.0.1:7999/1/detection/status`" | grep -q "ACTIVE"; then DETECTION_STATUS="active" else DETECTION_STATUS="pause" fi debug "Detection status : $DETECTION_STATUS" # valud arguments: status start pause function motion_control () { wget -q -O - "$MOTION_URL/$1" | grep Camera | sed -e "s/<[^>]*>//g" -e "s/.*Camera/Camera/" } function mobile_presence () { # ping mobile to wake/fill arp cache ping -c 1 "$1" &> /dev/null # check if arp cache contains MAC or not (incomplete) arp -an | grep "$1" | grep -v "incomplete" &> /dev/null return $? } function presence () { for i in $IP; do sudo arp -d $i if mobile_presence "$i"; then debug "$i is online" if [ ! "$DETECTION_STATUS" = "pause" ]; then logger "device $i is online, pausing motion detection" motion_control pause fi return 0 else debug "$i is offline" fi done return 1 } if ! presence; then debug "$IP appear to be offline... retrying..." if presence; then exit 0 fi debug "$IP is/are offline" if [ ! "$DETECTION_STATUS" = "active" ]; then logger "no device is online, starting motion detection" motion_control start fi fi