building a sensor network controller
play

Building a Sensor Network Controller Michael Pigg Chariot - PowerPoint PPT Presentation

Building a Sensor Network Controller Michael Pigg Chariot Solutions November 5, 2010 This work is licensed under the Creative Commons Attribution- Noncommercial-Share Alike 3.0 United States License. Friday, November 5, 2010 1 Chariot


  1. Building a Sensor Network Controller Michael Pigg Chariot Solutions November 5, 2010 This work is licensed under the Creative Commons Attribution- Noncommercial-Share Alike 3.0 United States License. Friday, November 5, 2010 1

  2. Chariot Solutions Practical, smart software development powered by Java, open source and emerging technologies Friday, November 5, 2010 2

  3. Agenda • What are we building? • Why use OSGi? • Look at interesting code features • Run the system Friday, November 5, 2010 3

  4. An engineer* walks into a room ... *Software guy with old, dusty electrical technology degree, really Friday, November 5, 2010 4

  5. and notices it’s too cold. Friday, November 5, 2010 5

  6. He walks into another and notices it’s too warm. Friday, November 5, 2010 6

  7. Hire someone to fix it? Friday, November 5, 2010 7

  8. No Way! Friday, November 5, 2010 8

  9. Build a system to monitor temperature in multiple rooms. Friday, November 5, 2010 9

  10. What should it do? Friday, November 5, 2010 10

  11. Requirements Collect temperature data from multiple locations Friday, November 5, 2010 11

  12. Requirements Record data for later analysis Friday, November 5, 2010 12

  13. Requirements No wires Friday, November 5, 2010 13

  14. Requirements Easily add new capabilities Friday, November 5, 2010 14

  15. Proposed Solution • Hardware • Custom wireless sensor module • Software • Controller software based on Apache Felix Friday, November 5, 2010 15

  16. Why OSGi and Felix? • Highly modular architecture • Capable of being updated at runtime • Already implemented solutions • console shell commands • configuration implementation • web-based configuration UI Friday, November 5, 2010 16

  17. Hardware Friday, November 5, 2010 17

  18. Sensor Module • Digi XBee wireless mesh network module • Has integrated ADC • Operates in voltage range of 2 AA batteries • Relatively low power consumption Friday, November 5, 2010 18

  19. Wireless Vref Module Temp Sensor Text (under board) Super Soldering Job* Professional Wiring* *Not so much Friday, November 5, 2010 19

  20. Life of a Node • Sleep for 5 minutes, then wake up • Sample ADC port • Send sample data over network • Go back to sleep Friday, November 5, 2010 20

  21. XBee XBee XBee XBee XBee USB Friday, November 5, 2010 21

  22. Software Friday, November 5, 2010 22

  23. XBee Communication Friday, November 5, 2010 23

  24. Connect XBee to PC • XBee to USB • Appears as serial port Friday, November 5, 2010 24

  25. XBee has custom protocol Friday, November 5, 2010 25

  26. XBeeLib • Implementation of XBee API protocol • Open source, BSD license • http://kenai.com/projects/xbeelib Friday, November 5, 2010 26

  27. Apache Mina • Eases implementation of custom protocol encoder/decoder • Support for fragmented packets • Comes with serial port transport Friday, November 5, 2010 27

  28. XBeeService XbeeLib xb Mina xbr Serial xbconfig XBee RXTX USB ManagedServiceFactory metatype.xml Config Mina Admin Core Metatype Service Indirect Exported Packages Friday, November 5, 2010 28

  29. RXTX requires native library Friday, November 5, 2010 29

  30. Where to put native library? Friday, November 5, 2010 30

  31. How to get native library installed? Friday, November 5, 2010 31

  32. Bundle-NativeCode • Parameters • path to native code in bundle JAR • osname (MacOS, Linux, etc.) • processor (x86, PowerPC, etc.) • osversion Friday, November 5, 2010 32

  33. <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.0.1</version> <extensions>true</extensions> <configuration> <instructions> <Import-Package>*</Import-Package> <Export-Package>net.michaelpigg.xbeelib.protocol,net.michaelpigg.xbeelib</Export-Package> <Embed-Dependency>rxtx,mina-transport-serial</Embed-Dependency> <Bundle-NativeCode>lib/rxtx/mac/x86_64/ librxtxSerial.jnilib; osname=MacOSX; processor=x86_64</Bundle- NativeCode> <Bundle-Activator>net.michaelpigg.xbeelib.impl.BundleActivator</Bundle-Activator> </instructions> </configuration> </plugin> Friday, November 5, 2010 33

  34. XBeeLib dependencies • Mina and most other dependencies are deployed as bundles • Mina serial transport and RXTX are embedded into XBeeLib bundle • RXTX is not OSGi-ready • Mina serial depends on RXTX Friday, November 5, 2010 34

  35. <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.0.1</version> <extensions>true</extensions> <configuration> <instructions> <Import-Package>*</Import-Package> <Export-Package>net.michaelpigg.xbeelib.protocol,net.michaelpigg.xbeelib</Export-Package> <Embed-Dependency>rxtx,mina-transport-serial</Embed- Dependency> <Bundle-NativeCode>lib/rxtx/mac/x86_64/librxtxSerial.jnilib; osname=MacOSX; processor=x86_64</Bundle- NativeCode> <Bundle-Activator>net.michaelpigg.xbeelib.impl.BundleActivator</Bundle-Activator> </instructions> </configuration> </plugin> Friday, November 5, 2010 35

  36. First Contact • XBeeLib provides simple shell commands for sending commands to XBee modules • xb - send command to local XBee • xbr - send command to remote XBee Friday, November 5, 2010 36

  37. Shell Commands • Felix provides the Gogo shell as of 3.0 • Bundles contribute commands by registering a service with two properties • osgi.command.scope • osgi.command.function Friday, November 5, 2010 37

  38. public void start(BundleContext context) throws Exception { Hashtable cmdProps = new Hashtable(); // these commands are in scope “xbee” cmdProps.put(CommandProcessor.COMMAND_SCOPE, “xbee” ); // “xb” and “xbr” are functions that can act as commands cmdProps.put(CommandProcessor.COMMAND_FUNCTION, new String[] { “xb”, “xbr” }); context.registerService( ToXbeeCommand.class.getName(), new ToXbeeCommand(context), cmdProps); } Friday, November 5, 2010 38

  39. Listing Shell Commands g! help felix:bundlelevel ..... felix:which gogo:cat .... gogo:until obr:deploy .... obr:source xbee:listports xbee:xb xbee:xbconfig xbee:xbr xbee:xmon xbee:xsample g! Friday, November 5, 2010 39

  40. Using Commands Send node discover command g! xb nd ND response: Frame ID = 109;Status = OK;Address = 0013a200403c5e93;Signal strength = 32; g! x1 = "0013a200403c5e93" 0013a200403c5e93 Request sample g! xbr $x1 is IS response: Frame ID = 11;Status = OK;Data: 010200013c g! Friday, November 5, 2010 40

  41. Transform Data Friday, November 5, 2010 41

  42. Incoming Data • Number resulting from ADC sample on XBee Friday, November 5, 2010 42

  43. XbeeAnalogData Transformer Interface • Implementations convert raw ADC reading to useful data • TemperatureSensorTransformer does this for our temperature sensor hardware Friday, November 5, 2010 43

  44. xbee-temp-sensor bundle xbee- listener XbeeAnalogDataTransfomer temp- sensor metatype.xml ManagedServiceFactory Config Metatype Admin Friday, November 5, 2010 44

  45. Sample with no Transformer g! xsample $x1 Command returned with status OK Raw data in response:1200dd Number of samples 1 Digital I/O No digital I/O data in response. Analog Data 1: DD(221) g! Friday, November 5, 2010 45

  46. Configuring Temperature Sensors Friday, November 5, 2010 46

  47. Config file? Friday, November 5, 2010 47

  48. NO! Friday, November 5, 2010 48

  49. Configuration Admin Service • Stores configuration for a service • Sends configuration to service • at startup • when configuration changes Friday, November 5, 2010 49

  50. ManagedService or ManagedServiceFactory? • ManagedService • Configures at most one instance • ManagedServiceFactory • Configures one or more instances Friday, November 5, 2010 50

  51. We need to configure multiple sensors Friday, November 5, 2010 51

  52. Implementation • Make up a PID • Implement ManagedServiceFactory • Register implementation as a service with the chosen PID Friday, November 5, 2010 52

  53. public class XbeeTemperatureSensorFactory implements ManagedServiceFactory { public void updated (String pid, Dictionary properties) throws ConfigurationException { // get configuration properties and copy to registration properties String address = properties.get(LOCATION_ADDRESS); String name = properties.get(LOCATION_NAME); Dictionary<String, String> registrationProperties = new Hashtable<String, String>(); registrationProperties.put( LOCATION_NAME, name); registrationProperties.put( LOCATION_ADDRESS, address); // create new transformer TemperatureSensorTransformer transformer = new TemperatureSensorTransformer(); // register newly configured transformer ServiceRegistration registration = bundleContext.registerService( XbeeAnalogDataTransformer.class.getName(), transformer, registrationProperties); } } Friday, November 5, 2010 53

Recommend


More recommend