Wireless Water Heater - Circuit...

8
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 imagina- ble 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 60 Issue 163 February 2004 CIRCUIT CELLAR ® www.circuitcellar.com I have built scores of embedded devices ranging from banking terminals to semiconductor fabrication con- trollers. These devices have used a vari- ety of processors from 4 to 32 bits. The nearly universal theme of these embed- ded devices has been communications. Few devices exist as islands unto them- selves. I have used RS-232, RS-422, RS-485, LonWorks, Ethernet, and oth- ers. 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 compa- nies, we did some pioneering work 15 years ago networking VHF radios. Those industrial products made it to mar- ket in spite of being slow and expensive (approximately $1000 per node). This sys- tem helped me understand the issues and complexities of the radio media. The design problems—such as interference, data dropouts, hidden nodes, and roaming across access points—have not changed, but they have been solved and stan- dardized with 802.11. (Well, at least 802.11b 11 Mbps is stable.) I have been enticed by some of the low- cost 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/unli- censed. But I always go back to the prob- lems 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 recov- ery, frequency hopping (if supported by the radio), and so on. Suddenly, my time- saver technology becomes a time-sink Wireless Water Heater Some people like to remotely start their cars when it’s cold outside. Dan took this idea one step further by Internet-enabling his mountainside retreat’s hydronics system. The Airborne- based system allows him to warm the house well in advance of his arrival. quagmire. So, I go back to tried-and-true options like Ethernet and RS-232. 802.11 MODULES The price of PC card 802.11b mod- ules has fallen through the floor. I often see cards from reputable compa- nies 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 FEATURE ARTICLE by Dan Beadle SRAM 128K × 3 Flash memory 512K × 3 Application processor Web server RTOS TCP/IP stack Command interface I/O support 802.11b Baseband processor MAC RF transceiver VREG 2.5 V Ground POST CONN LINK RF Status V DD 3.3 V GPIO Analog SPI Tx Rx CTS RTS ISP/Debug 2.5-V Ref 802.11b Radio T/R A/B External antenna Airborne wireless LAN node module Figure 1—The Airborne module includes everything needed for remote data acquisition and control. Copyright Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is prohibited

Transcript of Wireless Water Heater - Circuit...

Page 1: Wireless Water Heater - Circuit Cellarcircuitcellar.com/wp-content/uploads/2015/08/Beadle-CC163.pdf · that design, I plan to mount the module on a PCB with an RS-232 level shifter

Technologies announced its Airbornemodule at the Sensors Expo inAnaheim, California last September, Iordered an evaluation kit on the spot. Ibelieve that my purchase order, whichis written on the back of one of mybusiness cards, was their first order!

The Airborne evaluation kit arrivedpromptly (see Photo 1). I was surprisedthat it was completely turnkey. Eventhough I have Wi-Fi in my office, theyassume the worst and provide a completepackage, which includes all the imagina-ble cables as well as a Netgear Wi-FiGateway. Following the quick-start guide,I had the demo up and running quickly.

The Airborne module is designed tomount directly to my PCB. Althoughit has a 36-pin connector, many of thepins may be left open (see Figure 1).

Unlike the PC Card dumb radios,the Airborne module is a completeapplication processor that combines

60 Issue 163 February 2004 CIRCUIT CELLAR® www.circuitcellar.com

I have built scores of embeddeddevices ranging from banking terminalsto semiconductor fabrication con-trollers. These devices have used a vari-ety of processors from 4 to 32 bits. Thenearly universal theme of these embed-ded devices has been communications.Few devices exist as islands unto them-selves. I have used RS-232, RS-422,RS-485, LonWorks, Ethernet, and oth-ers. I am always on the lookout for abetter way of communicating.

