Skip to content

Commit

Permalink
Merge beta into master (EliasKotlyar#1786)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-devel authored Oct 24, 2021
1 parent d2fa6d7 commit f1cf7da
Show file tree
Hide file tree
Showing 21 changed files with 883 additions and 140 deletions.
52 changes: 44 additions & 8 deletions firmware_mod/bin/matrix
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
#!/bin/sh

CURL="/system/sdcard/bin/curl --silent"
JQ="/system/sdcard/bin/jq"

what="$1"
shift
data="$@"
CURL="/system/sdcard/bin/curl"

if [ "$what" = "m" ]; then
shift
sendtext="${@//\"/\\\"}"
else
filename="$2"
datafile="$3"
fi

. /system/sdcard/config/matrix.conf

uploadData() {
mimetype="$1"
msgtype="$2"

mxcuri="$($CURL -XPOST -H "Content-Type: $mimetype" --data-binary @"$datafile" "https://$host:$port/_matrix/media/r0/upload?filename=$filename&access_token=$access_token" | $JQ -cMr ".content_uri")"
if [ -n "$mxcuri" ] && [ "$mxcuri" != "null" ]; then
$CURL -XPOST -d '{"msgtype":"'"$msgtype"'", "body":"'"$filename"'", "url":"'"$mxcuri"'"}' "https://$host:$port/_matrix/client/r0/rooms/$room_id/send/m.room.message?access_token=$access_token"
fi
}

sendFile() {
echo "Sending file: $datafile"
uploadData "application/octet-stream" "m.file"
}

sendMessage() {
text="$(echo "${@}" | sed 's:\\n:\n:g')"
echo "Sending message: $text"
echo "Sending message: $sendtext"
$CURL -XPOST -d '{"msgtype":"m.notice", "body":"'"$sendtext"'"}' "https://$host:$port/_matrix/client/r0/rooms/$room_id/send/m.room.message?access_token=$access_token"
}

sendPicture() {
echo "Sending picture: $datafile"
filename="$filename.jpg"
uploadData "image/jpeg" "m.image"
}

$CURL -XPOST -d '{"msgtype":"m.text", "body":"'$text'"}' "https://$host:$port/_matrix/client/r0/rooms/$room_id/send/m.room.message?access_token=$access_token"
sendVideo() {
echo "Sending video: $datafile"
filename="$filename.mp4"
uploadData "video/mp4" "m.video"
}

[ "$what" = "m" ] && sendMessage $data
[ -z "$what" ] && echo -e "$0 <m|f|p> <data>\n m: message\n f: file\n p: picture"
[ "$what" = "f" ] && sendFile
[ "$what" = "m" ] && sendMessage
[ "$what" = "p" ] && sendPicture
[ "$what" = "v" ] && sendVideo
[ -z "$what" ] && echo -e "$0 <m|f|p|v> <data|filename>\n m: message\n f: file\n p: picture\n v: video"
81 changes: 51 additions & 30 deletions firmware_mod/bin/telegram
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,66 @@ sendMessage() {
}

sendFile() {
echo "Sending file: $1"
$CURL -s \
-X POST \
https://api.telegram.org/bot$apiToken/sendDocument \
-F chat_id="$userChatId" \
-F document=@"$1"
if [ -r $1 ]
then
echo "Sending file: $1"
$CURL -s \
-X POST \
https://api.telegram.org/bot$apiToken/sendDocument \
-F chat_id="$userChatId" \
-F document=@"$1"
else
echo "File not found: $1"
fi
}

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}"
if [ -r $1 ]
then
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}"
else
echo "File not found: $1"
fi
}

sendVideo() {
caption="$(hostname)-$(date +"%d%m%Y_%H%M%S")"
echo "Sending Video: $1 $caption" >> /tmp/telegram.log
$CURL -s \
-X POST \
https://api.telegram.org/bot$apiToken/sendVideo \
-F chat_id="$userChatId" \
-F video="@${1}" \
-F caption="${caption}"
if [ -r $1 ]
then
bytes=$(busybox stat -c %s $1)
caption="$(hostname)-$(date +"%d%m%Y_%H%M%S")"
echo "Sending Video: $1 $caption (${bytes}bytes)" >> /tmp/telegram.log
$CURL -s \
-X POST \
https://api.telegram.org/bot$apiToken/sendVideo \
-F chat_id="$userChatId" \
-F video="@${1}" \
-F caption="${caption}"
else
echo "File not found: $1"
fi
}

sendAnimation() {
caption="$(hostname)-$(date +"%d%m%Y_%H%M%S")"
echo "Sending Animation: $1 $caption" >> /tmp/telegram.log
$CURL -s \
-X POST \
https://api.telegram.org/bot$apiToken/sendAnimation \
-F chat_id="$userChatId" \
-F animation="@${1}" \
-F caption="${caption}"
if [ -r $1 ]
then
caption="$(hostname)-$(date +"%d%m%Y_%H%M%S")"
echo "Sending Animation: $1 $caption" >> /tmp/telegram.log
$CURL -s \
-X POST \
https://api.telegram.org/bot$apiToken/sendAnimation \
-F chat_id="$userChatId" \
-F animation="@${1}" \
-F caption="${caption}"
else
echo "File not found: $1"
fi
}

[ "$what" == "m" ] && sendMessage $data
Expand Down
2 changes: 2 additions & 0 deletions firmware_mod/config/motion.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ send_email=false
send_telegram=false
telegram_alert_type=image
send_matrix=false
matrix_alert_type=image
night_mode_event_delay=30

# General
Expand Down Expand Up @@ -63,6 +64,7 @@ ftp_videos_dir="motion/videos"
# Configure Dropbox snapshots and videos
dropbox_snapshot=false
dropbox_video=false
dropbox_url="https://content.dropboxapi.com/2/files/upload"
dropbox_token="token"
dropbox_stills_dir="/motion/stills"
dropbox_videos_dir="/motion/videos"
Expand Down
2 changes: 1 addition & 1 deletion firmware_mod/config/rtspserver.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ FRAMERATE_NUM=25
VIDEOFORMAT=2

# AudioFormat
# Can be: OPUS | MP3 | PCM | PCMU
# Can be: OPUS | MP3 | PCM | PCMU | OFF
AUDIOFORMAT=MP3
# Audio sampling rate
AUDIOINBR=16000
Expand Down
Loading

0 comments on commit f1cf7da

Please sign in to comment.