Tuesday, May 07, 2013

Vilar IP Cam - Network settings

I have 4 Vilar IP Cams. Recently I needed to move two of them to a new network. The setup program that came with the cam did not find the cameras so I had to do the setup via the web interface. It turned out however that the network settings page (Basic -> Network) did not save/apply the changes I made in to the page controls.

Since I'm Firefox user and I also do some pretty basic web development I enabled Firebug and checked what the malfunctioning Apply button actually does. 

It turned out that it was not simply a submit form button, but instead called settcpip JavaScript function. The same function was called on every click event as well. The function itself performed some IP address validation and if everyting was ok invoked:
document.form1.submit()
I debugged this settcpip function by:
  • Enabling Script debugging
  • Reloading the page (in Firebug UI)
  • In the first JavaScript shown by Firebug I searched for settcpip
  • Set breakpoint at the line
element = document.getElementById('StaticIP');
To my surpise the element turned out to be ... null. I checked the HTML source and yes - there was no such id.

I had two options:
  • Adapt the HTML to what JavaScript expected (i.e. change the options of the select tag to "StaticIP")
  • Short-circuit the function used to check for correct IP address

Since I already spent too much time fixing a bug present in ~20 obviously never tested versions of the firmware I decided to check if the form submit will work at all.

What I did was to go the Apply button source and replace settcpip with document.form1.submit()like in this screen shot:



After that hitting Apply worked like a charm and I was able to change my cam's IP address.

If you want to use the same trick, please bear in mind that a single mistake in the form may trigger your cam unreachable. Then you'll most probably need to reset it to factory defaults by pressing the reset switch for at least 20 seconds.

Thursday, May 31, 2012

Power supply for my Vilar IP camera

My Vilar IP camera served me well for almost an year until I had to replace its power supply. The symptoms were strange - the camera crashed, the PTZ was not working, but yet it transmitted ok.

The new power supply didn't last that long and even the video transmission failed.

Therefore I digged out an old 230W computer power supply (PS) and started thinking on wiring it to the 5V input of my camera.

Cutting the original power cable to get a connector that will fit was easy. Next I had to find out that the (+) was the red wire, while the (-) was the black one.

In order to check the needed wires of the computer PS it had to be working. Plugging it in did not made the trick, so I remembered that ATX PS had a low-power switch. Googling this I came across a page that made the obvious proposal to short-cicuit pin 14 and 15 (PS on and GND).

Luckily I wear a switcher with self-made zip handle made of clip. I took out the clip, cut it in half and bend it to produce an always-on power supply :)

I measured the different currents and found out that the black out is again GND. I've been burned by even more obvious things so I like to double check things. The red one turned ot to be +12V, while the yellow wire was the needed +5.12V

I soldered the cable from my camera to the wires of the ATX PS (red-red and balck-black), checked that the (+) is +5V and (-) is GND and decided to gave the IP camera a go with the new supply.

Suddenly the camera movement was faster (it sloooowly turned left/right with the old supply) and it responded to all requests as if it was just bought :)

Now I intend to power my Arduino Nano circut with the same ATS PS.

Thursday, April 05, 2012

Eclipse Right Through (RT) the Clouds

I prepared a Virtual Box image (accessible also here) that contains a tutorial on how to:
  • extend Cloud Foundry with a new framework
    • replace Tomcat with Virgo
    • add auto-detect code in VMC
    • add download/packaging code
  • use Cloud Foundry services
    • parse JSON from environment variables
    • connect to MySQL via JDBC
    • share Cloud Foundry services between applications
  • use Eclipse Link JPA
    • programatically initialize Data Source

You will need:
  • 10GB of disk space
  • 4GB memory
  • Virtual Box
  • 7-Zip

Saturday, November 26, 2011

Running Virgo on Cloud Foundry

In this post I provided a VM with Virgo and Cloud Foundry. Now I'll explains how to set up such VM on your own and to use updated (2011-11-27) Cloud Foundry version forked in GitHub.

Installation steps:

1. Download VirtualBox and install it.
2. Download VirtualBox's Extension Pack and install this as well. 

