Unfortunately the Ubiquiti AirCam Mini doesn’t, out of the box, allow you to FTP images from the camera to a remote server.
We can however fix that though in this instance we’re looking at sending single frames, not streamed video. The AirCam has something in common with many Ubiquiti products, it runs Linux. This means we can compile applications and use ssh and scp. For those that find compilation a bit daunting, at the bottom of this post, there’s a link to a tarball containing all the files you need to get this working. Just read the post so you know what’s going on.
One of the first things you may have noticed is that there’s no FTP client on the AirCam Mini. Somewhat annoying but we can change that fairly simply. You need to make sure you have a development environment setup on your Linux PC. Notice we’re adding the arm version of gcc too. If you’re using Ubuntu you can use the following command, you may be prompted for your root password.
sudo apt-get install build-essential gcc-arm-linux-gnueabi
Once those tools are installed we need to get a copy of the ncftp source code. Look at the section titled ‘Download NcFTP Client‘ and select the one marked NcFTP Client x.x.x source code (.tar.gz package), where x.x.x is 3.2.5 at the time of writing.
Once downloaded extract the tarball, change directory to the source and run the configure script with extra parameters
tar -zxvf ncftp-3.2.5-src.tar.gz cd ncftp-3.2.5 ./configure --disable-curses --without-ncurse
This with check for various dependencies for the build process. You’ll need to satisfy any specific issues that crop up. Now ncftp isn’t really setup for cross compiling so we need to make a slight change to the Makefile that the configure script created. Edit the Makefile and you should see something like this
# Generated automatically from Makefile.in by configure. #----------------------------------------------------------------------------- # # NcFTP makefile for the platform linux-x86-glibc2.12, on the host llamallamaduck. # #----------------------------------------------------------------------------- VER=3.2.5 CC=gcc CFLAGS=-D_REENTRANT -D_LARGEFILE64_SOURCE -O2 -W -Wall -Wno-format-y2k -DLINUX=26035 -DLINUX_GLIBC=32001 #CC=gcc #CFLAGS=-O2 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wbad-function-cast -Wwrite-strings -Wconversion STRIPFLAG=-s STRIP=strip
The file will contain more, this is just a snippet of the top, the part we’re interested in. Just under the line
VER=3.2.5
add
CROSS=arm-linux-gnueabi-
Note that we’ve deliberately truncated the file name to exclude the ‘gcc’ part for the arm compiler executable. Now change the lines that starts CC= and STRIP= so that they read
CC=${CROSS}gcc
and
STRIP=${CROSS}strip
Save the file, it should look something like this
# Generated automatically from Makefile.in by configure. #----------------------------------------------------------------------------- # # NcFTP makefile for the platform linux-x86-glibc2.12, on the host llamallamaduck. # #----------------------------------------------------------------------------- VER=3.2.5 CROSS=arm-linux-gnueabi- CC=${CROSS}gcc CFLAGS=-D_REENTRANT -D_LARGEFILE64_SOURCE -O2 -W -Wall -Wno-format-y2k -DLINUX=26035 -DLINUX_GLIBC=32001 #CC=gcc #CFLAGS=-O2 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wbad-function-cast -Wwrite-strings -Wconversion STRIPFLAG=-s STRIP=${CROSS}strip
We can now start the build process. Type
make
and hit return, the build process should start and you should see lots of files compiling
Compiling progress.c: [OK] Compiling bookmark.c: [OK] Compiling pref.c: [OK] Compiling preffw.c: [OK] Compiling trace.c: [OK] Compiling spool.c: [OK] Compiling spoolutil.c: [OK] Compiling log.c: [OK] Compiling gl_getline.c: [OK] Linking ncftp: [OK]
You may find that the compilation ends with something like
Compiling ncftpbatch: [OK] Compiling ncftpls: [OK] Done making NcFTP shell utilities. make[1]: Leaving directory `/home/andyp/ncftp-3.2.5/sh_util' make[1]: Entering directory `/home/andyp/ncftp-3.2.5/vis' Compiling wgets.c: [ERROR] arm-linux-gnueabi-gcc -D_REENTRANT -D_LARGEFILE64_SOURCE -O2 -W -Wall -Wno-fo rmat-y2k -DLINUX=26035 -DLINUX_GLIBC=32001 -Dvis -DO_S="linux-x86-glibc2.12" -DNCFTPPATH="/usr/local/bin/ncftp" -DSYSCONFDIR="/usr/local/etc" -DHAVE_CONFI G_H -DLINUX=26035 -DLINUX_GLIBC=32001 -I/home/andyp/ncftp-3.2.5 -I../libncftp -I../Strn -I../sio -I/home/andyp/ncftp-3.2.5 -I/home/andyp/ncftp-3.2.5/libncftp -I/home/andyp/ncftp-3.2.5/sio -I/home/andyp/ncftp-3.2.5/Strn wgets.c -c In file included from wgets.c:9: syshdrs.h:143: fatal error: ncurses.h: No such file or directory compilation terminated. make[1]: *** [wgets.o] Error 1 make[1]: Leaving directory `/home/andyp/ncftp-3.2.5/vis' make: *** [progs] Error 2
Don’t worry about this, although it’s an oddity since we’ve disabled ncurses in the configure. You would probably solve this by installing ncurses-devel or a similar package. In reality it doesn’t matter to us because, if you look a few lines further up your screen you should see
Compiling ncftpget: [OK] Compiling ncftpput: [OK] Compiling ncftpbatch: [OK] Compiling ncftpls: [OK]
Since ncftpput is what we’re interested and we have a compiled executable, we can copy this to the AirCam. The AirCam default username and password are ubnt obviously you’ll want to change that password at some point. Copy the ncftpput binary to your AirCam
scp bin/ncftpput ubnt@:[ip-address]
Replace [ip-address] with the ip address of your AirCam, also note that the colon (:) at the end of the line is required. Type the password for your AirCam when prompted.
ssh into your AirCam
ssh ubnt@[ip-address]
again replacingwith the ip address of your AirCam. This time, there’s no colon (:) at the end of the line. Again, enter your password when prompted.
The ‘more’ program is used by ncftpput to display its help screen, if you don’t need the help then you can skip this part. The AirCam Mini doesn’t have the more program so we need to supply one which this simple script will do. Save the file as ‘more’ and you’re nearly done.
#!/usr/bin/sh while read x ; do echo $x ; done
We need to make this script executable, so
chmod +x more
Next we need a script to actually do the FTP for us, create a new file and put the following in it
#!/usr/bin/sh PATH=$PATH:/etc/persistent ncftpput -u [user] -p [password] /tmp/snap.jpeg
Replace the
[user] [password]
keywords with the values appropriate for the target server you are trying to FTP to and save the file as send_file. The file needs to be made executable so
chmod +x send_file
You can test to see if this will FTP an image for you to your server by using
./send_file
You should find a file called snap.jpeg on your server if everything went well.
It’s all very well having this working by copying files to your AirCam Mini but it would be so much better if we didn’t have to copy everything to it after each reboot. So, lets make the AirCam Mini boot with our configuration and settings and automatically start the FTPing of images.
First of all we need to create a file called rc.poststart this will be run by the AirCam boot scripts after all the system startup processes have completed. The script will create a directory /etc/crontabs, copy a cron definition file to it and then start the cron daemon.
#!/usr/bin/sh mkdir /etc/crontabs cp /etc/persistent/ubnt /etc/crontabs/ crond
The file needs to be executable so
chmod +x rc.poststart
We also need a crontab file so the crond process knows to run our send_file script, edit a file called ubnt and add
*/1 * * * * /etc/persistent/send_file >/dev/null 2>&1
and save it. If you now do an ‘ls’ on your AirCam you should see
AirCam.v1.1.5# ls dropbear_dss_host_key dropbear_rsa_host_key more ncftpput rc.poststart send_file ubnt AirCam.v1.1.5#
Right now, everything you’ve done will be lost if your AirCam reboots. We need to stop that. Create another file and put the following in it
#!/usr/bin/sh cfgmtd -w -p /etc/
save the file and call it ‘save‘. Again we need to make this script executable, so
chmod +x save
When you run this script a backup, that is restored at boot, will be created and saved to flash. Now each time you boot the AirCam, your files will be restored, rc.poststart will run and you should start seeing images been sent via FTP to your server at 1 minute intervals.
To run the script use
./save
You should see some output resembling
AirCam.v1.1.5# ./save Found Active on[1] ... Found Backup1 on[2] ... Storing Active[2] ... [%100] Active->Backup[1] ... [%100] AirCam.v1.1.5#
I’ve added a tarball (aircam_ftp.tar.gz) with the files required for those that don’t want to go through the compile process. You can extract the contents, edit send_file changing the details for your server and scp the files to your AirCam.
It’s worth noting your AirCam will still function as normal, you can still connect to its web interface and make configuration changes. It’s more than likely that you will need to redo the above process if you flash a new version of the firmware on your camera.
If you have any questions or comments please leave them below.
Update : WARNING If you upgrade your AirCam to firmware 1.2 you will no longer be able to do this.
Hi, thanks for your effort in this project,
i would buy some aircam device but i need the upload feature..
there is a way to downgrade the firmware version, in case is 1.2 or more ?
alternatively did you find a solution for modern firmwares?
thanks
I haven’t tried downgrading but versions 1.1.3 and 1.1.5 are available from the Ubiquiti site. That might be worth a try.
I have tried it out and it works but if i call the save scipt the following message appears :
AirCam.v1.1.5# ./save
Found Active on[1] …
Found Backup1 on[2] …
Buffer too small.
Compression failed
any solution ?
thanks
now it works – i did a reboot and send all files again to the aircam without running any script before. Then running ./save again without any error und did a reboot. All Files are still on the aircam and all works very well.
Thanks to AndyP – Great work
Since I am using Centos, could you please send me a cross compiled version of ncftpput?
Many thanks in advance,
Prohu
Sorry I have found it! thanks!!
./send_file: line 5: ncftpput: not found
this is the error message i got after having copied all the files into the aircam..
Have you tried using the tarball from the link in the article?
Yes, exactly.
Same problem here, do you have some solution or ideas???
Finally I succeeded!
Nevertheless now I face the following problem, I suggested to the cam owner to reset the cam by pushing the rear button as since a while he has changed the router and the cam was not sending the images to the server anymore. I fear the reset erased the “patch”.
Any hint?
from a shell:
sudo nano /bin/aircamtowunderground.sh
Add the script. Change the username and variables.
#!/usr/bin/expect -f
# purpose: sending image to wunderground
# add to “crontab -e” : */5 * * * * /bin/aircamtowunderground.sh >/dev/null 2>&1
# connect via scp
spawn scp “ubnt@AIRCAMMINIIP:/tmp/snap.jpeg” /tmp/snap.jpeg
#######################
expect {
-re “.*es.*o.*” {
exp_send “yes\r”
exp_continue
}
-re “.*sword.*” {
exp_send “PASSWORD\r”
}
}
# ftp image from camera to wunderground
spawn ncftpput -u USER -p PASSWORD webcam.wunderground.com / /tmp/snap.jpeg
expect eof
exit
Can I reset the cam pushing the rear button and keeping the “patch” anyhow?
Even easier – use Security Monitor Pro to capture from the camera and FTP. All built in along with motion detection, e-mail alerts and much more.
http://www.deskshare.com/video-surveillance-software.aspx
True, except it requires an additional computer. Our solution means the camera can be installed, on it’s own, with no other hardware and provide a regular FTP upload to a webcam website. Which is what the client needed in this case.