Get started using AWS IoT Core for Amazon Sidewalk - AWS IoT Wireless

Get started using AWS IoT Core for Amazon Sidewalk

This section shows you how to get started with connecting your Sidewalk end devices to AWS IoT Core for Amazon Sidewalk. It explains how you can connect an end device to Amazon Sidewalk and pass messages between them. You'll also learn about the Sidewalk sample application and an overview of how to perform sensor monitoring using AWS IoT Core for Amazon Sidewalk. The sample application provides you with a dashboard to view and monitor changes to the sensor temperature.

AWS account and environment set up for connecting devices to AWS IoT Core for Amazon Sidewalk.

The following topics will help you get started with AWS IoT Core for Amazon Sidewalk.

Try the sensor monitoring tutorial

This section provides you an overview of the Amazon Sidewalk sample application on GitHub that shows you how to monitor the temperature of a sensor. In this tutorial, you use scripts that programmatically create the required wireless resources, provision the end device and flash the binaries, and then connect your end device to the application. The scripts that use the AWS CLI and Python commands create an AWS CloudFormation stack and wireless resources, and then flash the binaries and deploy the application onto your hardware development kit (HDK).

The following diagram shows the steps are involved when you run the sample application and connect your Sidewalk end device to the application. For detailed instructions including pre-requisites and configuration for this tutorial, see the README document in GitHub.

Application to monitor sensor temperature using AWS IoT Core for Amazon Sidewalk.

Introduction to onboarding your Sidewalk devices

This section shows you how to onboard your Sidewalk end devices to AWS IoT Core for Amazon Sidewalk. To onboard your devices, first add your Sidewalk device, then provision and register your device, and then connect your hardware to the cloud application. Before running this tutorial, review and complete Installing Python and Python3-pip.

The following steps show you how to onboard and connect your Sidewalk end devices to AWS IoT Core for Amazon Sidewalk. If you want to onboard devices using the AWS CLI, you can refer to the sample commands provided in this section. For information about onboarding devices using the AWS IoT console, see Connecting to AWS IoT Core for Amazon Sidewalk.

Important

To perform the entire onboarding workflow, you must provision and register your end device, and connect your hardware development kit (HDK). For more information, see Provisioning and registering your end device in the Amazon Sidewalk documentation.

Step 1: Create a destination for your Sidewalk end device

Here's an overview of the steps that you'll perform to add your destination to AWS IoT Core for Amazon Sidewalk. Using the AWS Management Console, or the AWS IoT Wireless API operations, or the AWS CLI, you run the following steps to create a destination which can be an AWS IoT rule or an MQTT topic. You can then connect to the hardware platform, and view and exchange messages. For a sample IAM role and AWS IoT rule used for the AWS CLI examples in this section, see Create an IAM role and IoT rule for your destination.

Store the destination name you create in this step. You'll use this information when you create a wireless device.

  1. Create IAM role

    Create an IAM role that grants AWS IoT Core for Amazon Sidewalk permission to send data to the AWS IoT rule. To create the role, use the CreateRole API operation or create-role CLI command. You can name the role as SidewalkRole.

    aws iam create-role --role-name lambda-ex \ --assume-role-policy-document file://lambda-trust-policy.json
  2. Create an AWS IoT rule for the destination

    Create an AWS IoT rule that will process the device's data and specify the topic to which messages are published. You'll observe messages on this topic after connecting to the hardware platform. Use the AWS IoT Core API operation, CreateTopicRule, or the AWS CLI command, create-topic-rule, to create a rule for the destination.

    Note

    You can also use an MQTT topic as a destination. For more information about how to create an MQTT topic, see MQTT topics.

    aws iot create-topic-rule --rule-name Sidewalkrule \ --topic-rule-payload file://myrule.json
  3. Create a destination

    Create a destination that associates your Sidewalk device with the IoT rule (or MQTT topic) that processes it for use with other AWS services. You can add a destination using the Destinations hub of the AWS IoT console, or the CreateDestination API operation or the create-destination CLI command. You'll send your Sidewalk end device's uplink data and location data to these destinations.

    aws iotwireless create-destination --name SidewalkDestination \ --expression-type RuleName --expression SidewalkRule \ --role-arn arn:aws:iam::123456789012:role/SidewalkRole

    Alternatively, if you want to provide an MQTT topic as the destination, replace the expression-type option with MqttTopic instead of RuleName. Replace SidewalkRule with the topic name.

Step 2: Add your Sidewalk device to AWS IoT Core for Amazon Sidewalk

