Tuesday, February 2

My SD card Swiss knife 3D printed from Ryanteck

I have a sense of deja vu every time I have to somehow catalogue and store my SD cards, it really reminds me of the floppy disks nightmare. With this Swiss knife things are bound to improve!

Have a look at my newly 3D printed SD card Swiss knife! Ryanteck made an excellent job.

It took some tweaking because the original design from Dranoweb needs ... some improvements but the end result is really nice.

Thursday, January 28

Ryanteck TrafficHat

Who wouldn't love to build a TrafficHat! Find out where to get one for your Raspberry Pi and how to go on assembling it and programming it.



Here you can find Ryan's documentation on his Wiki and the test code I have used for the traffic light

Also if you need to install GPIO Zero:
sudo apt-get install python-gpiozero
or for Python 3
sudo apt-get install python3-gpiozero

Wednesday, January 27

Raspberry Pi GPIO Reference Card Comparison

It has been really hard to decide who the winner of this review was. Ultimately though the scoring results identified without doubt the best of these products.
Find out which by watching the short video below.

Monday, January 25

Upgrade your old laptop with a Raspberry Pi


Have you ever wondered what to do with that old laptop you kept for so long because you never had the heart to trough it away?

Plug a Raspberry Pi2 into your old laptop and give it a second life! Also wouldn't it be great to get your Pi around the house with a very portable setup? I know you get a Pi-Top (I'll admit it's cool but $269.99 without the Pi!!!), you can get a Touchscreen even the original from the Pi Foundation, but the recycler in me sometimes screams for justice.

This setup I am using costs near to nothing and gets the dust off those useless laptops in the loft.

The idea is pretty easy; we get a Pi, plug it in two USB ports of the laptop via a Y cable, connect it via the Ethernet port to the NIC of the laptop, VNC into the Pi, configure the Wi-Fi and job done.


Fix the Pi on the back of your laptop's screen with whatever you can think of and enjoy a Pi with no dangling cables but with a nice keyboard, video and mouse setup.



I made sure that the steps to follow are as simple as possible and that the configuration should work in the majority of situations. By all means this can be further improved and I'll be glad to hear from anybody who might have suggestions.

The configuration and setup can be replicated pretty much on any laptop you might have, even a new one!

Hardware requirements


The requirements for the laptop are:
2 USB ports
1 NIC ethernet
1 Working keyboard and 1 Working Touchpad/Mouse :)
1 Working Screen :))



Mine is quite old as you can see



The Pi needs a Y USB cable with the usual micro connector on the other side. This StarTech 1 feet USB Y Cable for External Hard Drive - Dual USB A to Micro B can do just the job.
A short (20-30 cm) Ethernet cable CAT5e would be more than enough.
Finally a compatible Wi-Fi card.

This is essentially it from the HW point of view. The reason for the Y cable is to make sure that the Pi receives enough current to power itself correctly. Each USB ports in USB1/2 delivers a maximum of 500mA so if you have a laptop of that era you certainly need the Y cable.
The Ethernet cable doesn't need to be a cross-over although that wouldn't hurt if it is. The Pi is capable of Auto MDI-X and will be able to adjust to a straight or a crossover cable directly connected to the laptop; no Ethernet HUB/SWITCH required.

Software configuration


Software wise the Pi will come with its usual distro Raspbian and the Laptop in my case is Elementary Linux. Different combinations of distros should certainly work but might require adjustments compared to what I am showing here.

The quickest A quick way to have the best "Plug & Play" experience is to configure the laptop to work as a DHCP for the Pi, this will ensure that the Pi can just come out of a freshly burned SD card (If you use NOOBS you need to install an OS first) with no need for any configuration only requiring to only install VNC server on your Pi but with no need to configure its networking.

Most NetworkManager distributions should allow for "internet connection sharing" for each network cards. This allows for the laptop to use a service called Dnsmasq to provide automatic configuration of networking parameters for the guests, in our case the Pi. Great!
This is how I configured my laptop:




Once the "internet configuration sharing" is setup our Pi can be plugged in in the USB ports of the laptop and hooked to the Ethernet cable.
After a while we should have an IP for the PI but we are not going to know which is going to be that easily. Luckily both Rasbian and Elementary (Linux in general does) support something called mDNS out of the box. mDNS is for DNS what Link-local address is for IP (you know those 169.254.x.y addresses?) and it allows for DNS names to be setup "democratically" amongst computers in the same network. Raspbian sets its name as


