Matt Daubneys Blog



by on Jul.13, 2008, under jabber, linux, programming, python

This is a simple jabber bot which lets you jot down simple memos. Use the command “add:” to add a memo, e.g. “add: This is a memo”. the command “list” will give you all the memos in the database including their ids, and “delete: 3″ will delete the memo with id 3.

It’s written in Python with sleekxmpp as the xmpp library, and uses sqlite for the database :-)

Code can be found here

Leave a Comment more...

Bluetooth XMPP Doorbell

by on Feb.06, 2008, under bluetooth, Fun, jabber, ubuntu

Well, you know you have one of those really weird conversations along the lines of

“We need a doorbell!”

“What about a wireless mouse will that work?”

You know it won’t end well. This ended with the destruction of a bluetooth keyboard, a trip to maplins and the creation of a Python based doorbell. Here’s how we did it….

I initially investigated using a mouse to act as a button, as a wireless mouse was kicking around, but problems with curses and the mouse caused a rethink. A bit of investigation led me towards the fact that hacking a keyboard is quite easy. The flimsy on a keyboard just crosses some terminals that selects the character pressed from a kind of table. So if I connected a switch to two of these I could press a button which would be recognised as the letter “e”. Easy! Curses can check for a key press and do stuffs!

Here’s a few piccies of it being built.

With the added battery pack, and the box

You can kind of see the switch in the lid of the box here.

All connected

Here you can see the switch, battery pack and pcb wired up.

On the door

Here it is attached to the door.

The python code is very very basic! I’ll start to update it slowly and make it a bit better, but it works at the moment. I took some code from the pymedia tutorial and some from here. There are two files, one controls the sound, the other does everything else! They can be found (with usernames/passwords stripped) here. It’s also below for completeness!

import curses, xmpp, snd, time
emails = ['contact1','contact2']

wavfile = 'chooseyourownbell.wav'
login = 'USER' #
pwd   = 'PASSWORD'

cnx = xmpp.Client('', debug=['never'])
cnx.connect( server=('',5223) )
cnx.auth(login,pwd, 'daubbell')

stdscr = curses.initscr()

while 1:
    c = stdscr.getch()
    if c == ord('q'): break
    elif c == curses.KEY_MOUSE :
    elif c == ord('e'):
        for addy in emails:
            cnx.send( xmpp.Message( addy ,"Door!" ) )
            stdscr.addstr(time.ctime() + ': pinged ' + addy + '\n')
        stdscr.addstr(time.ctime() + ': Ummm... key not found \n')

 def playWAV( fname ):
  import as sound
  import time, wave
  f= fname, 'rb' )
  sampleRate= f.getframerate()
  channels= f.getnchannels()
  format= sound.AFMT_S16_LE
  snd1= sound.Output( sampleRate, channels, format )
  s= ' '
  while len( s ):
    s= f.readframes( 1000 ) s )

  # Since sound module is not synchronous we want everything to be played before we exit
  while snd1.isPlaying(): time.sleep( 0.05 )

And there you have it, still needs a little work, but a working Bluetooth Jabber Doorbell.

5 Comments 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...