You are on page 1of 8

Copyright Circuit Cellar Inc.

Reproduction of this publication in whole


or in part without written consent from Circuit Cellar, Inc. is
prohibited

FEATURE ARTICLE

by Dan Beadle

Wireless Water Heater


Some people like to remotely start their cars when its cold outside. Dan took this idea one
step further by Internet-enabling his mountainside retreats hydronics system. The Airbornebased system allows him to warm the house well in advance of his arrival.

have built scores of embedded


devices ranging from banking terminals
to semiconductor fabrication controllers. These devices have used a variety of processors from 4 to 32 bits. The
nearly universal theme of these embedded devices has been communications.
Few devices exist as islands unto themselves. I have used RS-232, RS-422,
RS-485, LonWorks, Ethernet, and others. I am always on the lookout for a
better way of communicating.
Wireless communications always have
been attractive. Eliminating wires makes
the product look cleaner and simplifies
connecting. At one of my prior companies, we did some pioneering work
15 years ago networking VHF radios.
Those industrial products made it to market in spite of being slow and expensive
(approximately $1000 per node). This system helped me understand the issues and
complexities of the radio media. The
design problemssuch as interference,
data dropouts, hidden nodes, and roaming
across access pointshave not changed,
but they have been solved and standardized with 802.11. (Well, at least
802.11b 11 Mbps is stable.)
I have been enticed by some of the lowcost radio modems. Many of them work
in the 450-MHz industrial band. They are
attractive because of their low cost and
the fact that they are low power/unlicensed. But I always go back to the problems that we had with our VHF network:
to get a good, reliable system, we would
be inventing RF-friendly protocols that
deal with temporary interference recovery, frequency hopping (if supported by
the radio), and so on. Suddenly, my timesaver technology becomes a time-sink

60

Issue 163

February 2004

quagmire. So, I go back to tried-and-true


options like Ethernet and RS-232.

Technologies announced its Airborne


module at the Sensors Expo in
Anaheim, California last September, I
ordered an evaluation kit on the spot. I
believe that my purchase order, which
is written on the back of one of my
business cards, was their first order!
The Airborne evaluation kit arrived
promptly (see Photo 1). I was surprised
that it was completely turnkey. Even
though I have Wi-Fi in my office, they
assume the worst and provide a complete
package, which includes all the imaginable cables as well as a Netgear Wi-Fi
Gateway. Following the quick-start guide,
I had the demo up and running quickly.
The Airborne module is designed to
mount directly to my PCB. Although
it has a 36-pin connector, many of the
pins may be left open (see Figure 1).
Unlike the PC Card dumb radios,
the Airborne module is a complete
application processor that combines

802.11 MODULES
The price of PC card 802.11b modules has fallen through the floor. I
often see cards from reputable companies advertised for approximately $20.
This component price is attractive
and fits great into WinCE solutions.
Just add a PC card interface and go.
Unfortunately, most of my deeply
embedded designs are cost-sensitive.
Doing a WinCE design adds between $50
and $75 for bigger CPUs, more memory,
and a PC card socket. So, a $20 Wi-Fi
card really costs between $70 and $95
in my design. Consequently, I have not
jumped on using PC Card modules.

DPAC AIRBORNE WI-FI MODULE


I had been looking for an embedded
RF solution for years, so when DPAC

SRAM
128K 3

GPIO
Analog
SPI
Tx
Rx
CTS
RTS
ISP/Debug

Flash
memory
512K 3

Airborne wireless LAN node module

Application
processor
Web server
RTOS
TCP/IP stack
Command interface
I/O support

802.11b Radio
802.11b
Baseband
processor
MAC

T/R

A/B

RF
transceiver
External
antenna

VREG
2.5 V

2.5-V Ref

VDD 3.3 V

Ground

POST

CONN

LINK

RF Status

Figure 1The Airborne module includes everything needed for remote data acquisition and control.
CIRCUIT CELLAR

www.circuitcellar.com

Copyright Circuit Cellar Inc. Reproduction of this publication in whole


or in part without written consent from Circuit Cellar, Inc. is
prohibited

ter reliability. My next thought


was to use simple copper to do
the hook-up. I started planning
a cable from my office/DSL
entry up to the logical thermostat location. Then I procrastinated. I could not bring myself
to run the wires along the surface of my redwood paneling.
(And it was not at all feasible
to remove the paneling.)
GETTING EMBEDDED
Wireless makes the probThe Airborne module is
lem a lot simpler: there are no
designed for embedded appliwires to run, and the applicacations. Its primary purpose
tions processor and digital I/O
appears to be for remote sensFigure 2The heater water flow valves are controlled by a relay driven by the
Airbornes DIO port.
on the module make the
ing and control. Interfaces
hardware design trivial.
include eight digital I/O ports
Normally, I set all of my thermostats
(3.3- and 5-V tolerant), eight analog
making it a snap for the heater system
down around 50F to keep the pipes
10-bit ADC inputs with a built-in
to keep warm. I have a small, efficient
from freezing. My first-cut strategy was
2.5-V reference, and one high-speed
heater; however, it takes forever to
to simply set the living room thermoserial port (up to 921.6 kbps)
warm the house from a 50F standby
stat to 70F and then use the DPAC
My imagination started running wild
to a livable 68F. Typically, I arrive
module to disable it. The living room
with ideas about how to apply this. I
late and shiver in my jacket for three
might drop below 50F, but enough
immediately incorporated Airborne
or four hours until the house warms
into a bid for a system to monitor the
upand that does not warm the entire heat will transfer from the other 50F
zones to keep it from freezing. Then,
status of a medical infusion pump. For house, just the portion needed to get
before going up the mountain, I would
that design, I plan to mount the module through the night.
VPN into my desk computer and use it
on a PCB with an RS-232 level shifter
I had been thinking for a while about
to access the Airborne web server and
and a power supply, and I instantly will
Internet-enabling the system. The idea
turn on the living room thermostat via
have an RS-232-to-Wi-Fi converter.
was to turn on the heater before we
a relay connected to a digital output.
More importantly, I can manage the
start up the mountain. I have DSL at
Kludgy? I guess, but its the firstphysical packaging to attach it to my
the house with a fixed IP. So, it seemed
generation prototype (see Figure 2).
customers pump.
like it would be a simple task to enable
The first release of the Airborne web
a thermostat. I considered using an X10
server does not allow me to directly
thermostat, but, after a few of our
WIRELESS HEATER CONTROL
control the digital I/O from the web
X10-enabled lights found a mind of
My mountain home, where I have
server. But it does provide a simple
their own, I decided that I wanted betvacationed for years, is well insulated,
way to do it via telnet by issuing command line interpreter (CLI) commands.
ISP and debug header
POST
Serial port
To provide a basic layer of security,
LINK
DB25F
DB9F
the
Airborne server requires userPower
TX RTS RX CTS
Power
WLN CFG
jack
name/password authentication. After
CONNECT
authentication, I have access to a rich
RS-232
9-V
set of CLI commands that let me conG0
Battery
Power
trol all aspects of the module (e.g.,
supply
G1
radio settings, network settings, and
RF ACT
digital I/O settings). In my case, I wantRESET
ANT1
Wireless
ed to use port F2, an available GPIO.
Prototyping
LAN node
G2
First, the port must be set to output
area
module
ANT2
with the IO-Dir F2 Out CLI comG3
External
mand, which sets the port direction
antenna
register to output. Then, controlling
RP-SMA
the relay is as simple as IO-Write F2 1
Peripheral
Mixed signal
High-speed
Communication
I/O
to set the relay on, and therefore
serial
enable it to warm my house to 70F.
Header for development access
Although it isnt perfect, I decided to
start with this simple solution in an
Figure 3The evaluation kit includes a prototyping area and headers to connect to all of the module pins for easy
effort to protect against the possibility
breadboarding.
I/O Signals

the radio and a 120-MIPS web


server CPU into a small 1 1.5
package. All of this costs
approximately $80. After a little fumbling to reread the
directions (Who really does
that?), I was browsing the
Airborne server from my
desktop via two wireless hops.

www.circuitcellar.com

CIRCUIT CELLAR

Issue 163

February 2004

61

Copyright Circuit Cellar Inc. Reproduction of this publication in whole


or in part without written consent from Circuit Cellar, Inc. is
prohibited

Figure 4The selected sensors interface directly to


the Airbornes ADC ports.

of my system failing and the house


freezingnot a pleasant thought.

IN HOT WATER
I have a hydronics system with a single boiler for both my space heating and
water heating needs. The system is kind
of like the boiler/radiator system, except
the water is not boiled, its just heated to
between 180 and 200F and circulated to
the various rooms. The same hot water
is circulated over and over throughout
the house to rooms calling for heat. The
lower temperature results in lower pressures, which allows heat radiators to be
placed in creative ways. Plastic PEX
coils are placed in the floor, along the
walls, and even in the towel holders.
The same recirculated water is fed to a

62

Issue 163

February 2004

heat exchanger/holding tank to supply


hot water to the faucets in the house.
The single boiler concept allows an
extremely efficient heater to supply all
of the houses heating needs. Although
my system was state-of-the-art when
it was installed a few years ago, it is
not without limitations.
For one thing, I often find myself taking a cold shower in the morning. I
have found the 50-gallon water supply
more than adequate for three or four
people, but when I have a house full of
guests, I often run out of hot water. The
cooler water refilling the holding tank

explains some of this. But I have speculated that most of the slow recovery in
winter is because the energy from the
combustion is going not only to the
water tank but also to warm the rooms.
This seems really stupid. The rooms are
well insulated and may only drop 1
per hour, but the hot water tank drops
several degrees per minute. Why bother
heating four space zones when the
water tank needs to heat my shower?
My ultimate goal is to reduce the
heating control system to an embedded processor bolted to the heater system in the basement. Before designing

Task

Server

Comment

Listing

Data presentation

ASPX Server (1) (see Figure 3) Focuses on the user experience

Data server

Web service (2)

Wraps the data and presents it


GetZones.asmx
over the Net to the ASPX server

Communicating with
Airborne server

Web service (2)

Interfaces to LAN via TCP/IP


to Wi-Fi

Data acquisition

Airborne module (3)

Acquires ADC Counts

Heater.aspx

HeaterController
.vb CLI.vb

Table 1In addition to listing the tasks, Ive provided you with names of the appropriate files, which you may
download from the Circuit Cellar ftp site.

CIRCUIT CELLAR

www.circuitcellar.com

Copyright Circuit Cellar Inc. Reproduction of this publication in whole


or in part without written consent from Circuit Cellar, Inc. is
prohibited

Copyright Circuit Cellar Inc. Reproduction of this publication in whole


or in part without written consent from Circuit Cellar, Inc. is
prohibited

the system, however, I


Like most analoga)
b)
wanted to experiment
to-digital converters,
with algorithms. I could do
the output is in
that faster on my desktop.
counts rather than in
So, the next step was data
direct physical measgathering. The most critiurements. The
cal data seemed to be
Airborne module anamonitoring calls for heat
log-to-digital convertfrom the various zones and
er provides 210 steps of
Photo
1aT
he
Airborne
evaluation
kit
comes
with
a
Wi-Fi
access
point,
cables,
and
a
prototyping
understanding the heat
the 2.5-V reference, or
area. bThe DPAC module provides a complete Wi-Fi embedded processor in 1.5 square inches.
exchanger efficiencies. The
about 2.4 mV per
data I wanted is available
count. Applying cerat the heater, not in my office.
tain formulas converts counts back to
transfer functions and to cover the
The next step in the process of
temperature. For the LM35DZ:
needed temperature ranges.
understanding the system had to do
The LM35DZ has a range from 0 to
2.5 V
1000 mV

mV = ADC Counts
with monitoring temperatures coming
100C. Because the water should nei1024 Counts
V
Temp. = mV 10C
out of the boiler and returning from
ther freeze nor boil, this sensor is ade2.5 V
1000 mV
10C
= ADC

each of the five zones (four space


quate for the recirculation system. It
1024 Counts
V
mV
heating zones and one water heating
provides a simple output of 10 mV per
zone). To do that, I needed to connect
1C. The 0- to 1000-mV output is with- For the LM61CIZ:
temperature sensors to the Airborne
in the 2.5-V range of the analog-to-digi
2.5 V
wireless module. I elected to use the
tal converter (ADC). The LM61CIZ is
Temp. = ADC Counts

