Skip to content

Data Listener Service

Dimitrios Amaxilatis edited this page Feb 14, 2012 · 1 revision

The Data Listener Service continuously receives all DEBUG messages generated from Testbed Runtime and is responsible for

  • identifying the sensor readings
  • extracting the information triplets containing {Device Urn, Capability Urn, Value}
  • inserting them to the WiseDB via Überdust WebApplication or JDBC/Hibernate calls.

Property File

The property file dataColletor.properties contains all properties concerning the the Testbed Runtime Listener.

 runtime.ipAddress=hostname.testbed.com
 runtime.port=9999
 testbed.session=http://hostname.testbed.com:8888/sessions
 testbed.prefix=urn:testbed:prefix:
 testbed.id=1
 sensors.names=temperature,humidity,ir
 sensors.prefixes=EM_T,EM_H,EM_I
 device.Types=iSense::,airquality::,id::

where:

  • runtime.ipAddress contains the testbed portal server url
  • runtime.port contains the testber overlay socket connector port
  • testbed.session contains the session url for testbed runtime
  • testbed.prefix contains the testbed prefix for all nodes
  • testbed.id contains the testbed id in the wisedb database
  • sensors.names contains the capability names to be associated sensor.prefixes
  • sensors.prefixes contains the names reported by the isense sensors
  • device.Types contains all possible identifiers for sensor names (mac addresses)

Connecting to Testbed-Runtime

Connection to Testbed-Runtime is done through the Overlay Socket Connector (using the Configuration described in Testbed Runtime Configuration) in order to receive messages from sensors without any reservation. Also it will be possible to receive messages from applications that are operating as part of an experiment but include some needed implementation of the default application that during the actual experiment provides the required extra information.

Extracting Sensor Readings

Sensor Readings are reported from all devices in the following format: id::SENSOR_MAC TYPE VALUE

  • SENSOR_MAC: is the hex value of the device's unique mac address. It is used as a unique identifier used to store Sensor Readings per Device. (ie id::0x9979)

  • TYPE: A unique identifier that described the type of the value (ie EM_T for Temperature).

  • VALUE: The value of the reading as a double value. (ie 20.4)

Committing new readings to WiseDB

During development we evaluated multiple techniques to commit node & link readings to the WiseDB.

MySQL Queries

The original implementation used MySQL batch queries to add readings to the WiseDB. It is simpler as an initial implementation but the user needs to implement its own methods for maintaining a connection to the database and have the exact knowledge of the database structure as well as a MySQL user and password, which makes the implementation inefficient.

    Connection conn = DriverManager.getConnection(url, username, password);
    stmt = conn.createStatement();
    stmt.addBatch("INSERT INTO...");
    stmt.addBatch("INSERT INTO...");
    stmt.addBatch("INSERT INTO...");
    ...
    int[] updateCounts = stmt.executeBatch();
    conn.commit();

Queries using Hibernate

The WiseDB implementation provides persistence managers for inserting/updating/deleting readings and metadata from the WiseDB database. With that, the user does not need to have specific knowledge of the database structure.

    NodeReadingController.getInstance().insertReading(nodeId, capabilityName, testbedId, readingValue,null, timestamp);
    LinkReadingController.getInstance().insertReading(sourceId, targetId,
       capabilityName, testbedId, reading, null, rssi, timestamp);

REST

The Überdust web application provides a RESTful interface in order to insert readings to the WiseDB by receiving HTTP GET requests in specific URLs. We provide a Java implementation of both the callers and the receivers yet with the REST interface any client that can access the web can use Überdust and store it's readings.

Using wget :

    wget http://uberdust.host.eu:8080/uberdust/rest/testbed/4/node/urn:prefix:1/capability/capability_name/insert/timestamp/101301230/reading/1.3/

Java client Method (included in our WebSocket Library) :

    final String restBaseUrl = "http://uberdust.host.eu:8080/uberdust/rest";

    // sample node readings
    NodeReading nodeReading1 = new NodeReading();
    nodeReading1.setTestbedId("1");
    nodeReading1.setNodeId("urn:ctinetwork:carrot_delete_me");
    nodeReading1.setCapabilityName("urn:ctinetwork:node:capability:lockScreen");
    nodeReading1.setTimestamp(Long.toString(new Date().getTime()));
    nodeReading1.setReading("30.2");

    // insert node reading using REST

    String result =
            InsertReadingRestClient.getInstance().callRestfulWebService(restBaseUrl + nodeReading1.toRestString());
    if (!result.contains("OK")) {
        throw new RuntimeException("Could not insert reading");
    }

WebSocket

In addition the REST interface a client can connect to Überdust via Web Sockets. Web Sockets are relatively new technology that provides bi-directional, full-duplex communications channels over a TCP socket stream. Using Web Sockets a client can use the Überdust service in a more conversational way than the REST interface thus extending Überdust as pub/sub system. Currently the Web Socket Servlet has not made it to a standard so Überdust uses a library developed only for the Resin application servlets. Clients require to use custom web socket libraries adhering to current version and protocol restrictions. An snippet of Java client using web socket follows.

    NodeReading nodeReading1 = new NodeReading();
    nodeReading1.setTestbedId("1");
    nodeReading1.setNodeId("urn:ctinetwork:carrot_delete_me");
    nodeReading1.setCapabilityName("urn:ctinetwork:node:capability:lockScreen");
    nodeReading1.setTimestamp(Long.toString(new Date().getTime()));
    nodeReading1.setReading("30.2");


    NodeReading nodeReading2 = new NodeReading();
    nodeReading2.setTestbedId("1");
    nodeReading2.setNodeId("urn:ctinetwork:carrot_delete_moi");
    nodeReading2.setCapabilityName("urn:ctinetwork:node:capability:lockScreen");
    nodeReading2.setTimestamp(Long.toString(new Date().getTime()));
    nodeReading2.setReading("30.0");

    final String webSocketUrl = "ws://uberdust.host.eu:8080/uberdust/insertreading.ws";

    InsertReadingWebSocketClient.getInstance().connect(webSocketUrl);
    InsertReadingWebSocketClient.getInstance().sendNodeReading(nodeReading1);
    InsertReadingWebSocketClient.getInstance().sendNodeReading(nodeReading2);
    InsertReadingWebSocketClient.getInstance().disconnect();

Back to Gathering Sensor Data from a Sensor Testbed