You may double click on the Extension Pack for Windows. Also note that the extensions are not needed if you want to setup Ubuntu on your own.

3. Download Ubuntu image and write down the user/password. 

I've tested with Ubuntu 11.04. Ubuntu Server is the best choice for productive systems, and in case you like developing with VI. 

Note that the recommended version is Ubuntu Server 10.04-2 LTS.

4. Start the image 

Some of the archives contain only HDD image, so you may need to configure the VM and attach the downloaded HDD image.

Other images come preconfigured. For those you may need to change the network adapter settings in VirtualBox.  Simply clicking on Network section and saving the auto-detected changes did the trick for me.

In general ensure the VM has at least 2GB memory. If you want to try every Cloud Foundry service and framework (or simply run the tests) you will need at least 3GB of memory.

The image may have keyboard layout you are not used to (Italy as was in my case), so it's a good idea to change this. For the Server (no GUI) you can do this with:
   sudo dpkg-reconfigure console-setup

Installing Guest Additions is definitely a good idea since it allows you to copy/paste install commands in the next steps, and what's more important allows hardware and host OS acceleration.

5. Install libtool using:
    sudo apt-get install libtool

6. Install CloudFoundry on the image as explained in this GitHub vcap repository fork

You may need to reboot the VM to allow RVM (Ruby Version Manager) to pick up the configuration in vcap folder and switch Ruby versions. Sourcing the configurations did not work for me.

7. Update Cloud Foundry with the Virgo modifications

