Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Serial Port Autodetection 0.8

danbim edited this page Jan 3, 2012 · 2 revisions

It's nicer to not having to edit config files Testbed Runtime implements means to auto-detect the sensor nodes serial port (e.g. /dev/ttyUSB0 or COM1) so that you don't have to update configuration files if you unplug and plug in again any sensor node.

Please note that the current implementation seems to be not working on Windows 7. Linux, Mac OS X and Windows XP seem to work fine, though.

The implementation works as follows: as Java is unbelievable bad with USB we're using native code here, i.e. on Linux we use a Perl-Script, on Windows there's an .exe file and on MAC OS X there's be a Perl script, too. The "devicelist" module of wsn-device-utils ships a jar that contains all dependencies and the native script/exe. At runtime this script/exe will be copied on some temporary folder like /tmp, executed and it's output will be parsed. The script delivers the following information (that is basically a CSV file):

        , /dev/ttyUSB0, isense
XBQTBYH2, /dev/ttyUSB1, telosb
        , /dev/ttyUSB2, isense
XBQTO21W, /dev/ttyUSB3, telosb
        , /dev/ttyUSB4, isense
XBQTCNPG, /dev/ttyUSB5, telosb
0001    , /dev/ttyUSB6, pacemate
0001    , /dev/ttyUSB7, pacemate
0001    , /dev/ttyUSB8, pacemate

So, as you can see it is easy to identify Telos B nodes as they have a unique ID in the first column. Pacemates and iSense node are also easy to identify as our device drivers (see [3]) can query the MAC address of the node by using hardware functionality. Unfortunately, this does not work for Telos B nodes.

Testbed Runtime 0.8 introduces the new WSNDeviceObserver class that observes serial ports using the scripts above and determines the MAC address of newly attached devices. It then fires an event to which Testbed Runtimes iWSN gateway application listens, thereby enabling it to (re-)connect to the device as soon as it is available. In order to use serial port autodetection and automatic (re-)connection you must configure your tr.iwsn-testbed.xml file according to this example:

<tr:testbed xmlns:tr="http://itm.uniluebeck.de/tr/xml">
  <nodes id="testbeduzl01.itm.uni-luebeck.de">
    // ...
    <applications>
    <application factoryclass="de.uniluebeck.itm.tr.runtime.wsndeviceobserver.WSNDeviceObserverFactory" name="WSNDeviceObserver">
      <do:wsnDeviceObserver xmlns:do="http://itm.uniluebeck.de/tr/runtime/wsndeviceobserver/config">
        <mapping mac="0x221e" usbchipid="XBUNEJDX"/>
        ...
      </do:wsnDeviceObserver>
    </application>
    <application factoryclass="de.uniluebeck.itm.tr.runtime.wsnapp.WSNDeviceAppFactory" name="WSNDeviceApp-urn:wisebed:uzl1:0x221e">
      <wsnd:wsnDevice xmlns:wsnd="http://itm.uniluebeck.de/tr/runtime/wsnapp/xml">
        <urn>urn:wisebed:uzl1:0x221e</urn>
        <type>telosb</type>
      </wsnd:wsnDevice>
    </application>
    <application factoryclass="de.uniluebeck.itm.tr.runtime.wsnapp.WSNDeviceAppFactory" name="WSNDeviceApp-urn:wisebed:uzl1:0x211c">
      <wsnd:wsnDevice xmlns:wsnd="http://itm.uniluebeck.de/tr/runtime/wsnapp/xml">
        <urn>urn:wisebed:uzl1:0x211c</urn>
        <type>isense48</type>
      </wsnd:wsnDevice>
    </application>
    </applications>
    // ...
  </nodes>
</tr:testbed>

As you can see the iSense and Pacemate nodes can be configured by simple configuring the URN and the type of the node. The MAC address will be derived from the URN suffix that has to be identical to the nodes' MAC address. For Telos B we need this piece of extra information that is contained in the <mapping>-tags of the WSNDeviceObserver application to let its implementation know which USB chip ID belongs to which MAC address.