通过MQTT消息配网

通过服务端下发的MQTT消息添加设备。

1. 配置依赖

    implementation 'com.tonyodev.fetch2:fetch2:3.0.3'
    implementation 'com.tonyodev.fetch2okhttp:fetch2okhttp:3.0.3'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.12.3'
    implementation 'com.google.protobuf:protobuf-javalite:3.8.0'
    implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'

2. 获取 INetConfigManager

IPCServiceManager.getInstance()
.getService(IPCServiceManager.IPCService.NET_CONFIG_SERVICE);

3. 配置authorkey & uuid

INetConfigManager.setAuthorKey(String authorKey);

INetConfigManager.setUserId(String userId);

4. 设置配网回调初始化SDK

仅配网接入:

iNetConfigManager.configNetInfo(new INetConfigManager.NetConfigCallback() {
            @Override
            public void configOver(boolean first, String token) {
            IMediaTransManager transManager = IPCServiceManager.getInstance().getService(IPCServiceManager.IPCService.MEDIA_TRANS_SERVICE);
            
            transManager.initIoTSDK(token, productId, uuid, authorKey);

            }
        });

接入IPC:

iNetConfigManager.configNetInfo(new INetConfigManager.NetConfigCallback() {
            @Override
            public void configOver(boolean first, String token) {
            IMediaTransManager transManager = IPCServiceManager.getInstance().getService(IPCServiceManager.IPCService.MEDIA_TRANS_SERVICE);
            
            transManager.initTransSDK(token, "/sdcard/", "/sdcard/", "", "", "");

            }
        });

Last updated