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

mqtt_simple connect to AWS

I have an AWS account and I am comfortable with the AWS IOT operation in general. I have used it in the past. I am trying to get the sample mqtt_simple to connect to AWS IOT and be able to send packets and receive packets to the nRF9160dk board.

 I am not sure how to set up mqtt_simple parameters? I have created a thing and certificates. I have named the thing "nrf-IMEI" as recommended so it has the board ID in it. All I want to do is to be able to publish a packet to a topic on my AWS account and receive a packet from a topic in my AWS account. I have done this several times in the past with other systems so I am comfortable with AWS IOT operations and formats. I just do not understand how to get mqtt_simple to publish from my board to AWS and subscribe to messages from AWS.

Is this the correct program to use. It seems like all the pieces are there I just do not know how to use them.

I appreciate any help you can give, This is an essential requirement of our production system. right now we are using the pre-production system with a modified version of asset_tracker to send sensor data to the nRF Connect site. We need to be able to send sensor data to our AWS site.

  • If I change CONFIG_CLOUD_BACKEND to "NRF_CLOUD" everything works perfectly. on RF Connect I see the following if I press the button 1.

    So the code is working fine just not finding the AWS_IOT backend so I cannot use my certificates and connect.

    {
    "state": {
    "reported": {
    "message": "Hello Internet of Things!"
    }
    }
    }

  • Hi Timothy,
    In the cloud client sample doc. there is a sentence:

    "Each cloud backend has specific setup steps that must be executed before it can be used."

    And in the AWS IoT lib doc
    "
    To connect to the AWS IoT broker, set the following mandatory options (specified in the Configuring library options section):


    So these are some configurations that you need to set in your projects prj.conf file and point the values etc..

    The available configurations in the AWS IoT lib. is shown in its Kconfig file.

    So to set your hostname in your project, you just put the following in prj.conf:

    CONFIG_AWS_IOT_BROKER_HOST_NAME="my_aws_name_broker"


    a small tip:

    instead of manually changing the Kconfig of the cloud client sample itself to use the "AWS_IOT" backend, you could also be set that as well in prj.conf:

    CONFIG_CLOUD_BACKEND="AWS_IOT"

    BR;
    Martin L.

  • Martin

    I did all of that I I also had to add  CONFIG_AWS_IOT=y

    all is working. THANK YOU!  now to merge this into asset_tracker.

    Cloud client has started
    Connecting to LTE network. This may take several minutes.
    Connected to LTE network
    CLOUD_EVT_CONNECTED
    CLOUD_EVT_READY
    Publishing message: {"state":{"reported":{"message":"Hello Internet of Things!"}}}
    Publishing message: {"state":{"reported":{"message":"Hello Internet of Things!"}}}

  • OK now I have good news, medium news, and bad news.

    good news: I had the original V1.2.0 mqtt_simple and cloud_client connecting to my AWS account and publishing. so that is good. I can talk to my AWS account with two different applications.

    medium news: I had the original V1.2.0 asset_tracker connecting to my client but as soon as it published it crashed. see messages below.

    *** Booting Zephyr OS build v2.1.99-ncs1 ***
    [00:00:00.186,584] <dbg> nrf9160_gps.init: MAGPIO set: AT%XMAGPIO=1,0,0,1,1,1574,1577
    [00:00:00.195,495] <dbg> nrf9160_gps.init: COEX0 set: AT%XCOEX0=1,1,1570,1580
    [00:00:00.203,216] <inf> asset_tracker: Asset tracker AWS started
    [00:00:00.210,388] <inf> asset_tracker: Connecting to LTE network.
    [00:00:00.217,224] <inf> asset_tracker: This may take several minutes.
    [00:00:00.232,269] <dbg> lte_lc.w_lte_lc_connect: Network mode: AT%XSYSTEMMODE=1,0,1,0
    +CEREG: 2,"9E03","026B8102",7,0,0,"11100000","11100000"
    [00:00:01.701,782] <dbg> lte_lc.parse_nw_reg_status: Network registration status: 2
    +CEREG: 5,"9E03","026B8102",7,,,"11100000","11100000"
    [00:00:05.553,405] <dbg> lte_lc.parse_nw_reg_status: Network registration status: 5
    [00:00:05.561,798] <inf> asset_tracker: Connected to LTE network
    [00:00:05.870,635] <dbg> aws_iot.broker_init: IPv4 Address found 54.209.247.240
    [00:00:10.967,834] <inf> aws_jobs: Subscribe: $aws/things/nrf-352656100378150/jobs/notify-next
    [00:00:10.978,332] <inf> aws_jobs: Subscribe: $aws/things/nrf-352656100378150/jobs/$next/get/#
    [00:00:10.988,372] <dbg> aws_iot.mqtt_evt_handler: MQTT client connected!
    [00:00:10.995,697] <inf> asset_tracker: CLOUD_EVT_CONNECTED
    [00:00:11.001,800] <inf> asset_tracker: CLOUD_EVT_READY
    [00:00:11.008,331[00:00:11.010,314] <dbg> aws_iot.aws_iot_send: Publishing to topic: $aws/things/nrf-352656100378150/shadow/update
    ] <inf>[00:00:11.022,460] <err> os: ***** USAGE FAULT *****
    [00:00:11.028,198] <err> os: Unaligned memory access
    [00:00:11.034,149] <err> os: r0/a1: 0x000fffff r1/a2: 0x0000000f r2/a3: 0x000fffff
    [00:00:11.042,999] <err> os: r3/a4: 0x2002ba74 r12/ip: 0x2002405c r14/lr: 0x0001e977
    [00:00:11.051,849] <err> os: xpsr: 0xa102b800
    [00:00:11.057,159] <err> os: s[ 0]: 0x00000000 s[ 1]: 0x00000000 s[ 2]: 0x00000000 s[ 3]: 0x00000000
    [00:00:11.067,810] <err> os: s[ 4]: 0x00000000 s[ 5]: 0xffffffff s[ 6]: 0xffffffff s[ 7]: 0x00000000
    [00:00:11.078,460] <err> os: s[ 8]: 0x00000000 s[ 9]: 0x00000000 s[10]: 0x00000000 s[11]: 0xffffffff
    [00:00:11.089,111] <err> os: s[12]: 0xffffffff s[13]: 0xffffffff s[14]: 0x00000000 s[15]: 0x00000000
    [00:00:11.099,761] <err> os: fpscr: 0x42b151d0
    [00:00:11.105,072] <err> os: Faulting instruction address (r15/pc): 0x00036fba
    [00:00:11.113,128] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    [00:00:11.121,093] <err> os: Current thread: 0x200237e4 (unknown)
    [00:00:11.127,990] <err> asset_tracker: Running main.c error handler

    BAD NEWS: now nothing connects to anything. any application I run to connect to NRF cloud or my AWS cloud gets a message that it can not connect. The same thing is happening on two different boards. I have reloaded certificates and got the same result. I am now dead in the water since I can not connect to anything. see below. I did not change anything in the applications or on my boards when it started to fail.

    I had these applications running on boath boards as of Friday 6/5 afternoon. then everything died.

    Please help. did Nordic change something that I need to update?

    [00:00:00.189,392] <dbg> nrf9160_gps.init: MAGPIO set: AT%XMAGPIO=1,0,0,1,1,1574,1577
    [00:00:00.198,272] <dbg> nrf9160_gps.init: COEX0 set: AT%XCOEX0=1,1,1570,1580
    [00:00:00.205,993] <inf> asset_tracker: Asset tracker started
    [00:00:00.219,421] <dbg> nrf_cloud_transport.nct_client_id_get: client_id = nrf-352656100379158
    [00:00:00.228,729] <dbg> nrf_cloud_transport.nct_topics_populate: shadow_base_topic: $aws/things/nrf-352656100379158/shadow
    [00:00:00.240,539] <dbg> nrf_cloud_transport.nct_topics_populate: accepted_topic: nrf-352656100379158/shadow/get/accepted
    [00:00:00.252,166] <dbg> nrf_cloud_transport.nct_topics_populate: rejected_topic: $aws/things/nrf-352656100379158/shadow/get/rejected
    [00:00:00.264,831] <dbg> nrf_cloud_transport.nct_topics_populate: update_delta_topic: $aws/things/nrf-352656100379158/shadow/update/delta
    [00:00:00.277,832] <dbg> nrf_cloud_transport.nct_topics_populate: update_topic: $aws/things/nrf-352656100379158/shadow/update
    [00:00:00.289,794] <dbg> nrf_cloud_transport.nct_topics_populate: shadow_get_topic: $aws/things/nrf-352656100379158/shadow/get
    [00:00:00.302,215] <inf> asset_tracker: Connecting to LTE network.
    [00:00:00.309,020] <inf> asset_tracker: This may take several minutes.
    [00:00:00.324,066] <dbg> lte_lc.w_lte_lc_connect: Network mode: AT%XSYSTEMMODE=1,0,1,0
    +CEREG: 2,"9E03","026B8102",7,0,0,"11100000","11100000"
    [00:00:01.753,387] <dbg> lte_lc.parse_nw_reg_status: Network registration status: 2
    +CEREG: 5,"9E03","026B8102",7,,,"11100000","11100000"
    [00:00:05.043,975] <dbg> lte_lc.parse_nw_reg_status: Network registration status: 5
    [00:00:05.052,368] <inf> asset_tracker: Connected to LTE network
    [00:00:05.371,307] <dbg> nrf_cloud_transport.nct_connect: IPv4 Address 0xef20af23
    [00:00:25.673,034] <err> asset_tracker: cloud_connect failed: -116
    [00:00:25.679,992] <err> asset_tracker: LTE link disconnect
    +CEREG: 0,"9E03","026B8102",7,0,0,"11100000","11100000"
    [00:00:28.626,892] <err> asset_tracker: Shutdown modem
    *** Booting Zephyr OS build v2.1.99-ncs1 ***
    [00:00:00.003,875] <inf> mcuboot: Starting bootloader
    [00:00:00.010,070] <inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x1
    [00:00:00.020,172] <inf> mcuboot: Boot source: none
    [00:00:00.025,665] <inf> mcuboot: Swap type: none
    [00:00:00.351,745] <inf> mcuboot: Bootloader chainload address offset: 0xc000
    [00:00:00.359,466] <inf> mcuboot: Jumping to the first image slot

  • Martin

    The problem of not connecting was the SIM cards were full on both boards. I am loading and trying things a hundred times a day and I forgot to check the SIM cards. That still lives the original problem that it connects to AWS and crashes as soon as I do the first publish. I still need any insight you have into solving that  problem.

Related