SETUP unifi cameras .. how to

Posted on
Thu May 03, 2018 6:12 pm
kw123 offline
User avatar
Posts: 5617
Joined: May 12, 2013
Location: Dallas, TX

SETUP unifi cameras .. how to

Karl Wachs 2018-05-03
how to ..
setup
== unifi - NVR video system
=== on virtual box running ubuntu
==== with shared folder and
====== unifi video files on your MAC
======= use with the UniFi indigo plugin

### are comments or explanations how / what to do
# are comments in files

###########
0. download
a) virtual box from oracle for OSX and install (https://www.virtualbox.org/wiki/Downloads)
b) virtualbox guest editions -- same as above
c) ubuntu iso file (https://www.ubuntu.com/download/desktop)


########### on the MAC
1. start virtual box , create a new VM , call it eg "unifiubuntu"

####
1.1 select 32 GB of VDI fixed space (that is plenty(I guess 16GB is enough if you store the videos outside the VM)

####
1.2 select downloaded ubuntu iso image as source

####
1.3 in setup select 2d and 3d acceleration
set display ram to 32 mbyte
select bridged network adapter (gives it a regular ip number (192.168.1.x) in your network )

####
1.4 setup shared folder point to your big hardisk folder eg ..../video
### manually in terminal
Code: Select all
VBoxManage sharedfolder add "unifiubuntu" --name "video" --hostpath  "/path/ to/video "  --automount"
### or in the virtual box menu
and
Code: Select all
sudo sudo chmod -R 777  /path/ to/video
sudo chown -R macuserid:everyone '/path/ to/video'
to grant rights to the video directory for the virtual box user
####
1.5 select 1 cpu (or 2 cpu if you have plenty .. one cpu works for 8 cameras full resolution on an mac pro 3,1 2008 uses ~ 40-60% of one MAC cpu = 6% of total cpu)

####
1.6 start machine , you should see Ubuntu x.x and . . . . will take a while
when graphics comes up: select install ubuntu, uncheck "download while ... etc" will do that later, or you can do it now .. your choice ~ 3 minutes extra
click on erase and install .. continue .. select timezone .. keyboard .. enter name .. username/passwd .. and important: login automatically
... have a coffee .. click on restart

###########
2. configure guest and command line boot (not graphics, it is too slow, uses too many resources)
after reboot in graphics, find and start terminal:

####
2.1 with grub setup boot into command line (http://ask.xmodulo.com/boot-into-comman ... ebian.html)
Code: Select all
sudo nano /etc/default/grub

### change /add comment the following lines:
Code: Select all
#GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="text"
GRUB_TERMINAL=console
CTRLo ### save
CTROx ### exit

### make changes active
Code: Select all
sudo update-grub
sudo systemctl set-default multi-user.target

### enable ssh remote login
Code: Select all
sudo apt-get install openssh-server

### get time client
Code: Select all
sudo apt-get install ntp

### downloads tree utility, comes handy
Code: Select all
sudo apt-get install tree

#### time for
Code: Select all
sudo reboot   

### will boot into command line ... much faster

### from now on you can use ssh from your mac to login, better copy paste .. (find the ip number of your new ubuntu server)
### also now set ip number to a fixed # on your dhcp server to your liking


###########
2.2 GUEST install, needed for shared folder:(https://www.techrepublic.com/article/ho ... rver-host/)
###Mount the CD-ROM with the command (first need to add the extention-iso file in virtual box menu)
Code: Select all
ssh userid@ipOfVbox
sudo mkdir /media/cdrom
sudo mount /dev/cdrom /media/cdrom

###Change into the mounted directory with the command
Code: Select all
cd /media/cdrom

###Install the necessary dependencies with the command
Code: Select all
sudo apt-get install -y dkms build-essential linux-headers-generic linux-headers-$(uname -r)


###Change to the root user and Install the Guest Additions package with the command (will take 2 min+)
Code: Select all
sudo su
./VBoxLinuxAdditions.run



###########
3. install unifi-video NVR:

### ### following: https://community.ubnt.com/t5/UniFi-Vid ... -p/1873291
### get clean ubuntu
Code: Select all
sudo apt-get update
sudo apt-get upgrade

### ### install unifi nvr video system
### get java FIRST !!!
Code: Select all
sudo apt-get install default-jre

### get unifi video
Code: Select all
wget https://dl.ubnt.com/firmwares/unifi-video/3.6.2/unifi-video_3.6.2~Ubuntu16.04_amd64.deb

### install it
Code: Select all
sudo dpkg -i unifi-video_3.6.2~Ubuntu16.04_amd64.deb

### remove installer
Code: Select all
rm -rf unifi-video_3.6.2~Ubuntu16.04_amd64.deb

### give unify-video the proper rights (you can use any directory ( instead of ...../osx) name you like
Code: Select all
mkdir /home/YOURID/osx
chown -R unifi-video  /home/YOURID/osx
sudo adduser unifi-video vboxsf
sudo adduser YOURID vboxsf

### make it mount on reboot:
Code: Select all
sudo nano /etc/rc.local

### add lines:
# let other props finish, then mount
Code: Select all
sleep 15
sudo mount -t vboxsf -o uid=unifi-video,gid=unifi-video video /home/YOURID/osx
CTRLo ### to save
CTRLx ### to exit


### if you want to change browser timeout to longer add the following lines to
Code: Select all
sudo nano /usr/lib/unifi-video/etc/system.properties

###
Code: Select all
debug=true
app.session.timeout=800000  #  ~ 1 day
CTRLo ### to save
CTRLx ### to exit
###

### then time to do
Code: Select all
sudo reboot

###########
4. setup UNIFI NVR parameters
### in the unifi NVR app / web browser ( https://ip#:7080)
### create account;
### login
### register in cloud
### the settings / system configurations/ change recording path to
Code: Select all
/home/YOURID/osx

### and save
### setup the cameras and enable recording



Then in the unfi plugin in config enter the proper filename, paths and virtualbox names and the plugin will read the cameras, track events and post event images in desired directories
Screen Shot 2018-05-03 at 19.10.44.png
Screen Shot 2018-05-03 at 19.10.44.png (85.99 KiB) Viewed 717 times


You should then see in the unfi plugin (after config )
Screen Shot 2018-05-03 at 19.05.30.png
Screen Shot 2018-05-03 at 19.05.30.png (125.3 KiB) Viewed 717 times

The devices will be created automatically. Two for each camera. One is the regular Unifi_xxx device (ip machine info) and the second is CameName_event) will hold the event info
- event #
- last event start / stop
- path to event jpeg file ( long complex name that changes for each event)
- date time of start.stop
also the event jpeg file will be copied to /the path you selected in config/CameraName_event.jpg:
Screen Shot 2018-05-04 at 11.41.58.png
Screen Shot 2018-05-04 at 11.41.58.png (58.41 KiB) Viewed 669 times



To use in a trigger on device/state = status changed; value = off. Then you can display /mail .. the corresponding image: /the path you selected in config/CameraName_event.jpg
You could also use the direct path to the video folder but that one is ugly and long and changes for event
( eg /Volumes/xx/Users/userid/video/4ecd1f83-573e-3c1c-99ac-e41cc081e60b/2018/05/04/meta/5aec69dc37cc103f92c63e09_full.jpg)



=========================
In comparison to security spy:

1. software is free
2. only works with unifi cameras
3. functionality is equivalent
4. full trigger support in indigo
5. cpu usage a little higher on the indigo server (~ sec spy:40% vs virtual box + unifi-NVR 50% of one cpu)
6. you could run the NVR software on a raspberry pi and mount the image/ video drive to your mac or reverse -- not tested -- might do this in the near future.
The CPU usage should be fine. Writing to disk might be the challenge (direct usb 2 HD(300Mbit) or over ethernet @ 100Mbit/sec to MAC)


====================
utilities

## a way to automate, not using the box interactive menu: start vbox ubuntu from terminal:
Code: Select all
/Applications/VirtualBox.app/Contents/MacOS/VBoxManage start  unifiubuntu  --type headless &

### in manual terminal mode you don't need the path , just VBoxmanage, BUT if you exec from eg indigo you need to add the full path.

### stop box smoothly:
Code: Select all
/Applications/VirtualBox.app/Contents/MacOS/VBoxManage controlvm  unifiubuntu acpipowerbutton   &

###########

###fix bad database
1. Stop the UniFi Video service:
Code: Select all
sudo service unifi-video stop
2. Delete the contents of the journal folder:
Code: Select all
sudo rm -rf /usr/lib/unifi-video/data/db/journal/*
3. Switch to the unifi-video user:
Code: Select all
sudo su unifi-video
4. Run:
Code: Select all
mongod --dbpath /usr/lib/unifi-video/data/db --repair
5. Exit to return to root:
Code: Select all
exit
6. Start the UniFi Video service:
Code: Select all
service unifi-video start



###start from scratch but with existing config ie camera names recording settings etc
Code: Select all
sudo service unifi-video stop
sudo nano /var/lib/unifi-video/data
set
Code: Select all
is_default=true
CTRLo ### to save
CTRLx ### to exit

start NVR
Code: Select all
sudo service unifi-video stop
start web session to NVR then one first page in browser select backup to restore from /usr/lib/unifi-video/data/backup

Karl

Posted on
Wed Jun 13, 2018 10:44 am
kw123 offline
User avatar
Posts: 5617
Joined: May 12, 2013
Location: Dallas, TX

Re: SETUP unifi cameras .. how to

just got the new 3G-Flex unifi camera >>$70<<

It is cute (w approved) and works well.

Has only 2 IR diodes, similar to the Wifi version.

I like it better than the Dome version. It is supposed to work inside and outside: have not tried it in rain ,
tried in sunlight and dark room, Both seem to be ok. And for $70 this is a real alternative.

Karl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest