Some more geeking around at home …

Continuing the techno-geekery at home

As written in a previous post I’d bought some wireless controlled electrical plug adapters primarily for use to remotely control the air conditioning unit in The Son’s room, especially in the evenings after he had been put down for the night. The adapters are controlled via a smartphone application, and certainly meet the functionality they promised. However, I’m a curious sort of person, and am always looking to see if ‘improvements’ can be made, and all the better if those improvements involve a bit of customisation and poking around with the Linux command line, or ‘messing around on my computers’ as the OH would describe it.

I’d already discovered that there was a project called ninjablocks that was set up to automate certain hardware and tasks, however in the negative column is that this project had run out of money and was winding up. In the positive column was they had a framework that ran on a Raspberry Pi Linux system, and allowed control from ‘the cloud’, although given the money has run out, how long this cloud remains is open to question. It’s also slightly overkill for my needs – I don’t really need to control my air con from the cloud. A bit more looking produced a simple perl script hosted on github. I had previously tried simply sending the UDP control packets via a netcat command to the S20 power adapters, but couldn’t reliably ensure that the adapters were switched on and off, and for my intended project I needed to ensure that the adapters were in the state I wanted them in.

From a Linux device on the same wireless network as the plug adapters, I can control their state (and query their current state) using this bauhn.pl script. e.g. ‘bauhn.pl <MAC address of plug adapter> on’ would switch it on. Nice and simple.

Automating the process – step one

As has probably become clear, I’ve been expanding my interest into the Raspberry Pi system boards. If you don’t already know, these are brilliant little system boards, and has recently been updated to version 2, with a multi-core CPU and 1GB of memory to play with.

pi2There’s a nice picture of a Pi 2 board showing the 4 USB sockets, 1 ethernet port (100Mbps), 1 HDMI out, and an audio socket. The 40 pins you can see are available for various uses (data, power, GPIO) allowing lots of (cheap) components to be added and providing a huge number of potential projects that this can be used. There are two ZIF sockets (the black and white ones in the picture), one for camera module, and one for a display module. To this, for my home automation project, I’m adding an AM 2302 temperature/humidity sensor as seen below.

temp-humid There is a great tutorial already written up on connecting one of these monitors to a Raspberry Pi, so I won’t need to go through all the steps here. Some soldering of the wires onto the connectors was listed, however I found using a crimping tool provided a secure enough connection, and avoided me having to try out soldering again – memories of ‘technology’ class at school came flooding back and ugly blobs of solder I’d used to connect two wires together. To say I was not good at soldering is an understatement, and it’s a skill I wasn’t in a hurry to re-visit.

Skipping forward …

Amazingly, I have my Raspberry Pi board connected to my temperature and humidity sensor and it all works exactly as listed. I made some modifications to the C code for recording the readings so that any obviously wrong readings were silently ignored and not added to the database of results. At the same time I discovered that my C coding is really not very good at all, so I’m in the process of putting together a python program/script to replace the C code that reads the sensor. This has all demonstrated to me that I’m also not much of coder at all – but I can quite happily lift pieces of code from around the Internet and put together a hodge podge of code that will work for my needs. Using python, as it’s a nice high level language, makes this even easier for me …

Anyway, with the components all working, I cobbled together an HTML page that draws a Google Chart from data in the MySQL database:

temp-humidAwesome! I can draw charts that automatically update themselves! I did discover that reading all records from the database would result in slower load times for the graphs, so I’ve limited the main page to just show the last six hours of readings.

Automating the process at home – step two

On my Raspberry Pi, I have set up a cron job that runs a bash script every five minutes between 7:00pm and 6:00am. This bash script queries the last record in the MySQL database, and if the temperature is above a threshold it will then call the aforementioned bauhn.pl script to turn the power adapter on. If the temperature is below a threshold then the same script will turn the adapter off.

temp-humid2As can be seen, the temperature (and humidity) fluctuate whilst the script runs. Basically, I have created a thermostat … Whoo! Admittedly, not the most exciting thing in the world – and given the bill of materials came to about US$50 or so, it probably wasn’t the most cost effective either. It was fun doing it though, and there is a sense of achievement that it actually works, or in the words of the OH ‘you’re such a geek’.

Running …

No post is complete without my latest running update: I ran last night. The GPS on the watch worked throughout my run! I used a wrist sweatband under the watch, so undoubtedly looked a bit naff, but I know where I ran! (round Happy Valley). I have warranty replaced my Jabra earphones for a fourth time, so had heartrate monitored whilst I ran – but had no music to listen to, as I had reset my watch which wiped the cached music and I hadn’t thought to resynchronise it:

doh Strava link: https://www.strava.com/activities/326531149 and https://www.strava.com/activities/326943413

Ran a bit further than usual – and due to mucking about with wondering why my music wasn’t working the run record was split into 2 activities. On the subject of the earphones – I’ve been contacted by the Director of Product Management and passed on my experience to him, so it will be interesting to see where that leads. I’m not expecting the current (fifth) set of earphones to last any longer than the previous sets though.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: