Weekend Project: Connect a letterbox to Jabber with XBee

May 16, 2010 at 19:05 (Electronics, linux) (, , , , , , )

As i promised this is my first XBee Project. I just needed a more or less useful application i can “test” the XBee’s in a real environment.

It is in my nature to do crazy things, so i thought it would be really cool to have a notification Jabber Message to my Phone when someone put some letters for me in my letterbox. Here it is ;)

01-08-2010 Update:
The FTDI Chip gives me A fscking LOT PAIN more to come in the next Post. DO NOT USE IT :)

This is my Setup:

  • XBee “Coordinator” API Mode connected through a FTDI USB Chip to a linux box
  • XBee “End Device” Interfaced with an Atmel ATTiny13v power by two 1.5v AA Batteries
  • Perl XBee Module API.pm from Thomas Jager
  • Jabber Perl Modules to enable sending messages
  • Siemens S685IP DECT Phone that can recieve Jabber messages

Before you read further you should note that i flashed the ZIGBEE firmware (XB24-ZB) API on my XBee’s because i don’t want to miss the mesh feature.

This Setup now runs with 2x Alkaline Batterys in the End-Device for 4 weeks now, and is still running!

— This setup is not the best-power saving setup —

I wanted my XBee to use only PIN HIBERNATE as Sleep-Mode and activate by the ATTiny.
This didn’t always work, maybe i will change the Setup later to use PIN HIBERNATE together with CTS Line to determine when we are “Clear to Send”…

Coordinator:

The coordinator is the middle of my Network. To the Coordinator End-Devices and Routers can connect.
There can be always only one coordinator in a Network.
My coordinator is interfaced with an FTDI Chip for easy connection to a USB enabled Computer.

The FTDI i used is an FT232BL and needs some external components to work, including a 6Mhz XTAL, see the schematics for more information.

Coordinator config (X-CTU):
-Networking-
ID: 001
SC: 1
-Addressing-
DH: 0
DL: 0
NI: COORDINATOR
-Serial Interfacing-
D7: 0
AP: 1
-Sleep Mode-
SM: 5
ST: 1338
-IO Settings-
D1: 3
P0: 0
– I/O Sampling-
IC: 2
V+: FFFF

Optionally you can add encryption by i don’t post my Settings here :)

Schematics:

End-Device:

The end-device is physically stored outside, power-driven by 2x 1.5V AA Batteries, and also connected to an ATTiny.
The ATTiny is not really required but i can control the behaviour of the XBee better.

In fact the ATTiny recognizes the letterbox-opening with an switch and does
1. recover the XBee from sleep by switching SLEEP_RQ on the XBee
2. switching the DIO1 line of the XBee to make it send a digital sample to the coordinator.

End-Device Config (X-CTU):
-Networking-
ID: 001
SC: 1
-Addressing-
DH: 0
DL: 0
NI: LETTERBOX
-Serial Interfacing-
AP: 1
AO: 1

Schematics:

ATTiny Code:
– please note i used BASCOM here, feel free to translate to ASM or avr-c –

$regfile = “attiny13.dat”
$crystal = 1200000

Config Portb.3 = Output
Config Portb.4 = Output
Config Portb.1 = Input
Enable Int0
Config Int0 = Low Level

Enable Interrupts

On Int0 Goon

‘high = Xbee Sleep
Portb.3 = 1
‘high = no current draw
Portb.4 = 1

Do
   NOP
   Powerdown
Loop

End
‘Label we jump to when the Opener is open ;)
Goon:
Disable Int0

‘Letterbox opened, go ahead
‘Activate XBEE
Portb.3 = 0

‘Push Sample-Line Low
Portb.4 = 0

Wait 10

‘Waitms 100
‘Send Sample
Portb.4 = 1

Wait 1
‘Xbee Shutdown
Portb.3 = 1

‘If someone put a Press in and the Opener Stays open
‘we don’t want to get a message every 10 seconds :)
Do
   Wait 1
Loop Until Pinb.1 = 1

Enable Int0

Return
Return

Xbee2Jabber on the Linux Host

As written before the Coordinator is connected to this host and is running some flavor of linux.
I used a Pre-written Perl Module that i extended to accept the XBee Explicit RX framing.

Please note i just extended the Library that i can get the sampling things out of the different Frame not to use anyting other.
If you want more please extend it on your own.

Get the Code here: http://www.divshare.com/download/11390948-788

Please note that Thomas Jager wrote the whole library and i just changed it.
Have a look here to get his original code: http://jager.no/projects/xbee

Have Phun, maybe the next time i will hook up my toilet to the internet ^^

Advertisements

4 Comments

  1. birgomi said,

    thanks a lot, you have a reference to guide me, this is my personal experience on the internet, thank you …………… please visit my web also,

  2. Jeremie said,

    Interesting article. :) What happened with the FTDI chip?

    • devbios said,

      It is now directly interfaced with a standalone Xbee.
      Looks like i have the problems only with my Linux interface as the Windows box running X-CTU is working seemless with it.

  3. Safety Jabber said,

    Can I just say what a relief to discover somebody who genuinely understands what they are discussing on the web. You definitely realize how to bring a problem to light and make it important. More and more people must look at this and understand this side of your story. I can’t believe you aren’t more popular given that you definitely have the gift.

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: