1 Star 0 Fork 0

百度开源 / iotcore-sdk-java

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

IoTCore sdk

IoT Core java sdk,包含:

  • 影子设备侧和控制侧sdk:隐藏了mqtt协议以及网络细节,方便用户使用物联网核心套件影子相关功能,支持多种认证方式(包含签名,ssl等),并提供上报信息,下发指令以及监听指令变化等功能。

帮助文档

  • 详细使用文档参见wiki SDK使用指南
  • 支持的java版本:1.8及以上

快速开始

| 其他场景参考 示例代码

添加maven依赖

<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的设备,再通过示例代码验证

Comments ( 0 )

Sign in for post a comment

About

Java SDK for baidu IoT Core service spread retract
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
1
https://git.oschina.net/baidu/iotcore-sdk-java.git
git@git.oschina.net:baidu/iotcore-sdk-java.git
baidu
iotcore-sdk-java
iotcore-sdk-java
main

Search