Building a Wireless Mesh Network Temperature Sensor

9,466 views

Published on

Overview of hardware and software used to build a wireless mesh network temperature sensor.

  • This is Creative Commons, so it is nonsense to not allow a download!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Building a Wireless Mesh Network Temperature Sensor

  1. 1. Building a Wireless Mesh Networked Thermometer Michael Pigg June 3, 2010This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
  2. 2. Chariot SolutionsPractical, smart software developmentpowered by Java, open source andemerging technologies
  3. 3. An engineer* walks into a room ...*Software guy with old, dusty electrical technology degree, really
  4. 4. and notices it’s too cold.
  5. 5. He walks into another and notices it’s too warm.
  6. 6. Hire someone to fix it?
  7. 7. No Way!
  8. 8. Build a system tomonitor temperature in multiple rooms.
  9. 9. Must have... Stories!• The system should be able to collect temperature data from at least 12 locations• The system should record collected temperatures in a database for later analysis• The system shall not require ripping into walls to run wires• Sensors shall not require ugly power bricks• The system should be able to control external devices
  10. 10. Temp Temp Temp Output Module Module Module Control Module TempModule Ether Control System
  11. 11. Sensor Output Voltage Analog to Temp DigitalModule Convertor Digital Value of Voltage Wireless Transmitter
  12. 12. Sensor Requirements• Low current draw• Can operate from 2 AA batteries• Output a nice linear voltage with a positive correlation to temperature• Come in a through-hole (not surface mount) package
  13. 13. MCP9700• 6 uA current draw (sweet!)• Output ranges from 0V to 2V• Comes in TO-92 package (3-pin through- hole)
  14. 14. Voltage to Temperature Tc = (V - 0.5) / 0.01 Output (V) Temp (deg C) 0 -50 0.5 0 0.75 25 0.9 40 1.2 70
  15. 15. Establishing a Reference• ADCs need a reference voltage• MCP9700 outputs 0-2V• As a practical matter, 1.2V = 70 deg C (158 F) is much warmer than I hope to measure• So a 1.2 V voltage reference should do
  16. 16. LM285LP• 1.235 V nominal shunt reference• requires only10µA to provide consistent voltage
  17. 17. Digi XBee• Wireless 2.4GHz module based on 802.15.4 spec• 100 ft indoor range• Operates on 2.8 to 3.4 V • 50mA operational • 50uA standby• Built-in Analog-to-Digital converter (ADC)
  18. 18. Major Temp Module Parts• XBee• MCP9700• LM285 (1.2 V Reference)• 2 AA batteries and holder• Case - Hammond 1593P series• SchmartBoard 2mm proto board
  19. 19. n PA i ned ig DesTop-secretPrototype
  20. 20. Wireless Module Vref Temp Sensor(under board) TextSuper Soldering Job* Professional Wiring**Not so much
  21. 21. Temp Temp Temp Module Module Module Temp EtherModule Control System
  22. 22. XBee, meet Computer• Droids makes a nice XBee to USB board• This will allow software to communicate with XBee network• Driver for USB chip is built into Linux, can be installed for Mac or Windows
  23. 23. Control SystemXBee USB
  24. 24. Speaking XBee• XBee supports two modes • AT - Acts like a modem with AT commands (hello, 1995) • API - Uses a byte protocol documented in the XBee product manual
  25. 25. XBee Interface Protocol • XBee operating in API mode • Basic frame format Start Length API-specific ChecksumDelimiter 2 bytes, MSB data 1 byte 0x7E first n bytes
  26. 26. Module Address Command • Command ID = MY • This command uses the ‘AT’ command API, which has an ID of 0x08 Start Length API-specific data ChecksumDelimiter 2 bytes, MSB n bytes 1 byte 0x7E first Frame AT Parameter API ID ID Command Value
  27. 27. Request AddressStart Length API Fr. ID Command Checksum0x7E 0x00 0x04 0x08 0x01 0x4D (M) 0x59 (Y) 0x50 Correlation 0xFF - Sum ID of data bytes
  28. 28. ResponseStart Length API Fr. ID Command0x7E 0x00 0x04 0x08 0x01 0x4D (M) 0x59 (Y) Same as request Address Checksum 0x0001 0x4F
  29. 29. This is looking ugly
  30. 30. Java: Who needsunsigned numbers?
  31. 31. Apache Mina• Java library for asynchronous I/O• Helps with • Implementing custom protocol coders and decoders • Dealing with partial packets• Provides a serial port transport so that we don’t have to deal with those details
  32. 32. XBeeLib• Implementation of XBee API protocol • Written in Java • Based on Apache Mina • Open source, BSD license • http://kenai.com/projects/xbeelib
  33. 33. XBeeLib xb Shell xmon Shell Command Command XBeeService Mina Core Mina Serial ConnectorUSB RXTX
  34. 34. XBeeLib xb Shell xmon Shell Command Command XBeeService Mina Core Command Encoder Mina Serial ConnectorUSB RXTX
  35. 35. XBeeLib xb Shell xmon Shell Command Command XBeeService Mina Core Command Response Decoder Command Encoder IO Data Frame Decoder Mina Serial ConnectorUSB RXTX
  36. 36. Control System OSGi contai ner XBeeLibXBee (transport handling)
  37. 37. OSGi• A runtime framework for Java• Software is deployed as bundles• An application is composed of one or more bundles
  38. 38. OSGi = Services• The core idea is to encourage a modular approach to building applications • Only classes explicitly declared as shared can be seen by other bundles • Provides mechanism for bundles to provide services to other bundles
  39. 39. Apache Felix• Apache implementation of OSGi standard• Provides a run-time platform for the monitoring software
  40. 40. Felix Shell• Provides an interactive console for the OSGi runtime environment• Implementing a shell command • Create class that implements Command • Register an instance of the class with the OSGi service registry
  41. 41. Demo XBeeLib
  42. 42. pHomeNet• Provides application-level services • Monitoring sensors • Acting on observations • Viewing collected observations• http://kenai.com/projects/phomenet
  43. 43. If an XBee transmits but nobody is listening...
  44. 44. Listening to XBees• xbee-listener bundle listens for incoming samples from XBee modules• Attempts to find a handler for the sample • Handlers implement XbeeAnalogDataTransfomer• If sample can be transformed to observation, call ObservationRecorder to persist in database• Post an OSGi event about the observation
  45. 45. Control System OSGi Service Registry Xbee Listener Observation Recorder Derby EclipseLink JPA XBeeLibXBee USB (transport handling)
  46. 46. Making sense of it all• temp-sensor bundle implements XbeeAnalogDataTransformer for temperature modules• Decodes samples to temperature observations• Provides ability to configure instances of temperature sensors
  47. 47. Control System OSGi Service Registry Temperature Module Services Xbee Listener Observation Recorder Derby EclipseLink JPA XBeeLibXBee USB (transport handling)
  48. 48. Demo temp-sensor bundle
  49. 49. Let’s be controlling• Switch bundle supports modules that turn outputs on/off• Listen for observation events posted by xbee-listener bundle• Provide ability to configure instances of switch modules
  50. 50. Control System OSGi Service Control Module Handler Registry Temperature Module Services Xbee Listener Observation Recorder Derby EclipseLink JPA XBeeLibXBee USB (transport handling)
  51. 51. Demo xbee-switch bundle
  52. 52. pHomeNet Status• Mostly a research project to date, despite it’s motivation• TODOs • Expand support for controllable devices • Expand sensor support (One Wire devices, external temperature probes)
  53. 53. Resources• XBee 802.15.4 OEM module • http://www.digi.com/products/wireless/point-multipoint/xbee-series1- module.jsp#overview• Droids XBee USB board • http://www.droids.it/990_002.html• MCP9700 Temperature Sensor • http://www.microchip.com/wwwproducts/Devices.aspx? dDocName=en022289

×