Make snapshot from Ubiquiti UVC camera

Moderator: leecollings

Post Reply
bramfm
Posts: 1
Joined: Friday 19 August 2016 12:46
Target OS: Linux
Domoticz version:
Contact:

Make snapshot from Ubiquiti UVC camera

Post by bramfm »

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: 94
Joined: Monday 30 November 2015 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by maomanna »

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: 5
Joined: Monday 14 November 2016 16:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by cybermaus »

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
User avatar
pushsafer
Posts: 7
Joined: Sunday 18 September 2016 22:21
Target OS: Windows
Domoticz version: 3.5877
Location: Germany
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by pushsafer »

If the camera needs a https connection > try to add

Code: Select all

--no-check-certificate
after wget.
Some cameras needs stream a cached image so i recommend to add a timestamp to the snapshot url:

wget --no-check-certificate https://user:[email protected]/s ... mp=XXXXXXX

If you need help with https://www.pushsafer.com, iam the developer, you can ask me.
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by Benneton »

maomanna wrote: Thursday 10 November 2016 10: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
Hi

Just got a Unifi G3 Flex which I want to add to Domoticz.
Did set the cam to standalone and update username and password
Added the CAM in Domoticz as per quote.
Unfortunately no picture at all :(
Anyone an idea?

Thanks
Bernard
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by Benneton »

So I got one step further after reset of camera I did add it again.
Now in the box to add the camera I get the picture when I hit test.
So it looks promising :)
When I then click add button I get:
Problem adding camera!

Anyone any idea?
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by Benneton »

Did get it solved.
After update of all packages running on the PI and a reboot
When I could open Domoticz again, I was able to add the camera.
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by Benneton »

So this did work.
Had picture in of Unifi G3 Flex cam in Domoticz.

Then I added the cam back into Unifi Protect management.
This changed the account and passwd and link got broken to Domoticz.

Logged on to the camera direct via web interface with Unifi account, to check if this could be done, and this works.

I do get a picture in the preview screen:
Image

So one should think that all is correct :)

Then when I hit update picture is not shown in the camera list:
Image

When I configure action on door sensor to send me a mail with snapshot I does not work.
on my other camera this works fine.
Also when I preview on the switches page the camera connected to the switch does not provide stream.
Again my other cams are working.

Anyone an idea how to get this working, without additional scripts etc. (not to good in).

Thanks
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by thecosmicgate »

Benneton wrote:So this did work.
Had picture in of Unifi G3 Flex cam in Domoticz.

Then I added the cam back into Unifi Protect management.
This changed the account and passwd and link got broken to Domoticz.

Logged on to the camera direct via web interface with Unifi account, to check if this could be done, and this works.

I do get a picture in the preview screen:
Image

So one should think that all is correct :)

Then when I hit update picture is not shown in the camera list:
Image

When I configure action on door sensor to send me a mail with snapshot I does not work.
on my other camera this works fine.
Also when I preview on the switches page the camera connected to the switch does not provide stream.
Again my other cams are working.

Anyone an idea how to get this working, without additional scripts etc. (not to good in).

Thanks
Tried the same , but didn't get any picture of stream at all.
What Domo version you're running ?
It's nice to be important, but it's more important to be nice
Scooter ;)
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by Benneton »

I have running version 4.10548 updated to day to it.
I now have it working, don't ask me why or how.

Only reference I saw in log file related to the IP CAM was this one:
2019-03-14 15:38:39.578 Status: Camera: settings (re)loaded

You might need to restart Domoticz, that was what I needed to do the first time around.

I do not know if I now have this working permanent or not, but that I will see in the coming weeks.

When it is permanent I can move over to a all Unifi CAM system.
maomanna
Posts: 94
Joined: Monday 30 November 2015 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by maomanna »

i used a bash script to send a snapshot to my phone when motion was detected.

create a file in domoticz/scripts, paste the script above into it.

call the script when motion is detected.
Christie939
Posts: 1
Joined: Tuesday 09 July 2019 9:42
Target OS: Windows
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by Christie939 »

Benneton wrote: Tuesday 05 March 2019 17:36
maomanna wrote: Thursday 10 November 2016 10: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
Hi

Just got a Unifi G3 Flex which I want to add to Domoticz.
Did set the cam to standalone and update username and password
Added the CAM in Domoticz as per quote.
Unfortunately no picture at all :(
Anyone an idea?

Thanks
Bernard
Thank you very much for taking the time to answer my question
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make snapshot from Ubiquiti UVC camera

Post by Benneton »

Hi,

Got a new additional camera, added it but did not work as my other G3's.
Used same procedure, and could see the stream when I test connection.
Then save no little image....
After trying an fiddling with settings I noticed that when I log on the camera via web interface that I had a difference.
to do this:
Camera IP, then username and password
On the configure page you can set :
Enable Anonymous Snapshot

Tick this on save and check you cam in Domoticz. This did the trick for me :)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests