本文描述如何使用物联网数据分析中的二维数据可视化功能,快速接入设备位置到地图。一般在空气质量检测、基站分布、资产管理等场景,需要接入设备位置到地图上,实时展示设备的运行状态,查看并管理设备。
步骤一、创建产品
步骤二、模拟设备
使用Link Kit SDK提供的Java SDK Demo模拟设备的GPS模块。
更新时间:2020-05-07 09:38
本文描述如何使用物联网数据分析中的二维数据可视化功能,快速接入设备位置到地图。一般在空气质量检测、基站分布、资产管理等场景,需要接入设备位置到地图上,实时展示设备的运行状态,查看并管理设备。
保存设备的设备证书(ProductKey、DeviceName、DeviceSecret),以备后续使用。
使用Link Kit SDK提供的Java SDK Demo模拟设备的GPS模块。
test_case.json文件中,填好结构体子属性的json串后,文件内容如下所示。
public class HelloWorld {
private static final String TAG = "HelloWorld";
private String pk, dn;
private ThingSample thingTestManager = null;
public static void main(String[] args) {
ALog.d(TAG, "Hello world!");
ALog.setLevel(ALog.LEVEL_DEBUG);
HelloWorld manager = new HelloWorld();
ALog.d(TAG, "args=" + Arrays.toString(args));
System.out.println(System.getProperty("user.dir"));
String diPath = System.getProperty("user.dir") + "/device_id.json";
String deviceInfo = FileUtils.readFile(diPath);
if (deviceInfo == null) {
ALog.e(TAG, "main - need device info path.");
return;
}
Gson mGson = new Gson();
DeviceInfoData deviceInfoData = mGson.fromJson(deviceInfo, DeviceInfoData.class);
if (deviceInfoData == null) {
ALog.e(TAG, "main - deviceInfo format error.");
return;
}
ALog.d(TAG, "测试一机一密和物模型");
manager.init(deviceInfoData);
}
public void init(final DeviceInfoData deviceInfoData) {
this.pk = deviceInfoData.productKey;
this.dn = deviceInfoData.deviceName;
LinkKitInitParams params = new LinkKitInitParams();
/**
* 设置Mqtt初始化参数
*/
IoTMqttClientConfig config = new IoTMqttClientConfig();
config.productKey = deviceInfoData.productKey;
config.deviceName = deviceInfoData.deviceName;
config.deviceSecret = deviceInfoData.deviceSecret;
config.channelHost = pk + ".iot-as-mqtt." + deviceInfoData.region + ".aliyuncs.com:1883";
/**
* 是否接受离线消息
* 对应mqtt的cleanSession字段
*/
config.receiveOfflineMsg = false;
params.mqttClientConfig = config;
/**
* 设置初始化设备证书信息,用户传入
*/
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.productKey = pk;
deviceInfo.deviceName = dn;
deviceInfo.deviceSecret = deviceInfoData.deviceSecret;
params.deviceInfo = deviceInfo;
/**
* 设置设备当前的初始状态值,属性需要和云端创建的物模型属性一致。
* 如果这里什么属性都不填,物模型就没有当前设备相关属性的初始值。
* 用户调用物模型上报接口之后,物模型会有相关数据缓存。
*/
Map<String, ValueWrapper> propertyValues = new HashMap<String, ValueWrapper>();
// 示例
// propertyValues.put("LightSwitch", new ValueWrapper.BooleanValueWrapper(0));
params.propertyValues = propertyValues;
thingTestManager = new ThingSample(pk, dn);
LinkKit.getInstance().init(params, new ILinkKitConnectListener() {
public void onError(AError aError) {
ALog.e(TAG, "Init Error error=" + aError);
}
public void onInitDone(InitResult initResult) {
ALog.i(TAG, "onInitDone result=" + initResult);
thingTestManager.readData(System.getProperty("user.dir") + "/test_case.json");
thingTestManager.report();
}
});
}
}
其中,目标产品或设备组选择产品,并从下拉框中选择已创建的位置属性产品。
至此,您已经将您的物联网设备快速的接入到地图中了。
在文档使用中是否遇到以下问题
更多建议
匿名提交