XRF Temperature Sensor -> XRF Slice of Pi

Over the last few days I have been working on getting my XRF Sensors all working with my Raspberry Pi. I have 3 XRF Temperature sensors. WHen I got them I updated the sensors to use a different Channel so that if someone else in the neighbourhood uses XRF we do not clash (in the future I will be looking to enable encryption too).

To start with I just used the button battery but decided as I would use a double AA battery back as I wanted to use have the update interval set to every minute. The battery back should give me around a years worth of use from 1 pair of batteries.

Once I built them up and boxed the sensors in I ended up with the following mostly damp proof unit…

So to get the system working I have a python script which takes the data from the SliceOfPi with the XRF receiver on and publishes a message using Mosquitto MQTT broker to a topic according to the data it receives. It also stores the data in an RRDTool database

import mosquitto
import os
import time
import serial
import datetime
import rrdtool
import re

broker = ""
tcpport = 1883

baud = 9600
port = '/dev/ttyAMA0'
ser = serial.Serial(port, baud)
rrddir = '/home/pi/rrd-data/'

mypid = os.getpid()
client_uniq = "pubclient_"+str(mypid)
mqttc = mosquitto.Mosquitto(client_uniq)
#connect to broker
mqttc.connect(broker, tcpport, 60, True)

#remain connected and publish
while mqttc.loop() == 0:
	llapMsg = ser.read(12)
	now = datetime.datetime.now()
	mqttc.publish("TempSensors", llapMsg)
	if re.search("TMPA", llapMsg):
		rrdfile = llapMsg[1:7]
		value = llapMsg[7:12]
		print now.strftime("%Y-%m-%d %H:%M:%S ") + 'String = |' + llapMsg + '| Updating RRD - File: ' + rrdfile + '.rrd with temperature value: ' + value
               	rrdtool.update(rrddir + 'XRFTemp/' + rrdfile + '.rrd','N:' + str(value));
	elif re.search("BATTLOW", llapMsg):
                sensor = llapMsg[1:3]
                print now.strftime("%Y-%m-%d %H:%M:%S ") + 'String = |' + llapMsg + '| Warning Sensor ' + sensor + ' has low battery'
	elif re.search("WAKE", llapMsg):
                sensor = llapMsg[1:3]
                print now.strftime("%Y-%m-%d %H:%M:%S ") + 'String = |' + llapMsg + '| Sensor ' + sensor + ' waking'
	elif re.search("BATT", llapMsg):
		rrdfile = llapMsg[1:7]
                value = llapMsg[7:11]
                print now.strftime("%Y-%m-%d %H:%M:%S ") + 'String = |' + llapMsg + '| Updating RRD - File: ' + rrdfile + '.rrd with battery voltage: ' + value
                rrdtool.update(rrddir + 'XRFBattery/' + rrdfile + '.rrd','N:' + str(value));
	elif re.search("SLEEPING", llapMsg):
                sensor = llapMsg[1:3]
                print now.strftime("%Y-%m-%d %H:%M:%S ") + 'String = |' + llapMsg + '| Sensor ' + sensor + ' sleeping'
		print now.strftime("%Y-%m-%d %H:%M:%S ") + 'String = |' + llapMsg + '| No match'

The Apache TomCat server on the RaspberryPi then uses php & rrd to create charts accordingly. Below is a sample of the output from the sensors.

Install Node.js v0.8.2 on Raspbian

Perform the following steps to get Node.js v0.8.2 installed on Raspbian (The latest OS release for the Raspberry Pi)

Prep the system and get all the components needed to compile

sudo apt-get install git-core build-essential

Download the source and patch it

git clone https://github.com/gflarity/node_pi.git
git clone https://github.com/joyent/node.git
cd node
git checkout origin/v0.8.2-release -b v0.8.2-release
git apply --stat ../node_pi/v0.8.2-release-raspberrypi.patch

Set the flags needed for compilation

export GYP_DEFINES="armv7=0"
export CXXFLAGS='-march=armv6 -mfpu=vfp -mfloat-abi=hard -DUSE_EABI_HARDFLOAT'
export CCFLAGS='-march=armv6 -mfpu=vfp -mfloat-abi=hard -DUSE_EABI_HARDFLOAT'

Configure the compilation

./configure --shared-openssl --without-snapshot

Make & install

sudo GYP_DEFINES="armv7=0" CXXFLAGS='-march=armv6 -mfpu=vfp -mfloat-abi=hard -DUSE_EABI_HARDFLOAT' CCFLAGS='-march=armv6 -mfpu=vfp -mfloat-abi=hard -DUSE_EABI_HARDFLOAT' make install



Home Automation – Raspberry Pi Links

Below is a number of links that have helped me setting up my Raspberry Pi

iWebKit – Great framework for developing web apps that look like native iPhone apps

Building iPhone Apps with HTML, CSS, and JavaScript – Making App Store Apps Without Objective-C or Cocoa

