Managing factory devices with a mobile app and ARTIK Cloud

Let’s build an Android application to manage remote devices connected to ARTIK Cloud via the LWM2M protocol. This sample is perfect for industrial IoT (IIoT) use cases.

In one such scenario, a fleet of motors operates across a factory plant. The motor manufacturer, which has a service plan with the factory, needs to have remote oversight of motor status, including keeping the motors updated with the current firmware. The manufacturer manages the motors using a mobile application. 

The diagram below illustrates our remote device scenario, which uses ARTIK Cloud’s device management features.

After completing this sample, you will learn how to use the ARTIK Cloud device management task APIs to:

  • Read device properties from a remote device
  • Write device properties to a remote device
  • Execute on a remote device (e.g. reboot)

In this sample system, we use an LWM2M client simulator to simulate the remote device (e.g. a motor in the above diagram). Find the source code of the Android app at GitHub.

Installation and setup

Now let’s set up your system so that you can play with this sample.

  1. Set up at ARTIK Cloud
  2. Set up LWM2M client simulator
  3. Set up Android project

Demo

  1. On the terminal, start akc_client (an LWM2M client simulator):
    %> akc_client -n -u coaps://coaps-api.artik.cloud:5686 -d YOUR_DEVICE_ID -t YOUR_DEVICE_TOKEN 

    The device (LWM2M client) is now connected to ARTIK Cloud’s LWM2M endpoint. Once the device responds to the LWM2M operations from ARTIK Cloud, it prints out the info in the terminal.

  2. Launch the app on your Android phone and login using your account. You will see a screen with two sections. The three top buttons initiate the interaction with the device via ARTIK Cloud; specifically, reading the properties from, writing a new timezone to, or rebooting the remote LWM2M device. The bottom button is for getting the device properties from the Device Mirror on ARTIK Cloud. Clicking a button shows the corresponding responses. 

  3. Click “READ PROPERTIES FROM ARTIK CLOUD”. Some properties are shown on the screen:

  4. Click “WRITE TO DEVICE” (at the top) to request writing a new timezone (e.g.”America/Los_Angeles”) to the remote device.  The remote LWM2M device acts on the operation and prints out the following in the terminal:
    %> Resource Changed: /3/0/15 

    This says that the timezone changed, per the LWM2M object and resource definition. The device will shortly synchronize with Device Mirror in the ARTIK Cloud. On the Android app, click “READ PROPERTIES FROM ARTIK CLOUD”. Note that the timezone in the bottom section is the same as in the top section (taskParameters).  This verifies that the timezone has changed on the device and the Device Mirror.

  5. Go to the Developer Dashboard to see the status of the tasks initiated by the Android app displayed as follows:

Implementation

It is straightforward to make a POST call to create a task on ARTIK Cloud. All tasks (reading the properties from, writing a new timezone to, rebooting LWM2M devices, etc.) are similar, but use different request parameters.

The coding is even simpler using ARTIK Cloud SDKs . The following method in  ManageDeviceActivity creates the task for changing the timezone using the Java SDK:

private void createWriteTask() {
    TaskRequest writeDeviceTaskRequest = new TaskRequest();
    writeDeviceTaskRequest.dtid(Config.DEVICE_TYPE_ID);
    writeDeviceTaskRequest.dids(ArtikCloudSession.getInstance().getDeviceIDArray());
    writeDeviceTaskRequest.taskType("W");
    writeDeviceTaskRequest.setProperty("deviceProperties.device.timezone");
    writeDeviceTaskRequest.taskParameters(new TaskParameters().value(getNewTimezone()));
    try {
        ArtikCloudSession.getInstance().getDevicesManagementApi().createTasksAsync(writeDeviceTaskRequest, mCallback);  // async sample call
    } catch (ApiException exc) {
        processFailure(tag, exc);
    }
}

What’s next?

It’s easy to develop an application to perform device management using ARTIK Cloud. Read more about the device management capability and  device management tasks. In addition, try Over-The-Air update in 5 minutes to experience how simple it is to update your firmware. If you are looking for device management starter code, check out Tutorials

Interested in trying out Samsung ARTIK Cloud? Sign up for a developer account and connect devices and services while bypassing silos. We look forward to seeing your IoT solutions!