1024 Counts

evaluation kit because I could directly


used for ambient temperatures, which
1000 mV

10C
600 mV
connect the sensors (see Figure 3).
can reach to 15C on occasion. It proV
mV

I chose a couple simple temperature


vides a simple output of 600 mV + 10 mV
sensors from National Semiconductor, per 1C for temperatures from 30 to
.NET WEB SERVER
the LM35DZ and LM61CIZ. I selected
100C. Both sensors use the same
I need to be able to access my heater
these two sensors for their simple
hook-up (see Figure 4).
controller over the Net for it to be
useful. I have been told that the next
version of the DPAC system will let
me directly view the temperatures and
control the relays via Java Script. For
now, I have to issue Airborne CLI
commands. More importantly, I must
have a degree of security. I dont want
hackers reprogramming my shower.
I decided to use .NET technology to
build a simple, secure system to access
the Airborne server. The general topology is shown in Figure 5. .NET allows
processing to be compartmentalized
across servers and disciplines. Refer to
Table 1 to see how I broke up the
tasks of displaying the current temperatures.
This small, but powerful, system
has several important benefits. For
instance, the complexities of the data
acquisition system are hidden from the
.aspx web programmer. Furthermore,
the data server can be anywhere, and
data acquisition and display are decoupled for simpler maintenance.
Lets dig into the key files. I have
spent most of my career programming
in C or C++. With the release of .NET,
I added VB.NET to my tool kit. Unlike
prior versions of VB, I consider

64

Issue 163

February 2004

CIRCUIT CELLAR

www.circuitcellar.com

Copyright Circuit Cellar Inc. Reproduction of this publication in whole


or in part without written consent from Circuit Cellar, Inc. is
prohibited

VB.NET a real language. One of the


key features is its full support for
object-oriented programming (OOP). I
find I program desktop applications
much faster than in the past.

.NET AND INHERITANCE


TCP/IP clients are extremely simple
with .NET. The CLI Class inherits from
the .NET built-in class TcpClient.
This provides a rich wrapper around the
lower-level Sockets class. Listing 1
shows the Class Inheritance for CLI and
its subclass, HeaterController.

ASPX Web server

Net
Web
service
server
2

3
Wi-Fi base
station

Figure 5Serving up the current temperature involves


several computers, a Wi-Fi access point, and the
DPAC Airborne module.

www.circuitcellar.com

TcpClient, a built-in .NET class,


inherits from Sockets, providing a
programmer-friendly wrapper to
Windows TCP/IP socket services.
CLI further refines TcpClient to
provide telnet connection setup and
conversion between Unicode and
ANSII. Finally, HeaterController
inherits these tools to do the real
work of sending CLI commands to
the Airborne controller and formatting the results (see Figure 6).

CLI.VB
CLI.VB provides a TCP/IP link to
the Wi-Fi bridge and ultimately access
to the Airborne module (see Listing 1).
You may download the complete listing for this file and all of the other
files from the Circuit Cellar ftp site.
As you can see in Listing 1, there
are only a couple of functions that I
added in my CLI subclass: Open,
Read, and SendCR. The Open routine
is where the magic happens. The
inherited TcpClient Connect
method is used to handle all of the
details of establishing a telnet con-

CIRCUIT CELLAR

nection with the host on port 23. As


with the other routines, most of the
code involves catching errors. I elected
to dump them to the debug console
and continue.
Read and Send routines perform
similar functions. Windows uses 2-byte
Unicode characters. The Net is based
on ASCII. The bulk of the routines
call the system encoding methods to
convert between ASCII and Unicode.
They also use the socket stream
underlying the TcpClient to perform
the actual reads and writes from and
to the network link.

HeaterController
Zone temperature
Ambient temperature
CLI
Open Telnet connection
Unicode read/send CR
Tcp Client
Sockets wrapper
Sockets
TCP/IP Routines

Figure 6The HeaterController borrows features from


the TCPClient through inheritance.

Issue 163

February 2004

65

Copyright Circuit Cellar Inc. Reproduction of this publication in whole


or in part without written consent from Circuit Cellar, Inc. is
prohibited

