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
.
This connector is a thin wrapper over the WIoTP DeviceClient
Java API.
The constructor Properties
and optionsFile
contents are those
demanded by DeviceClient
.
For more complex use cases this connector can be constructed to use
a supplied DeviceClient
. This gives an application complete
control over the construction and configuration of the underlying
connection to WIoTP.
An application that wants to be a WIoTP managed device
and an Edgent application must construct a WIoTP ManagedDevice
instance
and construct this device connector using it.
If the following link's page doesn't render in javadoc, paste it into a browser window.
See the IBM Watson IoT Platform documentation for Developing devices at
https://internetofthings.ibmcloud.com/
See WIoTP Java Client Library Releases for general information.
See WIoTP Migration from release 0.1.5 to 0.2.1 for details of changes that occurred to device event payloads and how to revert the behavior if needed.
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_DEVICE, CMD_FORMAT, CMD_ID, CMD_PAYLOAD, CMD_TS, RESERVED_ID_PREFIX
Constructor and Description |
---|
IotpDevice(Topology topology,
com.ibm.iotf.client.device.DeviceClient deviceClient)
Create a connector using the supplied WIoTP
DeviceClient . |
IotpDevice(Topology topology,
java.io.File optionsFile)
Create a connector for the IoT device specified by
optionsFile . |
IotpDevice(Topology topology,
java.util.Properties options)
Create a connector for the IoT 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.
|
java.lang.String |
getDeviceId()
Get the device's unique opaque device identifier.
|
java.lang.String |
getDeviceType()
Get the device's opaque device type identifier.
|
TSink<com.google.gson.JsonObject> |
httpEvents(TStream<com.google.gson.JsonObject> stream,
Function<com.google.gson.JsonObject,java.lang.String> eventId,
UnaryOperator<com.google.gson.JsonObject> payload)
Publish a stream's tuples as device events using the WIoTP HTTP protocol.
|
TSink<com.google.gson.JsonObject> |
httpEvents(TStream<com.google.gson.JsonObject> stream,
java.lang.String eventId)
Publish a stream's tuples as device events using the WIoTP HTTP protocol.
|
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.
|
java.lang.String |
toString() |
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.
See the IBM Watson IoT Platform documentation for additional properties.
options
- control optionstopology
- the connector's associated Topology
.public IotpDevice(Topology topology, java.io.File optionsFile)
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.
See the IBM Watson IoT Platform documentation for additional properties.
topology
- the connector's associated Topology
.optionsFile
- File containing connection information.public IotpDevice(Topology topology, com.ibm.iotf.client.device.DeviceClient deviceClient)
DeviceClient
.topology
- the connector's associated Topology
.deviceClient
- a WIoTP device client API object.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 TSink<com.google.gson.JsonObject> httpEvents(TStream<com.google.gson.JsonObject> stream, Function<com.google.gson.JsonObject,java.lang.String> eventId, UnaryOperator<com.google.gson.JsonObject> payload)
Each tuple is published as a device event with the supplied functions
providing the event identifier and payload from the tuple.
The event identifier and payload can be generated based upon the tuple.
The event is published with the equivalent of QoS.AT_MOST_ONCE
.
stream
- Stream to be published.eventId
- function to supply the event identifier.payload
- function to supply the event's payload.public TSink<com.google.gson.JsonObject> httpEvents(TStream<com.google.gson.JsonObject> stream, java.lang.String eventId)
Each tuple is published as a device event with the fixed event identifier.
The event is published with the equivalent of QoS.AT_MOST_ONCE
.
stream
- Stream to be published.eventId
- Event identifier.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
public java.lang.String getDeviceType()
IotDevice
getDeviceType
in interface IotDevice
public java.lang.String getDeviceId()
IotDevice
getDeviceId
in interface IotDevice
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2017 The Apache Software Foundation. All Rights Reserved - 4744f56-20170226-1707