raspberrypi.local

and once it gets an IP you should be able to ping raspberrypi.local without knowing the IP, excellent!
If you can ping it, you can SSH to it and that's the next thing to do.


We SSH to the Pi and start the VNC server (of course there will be a one off password to setup, keep it simple and use the Pi user password).



The server should be started with the same resolution of your laptop screen as we want to run the Pi in full screen on the laptop. The command to run on the Pi will be something like:

vncserver -geometry 1280x800 

or whichever is the resolution of your laptop, I hope you know how to find it :)


We now have a VNC server to connect to, note that it runs on screen :1 but don't try yet to get on the Pi until you have done the steps below otherwise you won't be able to use F8 to close the session as the keyboard might not work.

One thing you may find in fact is that once in fullscreen the keyboard is not working on the remote session. To fix this I had to edit /etc/X11/app-defaults/Vncviewer as sudo

sudo nano /etc/X11/app-defaults/Vncviewer

This is distribution dependant and you might have to look elsewhere for this file depending on what you run on the laptop.



The line that we are uncommenting is:

Vncviewer.grabKeyboard: true

on the laptop we should now be able to VNC safely to the Pi. The command I am using is:

xtightvncviewer raspberrypi.local:1 -fullscreen -compresslevel 3

we are connecting on host raspberrypi.local on screen 1 in fullscreen and compress the session to get better performance. I made a script just not to have to type that all the time.


You can play with compresslevel from 0 to 9 where 9 is less compressed. The network should not be the bottleneck as it is a dedicated fast-ethernet connection but the video card on you old laptop might be the one not actually able to keep up.

If the command above succeeds you should be prompted for the VNC server password you set earlier on and after that you should finally be in your Pi's desktop!!

We are not done yet unfortunately, a few more tweaks.

The first thing to do on the Pi is to configure the eth0 card as static IP.


The reason is still within the realm of keeping things as simple as possible. You remember that Dnsmasq you mentioned earlier? Well as a good DHCP it will keep on refreshing periodically the information of the Pi's Ethernet adapter not only with IP and Mask but also with Gateway, DNS and default route. Now, after we will enable the Wi-Fi card on the Pi we'll want for the default route and the DNS server to be only the ones of the Wireless card not the ones configured from the DHCP server on the laptop. This will ensure that the Pi will be able to connect to the internet only through its Wi-Fi card.
The best thing to do is to configure the IP address of the Pi's eth0 as the one it used to receive from the DHCP's laptop and


uncheck "Automatically configure empty options"

leaving the Router and DNS sections empty.



Note that this will configure the network mask of the Pi as 255.0.0.0 whilst the laptop interface will have a mask of 255.255.255.0. This is not going to cause any problems although it is quite an horrible thing to live with if you have done any serious networking in your life!

Next we need to edit:

sudo nano /etc/resolv.conf

on the Pi to remove the settings obtained from the laptop. We need to remove the line that says:

nameserver 10.42.0.1

or whichever is the IP of your laptop
it should look like this:


Lastly we need to remove the default route 0.0.0.0 associated with the laptop's address, in my case:

sudo route del -net 0.0.0.0 gw 10.42.0.1

so that the routes will look like this:


At this point we'll need to configure the Wi-Fi connection on the Pi in the standard way and we should be done!!!


After these steps connecting again should be just a question of powering up the laptop, starting the VNC server on the Pi (which can of course be set to start automatically) and VNC into the Pi.

What is left to do


A lot more automation can be done. When the laptop shuts down for example we should be able to also run a clean shutdown and wait for the Pi to be off before shutting down the laptop. The VNC session could also be run automatically at the startup of the laptop including passing the password for the Pi. The initial configuration of things for both the Pi and the laptop could be scripted to make things easy even for the less expert.
Finally get a better networking configuration, I hate that thing about the network mask!!

Also some good designer cloud come up with maybe a 3D printed enclosure or VESA fix like structure that can be adjusted to most laptop screens. It'll be nice to find a way to accommodate a breadboard too although having it always fixed on the back of the screen might not be ideal.

I leave it here I guess but this is clearly far from being something to "resell".

Notes


If your laptop comes with a Wi-Fi interface then you could use that to connect the Pi to the internet in a much more traditional ICS configuration. This hides the Pi behind a NAT and for the majority won't be a problem and work great, I preferred to use the laptop just as a KVM though.

