Usage Tips for the IoT Platform: Retrieving Device Status by Calling API Operations

Image for post
Image for post

Principle

In several IoT service scenarios, the real-time status of devices is imperative for state-specific (online or offline) processing. Alibaba Cloud IoT Platform provides multiple cloud API operations for retrieving the device status. This article explains how to call these API operations.

The device status is retrievable through the following API operations. Select API operations based on your service requirements.

Image for post
Image for post

Implementation

This article uses the Java SDK as an example, which requires the Java development environment as a preliminary. In the Maven project, add the following pom dependency to install Alibaba Cloud IoT SDK.

<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-iot</artifactId>
<version>6.11.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.13</version>
</dependency>

Now, set Config. Parameters to the AccessKey ID and AccessKey secret of the Alibaba Cloud account as well as the device information, respectively.

// The region ID of your IoT Platform service. For more information, see https://help.aliyun.com/document_detail/40654.html.
private static String regionId = "cn-shanghai";
// The AccessKey ID of your Alibaba Cloud account.
private static String accessKeyID = "Config.accessKey";
// The AccessKey Secret of your Alibaba Cloud account.
private static String accessKeySecret = "Config.accessKeySecret";
// The unique identifier of the product to which the queried device belongs.
private static String productKey = "Config.productKey";
// The name of the queried device.
private static String deviceName = "Config.deviceName";

Consider the sample code below.

/*   
* Copyright © 2019 Alibaba. All rights reserved.
*/
package com.aliyun.iot.demo.checkstatus;

For more details, refer to the official product documentation.

Original Source:

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store