Matt Daubneys Blog

Uncategorized

bzr+MQTT=Win \o/

by on Dec.31, 2011, under programming, python, ubuntu, Uncategorized

I’ve been meaning to post this for a little while, but now seems as good a time as any :)

My little team in the office has expanded since I started as the only developer. With two other devs on board managing the bzr commits has meant a little extra overhead to make sure I know when new revisions have been pushed. Thinking there had to be a better way then getting people to email me when they do a commit and push to the main branch I went digging through the bzr docs.

It turns out I’ve been “doing it wrong™”. The bzr repo was setup so that people could connect to it using sftp as that was a quick easy way to get things rolling when it was needed. Apparently bzr has an inbuilt “smart server” that can run scripts on certain hooks when certain events take place. This looked like the way to go!

First thing was setting up the smart server. I threw Apache onto the dev box, install mod-wsgi (because it’s so much better than mod-python) and started reading through the instructions. About an hour of screaming and poking I got the system running  as a smart server, meaning I could push using bzr+http instead of sftp. Now came the difficult part.

It seems that only very specific events can be hooked into on the server side. This wasn’t immediately obvious from the bzr docs, but a little shouting, throwing things at the monitor and emptying nerf after nerf at the keyboard eventually got me to the hook I wanted specifically.

Now I had the ability to hook into things with bzr, but where could I send the events that it was generating? EMail was a bit dull, so I went back to MQTT, with the thought of commits could now light a lamp in the office when they happen :) The code for the server side bzr plugin is below. You just need to drop it into your .plugins directory for your smart server (ensuring you set this up in you wsgi configuration).

from bzrlib import branch
import mosquitto as mqtt
import os

mqttServerIp = "192.168.0.250"

def post_push_hook(push_result):
    branchFolder = [x for x in str(push_result.branch.__dict__['_base']).replace("//","/").split("/") if x]
    connectSendDisconnect("new branch revision: "+str(push_result.new_revno),branchFolder[1])

def connectSendDisconnect(msg, branchName):
    mqttc = mqtt.Mosquitto("bzrlib"+str(os.getpid()))
    mqttc.connect(mqttServerIp, 1883, 60, True)
    mqttc.publish("/code/"+branchName, msg, 1, False)
    mqttc.loop()
    mqttc.disconnect()

branch.Branch.hooks.install_named_hook('post_change_branch_tip', post_push_hook, "My post_push hook")

Magic! Now a message will be sent on the “/code/branchName” topic every time a commit happens :) Using some borrowed python magic from http://chemicaloliver.net/programming/first-steps-using-python-and-mqtt/ I’ve made it integrate into the default Ubuntu notifications system so a nice little box pops up informing me of a commit and the new revision number of the branch :) Doubles aces!

Leave a Comment :, , , more...

Arduino powered lights and heating!

by on Nov.07, 2010, under arduino, learning, ubuntu, Uncategorized

Over the past few weeks as it gets colder, I’ve really started to notice the significant bite in heating costs from our flat being largely electrically heated. The main issue with this system is that none of the heaters have thermostats, they are either on, or off. As each heater is 2kW or greater, and there are 4 of them in the flat, that means at any one time we could be using 8kWh of electricity. Which is a lot of money during the day!

The solution? Build a thermostat for them (and replace 2 with a gas convection heater). The circuit for this is quite simple thanks to the fantastic home easy set of sockets. I bought a pack of three sockets (with a remote) and a light bulb holder (we’ll come back to that later). On top of this I needed a temperature sensor (tmp36), a 433MHz transmitter , a 433MHz reciever and an arduino uno.

Thanks to the lovely folks at the Home Easy Hacking Wiki getting this lot to work together with an arduino is easy as anything! Here is the basic circuit:

Home Easy Transmitter DiagramThis is only the transmitter/temperature sensor part. Initially you’ll need to build a receiver to get the ID of your remote. This can be found at this page in the arduino playground. Once you have your remotes ID, you just need a simple arduino sketch to turn the socket thats plugged into the heater on/off! Here it is….

HomeEasy homeEasy;
boolean isOn;
int incomingByte = 0;	// for incoming serial data
float timeOn=-900000;
int myCode = 1595082;  
 
void setup()
{
       Serial.begin(9600);
       homeEasy = HomeEasy();
       homeEasy.init();
       isOn = false; // 1 = On, 0 = Off
}
 
