This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Re-connect to the AWS IoT Cloud with nRF9160

Hello, guys.

We have nRF9160DK and nRF Connect SDK v1.3.0. The version of the LTE modem firmware is the latest (v.1.2.0).

In our design, we are able to initially connect to AWS IoT and exchange the data with the Cloud by using cloud_client example as a starting point. However, the trouble comes when we want to re-connect:

modem_configure() function is throwing the following error:

E: Modem could not be configured, error: -120

Before trying to re-connect, we close the Cloud connection with the following function calls:

int iot_stop(void)
{
    int ret;
    
    ret = cloud_disconnect(cloud_backend);
    printk("cloud_disconnect = %d\n", ret);

    return cloud_uninit(cloud_backend);
}

cloud_disconnect() function executes properly but cloud_uninit(cloud_backend) is returning -134. Is that OK?

By the way, here is how the modem_configure() function looks like:

static int modem_configure(void)
{
    int err = -1;
		err = lte_lc_init_and_connect_async(lte_handler);
		if (err) {
			LOG_ERR("Modem could not be configured, error: %d",
				err);
		}
    return err;
}

Am I missing something here? What would be the clear way to disconnect and re-connect to the cloud? As far as I remember, there were some troubles with modem_configure() function in previous SDK versions if the function is called outside main() function context. Is that still the case?

Thanks in advance for your time and efforts.

Sincerely,

Bojan.

Parents
  • Hi guys!

    Things are a little bit clearer now.

    1) It seems that there is no cloud_uninit(cloud_backend)function in AWS_IoT library so we can delete that line of the code.

    2) error 120 when we call modem_configure() function means the socket is already connected so there is no need to call modem_configure() when we want to re-connect.

    That's all sweet!

    However, in our system, the modem should be normally off and active only during the rare periods when we want to upload data. If we keep the socket connected, that would suck the juice from our battery so there is a need to completely turn off the modem between connection periods.

    I tried to include two more functions that would turn off the modem after disconnection from the cloud:

    cloud_disconnect(cloud_backend);
    lte_lc_offline();
    lte_lc_power_off();

    However, with those two functions included, we were unable to re-connect (with and without modem_configure() function included)!

    What would be the steps to completely turn off the modem and re-activate it again when we need it?

    Thanks in advance!

    Bojan.

  • Hello Bojan,

    What is the behavior when you try to re-connect after the disconnect? And how long is it between your disconnect and the re-connect? Have you checked your SIM Card's minimum shut down time?

    Best regards,

    Edvin

Reply Children
  • Hi, !

    Thanks for your reply. We get the following error when we try to re-connect:

    E: Modem could not be configured, error: -120

    This is when we try to completely disconnect from the network and turn off the modem with the following lines:

    cloud_disconnect(cloud_backend);
    lte_lc_offline();
    lte_lc_power_off();

    and when we try to re-connect after 10 seconds starting with the modem_configure() function call.

    It might be that 10 seconds is too short period. We did not check SIM Card's minimum shut down time, we will pay attention to that (we are using iBASIS eSIM that comes with the nRF9160-DK board)! Thanks for pointing that out for us!

    Cheers,

    Bojan.

  • If I am not mistaken, these sim cards have a minimum shut down time of ~10 minutes. Just for testing purposes, can you try to set a timer for 11 or 12 minutes, and then try to reconnect? Does it behave the same, or are you able to successfully reconnect? I am not sure how the different network distributers handle trying to break this specification.

    BR,

    Edvin

Related