Edit me

Edgent to Quickstart quickly!

IoT devices running Edgent applications typically connect to back-end analytic systems through a message hub. Message hubs are used to isolate the back-end system from having to handle connections from thousands to millions of devices.

An example of such a message hub designed for the Internet of Things is IBM Watson IoT Platform. This cloud service runs on IBM's Bluemix cloud platform and Edgent provides a connector.

You can test out the service without any registration by using its Quickstart service and the Edgent sample application: code, Javadoc.

You can execute the class directly from Eclipse, or using the script: edgent/java8/scripts/connectors/iotp/runiotpquickstart.sh

When run it produces output like this, with a URL as the third line.

Quickstart sample output

Pointing any browser on any machine to that URL takes you to a view of the data coming from the sample application. This view is executing in Bluemix, thus the device events from this sample are being sent over the public internet to the Quickstart Bluemix service.

Here's an example view:

Quickstart service output

Edgent code

The full source is at: IotpQuickstart.java.

The first step to is to create a IotDevice instance that represents the connection to IBM Watson IoT Platform Quickstart service.

// Declare a connection to IoTP Quickstart service
String deviceId = "qs" + Long.toHexString(new Random().nextLong());
IotDevice device = IotpDevice.quickstart(topology, deviceId);

Now any stream can send device events to the Quickstart service by simply calling its events() method. Here we map a stream of random numbers into JSON as the payload for a device event is typically JSON.

TStream<JsonObject> json = raw.map(v -> {
    JsonObject j = new JsonObject();
    j.addProperty("temp", v[0]);
    j.addProperty("humidity", v[1]);
    j.addProperty("objectTemp", v[2]);
    return j;

Now we have a stream of simulated sensor reading events as JSON tuples (json) we send them as events with event identifer (type) sensors using device.

device.events(json, "sensors", QoS.FIRE_AND_FORGET);

It's that simple to send tuples on an Edgent stream to IBM Watson IoT Platform as device events.