void loop()
{
  float temp = getTemp(0);
  Serial.println(temp);
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    // say what you got:
    if (incomingByte == 111){
      //turn on the group
      homeEasy.sendAdvancedProtocolMessage(myCode, 0, true, true );
      homeEasy.sendAdvancedProtocolMessage(myCode, 0, true, true );
    }
    else if (incomingByte == 102){
      // turn off the group
      homeEasy.sendAdvancedProtocolMessage(myCode, 0, false, true );
      homeEasy.sendAdvancedProtocolMessage(myCode, 0, false, true );
    }
  }
  if (temp < 18.0 && isOn == false && millis()-timeOn > 300000 ) {
     //turn on the heaters
     homeEasy.sendAdvancedProtocolMessage(myCode, 0, true, false );
     homeEasy.sendAdvancedProtocolMessage(myCode, 0, true, false );
     isOn = true;
     timeOn = millis();
  }
  else if (temp > 18.0 && isOn == true && millis()-timeOn > 300000 ) {
    homeEasy.sendAdvancedProtocolMessage(myCode, 0, false, false );
    homeEasy.sendAdvancedProtocolMessage(myCode, 0, false, false );
    isOn = false;
    timeOn = millis();
  }
}
 
/*
* getVoltage() – returns the voltage on the analog input defined by
* pin
*/
float getTemp(int pin){
return (((analogRead(pin) * .004882814)-0.5)*100.0); //converting from a 0 to 1023 digital range
                                        // to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}

This code ensures that there is no change in status for at least 5 minutes, basically so the socket doesn’t go continuously on/off and damage something! There is also a hook for a serial input to turn on the “group” of the remote. This is to turn on the light in my bedroom. I’m in the process of writing two simple bits of python to turn a light on/of depending which is run. This means I can set up a cron to turn on a light at a given time! Simple alarm clock :)

To get this code to work you’ll need the homeeasy library from here. You may need to alter the pin allocation in homeeasy.cpp, but that shouldn’t be too hard to do!

Next thing to do on this project is to get my Revo setup as a little wireless server box to graph the temperature changes and run the alarm clock. Conveniently it’s being replaced with a mac mini this week so has become available to complete the project. This will be a simple ubuntu box, running ubuntu server and little else really. Thought it may gain an ldap database for another, slightly different project.

1 Comment :, , , , , more...

Ubuntu UK Support

by on Aug.07, 2010, under ubuntu, Uncategorized

OK Ladies and Gents, having been away for a little bit for various reasons, it’s time to get the support ball rolling. First things First, a date for your diaries.

On the 26th of August I’m organising a meeting to formally create the group from those interested parties and to set out some priorities. Initially we need to focus on some given areas where people ask for support. Once we have one or two of these running we can then branch out into other areas and help improve things where necessary.

I’ll stick a formal agenda on the UK Wiki, but if people want to start thinking about the following things it would be appreciated.

  • How to report (issues/progress/problems fixed) for statistical purposes
  • Initial Targets (UK Section of the Forums/IRC/Stack Exchange/Mailing Lists?)
  • Blogging problems and resolutions
  • Training
    • How
    • Where
    • What to train on (problem solving techniques/diagnosis howto/?)
    • What materials do the training team have for this
    • Mentoring?
  • How to put people in contact with the correct person to solve their issue

This is not a comprehensive list of the issues we’ll need to cover, but gives a good starting point to mull over. If you want to do a mini implimentation of something yourself, have a go and let us know how it goes at the meeting.

If people want to get hold of me individually to go through any issues, you can get me in jabber (daubers at REMOVE THIS jabber dot org) or on irc.freenode.net in #ubuntu-uk (nick of daubers) or by email on (matt at REMOVE THIS TOO daubers dot co dot uk)

Leave a Comment :, , more...

Astrophotography

by on Nov.12, 2008, under Astronomy, FOSS, Fun, linux, Physics, ubuntu, Uncategorized, Uni

So,  the third epic astrophotography adventure was this evening. The first night, I had lots of frames of black, no stars at all. The second night was done by means of cheating, and I haven’t yet sorted the photos…. the third night and……

The Moon

The Moon

But more exciting than the moon (taken with a blue filter in case you where wondering…)

