Git Product home page Git Product logo

nrf9160dk-aws-iot's Introduction

nRF9160: AWS IoT

The AWS IoT sample demonstrates how an nRF9160-based device communicates with the AWS IoT message broker over MQTT. This sample showcases the use of the lib_aws_iot library. The sample implements lib_aws_fota through lib_aws_iot.

Requirements

The sample supports the following development kits:

Overview

The sample publishes two different types of messages in JSON object string format to the AWS IoT message broker. These messages are sent to the AWS IoT shadow topic $aws/things/<thingname>/shadow/update.

Below are the two types of messages that are published:

  • Type 1: The message comprises of a battery voltage value sampled from the nRF9160 SiP and a corresponding timestamp in milliseconds (UNIX time), that is retrieved from the lib_date_time library.
  • Type 2: The message adds a configurable firmware version number to type 1 messages. This firmware version number is used in correlation with FOTA DFU, which is supported by the sample and the lib_aws_iot library. See the lib_aws_fota library for information on how to create FOTA jobs.

A type 2 message is only published upon an initial connection to the sample, while a type 1 message is published sequentially with a configurable time in between each publishing of the data. In addition to publishing data, the sample also subscribes to the AWS IoT shadow delta topic, and two customizable application-specific topics. The customizable topics are not part of the AWS IoT shadow service and must therefore be passed to the lib_aws_iot library using the :caws_iot_subscription_topics_add function.

Configuration

Setup

To run this sample and connect to AWS IoT, complete the steps described in the lib_aws_iot documentation. This documentation retrieves the AWS IoT broker hostname, security tag, and client ID. The corresponding options that must be set for each of the aforementioned values are:

  • :kconfigCONFIG_AWS_IOT_BROKER_HOST_NAME
  • :kconfigCONFIG_AWS_IOT_SEC_TAG
  • :kconfigCONFIG_AWS_IOT_CLIENT_ID_STATIC

Set these options in the project configuration file located at samples/nrf9160/aws_iot/prj.conf. For documentation related to FOTA DFU, see lib_aws_fota.

Configuration options

The application-specific configurations used in the sample are listed below. They are located in samples/nrf9160/aws_iot/Kconfig.

CONFIG_AWS_IOT_SAMPLE_APP_VERSION

Publishes the application version number to the AWS IoT message broker.

CONFIG_AWS_IOT_SAMPLE_PUBLICATION_INTERVAL_SECONDS

Configures the time interval between each publishing of the message.

CONFIG_AWS_IOT_SAMPLE_CONNECTION_RETRY_TIMEOUT_SECONDS

Configures the number of seconds between each AWS IoT connection retry.

CONFIG_AWS_IOT_SAMPLE_DEVICE_ID_USE_HW_ID

Configures the sample to use HWID as Device ID.

Note

The sample sets the option :kconfigCONFIG_MQTT_KEEPALIVE to the maximum allowed value, 1200 seconds (20 minutes) as specified by AWS IoT Core. This is to limit the IP traffic between the device and the AWS IoT message broker for supporting a low power sample. In certain LTE networks, the NAT timeout can be considerably lower than 1200 seconds. As a recommendation, and to prevent the likelihood of getting disconnected unexpectedly, set the option :kconfigCONFIG_MQTT_KEEPALIVE to the lowest timeout limit (Maximum allowed MQTT keepalive and NAT timeout).

Building and running

Note

The sample might require increasing the values of the :kconfigCONFIG_AWS_IOT_MQTT_RX_TX_BUFFER_LEN and :kconfigCONFIG_AWS_IOT_MQTT_PAYLOAD_BUFFER_LEN options.

After building the sample, program it to your development kit.

Testing

  1. Power on or reset the kit.
  2. Observe the output in the terminal over UART.

Sample output

When the sample runs, the device boots, and the sample displays the following output in the terminal over UART:

*** Booting Zephyr OS build v2.3.0-rc1-ncs1-snapshot1-6-gad0444b058ef  ***
<inf> aws_iot_sample: AWS IoT sample started, version: v1.0.0
<inf> aws_iot_sample: LTE cell changed: Cell ID: 33703711, Tracking area: 2305
<inf> aws_iot_sample: PSM parameter update: TAU: -1, Active time: -1
<inf> aws_iot_sample: RRC mode: Connected
<inf> aws_iot_sample: Network registration status: Connected - roaming
<inf> aws_iot_sample: PSM parameter update: TAU: 3600, Active time: 60
<inf> aws_iot_sample: RRC mode: Idle
<inf> aws_iot_sample: AWS_IOT_EVT_CONNECTING
<inf> aws_iot_sample: RRC mode: Connected
<inf> aws_iot_sample: RRC mode: Idle
<inf> aws_iot_sample: RRC mode: Connected
<inf> aws_iot_sample: AWS_IOT_EVT_CONNECTED
<inf> aws_iot_sample: Publishing: {
"state":    {
        "reported":    {
        "app_version":    "v1.0.0",
        "batv":    4304,
        "ts":    1592305354579
        }
}
} to AWS IoT broker
<inf> aws_iot_sample: AWS_IOT_EVT_READY
<inf> aws_iot_sample: RRC mode: Idle
<inf> aws_iot_sample: LTE cell changed: Cell ID: 34237195, Tracking area: 2305
<inf> aws_iot_sample: Publishing: {
"state":    {
        "reported":    {
        "batv":    4308,
        "ts":    1592305414579
        }
}
} to AWS IoT broker
<inf> aws_iot_sample: Next data publication in 60 seconds
<inf> aws_iot_sample: RRC mode: Connected
<inf> aws_iot_sample: RRC mode: Idle
<inf> aws_iot_sample: LTE cell changed: Cell ID: 33703711, Tracking area: 2305
<inf> aws_iot_sample: RRC mode: Connected
<inf> aws_iot_sample: Publishing: {
"state":    {
        "reported":    {
        "batv":    4308,
        "ts":    1592305474596
        }
}
} to AWS IoT broker
<inf> aws_iot_sample: Next data publication in 60 seconds

To observe incoming messages in the AWS IoT console, navigate to the AWS IoT Core service and click MQTT test client. To observe messages that are sent from the device, subscribe to the $aws/things/<client_id>/shadow/update shadow topic or the wild card token #.

AWS IoT Core MQTT test client

AWS IoT Core MQTT test client

Testing and debugging

If you have issues with the sample, refer to gs_testing.

Dependencies

This sample uses the following libraries and drivers:

  • lib_aws_iot
  • lib_date_time
  • lte_lc_readme
  • modem_info_readme

It uses the following sdk-nrfxlib library:

  • nrfxlib:nrf_modem

In addition, it uses the following secure firmware component:

  • Trusted Firmware-M <ug_tfm>

nrf9160dk-aws-iot's People

Contributors

dexterhaslem avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.