认证与连接

本文主要介绍如何进行SDK初始化,建立设备与云端的连接。

设置参数

IotArguments_t arguments;
arguments.isAutoReconnect = true;
arguments.pIdentifier = IOT_IDENTIFIER;
arguments.securedConnection = IOT_SECURED_CONNECTION;
arguments.pHostName = IOT_SERVER_HOST;
arguments.port = IOT_SERVER_PORT;
arguments.pProductKey = pProductKey;
arguments.pDeviceName = pDeviceName;
arguments.pDeviceSecret = pDeviceSecret;
arguments.pRootCaPath = IOT_ROOT_CA;
arguments.pClientCertPath = IOT_CLIENT_CERT;
arguments.pPrivateKeyPath = IOT_PRIVATE_KEY;
arguments.pUserName = "";
arguments.pPassword = "";

设置回调

IotClientCallback_t callback;
callback.cbConnect = cbConnect;
callback.cbConnectFailure = cbConnectFailure;
callback.cbDisconnect = cbDisconnect;
callback.cbGetProperties = cbGetProperties;
callback.cbSetProperties = cbSetProperties;
callback.cbCallServices = cbCallServices;
callback.cbUploadStatus = cbUploadStatus;
callback.cbUploadResponses = cbUploadResponses;

初始化连接

IotClient_Init(callback, arguments);
IotClient_LocalPath(".");
IotClient_InitCloudLog(false, 2, 20);
IotClient_Connect();

results matching ""

    No results matching ""