Jupiter and 3 Moons (out of focus)

Jupiter and 3 Moons (out of focus)

Yup, Jupiter and 3 moons. A bit out of focus, but you can just about see them. A bit more practice and I might get a nice shot!!!

All of these images where converted out of RAW using FOSS. I’ll blog a bit more about the set up on a later date.

Leave a Comment more...

Gardening

by on Feb.10, 2008, under Uncategorized

For a couple of weeks I’ve wanted to get out and sort out the front garden, as it was full of dead plants and overgrown creepers. I’d had a brief idea of putting in some veg and some herbs (a bit of mint, some basil, maybe some thyme) as herbs tend to be a bit hardier then some plants. First though, all the rubbish needed to be cleared out, the beds dug and turned, and some compost needed to be worked into the soil. So a quick trip to Homebase was required.

We acquired a few bags of compost, a garden fork, and some plants (a foxglove, some pansies, some tulips a ficcus (I think!), some cucumber seeds and some spinach seeds) and started digging out the beds. Several hours later (try 5 or 6), after a lot of digging, some turning and some planting we had a nice new flower bed and a turned bed ready for the veg and herbs when they come out of the propogator :)

See my flickr for some pics!

1 Comment more...

Broked roof’s

by on Jan.20, 2008, under Uncategorized

Broken Roof

The landlady’s son found this hole in the roof, leading into one of the rooms in the property we don’t have access too. Annoying isn’t it? If the vandals caught, I hope they get time.  Explains why the house has been so cold though.

Leave a Comment more...

Revision and Coursework

by on Jan.08, 2008, under Uncategorized

For the past year I’ve been really hitting myself for not being able to find a work ethic, but since this morning I’ve actually managed to slip into one. It seems I just need to go hide myself in the library and actually get my head down and do some work. I will need to put some more videos on my iPod though… Anyway, managed to get a significant chunk of my lab report written today in the beginning of my monster week of catchup work and revision. Hopefully have it written and submitted by tomorrow afternoon so the revision can begin properly.

Really starting to pick up the banjo again now. Shall have to start learning some new tunes and try and get into a practice routine. It’s really quite stress relieving.

Leave a Comment more...

Exams

by on May.30, 2007, under Uncategorized

Well, only 1 exam left, and having (hopefully) scraped through the last 4 I shall be heading home on Sunday. Also a new picture on Flickr, from a BBQ-ing night :)

Anyway, since MSN is doing its normal routine of pretending to work but actually not working I think I shall go to bed. There is much revision to be done tomorrow! Also, electromag sucks.

Leave a Comment more...

Yesterday………

by on May.17, 2007, under Uncategorized

Was another day of revision really. Watched a few episodes of Farscape while on the revision trail and then went for a walk before lunch. Wandered along to Rosehill Quarry Community Park before lunch. It’s a really nice green space that’s just down the road from me. Having walked past on the way back from Uni several times I thought I should really go take a look and it’s really green, really pretty and has some spectacular views. There are some pictures on my flickr.

Anyway, I need to go to the library today to hand back a book and pay some fines, then I shall come back and hit the revision again. Whose idea where exams anyway?

Leave a Comment more...

Weekends, Revision and the TARDIS

by on May.15, 2007, under Uncategorized

I spend this weekend in, a very drizzly, Exeter. Was a very nice weekend with Kat, and even managed to get some new bootlaces. Wandering around the grounds of Exeter Uni, it makes Swansea feel very small. Maybe that’s why I like the place so much.

Managed to get a fair chunk of revision sorted today. Started to go through the maths past papers, became very aware that there was a question coming up regularly that wasn’t covered in the notes. One email later and I quickly discovered that it wasn’t covered in the course this year and hence won’t be in the exam. So no Linear Transforms this year. I also noticed that the Physics courses tend to cover far and away more material then the maths courses. As we don’t seem to have any modules run by the maths department next year, it makes me wonder if this has always been the case.

Also today I started pondering my summer PC upgrade. This year it’ll consist of a new hard drive (no. 3) and possibly a new CPU. It’ll also contain (if I can get it to work!) a new TARDIS shaped case, with easy slide access to major components (less the mobo due to all the connections going out the back. I shall start designing after the exams have passed.

Also today, my new T-Shirt arrived. Expect images soon….

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...