XBee Supply Voltage monitoring (3)

This is what you get when a battery powered XBee is struggling to stay alive cause the batteries aren’t supplying enough ‘juice’ anymore:

FF FF FF FF FF FD 7A 1F 33 40 00 A2 13 00 01 FF FF FF FF FF FF FF FF
01 53 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00
00 73 A0 73 B6 70 E0 73 CC 73 E2 06 40 75 5C 76 F0 76 3C 76 B4 76 3C
76 3C 73 F8 74 0E 74 22 75 1C 75 EC 75 60 74 2C 46 50 E6 00 01 02 00
00 00 00 E8 00 01 02 00 00 00 00 F3 E0 58 A0 FF FE 00 EC 30 BC 75 CA
A8 D8 B6 D5 9F FD 5A 7B FF FE 00 00 FF FE 00 00 FF FE 00 00 FF FE 00
00 FF FE 00 00 FF FE 00 00 FF FE FF FF 79 BE 01 4A 01 B0 01 62 01 4E
01 66 01 AC 01 60 01 82 01 9C 01 68 01 B2 01 94 08 1C 08 29 08 34 02
etc. etc. ...

For those not really experienced in recognizing XBee API frames from a byte stream: there’s not a single valid frame to be found inside all those bytes. But this is what my Coordinator received today.

But that’s OK; i intentionally left the XBee running on low batteries; I wanted to see what would happen. My code that should recognize valid XBee API packets just got it’s ultimate real life test. Cause normally, the byte stream coming from the Zigbee Coordinator is so clean you can hardly test it without writing a special tool that creates a mix of garbage, valid and invalid frames. Now i know for sure my code works! 🙂

Another good thing i saw, is that this ‘dying’ XBee didn’t create that much traffic resulting in other XBee’s not being able to get their messages to the Coordinator anymore.

This is really important actually; imagine you’re on holiday and a sensor runs out of battery power; do you really want to monitor your Home Automation system for that kind of trouble while you’re at the other side of the world? Become a slave of your own system? And have to call your neighbor that feeds the cat to remove the batteries or worse ? (“I don’t care how you do it, just do it.. Cut some red wires if you have to!”) Just to keep the system running? Not me!

In the meantime, this really nice weather only makes you want to play outside; sitting behind a computer with an airco blowing cold air in your neck is not my favorite right now:

RC Cars

Batteries are being charged! 🙂

XBee Supply Voltage monitoring (2)

Here are the results of the test i started 3 days ago. After 3 days of monitoring the XBee supply voltage the alkaline batteries were empty and with a bit of tweaking i got the data out of the logs and into an Excel sheet so i could create a chart:

XBee Supply Voltage

XBee Supply Voltage

OK, this looks good and it’s easy to do; all you need are some changed settings on the XBee, a Domotica system that can fire the ‘IS’ remote AT Command to your XBee and your done. Well, almost 🙂

The JeeNode has been running a small sketch that transmits a dummy string every 5 seconds; without any sleeping and also keeping the XBee on all the time:

#include <NewSoftSerial.h>

#define SERDBG 1
NewSoftSerial XBSerial = NewSoftSerial(2, 3);

int CTSpin = 7;
int XBpin  = 6;