Wireless communications always havebeen attractive. Eliminating wires makesthe product look cleaner and simplifiesconnecting. At one of my prior compa-nies, we did some pioneering work15 years ago networking VHF radios.Those industrial products made it to mar-ket in spite of being slow and expensive(approximately $1000 per node). This sys-tem helped me understand the issues andcomplexities of the radio media. Thedesign problems—such as interference,data dropouts, hidden nodes, and roamingacross access points—have not changed,but they have been solved and stan-dardized with 802.11. (Well, at least802.11b 11 Mbps is stable.)

I have been enticed by some of the low-cost radio modems. Many of them workin the 450-MHz industrial band. They areattractive because of their low cost andthe fact that they are low power/unli-censed. But I always go back to the prob-lems that we had with our VHF network:to get a good, reliable system, we wouldbe inventing RF-friendly protocols thatdeal with temporary interference recov-ery, frequency hopping (if supported bythe radio), and so on. Suddenly, my time-saver technology becomes a time-sink

Wireless Water HeaterSome people like to remotely start their cars when it’s cold outside. Dan took this idea onestep further by Internet-enabling his mountainside retreat’s hydronics system. The Airborne-based system allows him to warm the house well in advance of his arrival.

quagmire. So, I go back to tried-and-trueoptions like Ethernet and RS-232.

802.11 MODULESThe price of PC card 802.11b mod-

ules has fallen through the floor. Ioften see cards from reputable compa-nies advertised for approximately $20.This component price is attractiveand fits great into WinCE solutions.Just add a PC card interface and go.

Unfortunately, most of my deeplyembedded designs are cost-sensitive.Doing a WinCE design adds between $50and $75 for bigger CPUs, more memory,and a PC card socket. So, a $20 Wi-Ficard really costs between $70 and $95in my design. Consequently, I have notjumped on using PC Card modules.

DPAC AIRBORNE WI-FI MODULE I had been looking for an embedded

RF solution for years, so when DPAC

FEATURE ARTICLE by Dan Beadle

SRAM128K × 3

Flash memory 512K × 3

Applicationprocessor

Web serverRTOSTCP/IP stack Command interfaceI/O support

802.11bBaseband processor

MAC

RF transceiver

VREG2.5 V

Ground POST CONN LINK RF Status

VDD 3.3 V

GPIOAnalog

SPITxRx

CTSRTS

ISP/Debug

2.5-V Ref

802.11b RadioT/R A/B

External antenna

Airborne wireless LAN node module

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

Copyright Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is prohibited

Page 2: Wireless Water Heater - Circuit Cellarcircuitcellar.com/wp-content/uploads/2015/08/Beadle-CC163.pdf · that design, I plan to mount the module on a PCB with an RS-232 level shifter

www.circuitcellar.com CIRCUIT CELLAR® Issue 163 February 2004 61

ter reliability. My next thoughtwas to use simple copper to dothe hook-up. I started planninga cable from my office/DSLentry up to the logical thermo-stat location. Then I procrasti-nated. I could not bring myselfto run the wires along the sur-face of my redwood paneling.(And it was not at all feasibleto remove the paneling.)

Wireless makes the prob-lem a lot simpler: there are nowires to run, and the applica-tions processor and digital I/Oon the module make thehardware design trivial.

Normally, I set all of my thermostatsdown around 50°F to keep the pipesfrom freezing. My first-cut strategy wasto simply set the living room thermo-stat to 70°F and then use the DPACmodule to disable it. The living roommight drop below 50°F, but enoughheat will transfer from the other 50°Fzones to keep it from freezing. Then,before going up the mountain, I wouldVPN into my desk computer and use itto access the Airborne web server andturn on the living room thermostat viaa relay connected to a digital output.

Kludgy? I guess, but it’s the first-generation prototype (see Figure 2).

The first release of the Airborne webserver does not allow me to directlycontrol the digital I/O from the webserver. But it does provide a simpleway to do it via telnet by issuing com-mand line interpreter (CLI) commands.

