Exploring Connectivity Options for AWS IoT: Do We Need IoT SIM Cards?

Hi,

      I am currently working with the nRF9160DK board, using SDK version 2.5.1, and I have encountered an issue regarding connectivity to the AWS IoT cloud.

I have successfully connected my board to MQTT and have been able to publish and subscribe to topics using a regular SIM card with a data pack,so I confirmed that internet connection is done. However, when attempting to connect to AWS IoT using the same SIM card in the provided sample code, I am experiencing connectivity issues.

I have ensured that I configured all necessary parameters in the sample code given, including:

  • CONFIG_AWS_IOT_BROKER_HOST_NAME
  • CONFIG_MQTT_HELPER_SEC_TAG
  • CONFIG_AWS_IOT_CLIENT_ID_STATIC

Despite this, I am not receiving the expected output,
After flashing the sample, we can receive those two lines in the image. I'm not getting the remaining lines.


and I'm uncertain whether the SIM card compatibility could be a factor, or if there might be an issue with my code implementation.

Could you please provide guidance on whether an IoT-specific SIM card (LTE-M or NB-IoT) is required for connecting to AWS IoT? Additionally, I would appreciate any insights or troubleshooting tips you may have regarding this connectivity issue.

Thank you in advance for your assistance.

  • Hi,
        

    I've recently updated my SDK version to 2.6.0, and since then, I've encountered issues flashing only the asset tracking code. I've already raised a support ticket regarding this matter.

    Regarding the AWS IoT configuration, yes, I've created the necessary policy and attached it while creating the certificate, following the instructions provided in SDK version 2.6.0. I have also set up the policy as mentioned in the document.I followed like this below pic

    However, there's some confusion regarding setting the client ID and host name at runtime. Is it essential to set the client ID at runtime? If so, here's my understanding: Setting the client ID and host name at runtime means configuring the options in the project configuration, specifically CONFIG_AWS_IOT_BROKER_HOST_NAME="xxxxxxxxxxx80-ats.iot.us-east-2.amazonaws.com" and CONFIG_AWS_IOT_CLIENT_ID_STATIC="THING9160_DK". Would this configuration effectively set the endpoint at runtime?

    I've noticed discrepancies between the documentation for SDK version 2.4.0 and the instructions provided for SDK version 2.6.0. In version 2.4.0, there are explicit options like CONFIG_AWS_IOT_BROKER_HOST_NAME_APP and CONFIG_AWS_IOT_CLIENT_ID_APP. However, in the newer version, there's no mention of these options. Instead, the documentation suggests setting these parameters at runtime using the aws_iot_connect() function.

    Here's what the documentation states in SDK 2.6.0:

    • Setting client ID at runtime: The library supports passing in the client ID at runtime by setting the client_id entry in the aws_iot_config structure passed into the aws_iot_connect() function. The client_id entry must be a null-terminated string.

    • Setting the AWS host name at runtime: Similarly, the library supports passing in the endpoint URL at runtime by setting the host_name entry in the aws_iot_config structure passed into the aws_iot_connect() function.

      However, despite following these instructions, I encountered errors. If I include CONFIG_AWS_IOT_BROKER_HOST_NAME_APP and CONFIG_AWS_IOT_CLIENT_ID_APP into my new SDK version 2.6.0 AWS IoT sample, it throws errors. Could you please clarify how to correctly implement these runtime configurations? Should I still adhere to the older approach of setting CONFIG_AWS_IOT_BROKER_HOST_NAME_APP and CONFIG_AWS_IOT_CLIENT_ID_APP?, or is there a different procedure for SDK version 2.6.0? If possible, could you provide guidance or examples on how to correctly set these parameters at runtime within the aws_iot_connect() function?I have attach the code aws_iot_connect() below.do i need to do anything here.

      int aws_iot_connect(const struct aws_iot_config *const config)
      {
      	int err;
      	struct mqtt_helper_conn_params conn_params = {
      		.hostname.ptr = (config && config->host_name) ? config->host_name : NULL,
      		.hostname.size = (config && config->host_name) ? strlen(config->host_name) : 0,
      		.device_id.ptr = (config && config->client_id) ? config->client_id : NULL,
      		.device_id.size = (config && config->client_id) ? strlen(config->client_id) : 0,
      	};
      
      	/* Set the hostname to CONFIG_AWS_IOT_BROKER_HOST_NAME if it was not provided
      	 * in the configuration structure.
      	 */
      	if (conn_params.hostname.size == 0) {
      		LOG_DBG("No hostname provided, using Kconfig value: %s",
      			CONFIG_AWS_IOT_BROKER_HOST_NAME);
      
      		conn_params.hostname.ptr = CONFIG_AWS_IOT_BROKER_HOST_NAME;
      		conn_params.hostname.size = strlen(CONFIG_AWS_IOT_BROKER_HOST_NAME);
      	}
      
      	/* Set the device ID to CONFIG_AWS_IOT_CLIENT_ID_STATIC if it was not provided
      	 * in the configuration structure.
      	 */
      	if (conn_params.device_id.size == 0) {
      		LOG_DBG("No device ID provided, using Kconfig value: %s",
      			CONFIG_AWS_IOT_CLIENT_ID_STATIC);
      
      		conn_params.device_id.ptr = CONFIG_AWS_IOT_CLIENT_ID_STATIC;
      		conn_params.device_id.size = strlen(CONFIG_AWS_IOT_CLIENT_ID_STATIC);
      	}
      
      	err = shadow_topics_construct(conn_params.device_id.ptr);
      	if (err) {
      		LOG_ERR("shadow_topics_construct, error: %d", err);
      		return err;
      	}
      
      	err = mqtt_helper_connect(&conn_params);
      	if (err) {
      		LOG_ERR("mqtt_helper_connect, error: %d", err);
      		return err;
      	}
      
      	memset(&suback_conf, 0, sizeof(struct suback_conf));
      
      	err = k_sem_take(&subs_acked_sem, K_SECONDS(CONFIG_AWS_IOT_CONNECT_TIMEOUT_SECONDS));
      	if (err == -EAGAIN) {
      		LOG_ERR("Timed out waiting for subscription acknowledgments");
      
      		/* Explicitly disconnect the client to clear any MQTT helper library state. */
      		(void)aws_iot_disconnect();
      	}
      
      	return err;
      }
      

      aws_iot_config structure
      struct aws_iot_config {
          /** AWS IoT client ID. Must be NULL terminated.
           *  If not set (NULL), CONFIG_AWS_IOT_CLIENT_ID_STATIC will be used.
           */
          char *client_id;
       
          /** AWS IoT broker hostname. Must be NULL terminated.
           *  If not set (NULL), CONFIG_AWS_IOT_BROKER_HOST_NAME will be used.
           */
          char *host_name;
      };
      

    I appreciate your assistance in resolving this matter.

  • Hi,

    There are 2 options in NCS v2.6.0 for setting mentioned configuration. 
    First is to configure relevant parameters - CONFIG_AWS_IOT_BROKER_HOST_NAME and CONFIG_AWS_IOT_CLIENT_ID_STATIC - in prj.conf which are going to be used during building process. If you want to use mentioned Kconfig options, NULL should be passed as an argument to aws_iot_connect(), aws_iot_connect(NULL). 
    Another option is to use struct aws_iot_config where you can specify your connection options client_id and host_name inside the structure. For example, you can look at the function aws_iot_integration in the asset_tracker_v2 sample or in the relevant part of main.c in the aws_iot sample.

    Best regards,
    Dejan

  • Hi,
        

    I have followed the instructions provided by you for configuring the AWS IoT connection in two different ways, but I am still facing difficulties.

    Here is a summary of what I have done:

    Option 1: I have followed the first option, where I pass NULL as an argument to the aws_iot_connect()function.

    static void connect_work_fn(struct k_work *work)
    {
        int err;
    
        LOG_INF("Connecting to AWS IoT");
    
        err = aws_iot_connect(NULL);
        if (err == -EAGAIN) {
            LOG_INF("Connection attempt timed out, "
                "Next connection retry in %d seconds",
                CONFIG_AWS_IOT_SAMPLE_CONNECTION_RETRY_TIMEOUT_SECONDS);
    
            (void)k_work_reschedule(&connect_work,
                    K_SECONDS(CONFIG_AWS_IOT_SAMPLE_CONNECTION_RETRY_TIMEOUT_SECONDS));
        } else if (err) {
            LOG_ERR("aws_iot_connect, error: %d", err);
            FATAL_ERROR();
        }
    }
    

    Option 2: I have also tried the second option, where I use the struct aws_iot_config structure to specify connection options.
    static void connect_work_fn(struct k_work *work)
    {
        int err;
        const struct aws_iot_config config = {
            .client_id = CONFIG_AWS_IOT_CLIENT_ID_STATIC,
            .host_name = CONFIG_AWS_IOT_BROKER_HOST_NAME
        };
    
        LOG_INF("Connecting to AWS IoT");
    
        err = aws_iot_connect(&config);
        if (err == -EAGAIN) {
            LOG_INF("Connection attempt timed out, "
                "Next connection retry in %d seconds",
                CONFIG_AWS_IOT_SAMPLE_CONNECTION_RETRY_TIMEOUT_SECONDS);
    
            (void)k_work_reschedule(&connect_work,
                    K_SECONDS(CONFIG_AWS_IOT_SAMPLE_CONNECTION_RETRY_TIMEOUT_SECONDS));
        } else if (err) {
            LOG_ERR("aws_iot_connect, error: %d", err);
            FATAL_ERROR();
        }
    }
    


    In addition, I have configured the CONFIG_AWS_IOT_CLIENT_ID_STATIC and CONFIG_AWS_IOT_BROKER_HOST_NAME options in my prj.conf file as instructed.

    However, despite following these steps, I am still unable to establish a connection to AWS IoT. I am only getting output for the two lines mentioned in the screenshot below.

    Could you please review my setup and provide any guidance or suggestions on what might be causing this issue? I would greatly appreciate any assistance you can provide to help resolve this matter.

    Thank you for your attention to this request. Looking forward to your response.

  • Hi,    

     Even if I open another new sample code of AWS IoT and do not make any changes, including not adding any certificate details, I will still get only these two lines of output shared in my above screenshot .

  • Hi, 

    Did you get any additional information when you added CONFIG_LTE_LINK_CONTROL_LOG_LEVEL_DBG=y to your prj.conf file?

    Regarding your connectivity issue, did you get any errors in your logs so far?

    It looks like you are not able to connect to the network. In order to determine possible cause, could you provide a modem trace?
    For capturing traces, you can use Cellular Monitor. You would need to prepare device before capturing modem trace.

    Best regards,
    Dejan

Related