Asset Tracker v2 application. How to subscribe to non-AWS specific topic:

I have built and successfully run this application with the nRF Cloud and then I achieved a partial success with running this application with the AWS IoT.

When I run this app with the AWS IoT, I can see all relevant data sent from my nRF9160DK to the shadow topics of my thing created on AWS IoT, like the battery voltage values and time stamp values. 

However, I would also like to see, in the relevant AWS IoT topics, the data sent from my nRF9160DK device that relates to button presses on the nRF9160DK device.

Apparently, the data that relates to the button presses on the nRF9160DK device should be available in the AWS IoT topic: "<imei>/messages" but there is no data that I could see in this AWS IoT topic, despite receiving without any problems the battery voltage values and time stamp values in the AWS IoT shadow topics of my thing created on the AWS IoT.

According to the info in the nRF9160DK Get Started guide, in order to subscribe to non AWS specific topics, you need to:

1. Specify the number of additional topics that needs to be subscribed to, by setting the option: CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT. (I can see that this option is already set to: 3).

2. Pass a list containing application-specific topics in the function: aws_iot_subscription_topics_add() , after the function call: aws_iot_init() and before the function call: aws_iot_connect().

From my analysis of the file: aws_iot_integration.c  that is located in: asset_tracker_v2\src\cloud\aws_iot_integration.c , it appears that the topic: "<imei>/messages" is already included in the list of topics to which my nRF9160DK device will publish the relevant data.

I found a section of code in the main.c source file for sample: AWS-IoT that I consider to use in the app: Asset Tracker v2, in order to be able to subscribe to non AWS specific topics on AWS IoT,  while running the app: Asset Tracker v2 with AWS IoT. (I attach a copy of the section of code from the source file main.c for the sample:AWS-IoT).

I have two questions:

1. Is the non AWS specific topic the same as the application specific topic?

2. If  I need to insert the section of code from the main.c of the sample: AWS-IoT to the main.c of the app: Asset Tracker v2 (in order to be able to see the data in the AWS IoT topic:  <imei>/messages) , where exactly shall I insert this section of code in the main.c  source file for app: Asset Tracker v2 (or may be in another source .c file for this app)?

Regards,

JM