Here's an overview of the steps that you'll perform to add your Sidewalk end device to AWS IoT Core for Amazon Sidewalk. Store the information you obtain about the device profile and the wireless device that you create. You'll use this information to provision and register the end device. For more information about these steps, see Add your device to AWS IoT Core for Amazon Sidewalk.

  1. Create a device profile

    Create a device profile that contains the shared configurations for your Sidewalk devices. When creating the profile, specify a name for the profile as an alphanumeric string. To create a profile, either go to the Sidewalk tab of the Profiles hub in the AWS IoT console and choose Create profile, or use the CreateDeviceProfile API operation or the create-device-profile CLI command as shown in this example.

    // Add your device profile using a name and the sidewalk object. aws iotwireless create-device-profile --name sidewalk_profile --sidewalk {}
  2. Create your Sidewalk end device and optionally get the device location
    1. Create your Sidewalk end device

      Create your Sidewalk end device with AWS IoT Core for Amazon Sidewalk. Specify a destination name and the ID of the device profile obtained from the previous step. To add a device, either go to the Sidewalk tab of the Devices hub in the AWS IoT console and choose Provision device, or use the CreateWirelessDevice API operation or the create-wireless-device CLI command as shown in this example.

      Note

      Specify a name for your destination that's unique to your AWS account and AWS Region. You'll use the same destination name when you add your destination to AWS IoT Core for Amazon Sidewalk.

      // Add your Sidewalk device by using the device profile ID. aws iotwireless create-wireless-device --type "Sidewalk" --name "sidewalk_device" \ --destination-name "SidewalkDestination" \ --sidewalk DeviceProfileId="12345678-234a-45bc-67de-e8901234f0a1"
    2. (Optional) Create your Sidewalk end device and get the Sidewalk device location

      If you want to enable location data when you create your Sidewalk end device with AWS IoT Core for Amazon Sidewalk, enable positioning. Replace LocationDestination with the destination to which you want to send the device location data to. The destination can either be an AWS AWS IoT rule or an MQTT topic. You can use the destination you created in Step 1 above as your UplinkDestination. Alternatively, you can specify a different destination as LocationDestination.

      AWS IoT Core for Amazon Sidewalk resolves the location of your Sidewalk end device using Bluetooth Low Energy (BLE), Wi-Fi, or GNSS uplink messages published by your Sidewalk end device. For more information on AWS IoT's location resolution capabilities, see AWS IoT Core Device Location.

      Note

      You must enable positioning to use the device location feature.

      If you enable device location for the Sidewalk-enabled device, your raw uplink payload won't be propagated to the destination.

      // Add your Sidewalk device by using the device profile ID. aws iotwireless create-wireless-device --type "Sidewalk" --name ""sidewalk_device" \ --description "My Sidewalk Device Description" \ --positioning "Enabled" \ --destination-name "UplinkDestination" \ --sidewalk DeviceProfileId="12345678-234a-45bc-67de-e8901234f0a1",Positioning={DestinationName="LocationDestination"}
      Note

      For Bluetooth Low Energy based location, AWS IoT returns location coordinates based on the approximate location of nearby Sidewalk Gateways that are connected to Amazon Sidewalk and have the Community Finding feature enabled. Gateway Location Data is AWS Content and is provided to you solely for the purpose of assisting you in locating your devices that are connected to Amazon Sidewalk, and you must only use the data for that purpose. You must only use and access location data via the interface and functionality that we generally make available to you, and you must not attempt to re-identify, reverse engineer, or re-map any Gateway location data provided by us to you.

  3. (Optional) Update your existing Sidewalk end device and get the device's location data

    If you've already provisioned a Sidewalk end device in AWS IoT Wireless, you can update the device to get the device location data.

    Note

    You must enable positioning to use the device location feature.

    Replace LocationDestination with the destination name from the destination to which you want to send the device location data to.

    aws iotwireless update-wireless-device --id wireless-device-id \ --positioning "Enabled" \ --sidewalk Positioning={DestinationName="LocationDestination"}
  4. Get device profile and wireless device information

    Get the device profile and wireless device information as a JSON. The JSON will contain information about the device details, device certificates, private keys, DeviceTypeId, and the Sidewalk manufacturing serial number (SMSN).

    • If you're using the AWS IoT console, you can use the Sidewalk tab of the Devices hub to download a combined JSON file for your Sidewalk end device.

    • If you're using the API operations, store the responses obtained from the API operations GetDeviceProfile and GetWirelessDevice as separate JSON files, such as device_profile.json and wireless_device.json.

      // Store device profile information as a JSON file. aws iotwireless get-device-profile \ --id "12345678-a1b2-3c45-67d8-e90fa1b2c34d" > device_profile.json // Store wireless device information as a JSON file. aws iotwireless get-wireless-device --identifier-type WirelessDeviceId \ --identifier "23456789-abcd-0123-bcde-fabc012345678" > wireless_device.json

Step 3: Provision and register the end device

Using Python commands, you can provision and register your end device. The provisioning script uses the device JSON data that you obtained to generate a manufacturing binary image, which is then flashed on the hardware board. You then register your end device for connecting to the hardware platform. For more information, see Provisioning and registering your end device in the Amazon Sidewalk documentation.

Note

When registering your Sidewalk end device, your gateway must be opted in to Amazon Sidewalk, and your gateway and device must be in range of each other.

Step 4: Connect to Sidewalk end device and exchange messages

After you've registered your end device, you can then connect your end device and start exchanging messages and device data.

  1. Connect your Sidewalk end device

    Connect the HDK to your computer and follow the instructions provided by the vendor documentation to connect to your HDK. For more information, see Provisioning and registering your end device in the Amazon Sidewalk documentation.

  2. View and exchange messages

    Use the MQTT client to subscribe to the topic specified in the rule and view the message received. You can also use the SendDataToWirelessDevice API operation or the send-data-to-wireless-device CLI command to send a downlink message to your device and verify the connectivity status.

    (Optional) You can enable the message delivery status event to check whether the downlink message was successfully received.

    aws iotwireless send-data-to-wireless-device \ --id "<Wireless_Device_ID>" \ --payload-data "SGVsbG8gVG8gRGV2c2lt" \ --wireless-metadata Sidewalk={Seq=1,AckModeRetryDurationSecs=10}