Updated on 2022-02-24 GMT+08:00

Initializing LiteOS SDK Device-Cloud Interconnect Components

Call the atiny_init() function in the entrypoint function to initialize Agent Tiny.

Function

Description

int atiny_init(atiny_param_t* atiny_params, void** phandle);

Function for initializing device-cloud interconnect components, which is implemented by device-cloud interconnect components and invoked by devices. The parameters involved are as follows:

  • atiny_params. For details about the parameter, see the description of the atiny_param_t data structure.
  • phandle, an output parameter, which represents the handle of the currently created device-cloud interconnect component.

    Return value: Integer variable, indicating that the initialization is successful or failed.

The input parameter atiny_params needs to be set based on specific services. Developers can set the parameter by the following code:

#ifdef CONFIG_FEATURE_FOTA
     hal_init_ota();   //To define the FOTA functions, perform FOTA-related initialization.
 #endif

 #ifdef WITH_DTLS
     device_info->endpoint_name = g_endpoint_name_s;  //Encrypted device verification code
 #else
     device_info->endpoint_name = g_endpoint_name;    //Unencrypted device verification code
 #endif
 #ifdef CONFIG_FEATURE_FOTA
     device_info->manufacturer = "Lwm2mFota";    //Unencrypted device verification code
     device_info->dev_type = "Lwm2mFota";        //Device type
 #else
     device_info->manufacturer = "Agent_Tiny";   
 #endif
     atiny_params = &g_atiny_params;
     atiny_params->server_params.binding = "UQ";   //Binding mode
     atiny_params->server_params.life_time = 20;   //Life cycle
     atiny_params->server_params.storing_cnt = 0;  //Number of cached data packets

     atiny_params->server_params.bootstrap_mode = BOOTSTRAP_FACTORY;   //Boot mode
     atiny_params->server_params.hold_off_time = 10;    //Waiting latency

     //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;  //Server address
     bs_security_param->server_ip = DEFAULT_SERVER_IPV4;

 #ifdef WITH_DTLS
     iot_security_param->server_port = "5684";   //Encrypted device port number
     bs_security_param->server_port = "5684";

     iot_security_param->psk_Id = g_endpoint_name_iots;         //Encrypted device verification
     iot_security_param->psk = (char *)g_psk_iot_value;         //PSK password
     iot_security_param->psk_len = sizeof(g_psk_iot_value);     //PSK password length

     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";    //Unencrypted device port number
     bs_security_param->server_port = "5683";

     iot_security_param->psk_Id = NULL;    //No PSK-related parameter setting for unencrypted devices
     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

After setting the atiny_params parameter, initialize Agent Tiny based on the set parameter.

   if(ATINY_OK != atiny_init(atiny_params, &g_phandle))
    {
        return;
    }

After setting the atiny_params parameter, initialize Agent Tiny based on the set parameter.