public class IotpDevice extends java.lang.Object implements IotDevice
IotpDevice
implements the generic device model IotDevice
and thus can be used as a connector for
IotProvider
.
Edgent generic device model
,
IBM Watson IoT Platform,
Sample application
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
QUICKSTART_DEVICE_TYPE
Device type identifier ("iotsamples-edgent") used when using the Quickstart service.
|
CMD_FORMAT, CMD_ID, CMD_PAYLOAD, CMD_TS, RESERVED_ID_PREFIX
Constructor and Description |
---|
IotpDevice(Topology topology,
java.io.File optionsFile)
Create a connector to the IBM Watson IoT Platform Bluemix service.
|
IotpDevice(Topology topology,
java.util.Properties options)
Create a connector to the IBM Watson IoT Platform Bluemix service with the device
specified by
options . |
Modifier and Type | Method and Description |
---|---|
TStream<com.google.gson.JsonObject> |
commands(java.lang.String... commands)
Create a stream of device commands as JSON objects.
|
TSink<com.google.gson.JsonObject> |
events(TStream<com.google.gson.JsonObject> stream,
Function<com.google.gson.JsonObject,java.lang.String> eventId,
UnaryOperator<com.google.gson.JsonObject> payload,
Function<com.google.gson.JsonObject,java.lang.Integer> qos)
Publish a stream's tuples as device events.
|
TSink<com.google.gson.JsonObject> |
events(TStream<com.google.gson.JsonObject> stream,
java.lang.String eventId,
int qos)
Publish a stream's tuples as device events.
|
static IotpDevice |
quickstart(Topology topology,
java.lang.String deviceId)
Create an
IotpDevice connector to the Quickstart service. |
Topology |
topology()
Topology this element is contained in.
|
public static final java.lang.String QUICKSTART_DEVICE_TYPE
public IotpDevice(Topology topology, java.util.Properties options)
options
.
options
.
org=
organization identifiertype=
device typeid=
device identifierauth-method=token
auth-token=
authorization token
Properties options = new Properties();
options.setProperty("org", "uguhsp");
options.setProperty("type", "iotsample-arduino");
options.setProperty("id", "00aabbccde03");
options.setProperty("auth-method", "token");
options.setProperty("auth-token", "AJfKQV@&bBo@VX6Dcg");
IotDevice iotDevice = new IotpDevice(options);
Connecting to the server occurs when the topology is submitted for execution.
options
- control optionstopology
- the connector's associated Topology
.public IotpDevice(Topology topology, java.io.File optionsFile)
[device]
org = organization identifier
type = device type
id = device identifier
auth-method = token
auth-token = authorization token
For example:
[device]
org = uguhsp
type = iotsample-arduino
id = 00aabbccde03
auth-method = token
auth-token = AJfKQV@&bBo@VX6Dcg
Connecting to the server occurs when the topology is submitted for execution.
topology
- the connector's associated Topology
.optionsFile
- File containing connection information.public static IotpDevice quickstart(Topology topology, java.lang.String deviceId)
IotpDevice
connector to the Quickstart service.
Quickstart service requires no-sign up to use to allow evaluation
but has limitations on functionality, such as only supporting
device events and only one message per second.topology
- the connector's associated Topology
.deviceId
- Device identifier to use for the connection.Quickstart sample application
public TSink<com.google.gson.JsonObject> events(TStream<com.google.gson.JsonObject> stream, Function<com.google.gson.JsonObject,java.lang.String> eventId, UnaryOperator<com.google.gson.JsonObject> payload, Function<com.google.gson.JsonObject,java.lang.Integer> qos)
Each tuple is published as a device event with the supplied functions
providing the event identifier, payload and QoS from the tuple.
The event identifier and Quality of Service
can be generated based upon the tuple.
events
in interface IotDevice
stream
- Stream to be published.eventId
- function to supply the event identifier.payload
- function to supply the event's payload.qos
- function to supply the event's delivery Quality of Service
.QoS
public TSink<com.google.gson.JsonObject> events(TStream<com.google.gson.JsonObject> stream, java.lang.String eventId, int qos)
Each tuple is published as a device event with fixed event identifier and QoS.
events
in interface IotDevice
stream
- Stream to be published.eventId
- Event identifier.qos
- Event's delivery Quality of Service
.QoS
public TStream<com.google.gson.JsonObject> commands(java.lang.String... commands)
commands
will result in a tuple
on the stream. The JSON object has these keys:
command
- Command identifier as a Stringtsms
- Timestamp of the command in milliseconds since the 1970/1/1 epoch.format
- Format of the command as a Stringpayload
- Payload of the command
format
is json
then payload
is JSON corresponding to the
command specific data.payload
is String
public Topology topology()
TopologyElement
topology
in interface TopologyElement
Copyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641