I must admit that I have tried to find out whether the Pi supports Link-local address which would have made things less complicated but I couldn't find much about this and eventually opted for the more cumbersome "internet connection sharing" approach.

TIP


In the long run having to type a password for the laptop and one for the Pi can be tedious so my advice is to at least enable autologin on the laptop and disable the password prompt when exiting the screensaver

06-02-16 - UPDATE


Link-Local Address


Since I wrote this article I made a bit more research into the matter of Link-Local Address and specifically with regard to the support of this in Raspbian. It turns out that the Pi is more than capable of supporting IP auto configuration and this is in fact the quickest way to go about configuring the Pi in tailless mode (I like calling it this way!).
By configuring the laptop Ethernet interface as Link-Local only the adapter will get a 169.254.x.y address and will be immediately ready to resolve raspberrypi.local.



Thursday, January 21

VDI at home


Do you have some old laptops sitting around that aren't quite good enough to run a full desktop? Do you also have a good enough PC that could run some virtualisation platform? Then there is hope yet!

As I am writing this article I am using a rather old laptop with an Intel Atom with 2GB of RAM and everything is running pretty smoothly.

I have just renewed my home server running ESXi 6 on which I have installed Windows 7 in a VM. I then acquired 5 free VNC licences of RealVNC and installed a VNC server on the Windows box.

The laptop runs a light version of  Linux, in my case Elementary.

I have set the resolution of the Windows box to match the one of my laptop and simply run VNC viewer from my laptop to the Windows box in full screen.

The result is actually quite good!

There are enterprise level protocols that can serve the purpose in a much better way; smoother video refresh, better compression, multimedia support but for most of what I do VNC is absolutely fine.
I have no audio support, the videos are not very fluid but in general the experience is very good.
Also my session always stays there where I left it which is a good bonus because I can take that same session from pretty much any device I have in the house including my tablet.

Once you have one desktop floating in the house nobody will stop me from having two three more, no need for a beefy laptop, no need for dual boot, simply switch your session!

As I am writing about the upgrade process of my ESXi server in a bit more detail I will also go through what I did to setup the Desktop Virtualisation (strictly speaking this is not VDI in fact) so stay tuned!

Saturday, January 9

Ryanteck Snow Pi

Do you wanna build a snow man? All you need is a Raspberry Pi and a Snow Pi from Ryanteck!



Here you can find Ryan's documentation on his Wiki

Friday, December 11

Ryanteck Motor Controller and Charger Doctor


During the Black Friday and Cyber Monday I got hold of a few good deals from a few shops, one that I was particularly curious about was Ryanteck and I bought a couple of items which I have reviewed, build and tested in the videos below.

I really had fun with the Motor Controller and found the USB Charger Doctor to be a really useful tool.

These are the links I mentioned in the videos:
Ryanteck website

Python's code example for the Motor Controller
Ryan's GitHub

Motor Controller Soldering guide
Ryan's Wiki

Ryanteck - Motor Controller & Charger Doctor

Ryanteck - Motor Controller Build
 

Ryanteck - Motor Controller Code and Test

Thursday, December 3

Remoting into the Pi - all the tools you'll ever need


Being able to connect to a server somewhere out in the wild or in the neighbourhood of your local network is certainly something that has been going on for decades.
The most common activities that one would want to perform on a remote server are:
  • Issue commands
  • Transfer files
Commands needs User Interfaces which can either be:
  • Text based aka terminals
  • Graphical User Interface aka GUI
All of this have to be complimented with a number of protocols that allow the act of remoting from a client to a server.

Let's see what happens in the most frequent cases.

SSH

Issuing commands to a remote server is mostly done by using the SSH protocol. The Raspbian OS comes with an SSH server enabled by default so all we need to do is to get the right client for the platform from which we want to connect from.

On Windows the best know is PuTTY which in its basic incarnation looks like this


and it is an incredibly great tool to issue commands in a very versatile terminal window.
Somebody else built on top of PuTTY and tried to get to grips with the clatter caused by the need of having to deal with many sessions all opened at once.
The tool is MTPuTTY which is what it says on the tin: Multi-Tabbed PuTTY !


Fantastic, but if you are really hard core and you live in an era where virtual machines had not been invented, you can still use the never ageing Cygwin (although you might actually have good reasons to use it in favour of a VM)

SFTP and SCP

