Coder Social home page Coder Social logo

iotcore-sdk-java's Introduction

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

维护者

iotcore-sdk-java's People

Contributors

xiao1z avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.