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

Some example using AWS IoT library (subsys/net/lib/aws_iot/)

Hello guys,

We are developing a device that will based on nRF9160 SiP. We use nRFConnect SDK v1.3.0. The goal would be to connect to AWS IoT through MQTT and exchange messages. I used cloud_client example from nrf/samples/nrf9160 as a starting point and was able to establish a connection with the AWS IoT Thing (details here).

I noticed there is an AWS IoT library located at nrf/subsys/net/lib/aws_iot/ that would probably be more suitable for us to use.

Is there any sample that can help us understand how to use that library? Basically, what we need to put inside Kconfig and prj.conf files to properly configure our project?

Thanks in advance for your time and efforts.

Sincerely,

Bojan.

Parents
  • Hi!

    When you enable the AWS IoT backend, using CONFIG_CLOUD_BACKEND, the Cloud client sample uses the AWS IoT library. 

    See the Cloud client sample documentation:

    The Cloud client sample demonstrates how the generic Cloud API can be used to interface with multiple cloud backends. The current version of the sample supports the following libraries as cloud backends:

    Best regards,

    Heidi

  • Thanks for your clarification, !

    I indeed specified

    config CLOUD_BACKEND
    	string "String that selects the cloud backend to be used"
    	default "AWS_IOT"

    in my Kconfig  file.

    Please help me to understand better, can I replace generic Cloud API and use the API functions from AWS IoT library (e. g. aws_iot_init(), aws_iot_config, aws_iot_connect() etc.)?

    Is there any benefit of replacing generic Cloud APIs with the APIs from AWS IoT library?

    Of course, I would need to include the library with:

    include/net/aws_iot.h
    subsys/net/lib/aws_iot/src/

    Regards,

    Bojan.

  • Hi, the Cloud API uses the functions you list, just not directly. But that's what the application is using when you enable the AWS IoT backend.

    With regard to the benefit of using the AWS IoT library directly, I'll have to get back to you. 

  • Hi, !

    If Cloud API uses the functions from the AWS IoT library then it should be OK.

    Can you help me understand what would be the proper (clear) way to disconnect from the Cloud? I have a hard time to disconnect and re-connect again, as I described here.

    Cheers,

    Bojan.

  • Hi! The case you linked to has been assigned to another engineer who will answer that question for you.

    I can tell you that modem_configure returning error 120 means the socket is already connected, i.e. you don't need to configure the modem again. You are disconnecting from the cloud backend, not the network, so you don't need to run modem_configure every time you disconnect. 

    cloud_uninit returning error 134 means not supported, which I think might be because the AWS IoT library does not have an uninit function. To disconnect from the cloud, it should be enough to run the cloud_disconnect function. 

  • Hello, .

    Thanks for the great explanation. You were right about both:

    1) There is no cloud_uninit(cloud_backend)function in AWS_IoT library. Consequently, we can delete that line of the code from the disconnect procedure.

    2) The socket was already connected so there was no need to call modem_configure()

    So, if we disconnect from the cloud by simply calling cloud_disconnect(cloud_backend)function, we were able to re-connect by omitting modem_configure() function.

    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 onclude 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 again, if you're worried about battery consumption, completely disconnecting from the network each time is not the best way to go about this.

    I recommend you have a look at Power Saving Mode and check if your network operator supports this feature, and then go into PSM instead of completely de-attaching from the network. 

Reply Children
No Data
Related