To provide a basic layer of security,the Airborne server requires user-name/password authentication. Afterauthentication, I have access to a richset of CLI commands that let me con-trol all aspects of the module (e.g.,radio settings, network settings, anddigital I/O settings). In my case, I want-ed to use port F2, an available GPIO.

First, the port must be set to outputwith the IO-Dir F2 Out CLI com-mand, which sets the port directionregister to output. Then, controllingthe relay is as simple as IO-Write F2 1to set the relay on, and thereforeenable it to warm my house to 70°F.Although it isn’t perfect, I decided tostart with this simple solution in aneffort to protect against the possibility

the radio and a 120-MIPS webserver CPU into a small 1″ × 1.5″package. All of this costsapproximately $80. After a lit-tle fumbling to reread thedirections (Who really doesthat?), I was browsing theAirborne server from mydesktop via two wireless hops.

GETTING EMBEDDEDThe Airborne module is

designed for embedded appli-cations. Its primary purposeappears to be for remote sens-ing and control. Interfacesinclude eight digital I/O ports(3.3- and 5-V tolerant), eight analog10-bit ADC inputs with a built-in2.5-V reference, and one high-speedserial port (up to 921.6 kbps)

My imagination started running wildwith ideas about how to apply this. Iimmediately incorporated Airborneinto a bid for a system to monitor thestatus of a medical infusion pump. Forthat design, I plan to mount the moduleon a PCB with an RS-232 level shifterand a power supply, and I instantly willhave an RS-232-to-Wi-Fi converter.More importantly, I can manage thephysical packaging to attach it to mycustomer’s pump.

WIRELESS HEATER CONTROLMy mountain home, where I have

vacationed for years, is well insulated,

making it a snap for the heater systemto keep warm. I have a small, efficientheater; however, it takes forever towarm the house from a 50°F standbyto a livable 68°F. Typically, I arrivelate and shiver in my jacket for threeor four hours until the house warmsup—and that does not warm the entirehouse, just the portion needed to getthrough the night.

I had been thinking for a while aboutInternet-enabling the system. The ideawas to turn on the heater before westart up the mountain. I have DSL atthe house with a fixed IP. So, it seemedlike it would be a simple task to enablea thermostat. I considered using an X10thermostat, but, after a few of ourX10-enabled lights found a mind oftheir own, I decided that I wanted bet-

Figure 2—The heater water flow valves are controlled by a relay driven by theAirborne’s DIO port.

Power jack

DB25F DB9F

ISP and debug headerSerial port

9-V Battery Power

supply

Power

I/O S

igna

ls

Prototypingarea

Peripheral Mixed signal I/O Communication High-speed serial

TX RTS RX CTS

RS-232

WirelessLAN node

module

ANT1

ANT2

POST

LINK

WLN CFG

CONNECT

G0

G1

RF ACT

RESET

G2

G3

RP-SMA

Externalantenna

Header for development access

Figure 3—The evaluation kit includes a prototyping area and headers to connect to all of the module pins for easybreadboarding.

Copyright Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is prohibited

Page 3: Wireless Water Heater - Circuit Cellarcircuitcellar.com/wp-content/uploads/2015/08/Beadle-CC163.pdf · that design, I plan to mount the module on a PCB with an RS-232 level shifter

62 Issue 163 February 2004 CIRCUIT CELLAR® www.circuitcellar.com

heat exchanger/holding tank to supplyhot water to the faucets in the house.

The single boiler concept allows anextremely efficient heater to supply allof the house’s heating needs. Althoughmy system was state-of-the-art whenit was installed a few years ago, it isnot without limitations.

For one thing, I often find myself tak-ing a cold shower in the morning. Ihave found the 50-gallon water supplymore than adequate for three or fourpeople, but when I have a house full ofguests, I often run out of hot water. Thecooler water refilling the holding tank

of my system failing and the housefreezing—not a pleasant thought.

IN HOT WATERI have a hydronics system with a sin-

