My Eldest Son (Minion #1) and I started to build a Tweet-A-Watt and failed to follow the directions correctly, namely we made both of Receivers as standard receivers instead of only one and then half populate the second XBee receiver.

Well we had two choices, either cut the extra parts off, or something else. Given that I have yet to find a Kill-A-Watt locally, and I had this external/internal thermometer I'd been wanting to computerize for 10 years, I knew what I had to do:

I had to use the Thermometer to measure the temperature of my hot tub, and then tweet it!

I had recently given Minion #1 an assignment to describe a hot tub controller with no boundaries. He mentioned, well we could make it wireless, but no, that's silly...

I love it when a 10-year plan comes to fruition.

## Step 1: Build the Xbee Recievers

The trick to the Tweet-A-Watt is the configuration . In effect you set one of the devices up to repeat the values from the Kill-A-Watt with:

ATMY=1,SM=4,ST=3,SP=C8,D4=2,D0=2,IT=13,IR=1 <return>

This sets the address (1), sets the sleep mode, timer, and period, and then sets Pins 4 and 2 to Analog input mode (2), which will send 0x13 (19 decimal) packets, 1 ms between samples.

The trick here is the Analog Input. You can read small voltages (0-5V) directly by the XBee.
In the Tweet-A-Watt you would set pins 4 and 0 to sending the Amps and Volts measured by the Kill-A-Watt. In reality it does not send that, it sends the small voltage measured by the chips in the Kill-A-Watt to the receiver XBee which is attached to a computer. The software at the computer constantly reads the packets received and it recalculates the actual voltage and amperage, and then it calculates the Wattage.

## Step 2: The Thermometer

I bought two of these Indoor/Outdoor thermometers about 10 years ago from home depot. I was always fascinated that the outside "thermometer" plugged in to the base unit with what looked like a standard audio plug. I always wondered if I could measure temperature by plugging this into a mic jack on a computer.

Turns out I probably could make it work, but it would be tricky. The plug is actually a 3/32" jack, instead of a 1/8 audio plug. This is the standard plug for cell phones for external mics. This presented a problem as I could not find any mic plugs in my piles of junk that were not surface mount. I had to buy a set form Radio Shack (\$2), which added a major delay to the project (getting to a shack was not easy).

I took one unit apart before I suddenly realized how the who thing worked, it was a voltage divider! It was obvious once I thought about it. It made life very easy.

## Step 3: What Is a Voltage Divider?

One of the best places to learn about Electronic is Wisconsin Online dividers are explained on that page (lower right), or you can visit the Voltage Wikipedia Page.

In short, if you have two resistors in series, the voltage drop across each resistor is in proportion to the size of the resistor. If you have Voltage V across a circuit of R(1) + R(2), then V = V(1) + V(2). So if V=3V and V(2) = 2V, you know that the V(1) = 1V.

Now the basis of Ohm's Law is that the current (I) is V/R. In a series circuit, the current is the same throughout, so the current through A and B is the same for the whole circuit. Therefore I = V1/R1 = V2/R2.

We know V2 = V - V1, Plugging in, we see V1/R1 = (V-V1)/R2. Solving we get R2 = R1*(V-V1)/V1
So if know if we know V(1), V, and R(2), we can solve for R2.

If we have R2, we know the value of the Thermistor!

## Step 4: What Is a Thermistor?

A thermistor is a resistor that changes resistance with the temperature. Using the techniques from the Voltage Divider to determine the Resistance, we can tell what temperature it is.

The problem is that I have some cheap thermistor in a casing from a 10 year old product. How was I suppose to create a function to go from a resistance to a temperature? Well, I have a Thermometer that it plugs into!

So I measured a lot. I copied the temperature down and then measured the resistance of the Thermistor. I placed it in the fridge, then I place it in warm water. Later I would grab room temperatures since I had time.

I supposed I could have read the Wikipedia plage can tried to guess the a and b factors, but I assumed I was using a non-linear, possible failing component that no longer matched it manufacturing specifications. Oh and I am lazy.

So I dumped all the values into Excel, and then graphed it.

I was originally worried that I had to remember the deep dark math of something like "least squared fit" when I discovered that Excell will do this for me!

Clearly I am missing gaps on the graph, but I got lots of good data around hot tub temperatures (100-105F).

While checking the room temperature ranges I noticed something, that almost makes my work worthless. The "Precise Temp" thermometer reported a 3-7 degree error between "indoor" and "outdoor" when the Thermistor was inches away! Now this might be because I mixed and matched thermistor between units, but I am betting it has more to due with quality of a 10 year old, \$10 item&

Regardless of the "accuracy" of the temperature, I needed precision and multiple tests of the same range showed very close results over days. In the long run I will likely attach the thermistor to a pipe leading into the hot tub, so I will need an offset anyway.

So by getting Excel to display the equation, I then put it into the code, and so far it is "close."

## Step 5: Transmitter Circuit

The Transmitter circuit is simple. I chose a 100 kOhm resistor for R2 since it looked like it would fit the range from the graph, and I had a spare one from desoldering various things with the Minions. I connect this in series with the Thermistor via a connector. Then I added a battery pack. I Ran 3 V to VREF and the Top of the Voltage divider and to the Xbee +3V input. I put the GND (Battery Negative) to the GND input, and to the bottom of the divider. I then connected AD0 (Volts in) to the middle of the Voltage Divider Circuit.

AD0 will read a relative voltage from VREF to V(1). So as the battery declines, the relative voltage should decline the same. Eventually I will power the unit with a local power source.

The finished unit worked fine, we connect everything with alligator clips, which made it fragile. After I got the female 3/32" connection, I place the transmitter in a random plastic tub we had (an ex-hummus container). This should protect it from weather. Since I bought "panel mount" connectors, it was as simple as drilling a hole in the plastic to add the connector to the outside with a fairly water tight connection.

Once we had that it was time to test.

## Step 6: Home, Home, Has No Range

One of the first things we noticed, was that the range died a horrible death as soon as we walked out of the office with the transmitter. We tried from a different room, and the results were terrible. 1 feet away it crapped out. Time to look at solutions.

It occurred to me that where we testing we had 4 sources of Wi Fi within 5 feet, all in the 2.5 Ghz range like the Xbee. Also we did not "aim the Xbee at all. After researching I determine I could buy a more powerfull Xbee radio (about \$23) or add antennas.

One of the things I needed was a good Range test. The X-CTU software from Digi has a "Range Test" built in, but it did notthing. I spent some time tryin gto figure out how to make it work. Actually this was as easier done than said. I did not really need the X-CTU test, just the "RX Signal Strength Indicator" (RSSI) value.

I looked in the xbee.pyTweet-A-Watt uses and right there, line 39: [code]self.rssi = p[3][/code]

Which means it is part of the Xbee return value! (xb.rssi in wattcher), so I modified a debug line for my hack:

print str(counter) +": RSSI: " + str(xb.rssi) + " | " + time.strftime("%Y %m %d, %H:%M")+ ", " + ": Voltage: " + str(CalcualtedVolts) + " avgv " + str(avgv) + " Thermistor: " + str(x) + " Temperature: " + str(Temperature)

Which produces a line like this:
373: RSSI: 82 | 2009 04 26, 11:18, : Voltage: 1.80100585938 avgv 593 Thermistor: 71.2276559865 Temperature: 78.6813444881

You can also see RSSI with processing, from Tom's Igoe's page. Though you will want to modify the packet length (at the top), as Processing complained about writing past the end of the packet buffer size. I believe you must be greater than 2 * expected packet length. Tom's code looks backwards for a previous packet which means if it misses the Ox7E packet indicator, it could run for while. Given that I am near the outer edge of measuring range, it can happen for a while. I set mine to 600 and it stopped giving me the "error, disabling serialEvent()" message.

Tom's code merely prints the latest setting, which is not all that useful for me. My debug line let's me track changes as Minion #1 wonder around.

Now we had a good way to measure, more than "hey dad we have a packet" it was time to try some home brew antenna ideas!

Using ideas from http://www.usbwifi.orconhosting.net.nz/ I have found that the Corner Cube measured a decrease in dB, though in practice did not seem to help connect a disconnected pair. The Vegatible Steamer actually was the best at aiming and reconnecting. USB Wifi's setup is much different from some other folks. The steamers have a stem in the middle which makes for easy XBee placement. A pho bowl with tin foil also see promising (though we just removed the tin foil later and held it in place). We also tried making a parabola with a bending piece of hot wheels "track," but it did not seem to help.

One of the problems is that we were testing at the outer edge of the range. Most 2.5Ghz radio, XBee especially, use spread Spectrum which means they can take a but to "sync" and then the XBee software looks for the beginning of an XBee packet before trigger. This means if you get an all or nothing effect. Either the radios lock onto each other, or not. Sometime it seems like luck, but in fact you are an antenna at these ranges and can be impacting the results.

I went to buy two steamers but then found that the cost of a steamer from the local supermarket was \$10, and for the price of 2 steamers, I can get a more powerful XBee. So I looked at a few more places and found a pretty deep strainer which has turned out even better. It was \$7. I believe the deepness is important , since I am on the transmitting end of things, it reflects more of the signal (per the notes in http://www.usbwifi.orconhosting.net.nz/number13.jpg).

End results, is that with a vegetable steamer on one end (to be replaced) and a strainer on the other, I have signal about 20-30m, from an interior office, through 3-4 walls, out to the hot tub!

Pro tip: Remember to bring the strainer in if you want 1) Your spouse to stay, and/or 2) Want steamed vegetables later.

