Archive for May, 2008

Capturing Bluetooth events in Windows Mobile

Friday, May 30th, 2008

I wrote on Sunday about writing Bluetooth code for Windows Mobile for a location-based reminder app I hacked together.

At the time, I wrote about two main approaches for finding nearby Bluetooth devices:

  • searching for discoverable devices
  • registering for notifications for when paired devices connect and

For the location-based reminder app, I went with the first approach, and played with how to search for discoverable devices.

This afternoon, I tried out the other way – writing an app that registers with the OS for connect and disconnect notifications from paired devices.


A daily CurrentCost “bill”

Wednesday, May 28th, 2008

As I’ve finally got my home server capturing the electric meter readings from the CurrentCost, I thought it’d be good to try doing something with it.

I want to start with something a bit different to graphs, because there’s already been a lot of cool work done in different graphing approaches.

As I wrote yesterday, I’ve got a MySQL database that is storing the watt reading from the electric meter captured once every six seconds.

I wondered whether it makes sense to try and turn these figures into a financial cost. It might be interesting (and useful as a behaviour-altering thing) if we could get a “bill” from the CurrentCost meter each day that told us how much we spent on electricity the last day.

  Your CurrentCost bill for 2008-5-27

     Electricity usage   4.9802 units
      Cost ==           £0.4874

     Standing charge    £0.1582
     TOTAL COST FOR 2008-5-27 : £  0.65

I’m not entirely sure of my maths here, but I thought it could be interesting to give it a try.


Accessing MySQL from Perl on SlugOS

Tuesday, May 27th, 2008

I’ve written about my CurrentCost meter that I’m using to monitor my home electricity usage, and the small home server that I’ve set up to collect the data.

Yesterday, I decided to make a start on collecting the data. My plan was to copy what Nick had done and create a MySQL database to store the info, with a table to store a timestamp and the watt reading from the CurrentCost meter.

CREATE TABLE currentcostdl (  
    power FLOAT NOT NULL,  
    primary key(time));

I started with Nick’s Python scripts, but didn’t get very far.

The server, a NSLU-2 (or “slug”) is running SlugOS.

The problem was that there is no python-mysqldb package in the SlugOS repositories. I did try downloading the source for it from sourceforge to build it myself, but struggled to get the dependencies I needed to make it – urllib in particular was a big pain.

I also tried the debian package but again dependencies on SlugOS got in the way.

So I gave up on that and decided to do it myself using Perl – Perl and MySQL had to be easier, right?

Erm… not so much 🙂


Writing C++ code to run from C# for .NET Compact Framework

Sunday, May 25th, 2008

I mentioned earlier that I decided to write a DLL in C++ to invoke from my C# app for Windows Mobile. I’d not done this before, so thought I’d jot down a few quick notes about it.

I found a few detailed articles about this on MSDN that made for a good introduction to the topic:

There is a ton of information in these articles, so there isn’t much to add. Instead, I’ll give a quick, high-level overview.


Programmatically searching for nearby Bluetooth devices in Windows Mobile from C#

Sunday, May 25th, 2008

As part of my plan to write a location-based reminder app using Bluetooth devices, I need a way to know what bluetooth devices are near me.

I’ve not done any Bluetooth development before, so I’ve had to learn a few new bits and pieces tonight.


Custom properties in Outlook Mobile

Sunday, May 25th, 2008

As part of my plan to write a location-based reminder app using Bluetooth devices, I need a way to assign tasks to people, and people to specific Bluetooth device IDs.

I’ve decided to do this using custom properties in Outlook Mobile – the default PIM that comes on all Windows Mobile smartphones and PDAs.

I’ve not used this API before, but after a little playing, I’m impressed with how straightforward it all is.

The idea is that items in the Outlook Mobile PIM have pre-defined properties – so Contacts have fields such as ‘First Name’, or ‘Postcode’. But you can programmatically add new fields, and then store whatever you want in them.

For my purposes, I can add a “Bluetooth Device IDs” property to Contact items in my address book. I can also add pointers to Contact items to Task items in my to do list.

As this is just meant as a quick hack / proof-of-concept, I’m doing this in C#. The code looks something like this:


Writing a Bluetooth-based location-based reminder app

Sunday, May 25th, 2008

My bad back means that I’ve not spent too much time writing code for the past week or two. Tonight, I’m in the mood to try and hack something together.

I should probably try and do some work on my CurrentCost setup – now that I’ve got the new home server connected to the CurrentCost meter, I could write a script to start collecting data and do something with it.

But that can wait for another night – for tonight, I want to get back to doing something mobile.

One idea that I’ve had kicking around since last month is a location-based reminder app based around people – using Bluetooth as a way to know who is near you.

The idea was to have an application which lets you assign tasks in your Tasks list to Bluetooth device IDs for mobile phones and laptops. Then, when your phone sees that Bluetooth Device, it could remind you about that task.

For example, I could know that I want to talk to Will about a particular project. I can put this in my To Do list, but unless I’m actually looking at my To Do list when Will is around, it’s not very helpful.

But with this app, I set my To Do list to remind me to talk to him about it the next time I am near him – the next time his phone and/or laptop is within Bluetooth range, my mobile can prompt me with an alarm.


My new home server – a NSLU-2

Wednesday, May 21st, 2008

I finished putting together my latest gadget this afternoon – a mini home server made from a Linksys NSLU-2 NAS device and a portable USB harddrive.

Why did I want it?

Do I really need an excuse? 🙂

Now I have a full, albeit small, Linux server at home, I’m sure I can think of some fun things to do with it. But as I wrote last week, the catalyst that pushed me to doing this now was wanting something to collect data from my new CurrentCost electricity meter.

It needed to be cheap, small, and low-powered – no point having a server running all the time to monitor my home’s electricity usage if it makes a significant dent in my electricity usage all by itself!

What did I buy?

A NSLU-2 – a network storage link for USB 2.0 disk drives, by Linksys. This is a small NAS device that lets you make a USB harddrive available on a network. The firmware in it comes with enough software to create a network share for any portable USB harddrives or USB flash memory key that you plug in.

It’s a neat little gadget, but what makes it special is that it is very easy to flash the firmware and replace it with a full Linux distro. Plug in your USB harddrive, and you have a Linux server with as much space as you might want.

Oh – and for some reason, people call them “slugs”.