Making Electricity Usage Graphs with the Current Cost device – Great for getting started with a CurrentCost device

How to install Node.js on your Raspberry Pi – Tom Gallacher – Great site on how to install Node.js onto the pi – Not quite but it gets there in the end

Install node.js v0.8.2 – Nice simple instructions on how to install the latest version.

Node.js, MQTT and Websockets – Good tutorial getting started with web sockets

An MQTT/Websocket based Thermometer using the html5 meter tag – Good follow on to use for dynamic sites.

XRF -Sensors + Relays

Following on my post about automating my central heating I have decided on the main wireless technology to use – XRF. These are small 3.3v wireless serial transmitters that retail for <£10 each.

I am planning to use these for two parts of the system

1) Temperature Sensors ~£15 each

I will be using these for measuring the temperature around the house and also outside. They are small wireless devices that last around 1-2 months when powered by a CR2032 battery (setup to send a signal every few minutes). I am planning to use 2x AA batteries with a holder as this will give me a much longer time period – expected around 1 year.


2) Central Heating Relay – ~£18

This will be used for controlling the 240v central heating lines. To start with it will be connected in parallel with the existing controller (which will be set in permanent off mode). This will enable me to house the Raspberry Pi anywhere in the house and not need to be housed in the kitchen where the existing control unit is.


Unfortunately the Relay board does not come with a 240v PSU, it requires a  6v to 14v DC supply. As a result of this I will need to find a suitable PCB which will be used to power the relay box. All of this will be housed in a small box with fly-leads attached.


The main receiver will be a slice of Pi combined with a XRC model.

To start I will test using 2 temp sensors – 2 internal (Living Room & Bedroom & 1 external)

Internet Enabled Central Heating Controls

This is the start of me trying to build a small Internet Enabled central heating controls. The idea is to replace my existing Drayton Tempus 7 unit. I have the following requirements

  • Web Front End
  • 7 Day Planner for Central Heating
  • 7 Day Planner for Hot Water
  • 1/2/3 Hour Boost
  • Advance
  • Switching for 2A 240v ac
  • Survive power outage


  • Remote Temperature Sensors – Wireless?

At the moment I can see two products which could be used – Raspberry Pi or Arduino.

Current Thinking is

In terms of System Design…
Application A – Monitoring Application which will log the temperature to Mysql? or RRDTool
Application B – Control Centra Heating
WebServer – Display Temperatures & Update Heating Schedule

Mitsubishi ASX Dodgy Trip Computer & Poor Fuel Economy

When we bought our ASX we went for the 2WD 1.8 DiD Diesel as it was much more responsive than the petrol. While it did cost more we felt that due to its improved fuel efficiency over the petrol variant it would be worth it. The official stats for the car are as follows

Driving lts/100km (mpg)
Urban mode 6.7 (42.2)
Extra urban mode 4.8 (58.9)
Combined mode 5.9 (47.9)

When we first got the car one of the first journeys we did was from Southampton to Wetherby. A nice trip of around 260 miles. Before the journey we filled the tank and then had the trip computer set to “Auto” (which means it gives a rolling average of the last 50km) and through the whole journey the computer was saying > 60mpg. Most of the journey was done between 60-70mph with mostly constant speed.

We made a couple of other short journeys and then filled up the tank… the result – 38,6mpg – Yes thats LESS then quoted Urban value for what is definitely Extra Urban driving. I was expecting it to be AT LEAST into the 50mpg range.

After a few more fill-ups of  equally poor numbers compared to the trip computer ( Real mpg values of 33.1, 40.0, 38.7, 37.2)

This got me thinking to how accurate the trip computer was. After lots of research there was no easy way to get it to give a readout for a “trip”. It would always reset it self every day to 0! After a bit of research I found that you could get the car ECU to not reset from Manual Mode to Auto so this change was made and the car had what most people expect a trip computer to do

This resulted in some very interesting numbers clearly showing that Mitsubishi are not playing ball with the trip computer. Its amazing to see how in-accurate it is considering its one of the simplest things to work out. You only need 2 things. Distance traveled (it knows this from the milometer) and how much petrol its used (it knows how much its injecting).

So far I have done 4.5 full tanks

Distance Trip MPG MPG L/100km Trip Accuracy
357m 48.6 34.5 8.19 40.9%
432m 56.5 37.4 7.55 51.0%
413m 49.2 34.85 41.2%
486m 52.1 39.48 32.0%
294m 54.4 34.15 39.0%

The first 2 tanks included around 220-250 miles of motorway driving =~ half the tank so I would have expected to achieve a rate somewhere around the combined rate = 47.9

So from those numbers we can see that the trip computer was OVER READING by 41.2%, 51.0% and 40.9%

You could ‘maybe’ understand it being 5%? out but those numbers are just silly. My previous car was always within 0.5mpg of the real rate and our Mazda 3 is within 1mpg of the real rate.