Of course one of the most important things to do on an operating system which revolves all around files is to be able to move them back and forth, around and about via SFTP or SCP whenever this last one might be preferred.
SFTP on Raspbian come as part of the SSH server and also in this case there is nothing to be done on the Pi.
My favourite tools are Filezilla and WinSCP although the humble PSFTP installed with PuTTY can still do a great job if nothing else is available.
A great thing of WinSCP is that it will be able to import all your PuTTY sessions as you install it and it supports SCP  along with SFTP. In many instances I have seen people preferring WinSCP to Filezilla.


Filezilla though has my preference as it still supports FTP which is still somewhat handy for the likes of uploading content to websites.


There is of course more to see and discuss about these two great clients but it is time to move on to the next set of tools.

VNC

Text based terminals are great but we live in an extremely visual world and Graphical User Interfaces are preferred by many with good cause. One of the obvious desires then is to be able to interact directly with the Raspbian desktop and this can be achieved using some form of Virtual Network Computing based software.


There are quite a few incarnations of VNC servers and clients and although Rasbian doesn't come with a specific one the Raspberry Pi foundation seems to point to TightVNC which can be installed fairly easily following their simple guide.


As for the client side ... well there are quite a few but I use RealVNC which covers quite a few platforms and does the job excellently. Remember that your display will be display 1 and that to indicate to the VNC client that you are not connecting to the default screen 0 you will have to write <IP Address>:1 e.g. 10.42.0.53:1


X and the rest

If you feel more adventurous you can try the ways of the X server. The X Window System is based on the X11 protocol and has been on the scene for many years.



The advantage of this approach is the possibility to run programs that need a graphical interface from you terminal session. If for example you would need to quickly run the Pi's browser whilst working via PuTTY, you  can simply invoke epiphany and an X windows displaying the browser will come up on your screen.


Counterintuitively the X server will have to be installed on your "from" location.
I have always used Xming as it installs really easily and integrates perfectly with PuTTY.
Just remember to enable X forwarding in your PuTTY session before connecting.


As you run Xming nothing will seem to happen but the program's icon will be displayed in the notification area.


Running a command from PuTTY that will open up in X will result in an X icon being shown in your taskbar and that is for all matters and purposes a window within your client system.


Of course the best way to go to a Linux box is with a Linux box and this can be achieved in a number of ways. All of the above can be done from an Ubuntu machine whether it is your default operating system or you are running an instance as a virtual machine of your Windows host. The software to use will be rather different for the majority but the mechanisms described are the same.
One strange beast to mention in this realm is Cygwin which, as they say on its website,

"is a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows"

and that in fact will allow to work on your Windows box in a "Linuxy" way. One thing we could obviously do is to connect to a Pi from a Cygwin terminal. We can type in xinit and the following whitish window will pop up to indicate that an X server is available! Fantastic


Let's type in a few lines to connect to our Pi and in my case the command is:

ssh -X pi@10.42.0.53

This means that I am using the SSH client in Cygwin on which I am enabling X forwarding (-X) to my Cygwin X server and connect as the user pi to 10.42.0.53
Once I give the password I am in my Pi as shown by the green prompt. From there I can launch lxtask  and get my graphical task manager displayed via Cygwin. Isn't that the most useless thing? :)


Jokes apart though this shows probably one of the many coolest ways to connect to a remote Linux box and it is as close as native Linux as you can get on a Windows computer.

That's all folks

These tools covered most of the use cases that you will ever encounter but bare in mind that what I have listed here are only some of the tools that are available. Also the majority of what I described applies only to Windows. There is of course much more, there is also Apple stuff and one and a million way to do things in Linux.

Note that some of these softwares are also distributed as executable instead of full install. This is great when you want to carry your tools around on a USB key or when the administrators of the systems on which you need to work aren't too lenient on you installing new software. So when downloading check which type you are getting hold of.

Mostly if you can spare some money for those projects that accept donations you can play an important role in promoting what's good out there, right?

This closes "all the tools you'll ever need to remote into your Pi".
Have fun

Tuesday, December 1

Remoting into the Pi

In this video playlist I am going through the steps needed to connect remotely to a Raspberry Pi terminal session.
In a nutshell the videos will show the following:

  • Retrieve the IP address
  • Install Putty
  • Connect to the Pi
  • Customise the Putty sessions
Remoting into the Pi - Part 1

Remoting into the Pi - Part 2

Monday, November 23

Installing Rasbpian with Noobs



You bought yourself a shiny new Raspberry Pi, maybe the brand new Pi Zero and now you are really fidgety about doing something exciting with it but ... there are a few things that need to be done first.

I have provided three complementary videos that you can watch to go through the entire process or if you prefer you can go through the following brief instructions

This is in a nutshell what needs to happen:


  • Get an SD card
  • Format the SD card
  • Transfer NOOOBS onto the card
  • Boot your Raspberry Pi with NOOBS
  • Select and install the Operating System

The first thing you need to do is to get yourself an SD card with a suitable Operating System installed on it so that the Raspberry Pi can run all the basic software that is needed for it to do anything.

At this point NOOBS is your friend!

NOOBS is a piece of software that will help you installing the Operating System onto the SD card.

This can go either of two ways:


  1. Buy a card with a preloaded NOOBS on it
  2. Reuse one you already own and prepare it with NOOBS yourself.

The preferred Operating System for the Pi is Raspbian and its latest incarnation is called Jessie. The names of the versions of this OS are coming from Toys Story, the previous one in fact was called Wheezy!

Now Wheezy's character was a bit chubby and Jessie's was quite slim in the cartoon but despite this you will need a bigger SD card to store Jessie than you would have with Wheezy as the OS Jessie is a bit bigger than its predecessor. With this in mind make sure you use at least an 8 GB SD card for your Pi.


  • Follow this section only if you are reusing you card


If you are going to reuse your card you have to first format it or in other words prepare it to be able to transfer NOOBS onto it, to do so you can use a software called SDFormatter. It is a really easy install to perform and you can use the videos provided if in doubt.



Make sure to backup the contents of your SD card before proceeding as the tool will delete all files in it

Select the right drive letter corresponding to your SD card and click on Format. You will have to accept a couple of alert messages and you card will be ready shortly after.

Once the card is formatted you will need to transfer NOOBS on it. First of all let's get hold of NOOBS.



Once downloaded (it will take a while) it will have to be unpacked in a temporary folder of your choice.

With the content unpacked you will now have to select all the files and copy/paste them onto the SD card you have just formatted (that also will take a while).



The card is now ready to be ejected from the card reader and plugged into the Raspberry Pi.


  • Whether you have used your own card or purchased one with NOOBS pre-installed this is what needs to happen next


Make all the necessary connections to the video, the network, the mouse and keyboard and finally plug the power supply in.

After a short while you should lend onto this page



Select install near to Raspbian and ... after a while and a few rather useful information displayed during the installation, the process will terminate and prompt you for restarting into Rasbpian for the very first time.

Great! You made it, your Raspberry Pi is now ready for many adventures to come

Here are the embedded videos mentioned above

HW preparations to get started

Prepare the SD card, get hold of Noobs and transfer it onto the card

Connecting all up and install Raspian


Friday, November 20

Electronics Recycling Dumpster Diving

I have been very surprised time and time again every time I would go to the recycling centre by the amount of good quality things that get thrown away on a regular basis. Each time I would visit to dump I have always find time to have a peek at the electric and electronic appliances skip.

It is amazing to notice how people overcome their imposed limits and would pick things up as well as chuck their stuff away. Especially on a weekend there will be even some habitué who would always be at the recycling centre to be sure never to miss the best "donations" of the day and I thought : "Why not?" Why shouldn't we all do that without inhibitions and in fact with some sense of pride. "I recovered something from the garbage and gave it a second life"

It is a win!, win^2! loose?
It is a win for me as I get something for free.
It is a double win for the environment as the item doesn't need to be created again just for me and doesn't need to be destroyed. Destroying is the counterpart of creating and it is the counterpart of the costs that are not quite taken into account when giving a value to an item as it hits the market. Destroying or in the best case recycling costs money in the act of collecting and transforming our "garbage" and worse of it all, leaves a heritage to the future generations that will have to find a way to deal with it, most probably with additional costs.
It is a loose for industry maybe. Well industry needs to modernise itself and find a different way to survive, why not re-purposing items and reselling them?

Rant apart, here is the video of what I found at the recycling centre and the hurdles I had to overcome to get my bounty.


Thursday, November 19

Electronics Recycling at the local Charity Shop

Every Tuesday morning a volunteer helps the local charity shop to PAT test all electrical donations. On Tuesday afternoon I would be visiting the shop to see what goodies has the generous community given away.

In October I found a nice Kensignton laptop stand which came connected to a WiFi USB card from Netgear.

In the video below I went through this £5 purchase to see what could be salvaged and what could be chucked away.

Sunday, November 1

Halloween Automated Scarer 2015

A pinch of pygame, a hint of scapy and the Halloween concoction is ready!

This year's automated scarer was a bit more challenging than last. I stitched this together in a couple of days and ... it worked mostly as I wanted it to be. The most important thing is that children and parents enjoyed being scared by a few monstrous pumpkins and a bunch of my son's very horrific (but beautifully made) drawings.
Raspberry thirsty Vampire
Scary Witch of the South East

I wanted the animation to be easy to be activated and yes, I could have used other methods to detect people to be scared (which from now on I will refer to as scarables: a person suitable for the scarer) but I was curious about scapy and the possibility of detecting mobiles passing by.




I also found quite interesting digging through the enormous amount of information available on pygame which served perfectly the purpose of displaying the pictures and playing the sounds all of this without needing to drop into X leaving ample resources available on my RPi B

It is also entertaining to lookup the MAC addresses I collected to establish if we live in a posh area or not. The amount of Apple devices wasn't so many in the end, I will consider selling and buy elsewhere.
Ah and don't worry, the MACs I collected will be handed over to TalkTalk for safe keeping.



The Python script revolves mainly around the scapy command sniff which I used to search any broadcasting WiFi device within reach of my dongle.
The first thing to do is to setup the WiFi card into monitor mode which is done outside of python on the shell:

#/usr/bin sh
sudo service ifplugd stop
sudo ifconfig wlan0 down
sudo iwconfig wlan0 mode monitor
sudo ifconfig wlan0 up
sudo service ifplugd start

You can verify things are set properly by issuing iwconfig, this is my output:

wlan0     IEEE 802.11bgn  Mode:Monitor  Frequency:2.412 GHz  Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:off

Within scapy's lamda function we need to create a list to hold the MAC addresses that we'll acquire. Around the area where I live there are normally quite a few Access Points and other WiFi devices. The first thing to do then is to store all these MACs on a file so that they will not trigger any false "scares" each time that the Pi starts. I did this by running the script in "silent mode" for a couple of hours. I had created in this way a WiFi fingerprint of the area which I stored on a file that gets read at the start of the script and pre-loads all the MACs in the neighbourhood.

if path.isfile(fileName):
    with open(fileName, 'rb') as MAC_file:
        MAC_list = pickle.load(MAC_file)

for the serialisation I am using pickle which for the purpose works just fine

From here on any new MAC detected is a potential scarable,

Scapy offers a sniff command that can take as arguments an interface and a function amongst other options.

sniff(iface = "wlan0", prn = PacketHandler, store=0)

The store=0 turned out to be vitally important as it tells the sniff command to just monitor the packets and not store them in memory. I learned this the hard way as I the Pi stopped responding all together as its memory got full.
I have obviously specified to monitor packets on wlan0 and given a PacketHandler function which I use to specify what I am interested in about the packets seen by wlan0

def PacketHandler(pkt):
        if pkt.haslayer(Dot11):
                if pkt.type == 0:
                        if pkt.addr2 not in MAC_list:
                                MAC_list.append(pkt.addr2)
                                with open(fileName, 'wb') as MAC_file:
                                        pickle.dump(MAC_list, MAC_file)
                                        Call the Scare function

the layer I am interested in is Dot11 as in 802.11x and the packet type is 0 as in management. If the MAC is not in my list I will add it and write the list on a file.
The other very important thing that I do in the last if block is that I will start the animation for each new MAC added to the list.
Now, this could have done it in a number of ways, I wanted to explore the pygame events, I wanted to use two threads on for WiFi scanning the other for the animation, in the end at 16:30 of the 31st of November I decided to call a function directly after writing the list to a file.

image = images[random.randint(0, len(images)) - 1]
sound = sounds[random.randint(0, len(sounds)) - 1]
Scare(image, sound, screenSize)

The Scare function receives a random image and a random sound from two preloaded lists. I paste the PrepareImages only as the PrepareSounds is essentially the same

def PrepareImages():
        imagesNames = glob.glob('*.png')
        imageCache = []

        for imageName in imagesNames:
                try:
                        imageCache.append(pygame.image.load(imageName).convert())
                except:
                        raise UserWarning, "Could not load images"

        return imageCache

