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

WIP: Adding alarm functionality (and last motion in webinterface) #117

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions src/home/yi-hack-v3/etc/system.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ HTTPD=yes
TELNETD=no
FTPD=yes
DROPBEAR=yes
ALARM=no
29 changes: 29 additions & 0 deletions src/home/yi-hack-v3/script/alarm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
# Copyright 2018 Vladimir Dronnikov & Frank van der Stad
# GPL
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
source $YI_HACK_V3_PREFIX/yi-hack-v3/script/include_functions.sh

CAMERA_NAME=`more $YI_HACK_V3_PREFIX/yi-hack-v3/etc/hostname`;

TELEGRAM_BOT_TOKEN=$(get_config TELEGRAM_BOT_TOKEN)
TELEGRAM_CHAT_ID=$(get_config TELEGRAM_CHAT_ID)
TELEGRAM_SILENT=0

# This part is copyright 2018 Vladimir Dronnikov
# GPL
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
45 changes: 45 additions & 0 deletions src/home/yi-hack-v3/script/include_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh
# Copyright 2018 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
}

curl() {
LD_LIBRARY_PATH=/tmp/sd /tmp/sd/curl -k -q $@
}

photo() {
message=$(urlencode $2)
cp $1 /tmp/sd/record/last.jpg
if [ ! -z "$TELEGRAM_BOT_TOKEN" ]
then
curl -F photo="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendPhoto?chat_id=${TELEGRAM_CHAT_ID}&caption=$message&disable_notification=${TELEGRAM_SILENT}"
fi
}

video() {
message=$(urlencode $2)
cp $1 /tmp/sd/record/last.mp4
if [ ! -z "$TELEGRAM_BOT_TOKEN" ]
then
curl -F video="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendVideo?chat_id=${TELEGRAM_CHAT_ID}&caption=$message&disable_notification=${TELEGRAM_SILENT}"
fi
}