static void Send () {
  // send a dummy string
  XBSerial.print(" ");
  Serial.print(" ");

void setup() {
  // setup XBee

  // give XBee some time to join PAN

  // let the world know we're here

void loop() {

The JeeNode stopped working at around 2/3 of the horizontal axis, so after 48 hours or so where the voltage had already dropped to 2,64 V. The XBee is still working as i write this, with a voltage of 2,3 V. I wonder how long it takes for the XBee to give up too…

Conclusion: this can definitely be used as a way to remotely monitor my battery powered sensors; Yippee!

XBee Supply Voltage monitoring

One thing i would really like, is being able to monitor the voltage the JeeNode and XBee are running on. Now the XBee has a %V command, specially for reading the voltage on the Vcc pin. So let’s see of i can use this.

The first thing i noticed was that the XBee i configured with the AT End Device firmware, didn’t respond to the %V command. Hmm, correct; the manual was very clear about it: the %V command is only supported by a Router  and not by a Coordinator or an End Device. And it’s those End Devices  (which will run on batteries) that i want to monitor…

OK.. next command to have a look at was the ‘IS‘ command, which stands for Force Sample; this command forces a read of all enabled digital and analog input lines and a small comment told me it could also return the supply voltage: “Analog samples are ordered sequentially from AD0/DIO0 to AD3/DIO3, to the supply voltage.”  So lets try this one, shouldn’t be to hard i guess?

So i added support for this command to my API and started sending frames to the XBee:

Sending frame:7E 00 0F 17 01 00 13 A2 00 40 33 1F 7A A2 ED 00 49 53 FB

I won’t go into detail of every byte in the frame above, but the 2 bytes marked in red are the ASCII codes for ‘I’ and ‘S’: yes, ‘IS’, the command we want to be executed on the remote XBee. The response that came back from the XBee was encouraging, however, no supply voltage was present, only the values of some random Analog input lines i enabled:

Rcvd Frame:97 01 00 13 A2 00 40 33 1F 7A A2 ED 49 53 00 01 00 00 02 02 09
FrameID=1, Command=IS, Status=0, Command Data size = 6 (01 00 00 02 02 09)

With the help of an example i found out the meaning of the Command data:

IS response example

IS response example

OK… the frames that were being received looked nice, but it’s not what i want… where’s the supply voltage? The example above doesn’t show it either.. but it must be possible, right?

After searching for more than an hour, i suddenly bumped upon a setting in the X-CTU tool (in the I/O Sampling section), that had the following description:

Configure the supply voltage high threshold.  If the supply voltage measurement equals or drops below this threshold, the supply voltage will be included in an IO sample transmission.  RANGE:0-0XFFFF

Aahh, that must be it… this setting has a default of 0, causing the supply voltage to never be included in an IO sample! I set the value to FFFF, disabled all other I/O lines on the XBee et voila:

Rcvd Frame:97 01 00 13 A2 00 40 33 1F 7A A2 ED 49 53 00 01 00 00 80 0A BC
FrameID=1, Command=IS, Status=0, Command Data size = 6 (01 00 00 80 0A BC)

This means there is 1 sample set, containing the supply voltage, and the value is: 0ABC.

Multiply this with 1200/1024 and you get the supply voltage in mV:

($0ABC =) 2748 * 1200/1024 = 3220 mV. Great!

Tomorrow i’ll add some code to my HA system to periodically send an IS command to this XBee and store the results. And then just wait and see what happens when i let a JeeNode and XBee running on alkaline batteries 24/7…

New motion sensor in use

After my problems with the MS13 sensors yesterday, i managed to find some spare time (even though, or maybe because it was father’s day) to write a sketch for the new motion sensor i created during the last couple of weeks. Always taking one step at a time, i located the first prototype of this sensor at a place where i can see the enclosure LED from the living room: i want to know how it performs…

New motion sensor

New motion sensor

Now powered by 3 rechargable NiCd batteries and with all hardware nicely put away in the enclosure. In due time the enclosure will be moved out of sight so only the PIR will be visible. I’ve decided to use 3.5 mm jack plugs to be able to disconnect the enclosure from the sensor, so i can easily take the enclosure back to my office, because i don’t think the JeeNode is already running the final version of the ‘PIR’ sketch… 🙂

A new class, 2 database records and 1 line of code were enough to get the sensor working in my Domotica system:

procedure TAMN31112.ProcessInterfaceData;
  Pin(1).AsBoolean:= (O.Data[1]='1');

The new PIR can be viewed from my website (it’s called BP PIR):

Battery powered PIR

Battery powered PIR

The sketch is still under development; for instance, how much difference would it make if i change the DigitalRead() into a bitRead()? I’ll have to read more about that on JeeLabs … Other questions are: should i increase the heartbeat interval (currently 45 seconds) or the Motion report interval? Can i create some sort of battery power monitoring with the XBee? But that will all be investigated when i’ve finished building my second motion sensor based on JeeNode and XBee..

No more!

I wonder how Homeseer users deal with this..

Cause this is what you get when the batteries of a MS13 motion sensor are empty:

MS13 jamming

Yep.. last Saturday it happened again, around noon… one of my MS13 motion sensors had empty batteries, causing it to start sending rubbish all the time. Yes.. all the time! Side effect is that all other 433 MHz traffic is being jammed, causing a spike of more than 3600 unrecognized packets being received by my RFXCOM receivers. Fortunately i have 2 of those receivers, so not all data is lost. Otherwise my whole 433 MHz sensor network would have collapsed…

This time it was the motion sensor in the kitchen that had its batteries empty. Away with it! I removed the batteries and didn’t put new ones in. For me, the MS13 motion sensor is over and done with. No more!  This is the 3rd time in 2 years i had to go hunting for an MS13 that was jamming all other traffic. And of course, the faulty MS13 was the 3rd sensor of which i removed the batteries; so now i have to reprogram 2 of them again…Yuck!

I have better things to do… like finishing my own motion sensor, with heartbeat and no reprogramming needed when batteries are replaced… yeah!

Motion sensor in next stage

This weekend i spent some time to make the experimental PIR sensor setup i made some time ago, a bit more permanent. Ingredients:

Enclosure modified with hobby knifeThe enclosure i used this time is a bit different from the enclosure i used on a previous occasion. This one lacks the inner ribs and opening and closing is a bit harder: for opening the enclosure you need to put a screwdriver between the 2 halves and twist it to get the enclosure open.  The first thing i did was making my life easier by removing the ribs that keep the 2 halves together on one side of the enclosure. Some more modifications here and there now make it possible to open the enclosure without any additional tools, but still will not open by accident.

PIR enclosurePIR enclosure

I drilled a 10 mm hole into the PIR enclosure so that the PIR fitted nicely through the top plate; a drop of super glue on the inside did the rest. There was plenty of room for the 100k pull-down resistor inside the PIR enclosure so i soldered it to the PIR there. An extra hole of 4 mm and a cable tie for the wire completed the PIR box.

JeeNode, XBee

JeeNode, XBee

This being my first motion sensor built this way, i added a LED to be able to see what the XBee radio is doing; is it still transmitting or not, when, how often, etc. ? Maybe this is overkill, but when this sensor is placed somewhere in the house with no computer screen nearby, it can be very handy to see if the sensor is still functioning instead of running to and from the nearest screen…
If the flickering of the LED is to visible or annoying in the future, i can always disable it or make it invisible by a piece of tape over it; but for now, this LED seemed like a good idea to have. The LED lights up when the XBee is on and from the duration that the LED stays on i can see what’s happening; whether it’s transmitting (very short durations) or having PAN trouble (long).

The software part of this sensor will be the most time consuming of it all i guess. Since i want it to be battery powered, i’ll have to consider what is relevant information for my Domotica system, and when it is. In fact, the only thing that really matters is one single thing: fast motion detection! All the rest is less important.
Cause what do we Domoticans use this motion detection for? To turn things ON… not OFF; at least, i don’t.

Further more, a quick look in my events history tells me that from 01-04-2010 till today i missed (my 433 MHz RFXCOM receivers, i mean) a total 869 ‘OFF’ transmissions (meaning “no motion”) from my 10 MS13 motion detectors. That’s way to much to be called reliable! So my system already has the capability to deal with this situation of missing ‘OFF’ transmissions; when a MS13 hasn’t reported neither an ‘ON’ nor an ‘OFF’ for a specific time interval, i set the motion sensor back to ‘OFF’ in software.

So.. i could as well do without this ‘OFF’ completely; i don’t use it as a trigger, so why send this non-information anyway?

What i do want to have is a heartbeat, every 90 seconds or so. And i would like to have an ‘ON’ being sent with a specific interval when motion is detected continuously. That’s what I’ll be working on in the coming week.

To be continued.

Using the things you make can be hard

Today i finished something i should have done a long time ago, and it took me more time than i had in mind…

In March 2009 i started working on a Homeseer Plugin for the Fritz!Box FON 7170. I had the hardware, created a basic call monitor for myself and because i liked to share this nice feature of this FritZ!Box, i created the Plugin. Over time this Plugin evolved and new functions were added to it, mostly based on user request. The latest that was added to the Plugin was being able to parse the Fritz’s Phonebook and using a internet search engine to find a name with the phonenumber.

Strangely enough, i have been living without this functionality for quite some time, while all the Plugin users did have it.. time to catchup with myself!

So the situation was like this: i created a piece of software in a programming language (VB.NET) that i don’t really use on a daily basis and i wanted to translate this to Delphi, a language that i’ve been using for years and in which i created my complete Domotica system; so how hard could it be? I gave myself 2 hours and it should work. Sounds reasonable? Nope.

It’s those tiny differences that make a small job larger than you would have expected.

A small example. Consider capturing a HTTP response to a string variable and you want to put this response in an array of strings. All the lines in the response are terminated by a line feed (LF, 0x0A, chr(10), etc). In VB you would do something like this:

It works like you think it would, i know  🙂

Translating this to Delphi and knowing that there is a class called TStringList that can be used to maintain a list of strings, this shouldn’t be to hard to accomplish, cause it sounds like something that could do the very same job as the ‘array of String’ equivalent in VB.

But as i said, there’s a tiny difference.. splitting the response into multiple lines didn’t work as i expected… the response was split in a way that it looked like even a space was considered a delimiter! In Delphi, i had to use a different approach and also first replace the line feed (LF) with CR+LF before i got the same effect:

It can take some time to figure out why the Phonebook isn’t being parsed… pfff

New sensor shipment

It took a while before the package arrived, but here they are:

10 1-Wire DS18B20 sensors

10 1-Wire DS18B20 sensors

These sensors are going to be used to monitor the floor heating. This floor heating is made of 5 groups which can be controlled separately (manually, however 🙁 ).

In the coming fall i want to be able to monitor the temperature decrease in each group and see what happens when i turn the knobs.. I’m not sure if this will be another job for a JeeNode with XBee or that i’ll use the EDS HA7Net this time because it’s in the neighborhood monitoring the central heating and hot water usage and it still has plenty of capacity for 10 more sensors, so we’ll see.

I don’t know where i got the idea from, probably because i went through a lot of RC hardware lately but those who don’t like soldering wires to these small DS18B20 sensor should consider this:

DS18B20 in a RC servo connector

DS18B20 in a RC servo connector

A DS18B20 fits perfectly in a RC servo connector; they come with 3 wires and you can buy these connectors in any RC hobby shop; this picture only shows the connector without the wire, cause i cut it off years ago for whatever reason. The male connector on the other end of the wire will fit (with a little bit of help) in a 0.1″ raster, like a breadboard..  good for building a test setup without any soldering!

Small sensor enclosures

Enclosures can be found in any size you can imagine; but the smaller they get, the less choice there is.

But i found this one:

Small enclosure compared to a MS-13 This reduces the visible size of a motion sensor with more than a half and there’s no more antenna, yippee !

I never liked those MS13 motion sensors because of their size, but they worked ok so i just had to live with them… until now! 🙂

I placed the new sensor on the door frame next to an existing MS13. What a difference! The enclosure only contains the sensor; all the rest (batteries, JeeNode and XBee module) are located elsewhere; nearby, but out of sight. A wire running from the sensor to the other hardware can be hidden very easily, so all that remains to be seen is this enclosure, measuring 44 x 30 x 15 mm…

Soldering a new JeeNode, connecting the battery holder and the XBee and putting it in an enclosure is all that’s left to do now; so more results can be expected later this week. Exciting!