Video Doorbell with Raspberry Pi

I’ve been wanting to play with some video streaming for a while now, so last weekend I decided to order the Raspberry Pi Camera Board and see what it was capable of. This little camera – it’s tiny! – packs a punch! The still images are great, and the video is super clear. After messing around with it for a few hours, I figured I should do something constructive with it so set about thinking what would be useful/fun/something I always wanted to do.

Video Doorbell.

Yep. I’ve always fancied the idea of having a doorbell ping my mobile phone and let me see and speak to the person who rang it, there are probably already commercial products that do that (I haven’t looked) but quite frankly it wouldn’t be half as fun as building my own.

The general idea I currently have is:

  • Button is connected to GPIO, when pressed sends a message to a remote server to contact the device(s) registered
  • At the same time the camera is fired up and starts to send data to the remote server
  • If the mobile device accepts the ‘call’ then it connects to the video stream
  • If the mobile user hangs up (and there are no other mobile users viewing) then a message is sent to the remote server, and then onto the Pi to terminate the stream
  • If the hang up button is pressed on the Pi, then a message is sent to the remote server to contact the mobile device(s) to terminate the connection to the stream, and put the app back in the background

Something like that. I’m still not entirely sure what language(s) will be used, I had wanted to use Go so I could have a play with that, but I’m also thinking it would be quite cool if the entire stack – pi, server, mobile – was all written in JavaScript (node and Titanium) but I’m not sure yet, leaning more towards Go and native mobile apps, but we shall see Smile

I’ll be updating this post as things progress, stay tuned!

SnowCam: A WebRTC experiment with getUserMedia

I’d heard about WebRTC and navigator.getUserMedia as a way to access webcams and microphones, so after I somehow ended up here the other day, I figured it should be possible to do the same in JS and HTML5.

The basic idea was to take a webcam feed, apply a falling snow effect to it, and let the snow settle on any horizontal edges in the video. Just show me already!

Connecting it all up

Getting the webcam connected up to a <;video>; tag was pretty easy, just make sure to use the right vendor prefix and take note of the slight differences between the supported browsers (Firefox Nightly, Chrome, Opera). There is a shim available called The gUM Shield, but I found that after I’d put something together.

Next step was to apply some snow, so I placed a <;canvas>; tag over the top of the <;video>; tag, found simple example of particle generation, and had some snow.

Getting the snow to settle was a bit trickier. A bit of searching revealed that I would want to use a sobel convolution filter (Nice tut here) to find the edges in the current frame, and rather than combine the results from the 2 computations (horizontal and vertical) and place onto a canvas, just take the horizontal edges and put into a hash that I can check when placing the snow flake.

My first attempt at this ran pretty damn slow, the snow effect was stuttering the whole way through. That kind of made sense since I was trying to update ~300 flakes constantly on 1 canvas, and applying a fairly heavy computation to each frame of the webcam on another. This seemed to me to be the ideal time for a WebWorker. I moved the edge detection into the worker, and then just post the resulting hash back which gets injected into the snow object, this way as the snow is falling I can just check if there is a ledge to settle on by checking this.ledges[x][y] and if it exists we can ‘stick’ to the current x,y position, otherwise assume that it is falling – this lets us wipe away the snow from ledges as well.

This works pretty well, but I’m sure it can be optimised a fair bit more – there are some extra elements I probably don’t need to use, and some processing that could be removed – but for the moment I think it’s quite cool being able to see the various stages. I’ve tested this on Firefox Nightly, and the latest version of Chrome. It does run on Opera, but very slowly – I should probably look into that…

There are a couple of enhancements I want to add at some point:

  • Snow piling up when it lands on an existing flake
  • Connect to the microphone to allow the snow to be blown away

Give it a whirl

See it in action: http://ben.periton.co.uk/exp-SnowCam
Get the code: https://github.com/benperiton/SnowCam

If you are using Firefox nightly, you will need to enable the feature:

  • Type “about:config” in the address bar and say yes that you want to make changes
  • Find the “media.navigator.enabled” entry and set it to true

y

Configuring the Zotac ZBOX remote control

