ByeByeStandBye Plugs and the Raspberry Pi and why pilight is awesome

 

The story

I bought a set of BBSB (Bye Bye StandBye) plugs just to make my life easier, basically they are plugs/sockets with a remote control so you can turn them on and off without having to furtle behind the shelving to find the mains plug to turn everything off. They were quite nifty but the remote annoyed me as I either put it down somewhere and forgot or it managed to elope with a group of plectrums, hair bands and that pen you were just using not to be found for another week. I did a quick bit of research and discovered you can buy a controller that you can connect to your computer to manage them! Hurrah I thought, wait, how much? There also seems to be a whole range of compatibility issue between different brands and controller versions so I decided to not bother.

A bit later I came back to it and saw a post somewhere about controlling a similar device with a Raspberry Pi, now if there is one thing I have around the place it is Raspberry Pi machines… Next stop is a 433MHz transmitter / receiver pair. I bought one of these : http://www.amazon.co.uk/gp/product/B00E9OGFLQ less than £1.50 delivered (from China so may take a couple of weeks). It arrived and I connected it up using female to female jump wires and tried and utterly failed to get it working.

This weekend I had another push and after messing around with various bits of code and generally failing I can now control my switches using the Pi and found a lovely bit of software to help manage it and even put a snazzy web front end on it.

 

How I got it working!

If you are going to attempt this then everything is at your own risk, I don’t accept liability or responsibility for anything!

Standing on the shoulders of giants!

I messed around for ages with bits of code and information from various sites,  unhelpfully quite a few (specifically relating to the Bye Bye Standby products) referred to the forum (which I was assured had all the info) sadly this was broken and Google cache and Archive.org were not any help.

To wire it up I followed the diagram here:

http://www.homautomation.org/2013/10/09/how-to-control-di-o-devices-with-a-raspberry/

I didn’t bother hooking up an aerial to the receiver as I only used it to capture the remote settings, the transmitter just has a jump wire connected to it as an aerial.

As the software we are going to use is going to leverage the awesome WiringPi then you will need that too.

Now this is important, because we are using WiringPi all the software is going to refer to the WiringPi pin numbers NOT the physical pin numbers on the GPIO connector on the Pi.

If you have other things connected to your Pi then don’t worry,  providing you hook the 5v to a 5v pin and a ground to a ground and the data to a GPIO data pin (make note of the number as per WiringPi) then you will be fine.

To do all the hard work we are going to use the fantastic pilight.  (In an earlier version I mistakenly put capitals in it,  please note it should always be spelt lower case :-) )  pilight can do a heck of a lot and we are only just scratching the surface here,  it has a nice web interface and can hook into a lot of things but for now we are aiming for the lofty goal of turning a single socket on and off :-)

Next up install pilight from here.

Then you will need to edit the /etc/pilight/hardware.json file to make sure the data pins on your transmitter and receiver are correct,  remember this is the wiringpi pin numbers not the physical ones!

After you have done that then on the pi as root (hint sudo -s) then you run :

/usr/local/bin/pilight-receive

Then hold your BBSB remote near the receiver and press the button :

You should get something like this :

{
        "code": {
                "id": 0,
                "unit": 0,
                "state": "on"
        },
        "origin": "receiver",
        "protocol": "arctech_switches_old",
        "uuid": "0000-00-00-a3-94eb2d",
        "repeats": 1
}

Once you get data hit CTRL+C to get back to the prompt. Ok this was for button one “on” on my remote. Now the info we are really interested in is “id” and “unit” also “protocol”. For my BBSB plugs they show up as “archtech_switches_old” after this failed in the send command a quick google suggested I try kaku_switch_old as the protocol. You now shoud have all the info to turn switches on and off from the command line, the -i flag is the ID of the plug, in my setup I discovered that button one was ID 0 button two was ID 1, button three was ID 2 and button 4 was ID3. So running :

pilight-send -p kaku_switch_old  -i 1 -u 0 -t

Should turn socket 2 on ( -t = on and -f = off ) so then :

pilight-send -p kaku_switch_old  -i 1 -u 0 -f

Should turn it off again.

Next post will be pilight config,  I just want to get that bit up online while it is fresh in my mind :)

RasPi in the Sky – gstreamer first steps

See this for an explanation of the name :)

I did a bit of research around video streaming on the pi and there seem to be several methods used including using VLC or netcat or various other methods but they all seemed to be a little bit high latency and as we are going to be doing live video to a screen we want to keep that down so I went with Gstreamer.