HeaterController.VB
After getting the CLI layer debugged,
I decided I needed more functionality.
To keep things simple, I decided to further subclass CLI to add new functionality. So, I created HeaterController,
which inherits from CLI, which inherits from TcpClient, and so on.
HeaterControllers job is to issue
the actual CLI commands needed to
manipulate the Airborne application
layer. The key CLI commands are listed in Table 2.
I have included three public properties: RelayState (r/w), AmbientTemp
(ro), and ZoneTemp (ro). Other private
functions provide the interface to the
Airborne analog-to-digital converters
and perform the count-to-temperature
calculations.
The helper routine ADC(n) gets the
counts for a given Airborne port by
sending adc-read g followed by the
port number, n. It then reads the
response and converts the hex count
string to an integer.

WEB SERVICE WRAPPER


I could put the HeaterController.vb
right in the .ASPX file, but that would
mean hosting the display page on my
home server. I dont like that idea
from a security standpoint. Instead, I
prefer to use a web service that sits
behind a firewall.
GetZones.asmx provides a simple
WebMethod wrapper around the
HeaterController object (see
Listing 2). A cool thing about web services is how easy they are to test. I invoked
the service directly from a web browser.
Note that the web service passes an
array of floating-point temperatures,
which are all in a readable XML format.
The Zones WebMethod builds an
array and populates it by creating a
HeaterController object and using
it to get each ZoneTemp. It then closes
the object to drop the telnet connection to the Airborne module.

SERVING UP THE NET


Heater.aspx uses .NET Net controls
to display the data (see Listing 2).
The Update routine does most of the
work by creating a web services object
and using it to access the Zones
WebMethod running on a different

66

Issue 163

February 2004

(and firewalled) computer. Update


simply fetches the temperatures for
each zone and populates a text box.
Two buttons are provided. One converts between Fahrenheit and Celsius,
and the other forces an immediate
update of the web page.
I used one little trick to store the
F/C state. With web pages, each server

query is an independent event. In the


old days, you had to perform a lot of
tricks to store state information. With
.NET, Net controls automatically
store their state from call to call. So, I
decided to store the units type in an
invisible label, SelectedUnits.Text.
Other than that trick, the ASPX code
is plain vanilla.

Listing 1These excerpts from HeaterController.vb and CLI.vb use inheritance to access Windows TCP
sockets.
Imports System.Net.Sockets
******************************************************************
// Heater Controller - Inherits from CLI and TcpClient
// See HeaterController.vb on Circuit Cellar ftp site
******************************************************************
Public Class HeaterController
Inherits CLI
ReadOnly Property AmbientTemp() As Integer ' Ambient Temp in C
Get
Return LM65(2)
Ambient is ADC port 2
End Get
End Property
' ADC Conversion Routine for Ambient
Private Function LM65(ByVal Port As Integer) As Integer ' Read LM65
Dim V As Single = ADC(Port) / 1024 * 2.5 * 100 - 60
Return Int(V + 0.5)
End Function
' ADC Access Routine
Private Function ADC(ByVal Port As Integer) As Integer
Me.SendCr("adc-read g" + Port.ToString())
System.Threading.Thread.Sleep(100) ' Wait for response
Dim R As String = Me.Read()
Dim i As Integer = R.IndexOf("0x") ' replace 0x with &h
If i >= 0 Then R = "&h" & R.Substring(i + 2)
Return Val(R)
End Function
' See Site for complete source
End Class
******************************************************************
// TCP/IP Class to talk to Airborne module
******************************************************************
Public Class CLI
Inherits TcpClient
Dim Stream As NetworkStream
' The Socket stream
' Open Telnet Connection with remote host
Overridable Sub Open(ByVal hostname As String)
Try
Me.Connect(hostname, 23)
' Open host on telnet port
Stream = GetStream()
Use inherited method
Console.WriteLine("Telnet Connection Opened")
Catch e As SocketException
Console.WriteLine("SocketException: {0}", e)
End Try
End Sub
' Read response from Airborne
Function Read() As String
Dim Data As Byte() = New [Byte](256) {}
' Read the first batch of the TcpServer response bytes.
Dim n As Int32 = Stream.Read(Data, 0, Data.Length)
Dim s As String = System.Text.Encoding.ASCII.GetString(Data, 0, n)
Console.WriteLine("Read {0}", s)
Return s
End Function
' ..... Other methods
End Class

