

# Add your device to AWS IoT Core for Amazon Sidewalk
<a name="iot-sidewalk-create-device"></a>

Before creating a wireless device, first create a device profile. Device profiles define the device capabilities and other parameters for your Sidewalk devices. A single device profile can be associated with multiple devices.

After you create a device profile, when you retrieve information about the profile, it returns a `DeviceTypeId`. When you provision your end device, you'll use this ID, the device certificates, application server public key, and the SMSN.

## How to create and add your device
<a name="iot-sidewalk-device-how"></a>

1. Create a device profile for your Sidewalk end devices. Specify a profile name to use for your Sidewalk devices as an alphanumeric string. The profile will help identify the devices to associate it with.
   + (Console) When adding your Sidewalk device, you can also create a new profile. This helps you quickly add your device to AWS IoT Core for Amazon Sidewalk and associate it with a profile.
   + (API) Use the `CreateDeviceProfile` API operation by specifying a profile name and the Sidewalk object, `sidewalk {}`. The API response will contain a profile ID and ARN (Amazon Resource Name).

1. Add your wireless device to AWS IoT Core for Amazon Sidewalk. Specify a destination name and choose the device profile that you created in the previous step. 
   + (Console) When adding your Sidewalk device, enter a destination name, and choose the profile that you created.
   + (API) Use the `CreateWirelessDevice` API operation. Specify a destination name and the ID of the device profile obtained previously.  
**Wireless device parameters**    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/iot-wireless/latest/developerguide/iot-sidewalk-create-device.html)

1. Obtain the JSON file that contains the required information for provisioning your end device.
   + (Console) Download this file from the details page of the Sidewalk device that you created.
   + (API) Use the `GetDeviceProfile` and `GetWirelessDevice` API operations to retrieve information about your device profile and wireless device. Store the API response information as JSON files, such as *`device_profile.json`* and *`wireless_device.json`*.

# Add your device profile and Sidewalk end device
<a name="iot-sidewalk-add-device"></a>

This section shows how you can create a device profile. It also shows how you can use the AWS IoT console and the AWS CLI to add your Sidewalk end device to AWS IoT Core for Amazon Sidewalk.

## Add your Sidewalk device (console)
<a name="iot-sidewalk-add-device-console"></a>

