This sample app will create a TaskRequest to ARTIK Cloud using the DevicesManagement Task API.
The TaskRequests will be immediately scheduled to ARTIK Cloud and will act on any connected LWM2M clients.
- ARTIK Cloud Java SDK
- LWM2M Client Simulator from LWM2M C Client SDK
- Java >= 7
-
Create a device type (or use the one you already own) in the Developer Dashboard.
-
Enable Device Management Properties for your device type. You do this in the Device Type Dashboard—> Select Your Device Type —> Select Device Management —> Click "Enable Device Properties".
-
At My ARTIK Cloud, Connect a device (or use the one you already own) of the device type. Get the device ID and token, which you will need when running the example client later.
Clone this sample and import project to your IDE
%> git clone https://github.com/artikcloud/tutorial-java-deviceManagementLWM2MStarter
Import project and Install ARTIK Cloud Java SDK
-
Import the project into your IDE. If you are using eclipse, import the project as an
existing maven project
. -
Install the ARTIK Cloud Java SDK. Use
maven
, or alternatively download jar file by searching for "artikcloud" at https://search.maven.org/ (ie:artikcloud-java-2.0.7-jar-with-dependencies.jar
) and import this jar file to your project.
Update Config.java file
Replace with your own Device Id and Device Type Id into the Config.java file. Additionally add your User Access Token to Config.java.
The ARTIK Cloud LWM2M Client SDK for C client simulator is available as a sample program. Client simulator will be used as a LWM2M device connection to ARTIK Cloud.
-
Build and run the client simulator
-
Connect your device with the LWM2M client simulator and supply the
device id
anddevice token
as parameters. Keep this connection open. The LWM2M client simulator will output to console when it receives a task%> akc_client -n -u coaps://coaps-api.artik.cloud:5686 -d YOUR_DEVICE_ID -t YOUR_DEVICE_TOKEN
-
The LWM2M client simulator will also output to console when it receives a task. Here are a couple commands to familiarize yourself with the client simulator.
To read from Object 3 / Resource 15 which is the timezone property of the device
client%> read /3/0/15 URI: /3/0/15 - Value: America/Los_Angeles
You can
write
a property in similar fashion using thechange
commandclient%> change /3/0/15 Europe/Paris
*Note: Check out the LWM2M documentation for more information on object/resources
Run the QuickStartTasks.java file which will send a read, write, and execute task.
//From callback success
TaskEnvelope:class TaskEnvelope {
data: class Task {
filter: null
taskType: W
modifiedOn: 1482279165339
dtid: dtabcdef123456789000000
statusCounts: class TaskStatusCounts {
numFailed: 0
numCancelled: 0
totalDevices: 0
numCompleted: 0
numSucceeded: 0
}
property: deviceProperties.device.timezone
id: <REDACTED-TASK-ID>
dids: [<REDACTED-DEVICE-ID>]
taskParameters: class TaskParameters {
expiresAfter: 604800
value: America/Los_Angeles
}
createdOn: 1482279165339
status: REQUESTED
}
The connected LWM2M Client Simulator will also output to screen once it receives the Task. Here we see it has received a command to reboot and the /3/0/15 resource has changed
$ ./akc_client -n -u coaps://coaps-api.artik.cloud:5686 -d yourdeviceid -t yourdevicetoken
> REBOOT
Resource Changed: /3/0/15
Checkout the Tasks you have called and their statuses within the Device Type Dashboard—> Device Management —> Tasks Dashboard.
Screenshot:
- Peek into tests in ARTIK Cloud Java SDK for more device management SDK usage examples.
- Devices Management Starter Code learn to read and write to server properties.
Devices Management Java SDK API
Devices Management LWM2M - Java Client
Devices Management LWM2M - C Client
If you are not familiar with ARTIK Cloud, we have extensive documentation at https://developer.artik.cloud/documentation
The full ARTIK Cloud API specification can be found at https://developer.artik.cloud/documentation/api-reference/
Check out advanced sample applications at https://developer.artik.cloud/documentation/samples/
To create and manage your services and devices on ARTIK Cloud, create an account at https://developer.artik.cloud
Also see the ARTIK Cloud blog for tutorials, updates, and more: http://artik.io/blog/cloud
Licensed under the Apache License. See LICENSE.
Copyright (c) 2017 Samsung Electronics Co., Ltd.