Section of code from the main.c for sample aws-IoT.docx

  • Hi,

    1. Is the non AWS specific topic the same as the application specific topic?

    Yes. They are topics that AWS doesn't use for some special/predifined purpose. Note that they are not allowed to start with $.

    2. If  I need to insert the section of code from the main.c of the sample: AWS-IoT to the main.c of the app: Asset Tracker v2 (in order to be able to see the data in the AWS IoT topic:  <imei>/messages) , where exactly shall I insert this section of code in the main.c  source file for app: Asset Tracker v2 (or may be in another source .c file for this app)?

    The cloud_wrap_*_send() functions might be the best place: https://github.com/nrfconnect/sdk-nrf/blob/main/applications/asset_tracker_v2/src/cloud/aws_iot_integration.c#L380-L540 

    Best regards,

    Didrik

  • Hi,

    After some further analysis and experimenting I found that the data about the button presses on my nRF9160DK device was in fact being sent from my device to the aws IoT Core and it was available in the aws IoT topic: <IMEI>/messages , as expected.

    The only reason why I have not found this data was the incorrect value (number) that I was using for <IMEI> while trying to subscribe to the aws IoT topic: <IMEI>/messages.

    Once I used the correct value (number) for the <IMEI> , as per data obtained from the modem of my nRF9160DK device, using AT command: AT+CGSN , this problem has been resolved and I was able to see both:

    1. the data about the battery voltage (with its time stamp) sent from my device to the shadow topics of the aws IoT Core and     

    2. the data about the button presses on my device sent from my device to the topic: <IMEI>/messages on the aws IoT Core.

    However, when I thought that this problem has been resolved or good, something happened on the 14th January 2022. 

    I started receiving messages like:

    1. ERROR: cmake failed

    2. create_nordic_project.py failed

    3. CMake error at: C:/.../v1.7.0/zephyr/cmake/kconfig:268 (message): command failed with return code 1.

    4. src/watchdog/kconfig - not found (in 'rsource "src/watchdog/kconfig")

    As I run into problems on 14 January 2022 with creating Nordic projects using nRF Connect SDK 1.7.0 , I decided to upgrade to the latest version of the nRF Connect SDK 1.8.0 and I was able to successfully build and run the sample: AWS-IoT, using the nRF Connect SDK 1.8.0.

    However, there were issues when I tried to build and run the application: Asset Tracker v2, using nRF Connect SDK 1.8.0.

    In the past, when I was using the nRF Connect SDK 1.7.0 to build and run the application: Asset Tracker v2, I noticed that in order to be able to see the data sent from my nRF9160DK device to the AWS IoT in the relevant AWS IoT Core topics , I had to make the following changes in the prj.conf file for asset_tracker_v2 application:

    I had to disable the following option (by setting it to 'n'): CONFIG_NRF_CLOUD_MQTT=n

    and I had to enable the following option (by setting it to 'y'): CONFIG_AWS_IOT=y

    However, when I was using the nRF Connect SDK 1.8.0 and I tried to disable (by setting it to 'n') the option: CONFIG_NRF_CLOUD_MQTT=n in the prj.conf file for app: asset_tracker_v2, I was unable to complete the process of "Build Solution" in Segger IDE, with the following error messages popping up:  Build solution failed. Error was detected while compiling cloud_module.c. "A cloud transport service must be enabled".

    And in order to be able to successfully complete the process of "Build Solution" by Segger IDE, I had to enable this option (by setting it to 'y') as follows: CONFIG_NRF_CLOUD_MQTT=y

    This resulted in the successful build of the application: asset_tracker_v2, that I programmed into my nRF9160DK device.

    Once my nRF9160DK was programmed with the above version of the "Build Solution" for application: asset_tracker_v2, I could see ,via the Link Monitor, that all activities on my nRF9160DK device were running as expected and that my device was communicating with AWS IoT Core.

    However, I could not see any data from my device displayed in the relevant topics on the AWS IoT Core (neither in the shadow topics nor in the <IMEI>/messages topic).   This was in contrast to my earlier experience with the same application: asset_tracker_v2, that was built using the nRF Connect SDK 1.7.0 with the following option disabled by 'n': CONFIG_NRF_CLOUD_MQTT=n.

    What can be done to allow me to see the data sent from my nRF9160DK device to the AWS IoT Core, in the relevant topics of the AWS IoT Core that is: the shadow topics and the <IMEI>/messages topic?

    From my experience, it seems that one needs to be able to successfully complete the "Build Solution" process in Segger IDE with the following option in the prj.conf file disabled by 'n':  CONFIG_NRF_CLOUD_MQTT=n.

    What is the solution to this problem?

    Regards,

    JM

     

  • When you disabled CONFIG_NRF_CLOUD_MQTT, did you remember to enable CONFIG_AWS_IOT?

  • Hi,

    Yes, I did.

    However, I did enable it NOT in the prj.conf file but only in the ovelay-aws.conf file, where many lines of code that used to be listed in the prj.conf file as AWS IoT mandatory application specific configurations for AWS IoT (under the nRF Connect SDK 1.7.0) , have now been placed, under nRF Connect SDK 1.8.0.

    I attach copies of the ovelay-aws.conf file and the prj.conf file that I used with the application: asset_tracker_v2 ,using nRF Connect SDK 1.8.0.

    Regards,

    JM

    #
    # Copyright (c) 2021 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    CONFIG_AWS_IOT=y
    CONFIG_AWS_IOT_CLIENT_ID_STATIC="your_client_id"
    CONFIG_AWS_IOT_TOPIC_UPDATE_DELTA_SUBSCRIBE=y 
    CONFIG_AWS_IOT_TOPIC_GET_ACCEPTED_SUBSCRIBE=y
    CONFIG_AWS_IOT_TOPIC_GET_REJECTED_SUBSCRIBE=y
    CONFIG_AWS_IOT_AUTO_DEVICE_SHADOW_REQUEST=y
    CONFIG_AWS_IOT_MQTT_RX_TX_BUFFER_LEN=2048 
    CONFIG_AWS_IOT_MQTT_PAYLOAD_BUFFER_LEN=2048
    CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT=3
    CONFIG_AWS_IOT_CLIENT_ID_APP=n
    CONFIG_AWS_FOTA=y
    
    # Options that must be configured in order to establish a connection.
    CONFIG_AWS_IOT_SEC_TAG=201
    CONFIG_AWS_IOT_BROKER_HOST_NAME="a1xrz2twcds6b1-ats.iot.us-east-1.amazonaws.com"
    
    # MQTT Transport library
    # Maximum specified MQTT keepalive timeout for AWS IoT is 1200 seconds.
    CONFIG_MQTT_KEEPALIVE=1200
    

    #
    # Copyright (c) 2021 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    # General config
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
    CONFIG_ASSERT=y
    CONFIG_REBOOT=y
    CONFIG_RESET_ON_FATAL_ERROR=n
    CONFIG_FPU=y
    
    # Heap and stacks
    CONFIG_HEAP_MEM_POOL_SIZE=32768
    CONFIG_MAIN_STACK_SIZE=1280
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
    CONFIG_HW_STACK_PROTECTION=y
    
    # Logging
    CONFIG_LOG=y
    
    # DK - Used for buttons and LEDs in UI module.
    CONFIG_DK_LIBRARY_INVERT_LEDS=y
    
    # nRF modem library
    CONFIG_NRF_MODEM_LIB=y
    
    # AT Host library - Used to send AT commands directy from an UART terminal and to allow
    #		    integration with nRF Connect for Desktop LTE Link monitor application.
    CONFIG_AT_HOST_LIBRARY=y
    
    # Network
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_OFFLOAD=y
    
    # LTE link control
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=n 
    CONFIG_LTE_NETWORK_MODE_NBIOT_GPS=y
    ## Power saving timers.
    ### 320 hours PSM.
    CONFIG_LTE_PSM_REQ_RPTAU="11000001"
    ### 20 seconds active time.
    CONFIG_LTE_PSM_REQ_RAT="00001010"
    
    # Modem info library to obtain information about network and device
    CONFIG_MODEM_INFO=y
    
    # Settings - Used to store real-time device configuration to flash.
    CONFIG_SETTINGS=y
    CONFIG_SETTINGS_FCB=y
    CONFIG_FCB=y
    
    # FOTA
    CONFIG_FOTA_DOWNLOAD=y
    CONFIG_DFU_TARGET=y
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_1024=y
    CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    CONFIG_DOWNLOAD_CLIENT_BUF_SIZE=2300
    CONFIG_DOWNLOAD_CLIENT_MAX_HOSTNAME_SIZE=128
    
    # Flash - Used in FOTA, settings and storage for P-GPS.
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_STREAM_FLASH=y
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    
    # MCUBOOT
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_IMG_MANAGER=y
    CONFIG_MCUBOOT_IMG_MANAGER=y
    CONFIG_IMG_ERASE_PROGRESSIVELY=y
    
    # Watchdog
    CONFIG_WATCHDOG_APPLICATION=y
    
    # Event Manager
    CONFIG_EVENT_MANAGER=y
    CONFIG_LINKER_ORPHAN_SECTION_PLACE=y
    CONFIG_EVENT_MANAGER_LOG_EVENT_TYPE=n
    
    # cJSON - Used in cloud data encoding.
    CONFIG_CJSON_LIB=y
    
    # CAF - Common Application Framework
    CONFIG_CAF=y
    CONFIG_LED=y
    CONFIG_CAF_LEDS=y
    CONFIG_CAF_INIT_LOG_LED_READY_EVENTS=n
    CONFIG_CAF_INIT_LOG_LED_EVENTS=n
    CONFIG_CAF_INIT_LOG_MODULE_STATE_EVENTS=n
    
    # Default cloud transport service
    CONFIG_NRF_CLOUD_MQTT=y
    

  • How did you include the overlay config in your build?

Related