gle boiler for both my space heating andwater heating needs. The system is kindof like the boiler/radiator system, exceptthe water is not boiled, it’s just heated tobetween 180° and 200°F and circulated tothe various rooms. The same hot wateris circulated over and over throughoutthe house to rooms calling for heat. Thelower temperature results in lower pres-sures, which allows heat radiators to beplaced in creative ways. Plastic PEXcoils are placed in the floor, along thewalls, and even in the towel holders.The same recirculated water is fed to a

explains some of this. But I have specu-lated that most of the slow recovery inwinter is because the energy from thecombustion is going not only to thewater tank but also to warm the rooms.This seems really stupid. The rooms arewell insulated and may only drop 1°per hour, but the hot water tank dropsseveral degrees per minute. Why botherheating four space zones when thewater tank needs to heat my shower?

My ultimate goal is to reduce theheating control system to an embed-ded processor bolted to the heater sys-tem in the basement. Before designing

Figure 4—The selected sensors interface directly tothe Airborne’s ADC ports.

Task Server Comment Listing

Data presentation ASPX Server (1) (see Figure 3) Focuses on the user experience Heater.aspx

Data server Web service (2) Wraps the data and presents it GetZones.asmxover the ’Net to the ASPX server

Communicating with Web service (2) Interfaces to LAN via TCP/IP HeaterControllerAirborne server to Wi-Fi .vb CLI.vb

Data acquisition Airborne module (3) Acquires ADC Counts

Table 1—In addition to listing the tasks, I’ve provided you with names of the appropriate files, which you maydownload from the Circuit Cellar ftp site.

Copyright Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is prohibited

Page 4: Wireless Water Heater - Circuit Cellarcircuitcellar.com/wp-content/uploads/2015/08/Beadle-CC163.pdf · that design, I plan to mount the module on a PCB with an RS-232 level shifter

Copyright Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is prohibited

Page 5: Wireless Water Heater - Circuit Cellarcircuitcellar.com/wp-content/uploads/2015/08/Beadle-CC163.pdf · that design, I plan to mount the module on a PCB with an RS-232 level shifter

64 Issue 163 February 2004 CIRCUIT CELLAR® www.circuitcellar.com

the system, however, Iwanted to experimentwith algorithms. I could dothat faster on my desktop.So, the next step was datagathering. The most criti-cal data seemed to bemonitoring calls for heatfrom the various zones andunderstanding the heatexchanger efficiencies. Thedata I wanted is availableat the heater, not in my office.

The next step in the process ofunderstanding the system had to dowith monitoring temperatures comingout of the boiler and returning fromeach of the five zones (four spaceheating zones and one water heatingzone). To do that, I needed to connecttemperature sensors to the Airbornewireless module. I elected to use theevaluation kit because I could directlyconnect the sensors (see Figure 3).

I chose a couple simple temperaturesensors from National Semiconductor,the LM35DZ and LM61CIZ. I selectedthese two sensors for their simple

transfer functions and to cover theneeded temperature ranges.

The LM35DZ has a range from 0° to100°C. Because the water should nei-ther freeze nor boil, this sensor is ade-quate for the recirculation system. Itprovides a simple output of 10 mV per1°C. The 0- to 1000-mV output is with-in the 2.5-V range of the analog-to-digi-tal converter (ADC). The LM61CIZ isused for ambient temperatures, whichcan reach to –15°C on occasion. It pro-vides a simple output of 600 mV + 10 mVper 1°C for temperatures from –30° to100°C. Both sensors use the samehook-up (see Figure 4).

Like most analog-to-digital converters,the output is incounts rather than indirect physical meas-urements. TheAirborne module ana-log-to-digital convert-er provides 210 steps ofthe 2.5-V reference, orabout 2.4 mV percount. Applying cer-

tain formulas converts counts back totemperature. For the LM35DZ:

For the LM61CIZ:

.NET WEB SERVERI need to be able to access my heater

