From 27820482d3167adeb60dfaaa9089d12bec9e99a8 Mon Sep 17 00:00:00 2001 From: Frank van der Stad Date: Mon, 8 Jan 2018 17:10:43 +0100 Subject: [PATCH] Adding Alarm functionality (WIP) --- src/home/yi-hack-v3/etc/system.conf | 1 + src/home/yi-hack-v3/script/alarm.sh | 50 ++++++++++++++++++++++ src/home/yi-hack-v3/script/system.sh | 7 +++ src/home/yi-hack-v3/www/about.html | 25 ++++++----- src/home/yi-hack-v3/www/config.html | 64 ++++++++++++++++++++-------- 5 files changed, 118 insertions(+), 29 deletions(-) create mode 100644 src/home/yi-hack-v3/script/alarm.sh diff --git a/src/home/yi-hack-v3/etc/system.conf b/src/home/yi-hack-v3/etc/system.conf index e65e7f6..c2cc95a 100644 --- a/src/home/yi-hack-v3/etc/system.conf +++ b/src/home/yi-hack-v3/etc/system.conf @@ -3,3 +3,4 @@ HTTPD=yes TELNETD=no FTPD=yes DROPBEAR=yes +ALARM=no diff --git a/src/home/yi-hack-v3/script/alarm.sh b/src/home/yi-hack-v3/script/alarm.sh new file mode 100644 index 0000000..c0383d9 --- /dev/null +++ b/src/home/yi-hack-v3/script/alarm.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +# Copyright 2018 Vladimir Dronnikov +# Additional enhancements: Frank van der Stad +# GPL + +CONF_FILE="/yi-hack-v3/etc/system.conf" + +if [ -d "/usr/yi-hack-v3" ]; then + YI_HACK_V3_PREFIX="/usr" +elif [ -d "/home/yi-hack-v3" ]; then + YI_HACK_V3_PREFIX="/home" +fi + +get_config() +{ + key=$1 + grep $1 $YI_HACK_V3_PREFIX$CONF_FILE | cut -d "=" -f2 +} + +TELEGRAM_BOT_TOKEN=$(get_config TELEGRAM_BOT_TOKEN) +TELEGRAM_CHAT_ID=$(get_config TELEGRAM_CHAT_ID) +TELEGRAM_SILENT=0 + +CAMERA_NAME=`more $YI_HACK_V3_PREFIX/yi-hack-v3/etc/hostname`; + +curl() { + LD_LIBRARY_PATH=/tmp/sd /tmp/sd/curl -k -q $@ +} + +photo() { + cp $1 /tmp/sd/record/last.jpg + curl -F photo="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendPhoto?chat_id=${TELEGRAM_CHAT_ID}&caption=$2&disable_notification=${TELEGRAM_SILENT}" +} + +video() { + curl -F video="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendVideo?chat_id=${TELEGRAM_CHAT_ID}&caption=$2&disable_notification=${TELEGRAM_SILENT}" +} + +ALARM=0 +while true; do + test -r /tmp/sd/record/tmp.mp4.tmp && REC=1 || REC=0 + if [ "$REC" != "$ALARM" ]; then + ALARM="$REC" + [ "n$ALARM" == "n0" ] && rm /tmp/temp.jpg /tmp/temp.mp4 + fi + [ -r /tmp/motion.jpg -a ! -r /tmp/temp.jpg ] && cp /tmp/motion.jpg /tmp/temp.jpg && echo JPG ready && photo /tmp/temp.jpg "Photo from $CAMERA_NAME" + [ -r /tmp/motion.mp4 -a ! -r /tmp/temp.mp4 ] && cp /tmp/motion.mp4 /tmp/temp.mp4 && echo MP4 ready && video /tmp/temp.mp4 "Video from $CAMERA_NAME" + sleep 1 +done diff --git a/src/home/yi-hack-v3/script/system.sh b/src/home/yi-hack-v3/script/system.sh index 661662e..bb3020f 100755 --- a/src/home/yi-hack-v3/script/system.sh +++ b/src/home/yi-hack-v3/script/system.sh @@ -45,3 +45,10 @@ if [ -f "/tmp/sd/yi-hack-v3/startup.sh" ]; then elif [ -f "/home/hd1/yi-hack-v3/startup.sh" ]; then /home/hd1/yi-hack-v3/startup.sh fi + +if [[ $(get_config ALARM) == "yes" ]] ; then + if [ -f "/home/yi-hack-v3/script/alarm.sh" ]; then + sh /home/yi-hack-v3/script/alarm.sh & + fi +fi + diff --git a/src/home/yi-hack-v3/www/about.html b/src/home/yi-hack-v3/www/about.html index 86bee45..4c97057 100644 --- a/src/home/yi-hack-v3/www/about.html +++ b/src/home/yi-hack-v3/www/about.html @@ -50,7 +50,7 @@ - +

Yi-hack-v3 unlocks features not available with the official Yi camera firmware. Features implemented include:

- +

Version

Camera
@@ -76,10 +76,13 @@

Version

yi-hack-v3 Firmware
- +

More Information

https://github.com/shadow-1/yi-hack-v3 - + +

Last picture/video

+ Last + @@ -121,7 +140,7 @@

System Configuration

- +