How to use pushbullet to send video and recent pic

339 views
Skip to first unread message

Bradley Scott

unread,
Aug 28, 2018, 2:33:05 PM8/28/18
to motioneye
Let me say im not normally doing tutorials but still it took weeks for me to find the websites and days to implement it


Websites.
the website that lead me to a better tutorial, dekloos code gives errors like no tommorow 
good tutorial on how to set up a video being sent to pushbullet.


Follow Electronicsfaq.com's tutorial 1 through 6.2

Note (see picture 1 for reference): Modify the location of storage also the video must be avi

on lines 20
LATESTAVI=$(ls -tr1 /home/ftp/sdcard/$DATESTAMP/*.avi | tail -1 | sed 's#.*/##')

and 67
curl -i -X POST $UPLOAD_URL -F file=@/home/ftp/sdcard/$DATESTAMP/$LATESTAVI

  these two lines from "home to sdcard"  need to be replaced with the path you chose as the root directory
DONTUSE ANY OTHER PROGRAM BESIDES SSH TO FIND THE PATH DUE TO MIXING OF SUB FOLDERS (took me so long to realize this)

save the script and finish Electronicsfaq.com's tutorial step 6
while still in putty
run
bash pushbullet.sh

If you had any recent vids it will send that to the devices you set up such as the computer.
If it says no directory at the root location either change the root directory to defualt if its not, and if it is defualt change a random letter apply and you will be warned. Once warned wait till after the reboot and remove the random letter and the default path should be fixed. Both methods delete all old videos so be careful.
If you have to have to use a custom location use 
ls
and

cd
and hunt down 
I have no idea how to pull it off of a FTP server, i only could figure out.

Once the bash test works and you have  video being sent
Finish step 7 of Electronicsfaq.com's tutorial. Make sure you put the code in the Motion notification "Run An End of Command" or you will be spammed every second of the video recording

Run An End Command
ON
Command


Ive posted three sets of code below each do something different  and each have a few words changed.



working Example of Videos being sent 
CUSTOM TO MY SAVE LOCATION
#!/bin/bash

## Your PushBullet Access Token
## Fetch yours from your "Account Settings" Page: https://www.pushbullet.com/#settings/account
## PushBullet API Documentation link: https://docs.pushbullet.com/#api-quick-start
ACCESSTOKEN="****************************************"

## Following bash script function taken from https://gist.github.com/cjus/1047794
## It extracts value for a corresponding key from a JSON response.
function jsonval {
    temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $json_key`
    echo ${temp##*|}
}

## Get the current date and time
DATESTAMP=$(date +"%Y-%m-%d")
TIMESTAMP=$(date +"%H-%M-%S")

## Get the name of the latest AVI clip shot and placed with a folder on your Raspberry Pi's SD card
LATESTAVI=$(ls -tr1 /data/output/Camera1/$DATESTAMP/*.avi | tail -1 | sed 's#.*/##')


## The latest AVI might still be open and being written to.
## So if we try to upload the file rightaway, the file size will be reported to be greater than 25 MB
## and PushBullet will reject it. So we will wait for 30 seconds to allow the system to finish writing the file.
## Ideally we should use lsof utility to wait until the file is done writing, but lsof command is not available on Motion Pie.
sleep 30

## Pushing a file is a 3 step process
## Step 1: Send a request for file upload.
##    PushBullet will respond with a URL to which you can upload your file. (upload URL)
##    PushBullet will also respond with a URL at which the file will be available after upload. (File URL)
##   No push message is sent in this step.
##   File is not uploaded in this step.
##
## Step 2: Upload the file to the URL which was assigned to you in Step 1
##
## Step 3: A push need to be sent for that file. This push can include a message as well as the File URL generated in Step 1.

## Step 1: Request file upload
json="$(curl \
--header 'Access-Token: '$ACCESSTOKEN \
--header 'Content-Type: application/json' \
--data-binary '{"file_name":"'"$LATESTAVI"'","file_type":"video/avi"}' \
--request POST \

## Extract the JSON fields: espesially the Upload URL and File URL
json_key='upload_url'
UPLOAD_URL=`jsonval`

json_key='file_url'
FILE_URL=`jsonval`

json_key='file_name'
FILE_NAME=`jsonval`

json_key='file_type'
FILE_TYPE=`jsonval`

## Step 2: Upload the file
echo "About to  upload $LATESTAVI to $UPLOAD_URL"
curl -i -X POST $UPLOAD_URL -F file=@/data/output/Camera1/$DATESTAMP/$LATESTAVI
echo "Done uploading. File now available at $FILE_URL"

## Step 3: Send a push message including a link to the file. 
## If the Push is received on a smart phone, the file will be automatically downloaded to it.
echo "Now pushing the file $LATESTAVI to Devices."
curl \
--header 'Access-Token: '$ACCESSTOKEN \
--header 'Content-Type: application/json' \
--data-binary '{"type":"file","body":"Motion detected at '"$DATESTAMP $TIMESTAMP"'","file_name":"'"$FILE_NAME"'","file_type":"'"$FILE_TYPE"'","file_url":"'"$FILE_URL"'"}' \
--request POST \



working Example of RECENT PIC being sent 
CUSTOM TO MY SAVE LOCATION
Notice that the pic is jpg
#!/bin/bash

## Your PushBullet Access Token
## Fetch yours from your "Account Settings" Page: https://www.pushbullet.com/#settings/account
## PushBullet API Documentation link: https://docs.pushbullet.com/#api-quick-start
ACCESSTOKEN="****************************************"

## Following bash script function taken from https://gist.github.com/cjus/1047794
## It extracts value for a corresponding key from a JSON response.
function jsonval {
    temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $json_key`
    echo ${temp##*|}
}

## Get the current date and time
DATESTAMP=$(date +"%Y-%m-%d")
TIMESTAMP=$(date +"%H-%M-%S")

## Get the name of the latest AVI clip shot and placed with a folder on your Raspberry Pi's SD card
#LATESTAVI=$(ls -tr1 /data/output/Camera1/$DATESTAMP/*.avi | tail -1 | sed 's#.*/##')
LATESTIMG=$(ls -tr1 /data/output/Camera1/$DATESTAMP/*.jpg | tail -1 | sed 's#.*/##')

## The latest AVI might still be open and being written to.
## So if we try to upload the file rightaway, the file size will be reported to be greater than 25 MB
## and PushBullet will reject it. So we will wait for 30 seconds to allow the system to finish writing the file.
## Ideally we should use lsof utility to wait until the file is done writing, but lsof command is not available on Motion Pie.
sleep 30

## Step 1: Send a request for file upload.
##    PushBullet will respond with a URL to which you can upload your file. (upload URL)
##    PushBullet will also respond with a URL at which the file will be available after upload. (File URL)
##   No push message is sent in this step.
##   File is not uploaded in this step.
##
## Step 2: Upload the file to the URL which was assigned to you in Step 1
##
## Step 3: A push need to be sent for that file. This push can include a message as well as the File URL generated in Step 1.

## Step 1: Request file upload
json="$(curl \
--header 'Access-Token: '$ACCESSTOKEN \
--header 'Content-Type: application/json' \
--data-binary '{"file_name":"'"LATESTIMG"'","file_type":"image / jpg"}' \
--request POST \

## Extract the JSON fields: espesially the Upload URL and File URL
json_key='upload_url'
UPLOAD_URL=`jsonval`

json_key='file_url'
FILE_URL=`jsonval`

json_key='file_name'
FILE_NAME=`jsonval`

json_key='file_type'
FILE_TYPE=`jsonval`

## Step 2: Upload the file
echo "About to  upload $LATESTIMG to $UPLOAD_URL"
curl -i -X POST $UPLOAD_URL -F file=@/data/output/Camera1/$DATESTAMP/$LATESTIMG
echo "Done uploading. File now available at $FILE_URL"

## Step 3: Send a push message including a link to the file.
## If the Push is received on a smart phone, the file will be automatically downloaded to it.
echo "Now pushing the file $LATESTIMG to Devices."
curl \
--header 'Access-Token: '$ACCESSTOKEN \
--header 'Content-Type: application/json' \
--data-binary '{"type":"file","body":"Motion detected at '"$DATESTAMP $TIMESTAMP"'","file_name":"'"$FILE_NAME"'","file_type":"'"$FILE_TYPE"'","file_url":"'"$FILE_URL"'"}' \
--request POST \


Poor script i wrote to run both 
#!/bin/bash
echo "Starting Video upload" & bash pushbullet.sh & echo "Starting Picture upload" & bash pushbullet_pic.sh


Note: all 3 scripts are in the same location and if you use the 3rd script replace the one in Motion notification "Run An End of Command" with the 3rd scripts name. See picture 2







Picture 1



Capture.PNG










Picture 2


Capture.PNG




Good luck and sorry for the poor tutorial,summary on here to go for the real instructions. I dont know! ><

Reply all
Reply to author
Forward
Message has been deleted
0 new messages