controller over the ’Net for it to beuseful. I have been told that the nextversion of the DPAC system will letme directly view the temperatures andcontrol the relays via Java Script. Fornow, I have to issue Airborne CLIcommands. More importantly, I musthave a degree of security. I don’t wanthackers reprogramming my shower.

I decided to use .NET technology tobuild a simple, secure system to accessthe Airborne server. The general topol-ogy is shown in Figure 5. .NET allowsprocessing to be compartmentalizedacross servers and disciplines. Refer toTable 1 to see how I broke up thetasks of displaying the current temper-atures.

This small, but powerful, systemhas several important benefits. Forinstance, the complexities of the dataacquisition system are hidden from the.aspx web programmer. Furthermore,the data server can be anywhere, anddata acquisition and display are decou-pled for simpler maintenance.

Let’s dig into the key files. I havespent most of my career programmingin C or C++. With the release of .NET,I added VB.NET to my tool kit. Unlikeprior versions of VB, I consider

Temp ADC

V

..

= Counts V

Counts

mV

× ×

2 51024

1000

6− 000 mV

× °10 CmV

mVV

Temp

= ADC Counts V

Counts

mV

= mV

× ×

×

2 51024

1000.

. 110 C

= ADC V

Counts

mV

10 C

°

× × × °2 51024

1000.V mmV

Photo 1a—The Airborne evaluation kit comes with a Wi-Fi access point, cables, and a prototypingarea. b—The DPAC module provides a complete Wi-Fi embedded processor in 1.5 square inches.

a) b)

Copyright Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is prohibited

Page 6: Wireless Water Heater - Circuit Cellarcircuitcellar.com/wp-content/uploads/2015/08/Beadle-CC163.pdf · that design, I plan to mount the module on a PCB with an RS-232 level shifter

www.circuitcellar.com CIRCUIT CELLAR® Issue 163 February 2004 65

nection with the host on port 23. Aswith the other routines, most of thecode involves catching errors. I electedto dump them to the debug consoleand continue. Read and Send routines perform

similar functions. Windows uses 2-byteUnicode characters. The ’Net is basedon ASCII. The bulk of the routinescall the system encoding methods toconvert between ASCII and Unicode.They also use the socket streamunderlying the TcpClient to performthe actual reads and writes from andto the network link.

VB.NET a real language. One of thekey features is its full support forobject-oriented programming (OOP). Ifind I program desktop applicationsmuch faster than in the past.

.NET AND INHERITANCETCP/IP clients are extremely simple

with .NET. The CLI Class inherits fromthe .NET built-in class TcpClient.This provides a rich wrapper around thelower-level Sockets class. Listing 1shows the Class Inheritance for CLI andits subclass, HeaterController.

TcpClient, a built-in .NET class,inherits from Sockets, providing aprogrammer-friendly wrapper toWindows TCP/IP socket services.CLI further refines TcpClient toprovide telnet connection setup andconversion between Unicode andANSII. Finally, HeaterControllerinherits these tools to do the realwork of sending CLI commands tothe Airborne controller and format-ting the results (see Figure 6).

CLI.VBCLI.VB provides a TCP/IP link to

the Wi-Fi bridge and ultimately accessto the Airborne module (see Listing 1).You may download the complete list-ing for this file and all of the otherfiles from the Circuit Cellar ftp site.

As you can see in Listing 1, thereare only a couple of functions that Iadded in my CLI subclass: Open,Read, and SendCR. The Open routineis where the magic happens. Theinherited TcpClient Connectmethod is used to handle all of thedetails of establishing a telnet con-

HeaterControllerZone temperature Ambient temperature

CLIOpen Telnet connectionUnicode read/send CR

Tcp Client –Sockets wrapper

Sockets –TCP/IP Routines

Figure 6—The HeaterController borrows features fromthe TCPClient through inheritance.

’Net

ASPX Web server1

23

Web service server

Wi-Fi base station

C

Figure 5—Serving up the current temperature involvesseveral computers, a Wi-Fi access point, and theDPAC Airborne module.