urlencode() {
url=$(echo "$*" | sed -e 's/%/%25/g' -e 's/ /%20/g' -e 's/!/%21/g' -e 's/"/%22/g' -e 's/#/%23/g' -e 's/\$/%24/g' -e 's/\&/%26/g' -e 's/'\''/%27/g' -e 's/(/%28/g' -e 's/)/%29/g' -e 's/\*/%2a/g' -e 's/+/%2b/g' -e 's/,/%2c/g' -e 's/-/%2d/g' -e 's/\./%2e/g' -e 's/\//%2f/g' -e 's/:/%3a/g' -e 's/;/%3b/g' -e 's//%3e/g' -e 's/?/%3f/g' -e 's/@/%40/g' -e 's/\[/%5b/g' -e 's/\\/%5c/g' -e 's/\]/%5d/g' -e 's/\^/%5e/g' -e 's/_/%5f/g' -e 's/`/%60/g' -e 's/{/%7b/g' -e 's/|/%7c/g' -e 's/}/%7d/g' -e 's/~/%7e/g')
echo $url
}
25 changes: 25 additions & 0 deletions src/home/yi-hack-v3/script/last_motion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
# Copyright 2018 Vladimir Dronnikov & Frank van der Stad
# GPL
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
source $YI_HACK_V3_PREFIX/yi-hack-v3/script/include_functions.sh

CAMERA_NAME=`more $YI_HACK_V3_PREFIX/yi-hack-v3/etc/hostname`;

# This part is copyright 2018 Vladimir Dronnikov
# GPL
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
33 changes: 28 additions & 5 deletions src/home/yi-hack-v3/script/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
CONF_FILE="/yi-hack-v3/etc/system.conf"

if [ -d "/usr/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/usr"
YI_HACK_V3_PREFIX="/usr"
elif [ -d "/home/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/home"
YI_HACK_V3_PREFIX="/home"
fi

get_config()
{
key=$1
grep $1 $YI_HACK_V3_PREFIX$CONF_FILE | cut -d "=" -f2
key=$1
grep $1 $YI_HACK_V3_PREFIX$CONF_FILE | cut -d "=" -f2
}

if [ -d "/usr/yi-hack-v3" ]; then
Expand All @@ -37,11 +37,34 @@ if [[ $(get_config FTPD) == "yes" ]] ; then
fi

if [[ $(get_config DROPBEAR) == "yes" ]] ; then
dropbear -R
dropbear -R
fi

if [ -f "/tmp/sd/yi-hack-v3/startup.sh" ]; then
/tmp/sd/yi-hack-v3/startup.sh
elif [ -f "/home/hd1/yi-hack-v3/startup.sh" ]; then
/home/hd1/yi-hack-v3/startup.sh
fi

# Adding some symlinks for the last picture/video
if [ ! -d "/home/yi-hack-v3/www/img" ]; then
mkdir /home/yi-hack-v3/www/img
fi
if [ ! -f "/home/yi-hack-v3/www/img/last.jpg" ]; then
ln -s /tmp/sd/record/last.jpg /home/yi-hack-v3/www/img/last.jpg
fi
if [ ! -f "/home/yi-hack-v3/www/img/last.mp4" ]; then
ln -s /tmp/sd/record/last.mp4 /home/yi-hack-v3/www/img/last.mp4
fi

#Check if we use the telegram functionality
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
else
if [ -f "/home/yi-hack-v3/script/last_motion.sh" ]; then
sh /home/yi-hack-v3/script/last_motion.sh &
fi
fi

8 changes: 4 additions & 4 deletions src/home/yi-hack-v3/script/system_init.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh

if [ -d "/usr/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/usr"
YI_HACK_V3_PREFIX="/usr"
YI_PREFIX="/home"
UDHCPC_SCRIPT_DEST="/home/default.script"
elif [ -d "/home/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/home"
YI_HACK_V3_PREFIX="/home"
YI_PREFIX="/home/app"
UDHCPC_SCRIPT_DEST="/home/app/script/default.script"
fi
Expand All @@ -30,8 +30,8 @@ fi
if [ ! -f $YI_PREFIX/cloudAPI_real ]; then
mv $YI_PREFIX/cloudAPI $YI_PREFIX/cloudAPI_real
cp $YI_HACK_V3_PREFIX/yi-hack-v3/cloudAPI $YI_PREFIX/
rm $UDHCPC_SCRIPT_DEST
cp $UDHCP_SCRIPT $UDHCPC_SCRIPT_DEST
rm $UDHCPC_SCRIPT_DEST
cp $UDHCP_SCRIPT $UDHCPC_SCRIPT_DEST
if [ -f $DHCP_SCRIPT_DEST ]; then
rm $DHCP_SCRIPT_DEST
cp $DHCP_SCRIPT $DHCP_SCRIPT_DEST
Expand Down
23 changes: 12 additions & 11 deletions src/home/yi-hack-v3/www/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<li><a href="proxy_config.html">ProxyChains-ng</a></li>
<li><a href="config.html">System Config</a></li>
<li class="active"><a href="about.html">About</a></li>
<li><a href="last_motion.html">Last motion</a></li>
<li><a href="reboot.html">Reboot</a></li>
</ul>
</div><!--/.nav-collapse -->
Expand All @@ -50,7 +51,7 @@
<div class="page-header">
<h1>About yi-hack-v3</h1>
</div>

<p>Yi-hack-v3 unlocks features not available with the official Yi camera firmware. Features implemented include:</p>
<ul>
<li>Telnet Server</li>
Expand All @@ -66,7 +67,7 @@ <h1>About yi-hack-v3</h1>
<li>Yi Dome</li>
<li>Yi 1080p Dome</li>
</ul>

<h2>Version</h2>
<dl class="dl-horizontal">
<dt>Camera</dt>
Expand All @@ -76,10 +77,10 @@ <h2>Version</h2>
<dt>yi-hack-v3 Firmware</dt>
<dd><div class=hack_version></div></dd>
</dl>

<h2>More Information</h2>
<a href="https://github.com/shadow-1/yi-hack-v3">https://github.com/shadow-1/yi-hack-v3</a>

</div>

<!-- Bootstrap core JavaScript
Expand Down Expand Up @@ -120,7 +121,7 @@ <h2>More Information</h2>
}

/* yi-hack-v3_info protocol */

var socket_info;

if (typeof MozWebSocket != "undefined") {
Expand All @@ -134,7 +135,7 @@ <h2>More Information</h2>
try {
socket_info.onopen = function() {
init();
}
}

socket_info.onmessage = function got_packet(msg) {
jso = JSON.parse(msg.data);
Expand All @@ -147,25 +148,25 @@ <h2>More Information</h2>
for (var i = 0, max = CameraElements.length; i < max; i++) {
CameraElements[i].textContent = jso.camera;
}

document.getElementsByClassName("base_version")[0].textContent = jso.base_version;
document.getElementsByClassName("hack_version")[0].textContent = jso.hack_version;
}
}
}

socket_info.onclose = function(){

}
} catch(exception) {
alert('<p>Error' + exception);
alert('<p>Error' + exception);
}

function init() {
socket_info.send("SEND_CAM_INFO\n");
}

</script>

</body>

</html>
Loading