产品动态
HAL_API | 说明 |
HAL_SetDevInfo | 设备信息写入 |
HAL_GetDevInfo | 设备信息读取 |
ProductID/DeviceName/DeviceSecret/Cert/Key文件)配置在 SDK 中才能正确运行示例。在开发阶段,SDK 提供两种方式存储设备信息:platform/os/xxx/HAL_Device_xxx.c中修改设备信息,在无文件系统的平台下可以使用这种方式。/* product Id */static char sg_product_id[MAX_SIZE_OF_PRODUCT_ID + 1] = "PRODUCT_ID";/* device name */static char sg_device_name[MAX_SIZE_OF_DEVICE_NAME + 1] = "YOUR_DEV_NAME";#ifdef DEV_DYN_REG_ENABLED/* product secret for device dynamic Registration */static char sg_product_secret[MAX_SIZE_OF_PRODUCT_SECRET + 1] = "YOUR_PRODUCT_SECRET";#endif#ifdef AUTH_MODE_CERT/* public cert file name of certificate device */static char sg_device_cert_file_name[MAX_SIZE_OF_DEVICE_CERT_FILE_NAME + 1] = "YOUR_DEVICE_NAME_cert.crt";/* private key file name of certificate device */static char sg_device_privatekey_file_name[MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME + 1] = "YOUR_DEVICE_NAME_private.key";#else/* device secret of PSK device */static char sg_device_secret[MAX_SIZE_OF_DEVICE_SECRET + 1] = "YOUR_IOT_PSK";#endif
device_info.json文件修改设备信息,此方式下更改设备信息不需重新编译 SDK,在 Linux/Windows 平台下开发推荐使用这种方式。{"auth_mode":"KEY/CERT","productId":"PRODUCT_ID","productSecret":"YOUR_PRODUCT_SECRET","deviceName":"YOUR_DEV_NAME","key_deviceinfo":{"deviceSecret":"YOUR_IOT_PSK"},"cert_deviceinfo":{"devCertFile":"YOUR_DEVICE_CERT_FILE_NAME","devPrivateKeyFile":"YOUR_DEVICE_PRIVATE_KEY_FILE_NAME"},"subDev":{"sub_productId":"YOUR_SUBDEV_PRODUCT_ID","sub_devName":"YOUR_SUBDEV_DEVICE_NAME"}}
static DeviceInfo sg_devInfo;static int _setup_connect_init_params(MQTTInitParams* initParams){int ret;ret = HAL_GetDevInfo((void *)&sg_devInfo);if(QCLOUD_ERR_SUCCESS != ret){return ret;}initParams->device_name = sg_devInfo.device_name;initParams->product_id = sg_devInfo.product_id;......}
static int _serialize_connect_packet(unsigned char *buf, size_t buf_len, MQTTConnectParams *options, uint32_t *serialized_len) {............int username_len = strlen(options->client_id) + strlen(QCLOUD_IOT_DEVICE_SDK_APPID) + MAX_CONN_ID_LEN + cur_timesec_len + 4;options->username = (char*)HAL_Malloc(username_len);get_next_conn_id(options->conn_id);HAL_Snprintf(options->username, username_len, "%s;%s;%s;%ld", options->client_id, QCLOUD_IOT_DEVICE_SDK_APPID, options->conn_id, cur_timesec);#if defined(AUTH_WITH_NOTLS) && defined(AUTH_MODE_KEY)if (options->device_secret != NULL && options->username != NULL) {char sign[41] = {0};utils_hmac_sha1(options->username, strlen(options->username), sign, options->device_secret, options->device_secret_len);options->password = (char*) HAL_Malloc (51);if (options->password == NULL) IOT_FUNC_EXIT_RC(QCLOUD_ERR_INVAL);HAL_Snprintf(options->password, 51, "%s;hmacsha1", sign);}#endif......}
文档反馈