Make snapshot from Ubiquiti UVC camera

bramfm
Posts: 1
Joined: Friday 19 August 2016 12:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Make snapshot from Ubiquiti UVC camera

Postby bramfm » Wednesday 26 October 2016 4:10

I like the Ubiquiti cameras, however the API documentation just s*cks. So I started to experiment a little and I found out that every individual camera makes a snapshot every second. Getting the snapshot (snap.jpeg) of the camera is a little bit harder.
The thirst thing I tired was fetching the file via http, so something like http://xxx.xxx.xxx.xxx/snap.jpeg , this works only If you are already logged-in.
Next I tried:
wget --user=ubnt --password=yyyyyy https://xxx.xxx.xxx.xxx:/snap.jpeg this generates the "Unknown authentication scheme" error. It seems that you have to change someting in the camera to make this work. I am a bit lazy to adapt all my camera's.

So I decided to fetch snap.jpeg via scp, problem is however that you need to enter a password and that's not very convenient. There is a trick described on the ubiquiti fora where you have to upload the key into the camera, and again I didnt want to do that.

Next I used sshpass, I know this is not the most secure method, but what the heck it's behind my firewall

Code: Select all

sshpass -p yyyyyyyy scp -r [email protected]:/tmp/snap.jpeg /tmp/snap.jpeg


where yyyyyyy is the camera's password, and xxx.xxx.xxx.xxx is the camera's ip address.

If you want to call this script from within Domotics, be sure the camera key is in the known_hosts file for root:

Code: Select all

sudo ssh-keyscan -H xxx.xxx.xxx.xxx >> ~/.ssh/known_hosts


Now you have a snapshot in the /tmp directory. Via Pushsafer I want generate a notification with the snapshot. Be aware pushsafer is not free, but it offers much more funtionality with a better user interface than prowl, so a couple of euros is well spent.

The snapshot is rather big so you have to reduce it in size:

Code: Select all

convert -resize 40% /tmp/snap.jpeg /tmp/snap2.jpeg


Then you need to encode it via base64:

Code: Select all

base64 --wrap=0 /tmp/snap2.jpeg


The complete script:

Code: Select all

#!/bin/bash
sshpass -p yyyyyyyyyy scp -r [email protected]:/tmp/snap.jpeg /tmp/snap.jpeg
convert -resize 40% /tmp/snap.jpeg /tmp/snap2.jpeg

URL="https://www.pushsafer.com/api"
PRIVATEKEY="" #Your Private or Alias Key
TITLE="Bel!"
MESSAGE="Er wordt gebeld";
# DEVICE="131";                #Device or Device Group ID
ICON="55";
SOUND="3";
VIBRATION="0";
JPEG="$( base64 --wrap=0 /tmp/snap2.jpeg )"
PICTURE="data:image/png;base64,$JPEG";


if [ ${#PRIVATEKEY} == 0 ]
then
        echo "Error: You need to supply an app token"
        exit 1;
fi

if [ ${#MESSAGE} == 0 ]
then
        echo "Error: message may not be empty"
        exit 1;
fi

RESPONSE=`curl -s --data k=$PRIVATEKEY --data-urlencode t="$TITLE" --data-urlencode m="$MESSAGE" --data d="$DEVICE" --data i="$ICON" --data s="$SOUND" --data v="$VIBRATION" --data-urlencode p="$PI$

echo "Send Push"
echo "| TITLE: $TITLE"
echo "| MESSAGE: $MESSAGE"
echo "| RESPONSE: $RESPONSE"
echo "|____________________"

maomanna
Posts: 50
Joined: Monday 30 November 2015 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Postby maomanna » Thursday 10 November 2016 11:18

thanks!

But, do you know that you can easily add a unifi camera to Domoticz.

Set unifi camera as unmanaged
log in with standard credentials
change credentials
Add camera in Domoticz
fill in IP of the camera
new credentials
port 80
url: snap.jpeg

works like charm!
After adding, you can let the Unifi Video NVR manage the camera.
Camera keeps working in Domoticz

cybermaus
Posts: 2
Joined: Monday 14 November 2016 17:47
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Postby cybermaus » Friday 25 November 2016 18:27

bramfm wrote:Next I tried:
wget --user=ubnt --password=yyyyyy https://xxx.xxx.xxx.xxx:/snap.jpeg this generates the "Unknown authentication scheme" error. It seems that you have to change someting in the camera to make this work. I am a bit lazy to adapt all my camera's.

Not that I know it to work, but as a thought did you try:

Code: Select all

wget https://ubnt:[email protected]/snap.jpeg

or maybe drop the https

Code: Select all

wget --user=ubnt --password=yyyyyy http://xxx.xxx.xxx.xxx/snap.jpeg
wget http://ubnt:[email protected]/snap.jpeg

And I am assuming the : in your URL was a copy/paste error while posting, and you did not really try that anyway:

Code: Select all

                                                          *
wget --user=ubnt --password=yyyyyy https://xxx.xxx.xxx.xxx:/snap.jpeg



Return to “Camera's”

Who is online

Users browsing this forum: iamchinnapat and 0 guests