//linkkit云连接过程分析
三元组信息
//1.准备设备相关的信息,三元组相关信息
HAL_GetProductKey(device_info->product_key);
HAL_GetDeviceName(device_info->device_name);
HAL_GetDeviceSecret(device_info->device_secret);
HAL_GetDeviceID(device_info->device_id);
partner_id=...
module_id=..
secure_mode=MODE_TLS_DIRECT...
timestamp_str="2524608000000"
guider_sign=...
//把device_id,device_name,product_key,timestamp_str填充到"clientId%s" "deviceName%s" "productKey%s" "timestamp%s"计算hmac签名 guider_sign
//2.conn结构体填充数据
conn->port = 1883;
conn->host_name="%s.%s", 由dev.product_key,iotx_guider_get_domain(GUIDER_DOMAIN_MQTT))组成。
conn->username="%s&%s",由dev.device_name,dev.product_key组成。
conn->password 有guider_sign组成
conn->pub_key = iotx_ca_get();
_fill_conn_string(conn->client_id, len,"%s""|securemode=%d"",timestamp=%s,signmethod=" SHA_METHOD ",gw=%d" ",ext=%d""%s""%s"
#ifdef SUPPORT_ITLS
",authtype=id2"
#endif
",%s"
#ifdef MQTT_AUTO_SUBSCRIBE
",_ss=1"
#endif
"|"
, dev.device_id
, secure_mode
, timestamp_str
, gw
, ext
, partner_id
, module_id
, LIVING_SDK_VERSION
);
//3.conn的重要字段都已准备就绪,连云
//4.上报设备信息
iotx_report_devinfo
iotx_device_info_get(&dev);
aos_get_version_hex((unsigned char *)version);
aos_get_mac_hex((unsigned char *)mac);
random_num[i] = (char)HAL_Random(0xFF);
aos_get_chip_code((unsigned char *)chip_code);
ret = aos_get_version_info((unsigned char *)version, (unsigned char *)random_num, (unsigned char *)mac,
(unsigned char *)chip_code, (unsigned char *)output, AOS_ACTIVE_INFO_LEN);
ret = HAL_Snprintf(topic_name,
IOTX_URI_MAX_LEN,
"/sys/%s/%s/thing/deviceinfo/update",
dev.product_key,
dev.device_name);
ret = HAL_GetNetifInfo(network_interfaces);
snprintf(nif_str, HAL_MAC_LEN, "WiFi|%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
/* devinfo update message */
ret = HAL_Snprintf(msg,msg_len,DEVICE_INFO_UPDATE_FMT,iotx_report_id(),output,LINKKIT_VERSION,network_interfaces);
info_report_func(pclient, topic_name, 1, msg, strlen(msg));//IOT_MQTT_Publish_Simple
//5.上报FW信息
iotx_report_firmware_version
ret = HAL_Snprintf(topic_name, IOTX_URI_MAX_LEN,"/ota/device/inform/%s/%s", dev.product_key, dev.device_name);
info_report_func(pclient, topic_name, 1, msg, strlen(msg));
//6.订阅主题
iotx_redirect_region_subscribe
snprintf(p_topic, TOPIC_LENGTH, REDIRECT_SUB_TOPIC, p_device.product_key, p_device.device_name);
ret = IOT_MQTT_Subscribe(NULL, p_topic, IOTX_MQTT_QOS0, redirect_msg_cb, NULL);
#ifdef ALCS_ENABLED
res = dm_server_connect();
snprintf(topic, ALCS_MQTT_TOPIC_MAX_LEN, ALCS_MQTT_PREFIX ALCS_MQTT_THING_LAN_PREFIX_GET_REPLY_FMT, ctx->product_key, ctx->device_name);
__alcs_mqtt_subscribe((void *)ctx, topic)
snprintf(topic, ALCS_MQTT_TOPIC_MAX_LEN, ALCS_MQTT_PREFIX ALCS_MQTT_THING_LAN_PREFIX_UPDATE_FMT, ctx->product_key, ctx->device_name);
__alcs_mqtt_subscribe((void *)ctx, topic)
snprintf(topic, ALCS_MQTT_TOPIC_MAX_LEN, ALCS_MQTT_PREFIX ALCS_MQTT_THING_LAN_PREFIX_BLACKLIST_UPDATE_FMT, ctx->product_key, ctx->device_name);
__alcs_mqtt_subscribe((void *)ctx, topic)
....
#endif
//7.订阅一堆dm主题
iotx_dm_subscribe
dm_client_subscribe_all