概述
物联网数据分析,又称Link Analytics,是阿里云为物联网开发者提供的设备智能分析服务,全链路覆盖了设备数据生成、管理(存储)、清洗、分析及可视化等环节。有效降低数据分析门槛,助力物联网开发工作。物联网数据分析的主要能力包括:数据管理、数据开发、流数据分析和空间数据可视化。
本文从物联网平台产品创建开始,结合设备的创建、设备属性上报到LA数据分析:数据管理将数据存储,最后使用LA数据开发API实现数据的调用访问。
操作步骤
1、创建产品和设备
2、设备属性上报
3、LA数据存储
4、创建开发任务
5、生成API
6、SDK调用
6.1 pom.xml
<dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.3.5</version> </dependency>
6.2 code sample
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
public class demo1 {
public static void main(String[] args) throws ClientException {
String accessKey = "LTAIOZZg********";
String accessSecret = "v7CjUJCMk7j9aKduMAQLjy********";
DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Iot", "iot.cn-shanghai.aliyuncs.com");
IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret);
DefaultAcsClient acsClient = new DefaultAcsClient(profile); //初始化SDK客户端
String apiSrn = "acs:iot:*:18482178********:serveapi/getdata1";
CommonRequest request = new CommonRequest();
request.setMethod(MethodType.POST);
request.setVersion("2018-01-20");
request.setAction("InvokeDataAPIService");
request.setProduct("Iot");
request.putBodyParameter("ApiSrn", apiSrn);
request.putBodyParameter("Param.1.ParamName", "$device_name");
request.putBodyParameter("Param.1.ParamValue", "LADeviceDemo");
CommonResponse response = null;
try {
response = acsClient.getCommonResponse(request);
} catch (ClientException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
System.out.println(response.getData());
}
}
- 6.3 test result
```js
{"Data":{"ResultList":{"ResultList":[{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"},{"Data":"hello world"}]},"ApiSrn":"acs:iot::18482178*:serveapi/getdata1","FieldNameList":{"FieldNameList":["Data"]}},"RequestId":"D4C3EDDA-2F1A-4044-840A-779C85614852","Success":true}
```
更多开发语言测试可以使用Open API。