After purchasing the Zotac ZBOX nano AD10, I noticed that not all of the buttons on the remote worked in XBMCbuntu, and playing with various lirc options didn’t seem to yield any results.

Using the remote without any changes the following buttons would not work:

  • sleep
  • wake
  • teletext
  • programme
  • Windows button
  • red
  • blue
  • green
  • yellow

After a bit of playing with lirc, I could get some more buttons to be recognised by choosing Linux input layer (/dev/input/eventX) as the lirc device, but still the following buttons would not work:

  • teletext
  • Windows button
  • red
  • blue
  • green
  • yellow

I gave in and posted a message on the XBMC forums (XBMCbuntu some buttons not working PHILIPS MCE USB IR Receiver-Spinel plus) and an awesome user – FernetMenta – helped me out with a custom version of lirc that supports the Zotac remote.

I’ve reproduced the steps below, so that when I no doubt come to reinstalling at some point in the future, I don’t have to look too far!

[Update]
It seems some people are having issues when following these instructions, they worked just fine for me but then there are always little differences. Theres quite a bit of help in the comments at the bottom, of if you don’t fancy reading through them, I would suggest taking a look over at Guilmxm’s blog where he has put together instructions based on those below, as well as his updates from the comments.

1. Remove lirc

> sudo apt-get remove lirc

2. Install some extra packages

> sudo apt-get install automake dialog libtool

3. Download the version from FernetMenta (In case it ever moves, I’ve forked it over at my account)

> wget https://github.com/FernetMenta/lirc/tarball/master -O lirc.tar.gz
> tar -xf lirc.tar.gz

4a. Configure and install the new lirc, when running setup.sh, select driver zotac under usb, save & configure

> ./autogen.sh
> ./setup.sh
> make
> sudo make install

4b. If missing, create links in /usr/sbin

> cd /usr/sbin
> sudo ln -s ../local/sbin/lircd lircd
> sudo ln -s ../local/sbin/lircmd lircmd

5. Stop X11 from registering device as keyboard by putting the following at the bottom of /usr/share/X11/xorg.conf.d/10-evdev.conf

Section "InputClass"
  Identifier "PHILIPS MCE USB IR Receiver- Spinel plus"
  MatchProduct "PHILIPS MCE USB IR Receiver- Spinel plus"
  MatchIsKeyboard "true"
  Option "Ignore" "true"
EndSection

6. Add a alias in udev to /dev/remote by creating a new file at /etc/udev/rules.d/10-local.rules with the following:

SUBSYSTEM=="usb" , ATTRS{idVendor}=="0471", ATTRS{idProduct}=="20cc", SYMLINK+="remote", ACTION=="add", RUN+="/sbin/initctl --quiet emit --no-wait ir-ready"

6. Create config files – see below
7. Reboot and hopefully it should all work

/etc/lirc/hardware.conf

# hardware.conf for Zotac
#
REMOTE="Zotac MCE Remote"
REMOTE_MODULES=""
REMOTE_DRIVER="zotac"
REMOTE_DEVICE="/dev/remote"
REMOTE_SOCKET=""
REMOTE_LIRCD_CONF="zotac/lircd.conf.zotac"
REMOTE_LIRCD_ARGS=""
TRANSMITTER="None"
TRANSMITTER_MODULES=""
TRANSMITTER_DRIVER=""
TRANSMITTER_DEVICE=""
TRANSMITTER_SOCKET=""
TRANSMITTER_LIRCD_CONF=""
TRANSMITTER_LIRCD_ARGS=""
START_LIRCD="true"
LOAD_MODULES="true"
LIRCMD_CONF=""
FORCE_NONINTERACTIVE_RECONFIGURATION="false"
START_LIRCMD=""

 

/etc/lirc/lircd.conf

# Please make this file available to others
# by sending it to
#
# this config file was automatically generated
# using lirc-0.9.1-git(zotac) on Mon Apr  2 14:10:29 2012
#
# contributed by
#
# brand:                       zotac.conf
# model no. of remote control:
# devices being controlled by this remote:
#