Personally I like the petal-like appearance of the vegetable steamer.

## Step 7: Software

Starting with the Tweet-A-Wattsoftware I started hacking away at the python code. Mostly I needed to remove the Watts conversion, the history functions, and then I needed to add a number of divide by 0 protections (the Tweet-A-Watt assume packets will have data).

I then added the formula from Excel into the program and tested.

I set it to print every packet and I have lots of debug in the code to catch problems.

I tried to get the graphing portion working, but I gave up which brings me to:

Python Rant:
This is second time I have tried to do a major project in Python. I could not get all the libraries dependencies and base packages to work in under 20 hours in Windows, Windows 64, Ubuntu and Fedora. I finally had to build almost everything from scratch and even then some functions did not work. I tried 2.4, 2.5, 2.6 and various 3.X versions, and then versions of each library, which in turn had dependencies on other packages. While others may have rants against the language, I found merely installing, even using many of the "easy installers" to be daunting at best!

After I calculated the temperatures, I made a 1 degree adjustment, because I could not believe the hot tub was at 106F. I really do not believe it is at 105 either.

I then tweeked the reporting and twitter logic. Since I am not sure if I will get packets, or good packets, I chose to report the temp once an hour. I assume I will cut that back in a while.

Currently the script is running as a normal user. I will want to move it to a service eventually.

## Step 8: Next Steps

There are some obvious next steps:
1) Replace the Vegetable Strainer
a. Minions need their veggies!
b. That one was old anyway.
2) Place Hot Tub antenna under deck
a. The deck might make it even "further" but it will allow for an uglier setup.
b. I can then run the thermistor to the underside and find a better spot.
a. The easy one is an outside temperature sensor.
b. But there is no reason we could not detect the state of the control panels, espically the heat sensor that magically gets touched when kids are over.
c. Other weather sensors (wind, humidity, etc.)
d. It would be nice to control the hot tub and I could turn off heating for much of the night and day.
4) I can adjust the software
a. Minions already want better messages per temperature.
b. We should be able to respond to replies and DMs.
c. I should tweet more intelligently (less than once an hour).
d. I have some other fun things planned.
Argh, I've called my project the Tweet-A-Temp. I will change it to Tweet-A-PICAXE-Temp :-P Instructable coming soon!
Nice work! I don't know much about programming but I will eventually get a hang of it. :-) It also reminds me that I need to get to work on my instructables again... and not play some stupid online games...
Fun project. Glad you and the minion could work on this together. Thanks for sharing your tips, and I look forward to seeing progress on your next steps.