Java SDK
Overview
- The clients only support handling of JSON formatted messages currently.
- HTTP API support is provided by swagger-codegen:
WORK IN PROGRESS
Basic Usage
Applications
Simple example that initialises an application client from environment variables, connects, sends 1 command to a device, and then disconnects.
import com.google.gson.JsonObject;
import com.ibm.wiotp.sdk.app.ApplicationClient;
class simpleTest {
public static void main(String[] args) {
ApplicationClient appClient = new ApplicationClient();
appClient.registerCodec(new JsonCodec());
appClient.connect();
JsonObject data = new JsonObject();
data.addProperty("distance", 10);
appClient.publishCommand("myDeviceType", "myDeviceId", "mycommand", data);
appClient.disconnect();
}
}
Devices
Simple example that initialises a device client from environment variables, connects, sends 1 event, and then disconnects.
import com.google.gson.JsonObject;
import com.ibm.wiotp.sdk.app.DeviceClient;
class simpleTest {
public static void main(String[] args) {
DeviceClient deviceClient = new DeviceClient();
deviceClient.registerCodec(new JsonCodec());
deviceClient.connect();
JsonObject data = new JsonObject();
data.addProperty("distance", 10);
deviceClient.publishEvent("myevent", data);
deviceClient.disconnect();
}
}