begin remote

  name  zotac.conf
  bits           32
  eps            30
  aeps          100

  one             0     0
  zero            0     0
  gap          100123
  min_repeat      9
#  suppress_repeat 9
#  uncomment to suppress unwanted repeats
#  toggle_bit_mask 0x7004F

      begin codes
          KEY_SLEEP                0x00010082
          KEY_WAKEUP               0x00010083
          KEY_RECORD               0x000C00B2
          KEY_PAUSE                0x000C00B1
          KEY_STOP                 0x000C00B7
          KEY_REWIND               0x000C00B4
          KEY_PLAY                 0x000C00B0
          KEY_FORWARD              0x000C00B3
          KEY_LEFTSHIFT            0x000C00B6
          KEY_RIGHTSHIFT           0x000C00B5
          KEY_BACK                 0x000C0224
          KEY_INFO                 0x000C0209
          KEY_MENU                 0xFFBC000D
          KEY_UP                   0x00070052
          KEY_LEFT                 0x00070050
          KEY_RIGHT                0x0007004F
          KEY_DOWN                 0x00070051
          KEY_OK                   0x00070028
          KEY_VOLUMEUP             0x000C00E9
          KEY_VOLUMEDOWN           0x000C00EA
          KEY_MUTE                 0x000C00E2
          KEY_CHANNELUP            0x000C009C
          KEY_CHANNELDOWN          0x000C009D
          KEY_1                    0x0007001E
          KEY_2                    0x0007001F
          KEY_3                    0x00070020
          KEY_4                    0x00070021
          KEY_5                    0x00070022
          KEY_6                    0x00070023
          KEY_7                    0x00070024
          KEY_8                    0x00070025
          KEY_9                    0x00070026
          KEY_0                    0x00070027
          KEY_NUMERIC_STAR         0x10070025
          KEY_NUMERIC_POUND        0x10070020
          KEY_CLEAR                0x00070029
          KEY_TEXT                 0xFFBC005A
          KEY_TITLE                0x000C008D
          KEY_ENTER                0x00070028
          KEY_RED                  0xFFBC005B
          KEY_GREEN                0xFFBC005C
          KEY_YELLOW               0xFFBC005D
          KEY_BLUE                 0xFFBC005E
      end codes

end remote

 

~/.xbmc/userdata/Lircmap.xml

<lircmap>
    <remote device="zotac.conf">
        <power>KEY_SLEEP</power>
        <wake>KEY_WAKEUP</wake>
        <record>KEY_RECORD</record>
        <pause>KEY_PAUSE</pause>
        <stop>KEY_STOP</stop>
        <reverse>KEY_REWIND</reverse>
        <play>KEY_PLAY</play>
        <forward>KEY_FORWARD</forward>
        <skipminus>KEY_LEFTSHIFT</skipminus>
        <skipplus>KEY_RIGHTSHIFT</skipplus>
        <back>KEY_BACK</back>
        <info>KEY_INFO</info>
        <display>KEY_MENU</display>
        <up>KEY_UP</up>
        <left>KEY_LEFT</left>
        <right>KEY_RIGHT</right>
        <down>KEY_DOWN</down>
        <select>KEY_OK</select>
        <volumeplus>KEY_VOLUMEUP</volumeplus>
        <volumeminus>KEY_VOLUMEDOWN</volumeminus>
        <mute>KEY_MUTE</mute>
        <up>KEY_CHANNELUP</up>
        <down>KEY_CHANNELDOWN</down>
        <zero>KEY_0</zero>
        <one>KEY_1</one>
        <two>KEY_2</two>
        <three>KEY_3</three>
        <four>KEY_4</four>
        <five>KEY_5</five>
        <six>KEY_6</six>
        <seven>KEY_7</seven>
        <eight>KEY_8</eight>
        <nine>KEY_9</nine>
        <red>KEY_RED</red>
            <green>KEY_GREEN</green>
            <yellow>KEY_YELLOW</yellow>
            <blue>KEY_BLUE</blue>
        <star>KEY_NUMERIC_STAR</star>
        <hash>KEY_NUMERIC_POUND</hash>
        <subtitle>KEY_TEXT</subtitle>
        <title>KEY_TITLE</title>
        <clear>KEY_CLEAR</clear>
    </remote>