The Cloud Controller uses vcap_staging gem that does not support Virgo, so we have to update the gem with the Virgo specific code. To do this execute: 
   cd ~/cloudfoundry/vcap
   cp -r staging/lib/* ~/.rvm/gems/ruby-1.9.2-p180/gems/vcap_staging-0.1.25/lib/

Finally restart the Cloud Foundry:
   bin/vcap restart 

To be able to use the automatic discovery of Virgo applications in VMC we need to update the client:
   cd ~/cloudfoundry/
   git clone https://github.com/hsiliev/vmc.git
   cp vmc/lib/cli/frameworks.rb ~/.rvm/gems/ruby-1.9.2-p180/gems/vmc-0.3.13/lib/cli



How to install Virgo's Admin Console

1. Download and extract the archived console
2. In the directory where you extracted the archive, run:
   vmc push virgo
3. Request virgo.vcap.me and you should see the Splash Screen with link to the Admin Console in the upper right corner.






How to update to the latest Virgo version:
2. Go to vcap-java/virgo-setup
3. Edit virgo_manifest.yml to specify the exact version you want
4. Run rake virgo:prepare
5. Find the new version in 
   /tmp/virgo-<your version>/virgo.zip
6. Replace the ZIP in  
   ~/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/virgo/resources

The last two steps should be automated with the virgo:install task, but I haven't tested if this works.

    Tuesday, November 15, 2011

    Gentoo on Lenovo T520

    My new laptop is finally here. Lenovo T520 came with Windows 7, and if you ask me that's a bad choice for laptop with these specs. Neither the video (Intel HD), nor the 500GB HDD were made to be used by gamers where Windows is undisputed leader.

    So I made up my mind to made a switch and chose Gentoo Linux since I needed better git, ruby and java support, but besides all I wanted to be in control on what's happening with the hardware and software on my system :) From previous installations I found out that Ubuntu does not support odd or older hardware without kernel recompile. On the other hand the software packages in the most popular Linux distro are not the most stable thing (especially Gnome UI stuff).

    Since I had enough experience with Gentoo from setting up my development server and the surveillance system machine  I decided that I'll just stick with this source based distro with rolling updates. It is also used by several cloud computing companies, so it looks it's here to stay.

    I've done the basic setup almost exactly as recommended in the Gentoo Handbook. The concrete settings are detailed below.

    make.conf

    I used "native" architecture for GCC which leaves the optimization decision in the compiler. Since T520 has 4 cores the numer of compile/processing threads is set to 5. To speed up the emerge the download is made on background with "parallel-fetch" feature.

    CHOST="i686-pc-linux-gnu"
    CFLAGS="-march=native -O2 -pipe"
    CXXFLAGS="${CFLAGS}"
    MAKEOPTS="-j5"
    FEATURES="parallel-fetch -test"
    USE="mmx sse sse2 sse3 3dnow 3dnowext \
         dvd dvdr cdr vcd cdda \
         usb wifi laptop ieee1394 \
         lm_sensors \
         bash-completion symlink \
         ftp \
         bzip2 zip unzip 7zip rar \
         jpeg svg jpeg2k png gif mng \
         ffmpeg xvid x264 theora \
         truetype gd \
         mp3 faac faad amr \
         java javascript xml ruby python \
         sqlite \
         ssl sni \
         unicode \
         daemon threads \
         X xvfb dbus hal \
         gtk gnome gdu extras device-mapper policykit cairo \
         -kde -qt3 -qt4 \
         -ipv6"
    GENTOO_MIRRORS="http://mirrors.ludost.net/gentoo/ ftp://mirrors.ludost.net/gentoo/ http://distfiles.gentoo.bg/ http://ftp.gentoo.bg/ "
    SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"
    ACCEPT_LICENSE="dlj-1.1 Oracle-BCLA-JavaSE skype-eula"
    INPUT_DEVICES="evdev synaptics mouse keyboard"
    VIDEO_CARDS="intel vesa"
    LINGUAS="bg en"


    I'm a Gnome user, so the flags are set to disable QT and KDE. The IPv6 is of no use to me currently so I disabled it as well.

    I'm Java developer so I accepted Oracle's JDK 1.5 and 1.6 licences to enable installation of the software. Since Oracle changed the 1.6 licence and download pages it is no longer possible to install Java automatically. Fortunately emerge provides quite good hints when you have to download a package manually.

    Next I inserted my hardware configuration for X - keyboard, synaptic, external mouse, and Intel HD video card.

    Language configuration can also be added in make.conf to enable localization of console, X and Gnome/KDE.

    Linux Kernel Configuration

    I used the Gentoo's 3.0.6 kernel (gentoo-sources) with this configuration.

    LAN setup

    In /etc/conf.d/net you can use ifplugd to make the annoying delay on start-up go away, when there is no cable plugged (in the end this is a laptop):
    ifplugd_eth0="dhcp"
    Of course you will have to install ifplugd as described in the handbook.

    Wireless network

    The kernel configuration includes drivers for the wireless network on T520. This however is not enough to get it working.

    I found out that the network is Intel Centrino Advanced-N and followed Google to this Gentoo Forum Post. The post provides quite good guide on how to identify and emerge the right driver and firmware for your wireless chip.

    Gnome 

    As a pleasant surprise Gnome provided me with working functional keys out of the box. From changing video output through back-light to sleep buttons everything worked as expected.


    Not working 

    Currently I don't know how to get the card reader to work.

    Tuesday, November 08, 2011

    Installing ZoneMinder in Gentoo

    Installing ZoneMinder in Gentoo turned out to be a relatively easy task:

    emerge layman

    layman -o http://gpo.zugaina.org/lst/gpo-repositories.xml
    layman -a zugaina

    echo "source /var/lib/layman/make.conf" >> /etc/make.conf
    ACCEPT_KEYWORDS="~x86" emerge -av zoneminder


    If you are interested in the details you can take a look at Overlays @ Gentoo wiki

    Saturday, October 01, 2011

    Setting up Geovision 650 surveliance card in Gentoo

    I was trying to turn my old 2.2 Ghz Celeron based computer into a surveillance system. I needed a lot of computing power to be able to record from 4 cameras and to be able to integrate 2 new Vilar IP cameras as well. I chose Gentoo Linux since it does it's job as server OS quite well on my home development server.

    So after 3 hours I had a customized installation compiled with -march=native and kernel stripped down to the bare minimum.

    I tried to set up my Geovision 650 DVR card starting from the Linux module. I launched make menuconfig and was sure that I'll have everything ready in under an hour. As you can imagine this was not the case :) In the end it took me 2 days to have the card running and I decided to describe the steps.

    Gentoo installation
    I followed the handbook as usual and the installation was pretty straightforward and went smooth. The GCC configuration spared me the search for the CFLAGS of my CPU and I had to put -march=native to get everything optimized.

    USE flags
    I intended to use ZoneMinder so I added the needed flags right away (apache, mysql, php, perl). It turned out that to check the input of the card I had to use xawtv, so I enabled X as well.

    BT878 / BTTV module
    The module I needed was BTTV since Geovision 650 is equipped with two BT878 chips to allow decent capture from its 4 inputs. 

    However I was not able to find how to enable the compilation of the driver. I was more astonished than ashamed to find that the answer was the non-existent Infra-red Remote.... Turning the IR support in the kernel enabled the compilation of the module I desperately needed.

    I tried so hard to enable BT878 support so I decided to scan all options in kernel configuration screens. I removed a lot of unneeded stuff and between the flags that were unchecked was the one ensuring that my 80GB HDD was able to host single files with size more than 2TB.

    I recompiled the kernel and a few modules, replaced the old binaries, rebooted the machine...

    Missing kernel features
    ... and I found myself with read only EXT4 file system. It turned out that the LiveCD I used to create my root partition had large files suppport turned on. In fact the kernel has this by default. Using EXT4 tools seems to pick the kernel settings so before I was able to fit 2TB files on my small HDD and now the kernel was not able to process such files anymore.

    I found the solution in this blog and this was one of the reasons to describe my installation problems.

    BTTV driver configuration
    Gentoo now uses OpenRC to describe and configure modules (/etc/conf.d/modules). I put bttv driver in the list rebooted again to check if the driver will autodetect the card. Yes I know that modprobe would (or actually should) have done the same job but I had to be sure.

    What I found was card=0, autodetecting log entry shown by dmesg. So I had to find the correct card settings. Fortunatelly there are a lot of resources out there that hinted to use "card=<number>" parameter of bttv module. The question was what to put as number. Soon I found that 150 provides me with Geovision 600 which is pretty close relative to my GV-650. 

    Using my Windows experience I rebooted again and after several seconds found out that nothing changed. So time for modprobe tests with different numers only to find no change in bttv output.

    Fortunatelly the bttv sources were sitting quetly on my HDD. A dump of bttv.c showed that GV-600 has 0x96 value which was exactly 150 in decimal. I smiled happily and put the "correct" values in modules configuration: "card=150,150".

    The next Windows-style reboot revealed that bttv was not happy with this value as well. I had the same autodetect failure in the logs.

    I reported the problem in bugzilla. Meanwhile tried to search internet and found a Russian Google IRC chat that provided needed workaround. It turned out that udev kicked in too early and loaded the module before OpenRC was able to configure it correctly. OpenRC issued modprobe correctly but the module was already there. 

    So in the end - not really a bug :) Simply disabling coldplug with rc_coldplug="NO" in /etc.conf.d/udev did the trick.

    Testing video input
    I installed xawtv to test the output and after 2 hours of experiments I had no idea why the card won't work.

    Google found out several configurations working fine with GV600 or GV800 but none with GV650. Strange ... 

    I wondered what was the difference between GV600 and GV650. After some research it turned out that GV650 has one more BT878 chip than GV600, and in turn GV800 has 4 in total. 

    Consulting the bttv-cards.c file revealed that one of the chips in GV800 is "master" and the rest "slaves". This and the strange mapping between the inputs and the chips in this blog led me to the conclusion that I need to change my bttv configuration to "card=157,158" (master/slave).

    Another reboot and suddenly everything worked just fine.

    ZoneMinder
    The last time I tried to run ZoneMinder on Gentoo was 4 years ago. Too long as it turned out. 

    Today the ZoneMinder is nowhere to be found in the repositories and its configuration on your own is not easy. You have to hunt down the location of all dependencies, the libraries ffmpeg is build with and so on.
    Well I think I managed to dig all the needed info but configure just stopped with cryptic message about openssl library. Basically it says that the library is on the system but is messed up and unusable by ZoneMinder. 

    Seems like I'll have to create a new blog about this :)