From 1c76e0e00b6f79d9696036909b16bb560c11a2d0 Mon Sep 17 00:00:00 2001 From: Harry Gonzalez Date: Thu, 19 Jul 2018 09:46:55 -0500 Subject: [PATCH 1/4] Tweak Motion Sensitivity Description (#585) Tweak Motion Sensitivity Description --- firmware_mod/www/configmotion.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/firmware_mod/www/configmotion.html b/firmware_mod/www/configmotion.html index b47693c..44e481f 100644 --- a/firmware_mod/www/configmotion.html +++ b/firmware_mod/www/configmotion.html @@ -31,12 +31,12 @@
From 67da745397afc8632b83842eb89a8195d6565484 Mon Sep 17 00:00:00 2001 From: Julian Tatsch Date: Fri, 20 Jul 2018 13:09:16 +0200 Subject: [PATCH 2/4] Add telegram support #582 --- .gitignore | 1 + firmware_mod/bin/telegram | 43 ++++++++++++++++++++++++++ firmware_mod/config/motion.conf.dist | 1 + firmware_mod/config/telegram.conf.dist | 7 +++++ firmware_mod/scripts/detectionOn.sh | 7 +++++ 5 files changed, 59 insertions(+) create mode 100755 firmware_mod/bin/telegram create mode 100644 firmware_mod/config/telegram.conf.dist diff --git a/.gitignore b/.gitignore index feda6cd..10217f4 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ firmware_mod/System Volume Information/IndexerVolumeGuid firmware_mod/System Volume Information/WPSettings.dat firmware_mod/config/motion.conf firmware_mod/config/mqtt.conf +firmware_mod/config/telegram.conf firmware_mod/config/sendmail.conf firmware_mod/config/rtspserver.conf firmware_mod/config/ntp_srv.conf diff --git a/firmware_mod/bin/telegram b/firmware_mod/bin/telegram new file mode 100755 index 0000000..2a06f72 --- /dev/null +++ b/firmware_mod/bin/telegram @@ -0,0 +1,43 @@ +#!/bin/sh +what="$1" +shift +data="$@" +CURL="/system/sdcard/bin/curl" + +. /system/sdcard/config/telegram.conf + +sendMessage() { + text="$(echo "${@}" | sed 's:\\n:\n:g')" + echo "Sending message: $text" + + $CURL -s \ + -X POST \ + https://api.telegram.org/bot$apiToken/sendMessage \ + --data-urlencode "text=$text" \ + -d "chat_id=$userChatId" +} + +sendFile() { + echo "Sending file: $1" + $CURL -s \ + -X POST \ + https://api.telegram.org/bot$apiToken/sendDocument \ + -F chat_id="$userChatId" \ + -F document=@"$1" +} + +sendPhoto() { + caption="$(hostname)-$(date +"%d%m%Y_%H%M%S")" + echo "Sending Photo: $1 $caption" >> /tmp/telegram.log + $CURL -s \ + -X POST \ + https://api.telegram.org/bot$apiToken/sendPhoto \ + -F chat_id="$userChatId" \ + -F photo="@${1}" \ + -F caption="${caption}" +} + +[ "$what" == "m" ] && sendMessage $data +[ "$what" == "f" ] && sendFile $data +[ "$what" == "p" ] && sendPhoto $data +[ -z "$what" ] && echo -e "$0 \n m: message\n f: file\n p: picture" diff --git a/firmware_mod/config/motion.conf.dist b/firmware_mod/config/motion.conf.dist index 461e865..f35fdf3 100644 --- a/firmware_mod/config/motion.conf.dist +++ b/firmware_mod/config/motion.conf.dist @@ -17,4 +17,5 @@ save_snapshot=false max_snapshots=20 publish_mqtt_message=false sendemail=false +send_telegram=false save_dir=/system/sdcard/motion/stills diff --git a/firmware_mod/config/telegram.conf.dist b/firmware_mod/config/telegram.conf.dist new file mode 100644 index 0000000..42fa520 --- /dev/null +++ b/firmware_mod/config/telegram.conf.dist @@ -0,0 +1,7 @@ +############################################################ +# edit this file and move it to /system/sdcard/config/telegram.conf # +############################################################ + +# Add your Telegram credentials here (these are just examples) +apiToken="23132160:AAFrSEwzJ-X-64tLnD8JJ$JoAxWIMg$$w" +userChatId="30985132" diff --git a/firmware_mod/scripts/detectionOn.sh b/firmware_mod/scripts/detectionOn.sh index e10611c..08f2999 100755 --- a/firmware_mod/scripts/detectionOn.sh +++ b/firmware_mod/scripts/detectionOn.sh @@ -37,6 +37,13 @@ if [ "$sendemail" = true ] ; then /system/sdcard/scripts/sendPictureMail.sh& fi +# Send a telegram message +if [ "$send_telegram" = true ]; then + /system/sdcard/bin/getimage > $save_dir/$filename + /system/sdcard/bin/telegram p $save_dir/$filename + rm $save_dir/$filename +fi + # Run any user scripts. for i in /system/sdcard/config/userscripts/motiondetection/*; do if [ -x $i ]; then From a5efadc959af58b36fc0737c3128d5c4bbfc4e79 Mon Sep 17 00:00:00 2001 From: Julian Tatsch Date: Sat, 21 Jul 2018 08:32:32 +0200 Subject: [PATCH 3/4] Fix Telegram action deleting the snap, improved string quoting --- firmware_mod/scripts/detectionOn.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/firmware_mod/scripts/detectionOn.sh b/firmware_mod/scripts/detectionOn.sh index 08f2999..d4b66ba 100755 --- a/firmware_mod/scripts/detectionOn.sh +++ b/firmware_mod/scripts/detectionOn.sh @@ -1,8 +1,8 @@ #!/bin/sh # Source your custom motion configurations -. /system/sdcard/config/motion.conf -. /system/sdcard/scripts/common_functions.sh +. ../config/motion.conf +. common_functions.sh # Turn on the amber led if [ "$motion_trigger_led" = true ] ; then @@ -13,21 +13,21 @@ fi if [ "$save_snapshot" = true ] ; then filename=$(date +%d-%m-%Y_%H.%M.%S).jpg if [ ! -d "$save_dir" ]; then - mkdir -p $save_dir + mkdir -p "$save_dir" fi # Limit the number of snapshots - if [[ $(ls $save_dir | wc -l) -ge $max_snapshots ]]; then - rm -f "$save_dir/$(ls -l $save_dir | awk 'NR==2{print $9}')" + if [ "$(ls "$save_dir" | wc -l)" -ge "$max_snapshots" ]; then + rm -f "$save_dir/$(ls -l "$save_dir" | awk 'NR==2{print $9}')" fi - /system/sdcard/bin/getimage > $save_dir/$filename & + /system/sdcard/bin/getimage > "$save_dir/$filename" & fi # Publish a mqtt message if [ "$publish_mqtt_message" = true ] ; then - . /system/sdcard/config/mqtt.conf + . ../config/mqtt.conf /system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion ${MOSQUITTOOPTS} ${MOSQUITTOPUBOPTS} -m "ON" if [ "$save_snapshot" = true ] ; then - /system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/snapshot ${MOSQUITTOOPTS} ${MOSQUITTOPUBOPTS} -f $save_dir/$filename + /system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/snapshot ${MOSQUITTOOPTS} ${MOSQUITTOPUBOPTS} -f "$save_dir/$filename" fi fi @@ -39,14 +39,18 @@ fi # Send a telegram message if [ "$send_telegram" = true ]; then - /system/sdcard/bin/getimage > $save_dir/$filename - /system/sdcard/bin/telegram p $save_dir/$filename - rm $save_dir/$filename + if [ "$save_snapshot" = true ] ; then + /system/sdcard/bin/telegram p "$save_dir/$filename" + else + /system/sdcard/bin/getimage > "telegram_image.jpg" + + /system/sdcard/bin/telegram p "telegram_image.jpg" + + rm "telegram_image.jpg" + fi fi # Run any user scripts. for i in /system/sdcard/config/userscripts/motiondetection/*; do - if [ -x $i ]; then + if [ -x "$i" ]; then echo "Running: $i on" $i on fi From 69db2d677b44ca56fea058a0057309b76e7738d3 Mon Sep 17 00:00:00 2001 From: Julian Tatsch Date: Sat, 21 Jul 2018 09:52:17 +0200 Subject: [PATCH 4/4] Undo relative importing --- firmware_mod/scripts/detectionOn.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware_mod/scripts/detectionOn.sh b/firmware_mod/scripts/detectionOn.sh index d4b66ba..f8949da 100755 --- a/firmware_mod/scripts/detectionOn.sh +++ b/firmware_mod/scripts/detectionOn.sh @@ -1,8 +1,8 @@ #!/bin/sh # Source your custom motion configurations -. ../config/motion.conf -. common_functions.sh +. /system/sdcard/config/motion.conf +. /system/sdcard/scripts/common_functions.sh # Turn on the amber led if [ "$motion_trigger_led" = true ] ; then @@ -24,7 +24,7 @@ fi # Publish a mqtt message if [ "$publish_mqtt_message" = true ] ; then - . ../config/mqtt.conf + . /system/sdcard/config/mqtt.conf /system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion ${MOSQUITTOOPTS} ${MOSQUITTOPUBOPTS} -m "ON" if [ "$save_snapshot" = true ] ; then /system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/snapshot ${MOSQUITTOOPTS} ${MOSQUITTOPUBOPTS} -f "$save_dir/$filename"