CIRCUIT CELLAR

www.circuitcellar.com

Copyright Circuit Cellar Inc. Reproduction of this publication in whole


or in part without written consent from Circuit Cellar, Inc. is
prohibited

For obvious reasons, this public view


of my page does not expose the relay
control. Listing 3 gives a skeleton for
using the HeaterService web service.
.NET calls this consuming a service. The web pages Load routine simply creates a WS object to connect to
the web service provider Wi-FiHeater
on server dan. It then invokes the
Zones method to return the array of
single precision temperatures. From

there, I simply format


them into a text box and
mark the update time.

WHERE FROM HERE?

CLI Command

Function

Example

Auth
io-write
adc-read

Authenticate (log in)


Write to port bit
Read ADC counts

auth user pw
io-write g0 1
adc-read g2

Table 2CLI commands are necessary for manipulating the Airborne


Now that I am capturapplication layer. Note that Airborne requires lowercase commands.
ing data, I am off to build
the ultimate temperature
management system. Sensors in each
detect occupancy). Furthermore, they
room will monitor temperature, lightwill provide the option of overriding
ing, and motion (the latter two to help preprogrammed temperatures, and
they will display current temperature
and target temperature.
Listing 2Web services wrap the HeaterController object and convert to XMLall behind the scenes.
In addition to using these sensors in
the
rooms, I plan to put them outside
******************************************************************
to monitor outside air temperature so I
Excerpts from HeaterService
******************************************************************
can make better decisions. For examImports System.Web.Services
ple, if there is a small spread between
the desired and actual temperature but
<System.Web.Services.WebService(Namespace:="http://tempuri.org/
the sun is shining, should I heat now,
HeaterService/Service1")> _
Public Class WiFiHeater
or wait for nature?
Inherits System.Web.Services.WebService
These will report to the heater controller
in the basement. I have decided to
<WebMethod()> _
go ahead and add a microcontroller to
Public Function Zones() As Single()
Dim Z(6) As Single
' Array of floats
manage the valves. The controller will do
' Create Object to access WiFi server
all the things that typical zone setback
Dim Heater As New HeaterController("192.168.111.60")
thermostats do, but it will also integrate
' Local Address
the outside sensors. And, for sure, it will
Z(0) = 5
' Zones(0) holds number of real zones
Z(1) = Heater.ZoneTemp(1)
give priority to my shower! Stay tuned for
...
the ultimate Wi-Fi heater controller! I
Z(5) = Heater.ZoneTemp(5)
Heater.Close()
Heater.Dispose()
Return Z
End Function
End Class

Listing 3These excerpts from Web Client demonstrate the consuming of a web service.
*****************************************************************
// Heater Web ASPX web page (DotNet)
*****************************************************************
Public Class WebForm1
Inherits System.Web.UI.Page
Page Load Routine - first time loaded.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim Ws As New dan.WiFiHeater
' create link to WebService on Dan
Dim Z() As Single = Ws.Zones()' Zones returns array of
temperatures
Dim i As Integer
TextBox1.Text = ""

' Clear out the text box

For i = 1 To 5
' display temp for each zone
TextBox1.Text += "Zone " & i.ToString & ": " & Units(Z(i))
+ vbCrLf
Next
lblUpdated.Text = "Last Updated " & Now.ToShortTimeString()
End Sub
End Class

www.circuitcellar.com

CIRCUIT CELLAR

Dan Beadle leads a contract product


development company that takes
products from concept to production.
Dan has been developing embedded
systems for more than 20 years. He
has a B.A. in Physics from UC Irvine
and an M.B.A. from Pepperdine
University. You may contact him at
dan.beadle@inclinesoftworks.com.

PROJECT FILES
To download the code, go to ftp.circuitcellar.com/pub/Circuit_Cellar/
2004/163.

SOURCES
Airborne evaluation kit and
Airborne module
DPAC Technologies Corp.
(800) 642-4477
www.dpactech.com
LM35DZ and LM61CIZ
Temperature sensors
National Semiconductor Corp.
(800) 272-9959
www.national.com
Issue 163

February 2004

67