The first page I came across seemed to be ideal :  http://pi.gbaman.info/?p=150  and this got me up and going but I ran into issues with the sending and listening commands.  http://blog.tkjelectronics.dk/2013/06/how-to-stream-video-and-audio-from-a-raspberry-pi-with-no-latency/ helped with sending but as the commands on both pages were for listening using a Mac I was out of luck.  After a quick poke around mailing lists and google fu I have now got it up and running.

 

So after setting up the environment as described in either of the above I have  been using the following commands.  I am not a gstreamer scientist and there are probably much better ways of doing it but this seems to be working here.

Sending Pi (pivate-eye) note you will have to change the IP address

raspivid -t 999999 -w 1080 -h 720 -fps 25 -hf -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=10.42.0.112 port=5000

10.42.0.112 is the address of the sending pi.

On the listening pi (pi-tv) watch out for the ip address in it

gst-launch-1.0 -v tcpclientsrc host=10.42.0.112 port=5000 ! gdpdepay ! rtph264depay ! h264parse ! omxh264dec ! videoconvert ! autovideosink sync=false

Latency:

 

I have done some quick tests as to the latency of the video link and how it changes with resolution.   These are only very quick tests so may not be that accurate.  The methodology was to put a stopwatch on screen, stream the screen via the webcam with both the onscreen clock and the video playback of the clock visible then to take a picture using a digital camera and then just subtract the differences between the clocks.

320 x  240 = 176 ms

640 x 480 = 137 ms

800 x 600 = 325 ms

As you can see this doesn’t quite look right but it was just a quick test just to get some ballpark figures.  I have also not run multiple tests over time to see if there is drift in the lag so there is a lot more work required here. Oh and also there is a good chance that my gstreamer commands could be optimised and improved.

Also can I just say a big thanks to Odie_ on #raspberrypi on Freenode who correctly spotted I hadn’t checked my camera when I couldn’t get it working and suggested the latency methodology and generally kept prodding me until I got it working and documented on the net :)

New Project : Pi in the Sky!

I was asked by the nice folk at Red Spider Hire if I fancied going up in one of their fantastic machines to take some pictures at the village show.  I was totally up for this until I realised it clashed with the date of a friends birthday party.   Something needed to be done.

So I decided to replace myself with a couple of Raspberry Pi machines :-)

The plan:

Get the first Pi (pivite-eye) with the CSI Raspberry Pi camera to stream live video to the second Pi (pi-tv) where it will be displayed on a monitor or projector or something.   Pi-TV and Pivate-eye will communicate over wifi provided by a MiFi wireless 3G access point.   This will also allow Pi-TV to take screenshots and post them to twitter etc and any other sillyness.

Challenges:

  • Getting it to work!
  • Video resolution vs latency
  • Video resolution vs bandwidth
  • Automating the setup so it can be setup or reset without my intervention.
  • Automating video snapshotting
  • Automating twitter posting
  • Weatherproofing

 

Cross compiling Xerces 32bit library on a 64bit machine

Oh the bundle of joy this was….

To build 32 bit serves on a 64 bit machine you need to run the following :-)

apt-get install libc6-i386  libc6-dev-i386 lib32gcc1 libstdc++6  libstdc++6-4.4-dev g++-multilib gcc-multilib

CC=”gcc-4.4 -m32″ CXX=’g++ -m32′ LDFLAGS=”-m32 -L/lib32 -L/usr/lib32 -Wl,-rpath,/lib32 -Wl,-rpath,/usr/lib32″ ./configure –v

make

make install

ln -s /usr/local/lib/libxerces-c-3.1.so /usr/lib32/libxerces-c-3.1.so

Hope this helps someone :-)

Oh install readelf so you can run

readelf -h /usr/lib32/libxerces-c-3.1.so

To check it has compiled as 32 bit :-)

error 25007. Error occurred while initializing fusion. Setup could not load fusion with LoadLibraryShim(). Error: 0×80131700

When trying to reinstall .NET 2 after a failed install/reinstall you may get this message.

error 25007. Error occurred while initializing fusion. Setup could not load fusion with LoadLibraryShim(). Error: 0×80131700

You will also go and do all sorts of stuff to get it working.  What they don’t tell you is:

UNINSTALL .NET 4 TOO AND REBOOT BEFORE REINSTALLING….