Copyright Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is prohibited

Page 7: Wireless Water Heater - Circuit Cellarcircuitcellar.com/wp-content/uploads/2015/08/Beadle-CC163.pdf · that design, I plan to mount the module on a PCB with an RS-232 level shifter

66 Issue 163 February 2004 CIRCUIT CELLAR® www.circuitcellar.com

HeaterController.VBAfter getting the CLI layer debugged,

I decided I needed more functionality.To keep things simple, I decided to fur-ther subclass CLI to add new function-ality. So, I created HeaterController,which inherits from CLI, which inher-its from TcpClient, and so on.HeaterController’s job is to issue

the actual CLI commands needed tomanipulate the Airborne applicationlayer. The key CLI commands are list-ed in Table 2.

I have included three public proper-ties: RelayState (r/w), AmbientTemp(ro), and ZoneTemp (ro). Other privatefunctions provide the interface to theAirborne analog-to-digital convertersand perform the count-to-temperaturecalculations.

The helper routine ADC(n) gets thecounts for a given Airborne port bysending adc-read g followed by theport number, n. It then reads theresponse and converts the hex countstring to an integer.

WEB SERVICE WRAPPERI could put the HeaterController.vb

right in the .ASPX file, but that wouldmean hosting the display page on myhome server. I don’t like that ideafrom a security standpoint. Instead, Iprefer to use a web service that sitsbehind a firewall.

GetZones.asmx provides a simpleWebMethod wrapper around theHeaterController object (seeListing 2). A cool thing about web servic-es is how easy they are to test. I invokedthe service directly from a web browser.Note that the web service passes anarray of floating-point temperatures,which are all in a readable XML format.

The Zones WebMethod builds anarray and populates it by creating aHeaterController object and usingit to get each ZoneTemp. It then closesthe object to drop the telnet connec-tion to the Airborne module.

SERVING UP THE ’NETHeater.aspx uses .NET ’Net controls

to display the data (see Listing 2).The Update routine does most of thework by creating a web services objectand using it to access the ZonesWebMethod running on a different

(and firewalled) computer. Updatesimply fetches the temperatures foreach zone and populates a text box.

Two buttons are provided. One con-verts between Fahrenheit and Celsius,and the other forces an immediateupdate of the web page.

I used one little trick to store theF/C state. With web pages, each server

query is an independent event. In theold days, you had to perform a lot oftricks to store state information. With.NET, ’Net controls automaticallystore their state from call to call. So, Idecided to store the unit’s type in aninvisible label, SelectedUnits.Text.Other than that trick, the ASPX codeis plain vanilla.

Listing 1—These excerpts from HeaterController.vb and CLI.vb use inheritance to access Windows TCPsockets.

Imports System.Net.Sockets******************************************************************// Heater Controller - Inherits from CLI and TcpClient // See HeaterController.vb on Circuit Cellar ftp site******************************************************************Public Class HeaterControllerInherits CLIReadOnly Property AmbientTemp() As Integer ' Ambient Temp in CGetReturn LM65(2) � Ambient is ADC port 2

End GetEnd Property' ADC Conversion Routine for AmbientPrivate Function LM65(ByVal Port As Integer) As Integer ' Read LM65Dim V As Single = ADC(Port) / 1024 * 2.5 * 100 - 60Return Int(V + 0.5)

End Function' ADC Access RoutinePrivate Function ADC(ByVal Port As Integer) As IntegerMe.SendCr("adc-read g" + Port.ToString())System.Threading.Thread.Sleep(100) ' Wait for responseDim R As String = Me.Read()Dim i As Integer = R.IndexOf("0x") ' replace 0x with &hIf 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 CLIInherits TcpClientDim Stream As NetworkStream ' The Socket stream' Open Telnet Connection with remote hostOverridable Sub Open(ByVal hostname As String)TryMe.Connect(hostname, 23) ' Open host on telnet portStream = GetStream() � Use inherited methodConsole.WriteLine("Telnet Connection Opened")

