更新时间:2022-02-21 GMT+08:00
LiteOS SDK端云互通组件初始化
在入口函数中,需要调用atiny_init()进行agent tiny的初始化相关操作。
接口名 |
描述 |
int atiny_init(atiny_param_t* atiny_params, void** phandle) |
LiteOS SDK端云互通组件的初始化接口,由LiteOS SDK端云互通组件实现,设备调用。 参数列表:参数atiny_params为入参,包含初始化操作所需的各个变量,具体请参考服务器参数结构体atiny_param_t;参数phandle为出参,表示当前创建的agent tiny的句柄。 返回值:整形变量,标识初始化成功或失败的状态。 |
对于入参atiny_params的设定,要根据具体的业务来进行。开发者可以参考下面的代码。
#ifdef CONFIG_FEATURE_FOTA hal_init_ota(); //若定义FOTA功能,则需进行FOTA相关初始化 #endif #ifdef WITH_DTLS device_info->endpoint_name = g_endpoint_name_s; //加密设备验证码 #else device_info->endpoint_name = g_endpoint_name; //非加密设备验证码 #endif #ifdef CONFIG_FEATURE_FOTA device_info->manufacturer = "Lwm2mFota"; //设备厂商 device_info->dev_type = "Lwm2mFota"; //设备类型 #else device_info->manufacturer = "Agent_Tiny"; #endif atiny_params = &g_atiny_params; atiny_params->server_params.binding = "UQ"; //绑定方式 atiny_params->server_params.life_time = 20; //生命周期 atiny_params->server_params.storing_cnt = 0; //缓存数据报文个数 atiny_params->server_params.bootstrap_mode = BOOTSTRAP_FACTORY; //引导模式 atiny_params->server_params.hold_off_time = 10; //等待时延 //pay attention: index 0 for iot server, index 1 for bootstrap server. iot_security_param = &(atiny_params->security_params[0]); bs_security_param = &(atiny_params->security_params[1]); iot_security_param->server_ip = DEFAULT_SERVER_IPV4; //服务器地址 bs_security_param->server_ip = DEFAULT_SERVER_IPV4; #ifdef WITH_DTLS iot_security_param->server_port = "5684"; //加密设备端口号 bs_security_param->server_port = "5684"; iot_security_param->psk_Id = g_endpoint_name_iots; //加密设备验证码 iot_security_param->psk = (char *)g_psk_iot_value; //PSK码 iot_security_param->psk_len = sizeof(g_psk_iot_value); //PSK码长度 bs_security_param->psk_Id = g_endpoint_name_bs; bs_security_param->psk = (char *)g_psk_bs_value; bs_security_param->psk_len = sizeof(g_psk_bs_value); #else iot_security_param->server_port = "5683"; //非加密设备端口号 bs_security_param->server_port = "5683"; iot_security_param->psk_Id = NULL; //非加密设备,无需PSK相关参数设置 iot_security_param->psk = NULL; iot_security_param->psk_len = 0; bs_security_param->psk_Id = NULL; bs_security_param->psk = NULL; bs_security_param->psk_len = 0; #endif
设定好atiny_params后,即可根据设定的参数对agent tiny进行初始化。
if(ATINY_OK != atiny_init(atiny_params, &g_phandle)) { return; }
对于初始化接口atiny_init()内部,主要进行入参合法性的检验,agent tiny所需资源的创建等工作,一般不需要开发者进行修改。
父主题: 端侧对接流程