Android SDK

Installation

It is recommended to install through JCenter. First, add JCenter as a repository in the root build.gradle file:

...
buildscript {
    ...
    repositories {
        ...
        jcenter()
    }
    ...
}
...

Add the Nabto Client Edge Android library to the individual projects where it is needed. That is, add a dependency in the project level build.gradle file:

...
dependencies {
    ...
    implementation 'com.nabto.edge.client:library:1.0.+'
}
...

Hello, world!

This example client sets up a connection and connects to a device. It then makes a CoAP request to the device which has registered a CoAP endpoint called /hello-world (such as provided by the CoAP Hello, World device).

NabtoClient client = NabtoClient.create(...);
Connection connection = client.createConnection();
JSONObject options = new JSONObject();
options.put("ProductId", ...);
options.put("DeviceId", ...);
options.put("ServerKey", ...);
options.put("ServerUrl", ...);
options.put("PrivateKey", ...);
connection.updateOptions(options.toString());

connection.connect();
Coap coap = connection.createCoap("GET", "/hello-world");
coap.execute();

int statusCode = coap.getResponseStatusCode();
int contentFormat = coap.getResponseContentFormat();
byte[] payload = coap.getResponsePayload();

...

connection.close();