To add your Sidewalk device using the AWS IoT console, go to the [Sidewalk tab of the Devices hub](https://console.aws.amazon.com/iot/home#/wireless/devices?tab=sidewalk), choose **Provision device**, and then perform the following steps.

![\[Workflow for adding, provisioning, and registering your Sidewalk device to connect to the cloud.\]](http://docs.aws.amazon.com/iot-wireless/latest/developerguide/images/iot-sidewalk-provision-device.PNG)


1. 

**Specify device details**

   Specify the configuration information for your Sidewalk device. You can also create a new device profile, or choose an existing profile for your Sidewalk device.

   1. Specify a device name and optional description. The description can be up to 2,048 characters long. These fields can be edited after you create the device.

   1. Choose a device profile to associate with your Sidewalk device. If you have any existing device profiles, you can choose your profile. To create a new profile, choose **Create new profile**, and then enter a name for the profile.
**Note**  
To attach tags to your device profile, after you create your profile, go to the [Profiles hub](https://console.aws.amazon.com/iot/home#/wireless/profiles) and then edit your profile to add this information.

   1. Specify the name of your destination that will route messages from your device to other AWS services. If you haven't already created a destination, go to the [Destinations hub](https://console.aws.amazon.com/iot/home#/wireless/destinations) to create your destination. You can then choose that destination for your Sidewalk device. For more information, see [Add a destination for your Sidewalk end device](iot-sidewalk-qsg-destination.md).

   1. Choose **Next** to continue adding your Sidewalk device.

1. 

**Associate Sidewalk device with AWS IoT thing (Optional)**

   You can optionally associate your Sidewalk device to an AWS IoT thing. IoT things are entries in the AWS IoT device registry. Things make it easier to search and manage your devices. Associating a thing with your device lets your device access other AWS IoT Core features.

   To associate your device with a thing, choose **Automatic thing registration**.

   1. Enter a unique name for the IoT thing that you want to associate your Sidewalk device. Thing names are case sensitive and must be unique in your AWS account and AWS Region.

   1. Provide any additional configurations for your IoT thing, such as using a thing type, or searchable attributes that can be used to filter from a list of things.

   1. Choose **Next** and verify the information about your Sidewalk device, and then choose **Create**.

## Add your Sidewalk device (CLI)
<a name="iot-sidewalk-add-device-api"></a>

To add your Sidewalk device and download the JSON files that will be used to provision your Sidewalk device, perform the following API operations.

**Topics**
+ [Step 1: Create a device profile](#iot-sidewalk-profile-create)
+ [Step 2: Add your Sidewalk device](#iot-sidewalk-device-create)

### Step 1: Create a device profile
<a name="iot-sidewalk-profile-create"></a>

To create a device profile in your AWS account, use the [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CreateDeviceProfile.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CreateDeviceProfile.html) API operation or the [https://docs.aws.amazon.com/cli/latest/reference/create-device-profile.html](https://docs.aws.amazon.com/cli/latest/reference/create-device-profile.html) CLI command. When creating your device profile, specify the name and provide any optional tags as name-value pairs.

For example, the following command creates a device profile for your Sidewalk devices:

```
aws iotwireless create-device-profile \ 
    --name sidewalk_profile --sidewalk {}
```

Running this command returns the Amazon Resource Name (ARN) and the ID of the device profile as output.

```
{
    "DeviceProfileArn": "arn:aws:iotwireless:us-east-1:123456789012:DeviceProfile/12345678-a1b2-3c45-67d8-e90fa1b2c34d",
    "DeviceProfileId": "12345678-a1b2-3c45-67d8-e90fa1b2c34d"
}
```

### Step 2: Add your Sidewalk device
<a name="iot-sidewalk-device-create"></a>

To add your Sidewalk device to your account for AWS IoT Core for Amazon Sidewalk, use the [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CreateWirelessDevice.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CreateWirelessDevice.html) API operation or the [https://docs.aws.amazon.com/cli/latest/reference/create-wireless-device.html](https://docs.aws.amazon.com/cli/latest/reference/create-wireless-device.html) CLI command. When creating your device, specify the following parameters, in addition to an optional name and description for your Sidewalk device.

**Note**  
If you want to associate your Sidewalk device with an AWS IoT thing, use the [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_AssociateWirelessDeviceWithThing.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_AssociateWirelessDeviceWithThing.html) API operation or the [https://docs.aws.amazon.com/cli/latest/reference/associate-wireless-device-with-thing.html](https://docs.aws.amazon.com/cli/latest/reference/associate-wireless-device-with-thing.html) CLI command.

The following command shows an example of creating a Sidewalk device:

```
aws iotwireless create-wireless-device \ 
     --cli-input-json "file://device.json"
```

The following shows the contents of the file `device.json`.

**Contents of device.json**

```
{
  "Type": "Sidewalk",
  "Name": "SidewalkDevice",  
  "DestinationName": "SidewalkDestination",
  "Sidewalk": {
    "DeviceProfileId": "12345678-a1b2-3c45-67d8-e90fa1b2c34d"    
    }
}
```

Running this command returns the device ID and Amazon Resource Name (ARN) as output.

```
{
    "Arn": "arn:aws:iotwireless:us-east-1:123456789012:WirelessDevice/23456789-abcd-0123-bcde-fabc012345678",
    "Id": "23456789-abcd-0123-bcde-fabc012345678"
}
```

#### (Optional) Create your Sidewalk end device and get the Sidewalk device location
<a name="iot-sidewalk-device-create-devicelocation"></a>

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 name to which you want to send the device location data to.

**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" \
  --destination-name "UplinkDestination" \
  --positioning "Enabled" \
  --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.

# Obtain device JSON files for provisioning
<a name="sidewalk-json-get"></a>

After you've added your Sidewalk device to AWS IoT Core for Amazon Sidewalk, download the JSON file that contains the information required to provision your end device. You can retrieve this information using the AWS IoT console or the AWS CLI. For more information about how to provision the device, see [Provisioning and registering your end device](https://docs.sidewalk.amazon/provisioning/) in the *Amazon Sidewalk documentation*.

## Obtain JSON file (console)
<a name="iot-sidewalk-json-get-console"></a>

To obtain the JSON file for provisioning your Sidewalk device:

1. Go to the [Sidewalk devices hub](https://console.aws.amazon.com/iot/home#/wireless/devices?tab=sidewalk).

1. Choose the device that you added to AWS IoT Core for Amazon Sidewalk to view its details.

1. Obtain the JSON file by choosing **Download device JSON file** in the details page of the device that you added.

   A `certificate.json` file will be downloaded that contains the required information for provisioning your end device. The following shows a sample JSON file. It contains the device certificates, private keys, the Sidewalk manufacturing serial number (SMSN), and the `DeviceTypeID`.

   ```
   {
     "p256R1": "grg8izXoVvQ86cPVm0GMyWuZYHEBbbH ... DANKkOKoNT3bUGz+/f/pyTE+xMRdIUBZ1Bw==",
     "eD25519": "grg8izXoVvQ86cPVm0GMyWuZYHEBbbHD ... UiZmntHiUr1GfkTOFMYqRB+Aw==",
     "metadata": {    
       "devicetypeid": "fe98",
       "applicationDeviceArn": "arn:aws:iotwireless:us-east-1:123456789012:WirelessDevice/897ce68e-3ca2-4ed0-85a2-30b0666c4052",
       "applicationDeviceId": "897ce68e-3ca2-4ed0-85a2-30b0666c4052",
       "smsn": "82B83C8B35E856F43CE9C3D59B418CC96B996071016DB1C3BE5901F0F3071A4A",
       "devicePrivKeyP256R1": "3e704bf8d319b3a475179f1d68c60737b28c708f845d0198f2d00d00c88ee018",
       "devicePrivKeyEd25519": "17dacb3a46ad9a42d5c520ca5f47f0167f59ce54d740aa13918465faf533b8d0"
     },
     "applicationServerPublicKey": "5ce29b89c2e3ce6183b41e75fe54e45f61b8bb320efbdd2abd7aefa5957a316b"
   }
   ```

In the details page of your Sidewalk device, you'll also see information about:
+ The device ID, its Amazon Resource Name (ARN), and details about any AWS IoT thing that the device is associated with.
+ The device profile and destination details.
+ The time at which the last uplink message was received from the device.
+ The status that indicates whether your device has been provisioned or registered.

## Obtain JSON file (CLI)
<a name="iot-sidewalk-json-get-api"></a>

To obtain the JSON files for provisioning your Sidewalk end device using the AWS IoT Core for Amazon Sidewalk API or the AWS CLI, save the API response from retrieving information about your device profile and wireless device as JSON files, such as *`wireless_device.json`* and *`device_profile.json`* temporarily. You'll use them for provisioning your Sidewalk device.

The following shows how to retrieve the JSON files.

**Topics**
+ [Step 1: Get device profile information as JSON file](#iot-sidewalk-profile-get)
+ [Step 2: Get Sidewalk device information as JSON file](#iot-sidewalk-get-device)

### Step 1: Get device profile information as JSON file
<a name="iot-sidewalk-profile-get"></a>

Use the [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetDeviceProfile.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetDeviceProfile.html) API operation or the [https://docs.aws.amazon.com/cli/latest/reference/get-device-profile.html](https://docs.aws.amazon.com/cli/latest/reference/get-device-profile.html) CLI command to get information about your device profile that you added to your account for AWS IoT Core for Amazon Sidewalk. To retrieve information about your device profile, specify the profile ID.

The API will then return information about the device profile matching the specified identifier and the device ID. You save this response information as a file, and give it a name such as *`device_profile.json`*.

The following shows an example CLI command:

```
aws iotwireless get-device-profile \ 
    --id "12345678-a1b2-3c45-67d8-e90fa1b2c34d" > device_profile.json
```

Running this command returns the parameters of your device profile, the application server public key, and the `DeviceTypeID`. The following shows a JSON file that contains a sample response information from the API. For more information about the parameters in the API response, see [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetDeviceProfile.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetDeviceProfile.html).

**`GetDeviceProfile` API response (Contents of `device_profile.json`)**

```
{
    "Arn": "arn:aws:iotwireless:us-east-1:123456789012:DeviceProfile/12345678-a1b2-3c45-67d8-e90fa1b2c34d",
    "Id": "12345678-a1b2-3c45-67d8-e90fa1b2c34d",
    "Name": "Sidewalk_profile",
    "LoRaWAN": null,
    "Sidewalk":
    {        
        "ApplicationServerPublicKey": "a123b45c6d78e9f012a34cd5e6a7890b12c3d45e6f78a1b234c56d7e890a1234",
        "DAKCertificateMetadata": [
            {                
                "DeviceTypeId: fe98,
                "CertificateId": "43564A6D2D50524F544F54595045",
                "FactorySupport": false,
                "MaxAllowedSignature": 1000                
            }
        ],
        "QualificationStatus": false
    }
}
```

### Step 2: Get Sidewalk device information as JSON file
<a name="iot-sidewalk-get-device"></a>

Use the [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetWirelessDevice.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetWirelessDevice.html) API operation or the [https://docs.aws.amazon.com/cli/latest/reference/get-wireless-device.html](https://docs.aws.amazon.com/cli/latest/reference/get-wireless-device.html) CLI command to get information about your Sidewalk device that you added to your account for AWS IoT Core for Amazon Sidewalk. To get information about your end device, provide the identifier of the wireless device that you obtained when adding your device. 

The API will then return information about the device matching the specified identifier and the device ID. Save this response information as a JSON file. Give the file a meaningful name, such as *`wireless_device.json`*.

The following shows an example of running the command using the CLI:

```
aws iotwireless get-wireless-device --identifier-type WirelessDeviceId \ 
    --identifier "23456789-abcd-0123-bcde-fabc012345678" > wireless_device.json
```

Running this command returns the device details, device certificates, private keys, and the Sidewalk manufacturing serial number (SMSN). The following shows an example output of running this command. For more information about the parameters in the API response, see [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetWirelessDevice.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetWirelessDevice.html).

**`GetWirelessDevice` API response (Contents of `wireless_device.json`)**

```
{
    "Arn": "arn:aws:iotwireless:us-east-1:123456789012:WirelessDevice/23456789-abcd-0123-bcde-fabc012345678",
    "Description": "test-description",
    "DestinationName": "SidewalkDestination",
    "Id": "23456789-abcd-0123-bcde-fabc012345678",
    "LoRaWAN": "null",
    "Name" : "test-name",
    "Positioning": "Enabled"
    "Sidewalk": {        
        "CertificateId": "4C7438772D50524F544F54595045",
        "DeviceCertificates": [
            {
                "SigningAlg": "Ed25519",
                "Value": "WUqB/E50VP7oZpHtYoBgpzJXYvhv51y/DBIfzNhrleo4UzOWCsIzbaJwft
                            +IPBSUQthDifJDYik0DuU1jLvuR8cpK7YyI7cUD/oZG+4Pro/s3nAIhy
                            XmhUlepmbveVxM8boiTiaUlL4iB9DoKrB41pWdHeg7hR8BDrE1m4sf5Q
                            9ZUwDy5BqMafeW0RUKZMVunpChji0dwC5VoSSb8IT7V+bKTJXXdZ8lP1
                            1jsiuJfwF64Eq1NCe2qKb7gql5u+qBE7vatDOSonwN56I6Ah8HWYRSyJ
                            Tk7DSJKknSY7KGyLjs0qMI8L8AeJ++UIO/jOsGnhC6Ku1ba62bEPmIBr
                            +889NhOngiIt1+1DrSOO59a1PLYqfVa5ejKq0tzzbyNG/m/oW72kkGGH
                            Ruec2zOXEO86kf4X0qzFfTKoo/6lt67XfXIQkO4wApCgJ8AHwHa3xz+d
                            h+W6mFwYFRqrQQT8s0SjSuDtLCaqZhnch47MZk7E/itqP4JnJ7RsJHWx
                            XsG2gTNlRghfG+zhpKzVVdvVVZeZ22f2WZ2QoGlzXxrW0/b7mqpO2l+8
                            fzRYYdqAp1AAADGz+gFBeX/ZNN8VJwnsNfgzj4me1HgVJdUo4W9kvx9c
                            r2jHWkC3Oj/bdBTh1+yBjOC53yHlQK/l1GHrEWiWPPnE434LRxnWkwr8
                            EHD4oieJxC8fkIxkQfj+gHh"
            },
            {
                "SigningAlg": "P256r1",
                "Value": "hDdkJw9L2uMCORjImjMHqzNR6nYYh6QKncSl5GthQNmHmGU8a+SOqDXWwDNt3
                            VSntpbTTQl7cMIusqweQo+JPXXWElbGh7eaxPGz4ZeF5yM2cqVNUrQr1l
                            X/6lZ+OLuycrFrLzzB9APi0NIMLqV/Rt7XJssHQs2RPcT1ul/2XVpa6zt
                            ULJeQi2JwhTb/k48wbh/EvafG/ibrIp4O3ZDa4f+5SVWvbY5eyDDXcohv
                            z/OcCtuRjAkzKBCvIjBDnCv1McjVdCO3+utizGntfhAo1RZstnOoRkgVF
                            2WuMT9IrUmzYximuTXUmWtjyFSTqgNBZwHWUTlMmjlpLCVzZQWM4zOisX
                            UAAALPsP34BS6EzJO5AsS5pC7QTpjBtAbLN9SdXOT9w4H1x8Nkp0ujLxW
                            RN37IEy0V9DrPK2w1g74uqWPfUPnSBjtvM55JnQpmm23WQNvHa1Vr6zmW
                            DjzjHpcNirPbzXyBlKEhkX4xylaSMnm4UrVXtAMaAJ/csC4HPTKr3dazd
                            vEkhwGAAAIFByCjSp/5WHc4AhsyjMvKCsZQiKgiI8ECwjfXBaSZdY4zYs
                            RlO3FC428H1atrFChFCZT0Bqt5LPXD38bMSB+vAUJiP8XqiEdXeqf2mYM
                            J5ykoDpwkve/cUQfPpjzFQlQfvwjBwiJDANKkOKoNT3bUGz+/f/pyTE+x
                            MRdIUBZ1Bw=="
            }
        ],
        "DeviceProfileId":"0ff5b0c6-f149-4498-af34-21993acd52a7",
        "Positioning": {
                        "DestinationName": SidewalkLocationDestination,
                        },
        "PrivateKeys": [
            {
                "SigningAlg": "Ed25519",
                "Value": "2c24d4572327f23b9bef38097137c29224a9e979081b3d90124ac9dfa477934e"
            },
            {
                "SigningAlg": "P256r1",
                "Value": "38d526f29cfaf142f596deca187bd809ef71bc13435eedc885b63bb825d63def"
            }
        ],        
        "SidewalkManufacturingSn": "843764270F4BDAE3023918C89A3307AB3351EA761887A40A9DC
                            4A5E46B6140D9",
        "Status": "PROVISIONED"
    },
    "Type": "Sidewalk",
    
    ...
    
}
```

## Next steps
<a name="iot-sidewalk-json-next"></a>

Store the JSON files, *`wireless_device.json`* and *`device_profile.json`* temporarily, as you'll use them in the next step to provision and register your end device for connecting to the hardware platform. For more information, see [Provisioning and registering your end device](https://docs.sidewalk.amazon/provisioning/) in the *Amazon Sidewalk documentation*.