</lircmap>

Zotac ZBOX nano AD10 + XBMCbuntu + tweaks = awesome media center

I finally had enough of running XBMC on the Apple TV, it wasn’t the fastest box on the planet and the remote is not the easiest of things to use to navigate around. The last update was the proverbial straw. In order to watch Netflix in the UK I needed to update my ATV2 to a IOS 5.x version which was all cool, except that at the time there was only a tethered jailbreak. This was not such a problem until the other day when the ATV2 decided to have a fit and freeze, which needed a restart, which needed a tethered boot, which I couldn’t get going for love nor money. Signs seem to indicate a dodgy USB cable, so at some point I’ll try and sort it out, but the most obvious solution seemed to be to move to an actual computer, rather than a walled garden with a hole punched in it.

I have a Raspberry Pi arriving in the next week or so, and I briefly considered using that to run XBMC, but that seems like a waste when there are far more interesting ideas floating around in my head for it!

After some searching around for a bit I stumbled upon the Zotac ZBOX nano AD10 which seemed to offer exactly what I wanted;

  • 1080 HD
  • HD Audio
  • Gigabit LAN
  • Small form factor

The price wasn’t too bad, £189.99 – and although it doesn’t come with a HDD or RAM., it does come with a MCE remote control, USB IR extender and a VESA mount kit (with screws!) for attaching to the back of the TV.

I chucked in an old 2.5″ 160GB HDD, and 1GB or RAM and so far it seems to be screaming along! Looking at the memory usage whilst playing a 720p movie (I don’t have any 1080 to try just yet – ATV2 wouldn’t play them) it seemed to max out at ~ 720mb mark, so 1GB will probably be plenty to power it. (The box itself supports up to 4GB, so I think a new 2GB chip would be more than enough to keep it going)

For the OS I went with XBMCbuntu, it just makes sense when all the box will be used for is XBMC, why bother installing all the other crap that is not needed? The ZBOX can be booted from either an external DVD or bootable USB drive, just jump into the BIOS (hit del on boot – incidentally one of the most colourful BIOS I’ve seen!) and set up the boot order – I had to plug/unplug the USB whilst in here to get it to recognise.

So far everything has worked out of the box, apart from a couple of little bits that Im still investigating:

HD Audio [solved]
I had to change the pass-though device to be HDMI (ALSA) instead of whatever it was set to. I’m not sure if this is giving me proper HD sound, but the surround sound seems to work fine. Maybe I’ll look into this a bit more if I ever get a surround sound system that supports 8-channel LPCM output Razz

Not all remote buttons work [solved]
Some of the buttons on the remote don’t work, namely the Sleep, Wake, Teletext, Program, Windows Button, Red, Blue, Green or Yellow buttons. This can be fixed by using lirc to control the remote, rather than the kernel – as it does OOTB. You can get a few more buttons working (Sleep,Wake,Program) by running

> sudo dpkg-reconfigure lirc

and choosing Linux input layer (/dev/input/eventX) for receiver and none for transceiver. To get all the buttons working however, you can follow the instructions in my other post on Configuring the Zotac ZBOX Remote Control

Freezes on resume
Ongoing

Power on device using remote
Ongoing

My first time with WordPress

Having decided that I was going to setup a website this weekend, the time came to put something together. Normally I would start from scratch, playing around in Photoshop then knocking up some prototypes, then onto the full layout etc. This time round I couldn’t face doing any more coding – pretty hectic at work – so I figured I’d give WordPress a go. I’d never really considered it before, no real reason not to it just never entered my mind.

A quick install later, and it was up and running. Very nice bit of kit it is too!

I spent a few hours searching around for a theme to use, eventually settling on one from Pixel Perfect. A couple more hours of configuring, installing plugins, modifying plugins and templates and testing, and I had a pretty decent first pass at a new site – in a lot less time than it would have taken me normally.

The process was simple, painless, and even enjoyable! Defiantly going to be using it again.