Fetch the repository succeeded.
IoT Core java sdk,包含:
| 其他场景参考 示例代码
<dependency>
<groupId>com.baidu.iot</groupId>
<artifactId>iot-device-sdk-avatar-deviceside</artifactId>
<version>1.0.2</version>
</dependency>
String iotCoreId = "yourIoTCoreId";
String deviceName = "yourDeviceKey";
String username = "yourIoTCoreId/yourDeviceKey";
char[] password = "yourDeviceSecret".toCharArray();
IoTDeviceFactory factory = new IoTDeviceFactory(IoTDeviceFactory.Config.builder()
.iotCoreId(iotCoreId)
.build());
Device device = factory.getDevice(deviceName,
MqttConfigFactory.genPlainMqttConfig(iotCoreId, username, password))
.blockingGet();
Map<PropertyKey, PropertyValue> properties = new HashMap<>();
properties.put(new PropertyKey("test"), new PropertyValue("\"test value\""));
device.updateReported(properties).blockingSubscribe(new DisposableSingleObserver<Status>() {
@Override
public void onSuccess(@NonNull Status status) {
System.out.println("Update reported success, status:" + status);
}
@Override
public void onError(@NonNull Throwable e) {
System.out.println("Update reported failure");
e.printStackTrace();
}
});
参考 创建设备 创建可以连接到iotCore的设备,再通过示例代码验证
Sign in for post a comment
Comments ( 0 )