Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof-Of-Concept PR: immediate motion detection on S-CAM #142

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/busybox/.config
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ CONFIG_HEXEDIT=y
# CONFIG_I2CSET is not set
# CONFIG_I2CDUMP is not set
# CONFIG_I2CDETECT is not set
# CONFIG_INOTIFYD is not set
CONFIG_INOTIFYD=y
# CONFIG_LESS is not set
CONFIG_FEATURE_LESS_MAXLINES=0
# CONFIG_FEATURE_LESS_BRACKETS is not set
Expand Down
3 changes: 3 additions & 0 deletions src/busybox/install.busybox
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ echo "#!/mnt/mmc/sonoff-hack/bin/busybox" > ../../build/sonoff-hack/usr/bin/wget
chmod 0755 ../../build/sonoff-hack/usr/bin/wget
echo "#!/mnt/mmc/sonoff-hack/bin/busybox" > ../../build/sonoff-hack/usr/bin/xargs
chmod 0755 ../../build/sonoff-hack/usr/bin/xargs
echo "#!/mnt/mmc/sonoff-hack/bin/busybox" > ../../build/sonoff-hack/usr/bin/inotifyd
chmod 0755 ../../build/sonoff-hack/usr/bin/inotifyd

36 changes: 36 additions & 0 deletions src/static/static/sonoff-hack/script/fast_motion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

SONOFF_HACK_PREFIX="/mnt/mmc/sonoff-hack"
MQTT_HOST=192.168.11.5
MQTT_USER=openhab_iot
MQTT_PASS=PASSWORD

#LOG_FILE="/dev/null"
LOG_FILE="/tmp/fastmotion.log"

log() {
echo "$(date +'%Y-%m-%d %H:%M:%S') -" "$*" >> $LOG_FILE
}
run() {
${SONOFF_HACK_PREFIX}/usr/bin/inotifyd - /tmp:n | while read a b c; do
log received $a $b $c
if [ "$c" = "colinkPushNotice" ]; then
${SONOFF_HACK_PREFIX}/bin/mosquitto_pub -h ${MQTT_HOST} -u ${MQTT_USER} -P ${MQTT_PASS} -t cam1/fast_motion -m ON
${SONOFF_HACK_PREFIX}/bin/snapshot -f /tmp/snapfast.jpg
${SONOFF_HACK_PREFIX}/bin/mosquitto_pub -h ${MQTT_HOST} -u ${MQTT_USER} -P ${MQTT_PASS} -t cam1/fast_image -f /tmp/snapfast.jpg
sleep 5
${SONOFF_HACK_PREFIX}/bin/mosquitto_pub -h ${MQTT_HOST} -u ${MQTT_USER} -P ${MQTT_PASS} -t cam1/fast_motion -m OFF
fi
done
}

run_loop() {
while true; do
log "Starting fast mation detection ..."
run
log "aborted ... waiting 10 seconds"
sleep 10
done
}

run_loop
3 changes: 3 additions & 0 deletions src/static/static/sonoff-hack/script/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ fi
# Run rtsp watchdog
$SONOFF_HACK_PREFIX/script/wd_rtsp.sh &

# Run fast_motion
$SONOFF_HACK_PREFIX/script/fast_motion.sh &

# Add crontab
CRONTAB=$(get_config CRONTAB)
FREE_SPACE=$(get_config FREE_SPACE)
Expand Down