All .wav and .png files where in the same path as the script.
Everywhere I looked for examples of pygame.image.load I found that it is highly recommended to convert the images to improve performance. I certainly noted an improvement

The Scare function looks like this

def Scare(image, sound, screenSize):
        image = pygame.transform.scale(image, screenSize)
        frame = image.get_rect()
        white = (255, 255, 255)
        black = (0, 0, 0)
        screen = pygame.display.set_mode(screenSize)

        playing = sound.play()
        while playing.get_busy():
                screen.fill(white)
                screen.blit(image, frame)
                pygame.display.flip()
                pygame.time.delay(1000)
        screen.fill((black))
        pygame.display.flip()

it will resize the picture (sometimes deforming it as the source did not have the same proportions of the screenSize I selected), set the screen, play the sound.
Whilst playing the sound the picture would be displayed (blit) and a 1 second delay also added to get the shivers deep in the scarable's spine.
After the sound is played the screen turns black again.


That's it really, ciao!







Tuesday, December 2

Ghetto ESXi server

How would you like to transform your sluggish desktop based hypervisor into a super fast server based one?


Well in fact maybe I have exaggerated a tiny bit, you are not going to transform a desktop PC into a blade server but ... the end result is pretty neat considering that for the majority is free and fairly easy to achieve.

I have had for quite a while a PC at home continually powered on and running a bunch of virtual machines. The hardware is nothing spectacular:
  • Intel Core i5 750 (1st Gen)
    • 64 bit 
    • Intel® Virtualization Technology (VT-x) 
  • 6 GB of RAM
  • Sata disks
  • 3 NICs (one Realtek and two Intel)
that's it really but it is enough to fulfil the minimum requirements to run ESXi. The full list of supported hardware is available via the VMware compatibility matrix.

The biggest trouble I had with my system was that it ran Window 7 Home edition and Oracle VirtualBox for the virtualisation platform. Don't get me wrong, VirtualBox is great, the trouble though is having a full blown OS like Windows underneath which needs updating, chews a lot of RAM on its own, gets all sorts of security issues, etc. One can use Linux I guess to get less of a footprint and it works better as a server in many ways but the bulk of the problem pretty much stays.
If you have ever used VMware ESXi I really don't need to sell this to you, it is designed to be a great hypervisor and many will consider it simply the best.

So I had this idea brewing for quite a while to see whether I could install the standalone version of ESXi onto my PC, take all my VMs and convert them to VMware. Turns out that last week I managed to just that!

Creating the ESXi image

The first problem to solve was to get an image that will work with the hardware I had. For most of what I have done below I followed the instructions on this blog.
  1. Download the base image from VMware. I got my ESXi 5.5U1 from this link
  2. As my PC has a realtek card and ESXi 5.5 does not have drivers for it,
  3. Download the ESXi customiser to inject the drivers in the base image
  4. As an optional step I also wanted to use a USB key to perform the installation instead of a CD. The utility is called Rufus and can be downloaded here. This site also explain quite well how to use the utility.
With all of the above done I then had a USB key with a customised imaged for my bare metal hypervisor"to be.

After setting the BIOS to boot from the USB key I just followed the rather easy installation process for ESXi. The last step of it is to setup the management network which will then give you access from the vSphere client which can be found here

That was it for the installation, I might go through the configuration in a further post. The only problem I am having so far is to do with the chassis fan which is currently running at max speed as I guess the ACPI drivers aren't compatible with the mainboard. I will buy a quite fan to replace mine with.

In the next post I will go through how to convert and move the VMs from my VirtualBox to my new shiny hypervisor.


Friday, October 31

Halloween Automated Scarer part 2

And so this is the scarer in a box, all finished and connected up ready to spring into action


by either using the QR code or send an SMS to my Nokia 7250i the Python code will parse the incoming SMS. If the message says "scare" it will tell the PIC to scream. The PIC will be scared via its serial port and will then activate the motor back and forth a few times




Once installed in place the motor is linked to four fishing lines two are wound clockwise and two counter-clockwise. What is attached to the lines weighs pretty much the same on each and because they are wound in opposite direction the motor doesn't have to struggle much at all.


That's it really, the code isn't terribly interesting but I would be glad to provide it if needed.
Here is a short video of the final effect.



And this is the sign I had outside my house.



In the end I did not have many customers scared but quite a few took the time to watch the animation and enjoyed the novelty. A witch was particularly interested in the QR code, not even her could think of such sorcery!