Are Mitsubishi trying to pull a fast one – trying to con the media when they test their cars. How many do a real fuel consumption test and how many just rely on the published and trip computer numbers.

Once I have a few more readings I will see what Mitsubishi have to say.

rsync hanging between Mac OSX Lion (10.7.3) and Windows Home Server

I have a script with some rsync commands for backing up a load of folders with photos etc (I also have time-machine but this provides me with duplication). The backup is running between my Macbook Air running Lion (10.7.3) at the moment to my Windows Home Server (V1)

Most times I run rsync with lots of files its hanging half way through. I also found it to be rather slow. On further investigation it looks like the rsync that ships with Lion is fairly old – v2.6.9

After downloading and installing a more recent version – Rsync v3.0.6 it now no longer hangs and also runs much much quicker

Remote Start on Mitsubishi ASX (With SmartKey)

With the few cold/frozen mornings we have recently I remembered why I liked keeping my car int he garage. Unfortunately the ASX doesn’t really fit with the dryer in there as well.

There is an official remote start from Mitsubishi but its designed only for automatics and comes in around $500 which is way more than I was prepared to pay. While it is possible to fit the remote starts that are designed for automatics on manual transmissions its highly NOT recommended as there is nothing stopping you by accident starting it while in gear.

There are two components required to get Remote Start on the ASX with SmartKey

The Clifford Remote Start comes with a module & remotes which gives you remote start along with the usual lock/unlock and is also capable of a number of other operations such as turning on the rear demister. There are no modules which will use the existing remotes (some modules claim to work if you can double click the lock button on the remote but this activates the deadlock on the UK ASX so not suitable)

The DB-All is where the magic happens. It interfaces into the cars CAN-BUS so that it can lock, unlock, door sense, handbrake sense, etc all without connecting up each cable. This makes a huge difference to the number of connections required to get the system working. The module also disables the requirement for the SmartKey to be present while in remote start mode. The DB-All module is universal and needs to be programmed with the firmware for your car. This can be downloaded from the XpressKit web site or they can be purchase pre-programmed.

When the car is in remote stat mode the car is LOCKED. The car must be unlocked using the remote. As soon as the door is opened the engine will be cut. It must then be restarted in the usual way. Unfortauntely at the moment its not possible to perform key take-over on the ASX. Hopefully this will come in time in the shape of a firmware update for the DB-ALL

Connecting up the Clifford & DB-All

Pictures showing location of connectors

(c) Directed 2011

There are two further connections:

  • You will need to get behind the Push-To-Start button. To do this you need to remove the dial surround. This can be easily removed with a little pull towards the driver which released all the clips.
  • The final connection to to the Clutch Interlock Switch. There are two sensors on the clutch so make sure you get the one with the pink connection on pin2

Indicator Connections

On the clifford module uts not required to connect up the indicators. The main reason for this is because when you are locking / unlocking your car its the car that is actually doing this and so the lights will flash as usual. The only time the clifford module will flash the lights are when priming remote start and to show errors. Even if you don’t connect up the indicators you can still hear the relays so will know if its working.

If you do want to connect up the indicators you must also move a jumper on the Clifford Case to tell the unit that the indicators require a +ve signal. By default it provides a -ve signal thus not flashing the lights.

Programming the DB-All

  1.  Connect the 12-pin & 14-pin harnesses to the module. Press & hold the Programming button, then connect the 4-pin D2D harness.
  2. Wait until the LED turns ON orange then release the Programming button. The LED turns ON red.
  3. Make sure the key is in the vehicle. Press the push-to-start button twice to the ON position. The green LED turns ON for 3 seconds and shuts off.
  4. The module is now programmed, press once again to OFF position

Once the DB-All is programmed you then need to program the Clifford to pick up the tach

  1. Start the vehicle with the key. Within 5 seconds, press and hold the Control button.
  2. After 3 seconds the status LED on your Control Center lights constant when the tach signal is learned.
  3. Release the Control button.

To remote start you must follow the following procedure:

  1. With the engine running, set the parking brake and leave the engine run- ning. For Pit Stop or Turbo Timer mode (to leave the engine running after arming) open the driver door.
  2. Release the foot brake (if pressed during Step 1), or press and release the foot brake anytime. As long as the engine is running there is no time limit to perform this step.
  3. Within 20 seconds of foot brake release, press any command button on the remote, after 20 seconds return to Step 2 (For Turbo Timer Mode, press the optional dash mounted activation button, or send the Timer Mode command from the Advanced Start menu).
  4. The vehicle lights flash 5 times to confirm MTS mode enable and the remote start activates the ignition outputs.
  5. Turn Off and remove the key from the ignition switch, the engine remains running.
  6. Exit the vehicle, close all the doors and lock the system.
  7. The engine turns off after a few seconds. If the door is opened in Step 3 then the engine continues to run.

You can now remote start the vehicle. If a door is opened before the next remote start activation, the system will not remote start the vehicle.


Thanks to Ed for getting hold of the Clifford & Xpresskit modules.