Catch e As SocketExceptionConsole.WriteLine("SocketException: {0}", e)

End TryEnd Sub' Read response from AirborneFunction 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

Copyright Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is prohibited

Page 8: Wireless Water Heater - Circuit Cellarcircuitcellar.com/wp-content/uploads/2015/08/Beadle-CC163.pdf · that design, I plan to mount the module on a PCB with an RS-232 level shifter

For obvious reasons, this public viewof my page does not expose the relaycontrol. Listing 3 gives a skeleton forusing the HeaterService web service..NET calls this “consuming a serv-ice.” The web page’s Load routine sim-ply creates a WS object to connect tothe web service provider Wi-FiHeateron server dan. It then invokes theZones method to return the array ofsingle precision temperatures. From

www.circuitcellar.com CIRCUIT CELLAR® Issue 163 February 2004 67

detect occupancy). Furthermore, theywill provide the option of overridingpreprogrammed temperatures, andthey will display current temperatureand target temperature.

In addition to using these sensors inthe rooms, I plan to put them outsideto monitor outside air temperature so Ican make better decisions. For exam-ple, if there is a small spread betweenthe desired and actual temperature butthe sun is shining, should I heat now,or wait for nature?

These will report to the heater con-troller in the basement. I have decided togo ahead and add a microcontroller tomanage the valves. The controller will doall the things that typical zone setbackthermostats do, but it will also integratethe outside sensors. And, for sure, it willgive priority to my shower! Stay tuned forthe ultimate Wi-Fi heater controller! I

there, I simply formatthem into a text box andmark the update time.

WHERE FROM HERE?Now that I am captur-

ing data, I am off to buildthe ultimate temperaturemanagement system. Sensors in eachroom will monitor temperature, light-ing, and motion (the latter two to help

PROJECT FILESTo download the code, go to ftp.cir-cuitcellar.com/pub/Circuit_Cellar/2004/163.

SOURCESAirborne evaluation kit andAirborne moduleDPAC Technologies Corp.(800) 642-4477www.dpactech.com

LM35DZ and LM61CIZTemperature sensorsNational Semiconductor Corp.(800) 272-9959www.national.com

Dan Beadle leads a contract productdevelopment company that takesproducts from concept to production.Dan has been developing embeddedsystems for more than 20 years. Hehas a B.A. in Physics from UC Irvineand an M.B.A. from PepperdineUniversity. You may contact him [email protected].

Listing 2—Web services wrap the HeaterController object and convert to XML—all behind the scenes.

******************************************************************Excerpts from HeaterService******************************************************************Imports System.Web.Services

<System.Web.Services.WebService(Namespace:="http://tempuri.org/HeaterService/Service1")> _

Public Class WiFiHeaterInherits System.Web.Services.WebService

<WebMethod()> _Public Function Zones() As Single()Dim Z(6) As Single ' Array of floats' Create Object to access WiFi serverDim Heater As New HeaterController("192.168.111.60") ' Local Address

Z(0) = 5 ' Zones(0) holds number of real zonesZ(1) = Heater.ZoneTemp(1)...Z(5) = Heater.ZoneTemp(5)Heater.Close()Heater.Dispose()Return Z

End FunctionEnd Class

Listing 3—These 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.LoadDim Ws As New dan.WiFiHeater ' create link to WebService on DanDim 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 zoneTextBox1.Text += "Zone " & i.ToString & ": " & Units(Z(i)) + vbCrLf

NextlblUpdated.Text = "Last Updated " & Now.ToShortTimeString()

End SubEnd Class

CLI Command Function Example

Auth Authenticate (log in) auth user pwio-write Write to port bit io-write g0 1adc-read Read ADC counts adc-read g2

Table 2—CLI commands are necessary for manipulating the Airborneapplication layer. Note that Airborne requires lowercase commands.

Copyright Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is prohibited