

# Managing devices with AWS IoT Core for LoRaWAN
Managing LoRaWAN devices

Following are some important considerations when using your devices with AWS IoT Core for LoRaWAN. For information about how to add your device to AWS IoT Core for LoRaWAN, see [Onboard your devices to AWS IoT Core for LoRaWAN](lorawan-onboard-end-devices.md).

## Device considerations


When selecting a device that you want to use for communicating with AWS IoT Core for LoRaWAN, consider the following.
+ Available sensors
+ Battery capacity
+ Energy consumption
+ Cost
+ Antenna type and transmission range

## Using devices with gateways qualified for AWS IoT Core for LoRaWAN


The devices that you use can be paired with wireless gateways that are qualified for use with AWS IoT Core for LoRaWAN. You can find these gateways and developer kits in the [AWS Partner Device Catalog](https://devices.amazonaws.com/search?page=1&sv=iotclorawan). We also recommend that you consider proximity of these devices to your gateways. For more information, see [Using qualified gateways from the AWS Partner Device Catalog](lorawan-manage-gateways.md#lorawan-qualified-gateways).

## LoRaWAN version


AWS IoT Core for LoRaWAN supports all devices that comply to 1.0.x or 1.1 LoRaWAN specifications standardized by LoRa Alliance.

## Activation modes


Before your LoRaWAN device can send uplink data, you must complete a process called *activation* or *join* procedure. To activate your device, you can either use OTAA (Over the air activation) or ABP (Activation by personalization). We recommend that you use OTAA to activate your device because new session keys are generated for each activation, which makes it more secure.

Your wireless device specification is based on the LoRaWAN version and activation mode, which determines the root keys and session keys generated for each activation. For more information, see [Add your wireless device specification to AWS IoT Core for LoRaWAN using the console](lorawan-end-devices-add.md#lorawan-end-device-spec-console).

## Device classes


LoRaWAN devices can send uplink messages at any time. Listening to downlink messages consumes battery capacity and reduces battery duration. The LoRaWAN protocol specifies three classes of LoRaWAN devices.
+ Class A devices sleep most of the time and listen for downlink messages only for a short period of time. These devices are mostly battery-powered sensors with a battery lifetime of up to 10 years.
+ Class B devices can receive messages in scheduled downlink slots. These devices are mostly battery-powered actuators.
+ Class C devices never sleep and continuously listen to incoming messages and so there isn't much delay in receiving the messages. These devices are mostly mains-powered actuators.

For more information about these wireless device considerations, refer to the resources mentioned in [Learn more about LoRaWAN](what-is-iot-lorawan.md#lorawan-learn-more).

**Topics**
+ [

## Device considerations
](#lorawan-devices-criteria)
+ [

## Using devices with gateways qualified for AWS IoT Core for LoRaWAN
](#lorawan-devices-qualified-gateways)
+ [

## LoRaWAN version
](#lorawan-lorawan-version)
+ [

## Activation modes
](#lorawan-activation-modes)
+ [

## Device classes
](#lorawan-device-classes)
+ [

# Using adaptive data rate (ADR) with AWS IoT Core for LoRaWAN
](iot-lorawan-adr.md)
+ [

# View format of uplink messages sent from LoRaWAN devices
](lorawan-uplink-metadata-format.md)
+ [

# Queue downlink messages to send to LoRaWAN devices
](lorawan-downlink-queue.md)
+ [

# Managing LoRaWAN traffic from public networks (Everynet)
](iot-lorawan-roaming.md)

# Using adaptive data rate (ADR) with AWS IoT Core for LoRaWAN
Performing ADR for LoRaWAN devices

To optimize the device transmission power consumption while making sure that messages from the end devices are received at the gateways, AWS IoT Core for LoRaWAN uses adaptive data rate. Adaptive data rate instructs the end devices to optimize the data rate, transmission power, and the number of retransmissions while attempting to reduce the error rate of the packets received at the gateways. For example, if your end device is located close to the gateways, adaptive data rate reduces the transmission power and increases the data rate. 

**Topics**
+ [

## How adaptive data rate (ADR) works
](#iot-lorawan-adr-algorithm)
+ [

## Configure data rate limits (CLI)
](#iot-lorawan-adr-use)

## How adaptive data rate (ADR) works


To enable ADR, your device must set the ADR bit in the frame header. Once the ADR bit is set, AWS IoT Core for LoRaWAN sends the `LinkADRReq` MAC command and your devices respond with the `LinkADRAns` command which includes the ACK status of the ADR command. Once your devices ACK the ADR command, it will then follow the ADR instructions from AWS IoT Core for LoRaWAN and adjust the transmission parameter values for optimal data rate. 

The AWS IoT Core for LoRaWAN ADR algorithm uses the SINR information in the uplink metadata history to determine the optimal transmission power and data rate to use for the devices. The algorithm uses the 20 most recent uplink messages that start once the ADR bit is set in the frame header. To determine the number of retransmissions, it uses the packet error rate (PER), which is a percentage of the total number of packets that are lost. When you use this algorithm, you can only control the range of data rates, that is, the minimum and maximum limits for the data rates.

## Configure data rate limits (CLI)


By default, AWS IoT Core for LoRaWAN will perform ADR when you set the ADR bit in the frame header of your LoRaWAN device. You can control the minimum and maximum limits for the data rate when creating a service profile for your LoRaWAN devices using the AWS IoT Wireless API operation [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CreateServiceProfile.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CreateServiceProfile.html), or the AWS CLI command, [https://docs.aws.amazon.com/cli/latest/reference/iotwireless/create-service-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/create-service-profile.html).

To specify the minimum and maximum limits for the data rate, use the `DrMin` and `DrMax` parameters with the `CreateServiceProfile` API operation. The default minimum and maximum data rate limits are 0 and 15. For example, the following CLI command sets a minimum data rate limit of 3 and a maximum limit of 12.

To specify the minimum and maximum limits for the transmit power range of LoRaWAN devices, use the `TxPowerIndexMin` and `TxPowerIndexMax` parameters with the `CreateServiceProfile` API operation. The default minimum and maximum power ranges are 0 and 15. The following following CLI command sets a minimum Transmit Power Index of 3 and a maximum of 12.

**Note**  
Regional parameters override service profile settings for minimum and maximum Transmit Power Index (`TxPowerIndexMin` and `TxPowerIndexMax`). For example, if you set `TxPowerIndexMin` to 14 for a device that operates in the US915 Band, the configuration you set won't be applied. To learn more about regional parameters, see [RP002-1.0.4 Regional Parameters](https://resources.lora-alliance.org/technical-specifications/rp002-1-0-4-regional-parameters).

To specify the minimum and maximum number of transmissions, use the `NbTransMin` and `NbTransMax` parameters with the `CreateServiceProfile` API operation. The default minimum and maximum number of transmissions is 0 and 3.

```
aws iotwireless create-service-profile \ 
    --lorawan DrMin=3,DrMax=12,TxPowerIndexMin=3,TxPowerIndexMax=12,NbTransMin=1,NbTransMax=4
```

Running this command generates an ID and an Amazon Resource Name (ARN) for the service profile.

```
{
    "Arn": "arn:aws:iotwireless:us-east-1:123456789012:ServiceProfile/12345678-a1b2-3c45-67d8-e90fa1b2c34d",
    "Id": "12345678-a1b2-3c45-67d8-e90fa1b2c34d"
}
```

You can get the values of the parameters specified using the AWS IoT Wireless API operation [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetServiceProfile.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetServiceProfile.html), or the AWS CLI command, [https://docs.aws.amazon.com/cli/latest/reference/iotwireless/get-service-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/get-service-profile.html). 

```
aws iotwireless get-service-profile --id "12345678-a1b2-3c45-67d8-e90fa1b2c34d"
```

Running this command generates the values for the service profile parameters.

```
{
    "Arn": "arn:aws:iotwireless:us-east-1:651419225604:ServiceProfile/12345678-a1b2-3c45-67d8-e90fa1b2c34d",
    "Id": "12345678-a1b2-3c45-67d8-e90fa1b2c34d",
    "LoRaWAN": {
        "AddGwMetadata": false,
        "DrMax": 12,
        "DrMin": 3,
        "NbTransMax": 4,
        "NbTransMin": 1,
        "PrAllowed": false,
        "RaAllowed": false,
        "TxPowerIndexMax": 12,
        "TxPowerIndexMin": 3
    }
}
```

If you've created multiple profiles, you can use the API operation, [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_ListServiceProfiles.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_ListServiceProfiles.html), or the AWS CLI command, [https://docs.aws.amazon.com/cli/latest/reference/iotwireless/list-service-profiles.html](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/list-service-profiles.html) to list the service profiles in your AWS account, and then use the `GetServiceProfile` API or the `get-service-profile` CLI command to retrieve the service profile for which you customized the data rate limits. 

# View format of uplink messages sent from LoRaWAN devices
View LoRaWAN uplink message format

To faciliate seamless connection between your LoRaWAN devices and the cloud, you can use AWS IoT Core for LoRaWAN. The AWS IoT Core for LoRaWAN service provides secure and reliable data exchange between your LoRaWAN devices and AWS IoT Core. It acts as a bridge, translating the LoRaWAN protocol into MQTT messages that can be seamlessly ingested by AWS IoT Core. You can use this capability in applications, such as real-time data processing, device state management, and integration with other AWS services. 

After you've connected your LoRaWAN device to AWS IoT Core for LoRaWAN, your devices can start sending messages to the cloud. Uplink messages are messages that are sent from your device and received by AWS IoT Core for LoRaWAN. Your LoRaWAN devices can send uplink messages at any time, which are then forwarded to other AWS services and cloud-hosted applications. Messages that are sent from AWS IoT Core for LoRaWAN and other AWS services and applications to your devices are called downlink messages.

This topic shows how you can observe the format of the uplink message that you'll receive from your wireless device.

## Before you can observe the uplink messages


You must have onboarded your wireless device and connected your device to AWS IoT so that it can transmit and receive data. For information about onboarding your device to AWS IoT Core for LoRaWAN, see [Onboard your devices to AWS IoT Core for LoRaWAN](lorawan-onboard-end-devices.md).

## What do the uplink messages contain?


LoRaWAN devices connect to AWS IoT Core for LoRaWAN by using LoRaWAN gateways. The uplink message that you receive from the device will contain the following information.
+ Payload data that corresponds to the encrypted payload message that is sent from the wireless device.
+ Wireless metadata that includes:
  + Device information such as DevEui, the data rate, and the frequency channel in which the device is operating.
  + Optional additional parameters and the gateway information for gateways that are connected to the device. The gateway parameters include the gateway's EUI, the SNR, and RSSi.

  By using the wireless metadata, you can obtain useful information about the wireless device and the data that is transmitted between your device and AWS IoT. For example, you can use the `AckedMessageId` parameter to check whether the last confirmed downlink message has been received by the device. Optionally, if you choose to include the gateway information, you can identify whether you want to switch to a stronger gateway channel that's closer to your device.

## How to observe the uplink messages?


After you've onboarded your device, you can use the [MQTT test client](https://console.aws.amazon.com/iot/home#/test) on the **Test** page of the AWS IoT console to subscribe to the topic that you specified when creating your destination. You'll start to see messages after your device is connected and starts sending payload data.

This diagram identifies the key elements in a LoRaWAN system connected to AWS IoT Core for LoRaWAN, which shows the primary data plane and how data flows through the system.

![\[Image showing how AWS IoT Core for LoRaWAN data is passed from a wireless device to AWS IoT and other services.\]](http://docs.aws.amazon.com/iot-wireless/latest/developerguide/images/iot-lorawan-data-flow.png)


When the wireless device starts sending uplink data, AWS IoT Core for LoRaWAN wraps the wireless metadata information with the payload and then sends it to your AWS applications.

## Uplink message examples


The following examples show the format of the uplink message received from your device. The format includes the gateway metadata that varies depending on whether you're using the public network, or your own private LoRaWAN gateway that you onboarded to AWS IoT Core for LoRaWAN.

### Uplink message example with private LoRaWAN gateway


This example uses a private LoRaWAN gateway to show the gateway metadata information in the uplink message. The metadata consists of the gateway EUI, SNR (signal to noise ratio), and RSSI (Received signal to strength indicator). These values can help you determine the strength of your gateway channel and whether to switch to a stronger channel.

In the metadata, the field:
+ `Battery` indicates the battery level reported by the device. It ranges from 0 to 255. 0 indicates that the device is connected to an external power source. 1 and 254 are the minimum and maximum battery levels. A value of 255 indicates that the device cannot measure the battery level.
+ `Margin` represents the demodulation SNR (signal-to-noise ratio) in dB rounded to the nearest integer value. It ranges from -32 to \$131.

```
{
    "WirelessDeviceId": "5b58245e-146c-4c30-9703-0ca942e3ff35", 
    "PayloadData": "Cc48AAAAAAAAAAA=",    
    "WirelessMetadata":
    {
        "LoRaWAN":
        {
            "ADR": false,
            "Bandwidth": 125,
            "ClassB": false,
            "CodeRate": "4/5",
            "DataRate": "0",
            "DevAddr": "00b96cd4",
            "DevEui": "58a0cb000202c99",            
            "FOptLen": 2,
            "FCnt": 1,
            "Fport": 136,   
            "Frequency": "868100000",  
            "Battery": 210,
            "Margin": -6,
            "Gateways": [
             {
                    "GatewayEui": "80029cfffe5cf1cc",      
                    "Snr": -29,
                    "Rssi": 9.75
             }
             ],  
            "MIC": "7255cb07",  
            "MType": "UnconfirmedDataUp",
            "Major": "LoRaWANR1",
            "Modulation": "LORA", 
            "PolarizationInversion": false,    
            "SpreadingFactor": 12,                         
            "Timestamp": "2021-05-03T03:24:29Z"
            
        }
    }
}
```

### Uplink message example with public network


You can also connect to the public network instead of your own private LoRaWAN gateway. The public network is provided and operated as a service directly by Everynet. The following example shows the public LoRaWAN network metadata in the uplink message. The metadata consists of the ID of the gateway and the network provider (Everynet), whether downlink is allowed, and the SNR and RSSI values. For more infrrmation about the public network, see [Managing LoRaWAN traffic from public networks (Everynet)](iot-lorawan-roaming.md).

**Note**  
The uplink message will mention `PublicGateways` to indicate that it's received from the public network and not a private LoRaWAN gateway.

```
{
    "WirelessDeviceId": "5b58245e-146c-4c30-9703-0ca942e3ff35", 
    "PayloadData": "Cc48AAAAAAAAAAA=",    
    "WirelessMetadata":
    {
        "LoRaWAN":
        {
            "ADR": false,
            "Bandwidth": 125,
            "ClassB": false,
            "CodeRate": "4/5",
            "DataRate": "0",
            "DevAddr": "00b96cd4",
            "DevEui": "58a0cb000202c99",            
            "FOptLen": 2,
            "FCnt": 1,
            "Fport": 136,   
            "Frequency": "868100000",     
            "PublicGateways": [ 
                { 
                    "DlAllowed": true,
                    "Id": "0x3abe094",
                    "ProviderNetId": "0x0000b",
                    "RfRegion": "US915",
                    "Rssi": -12,
                    "Snr": 6.75
                }
            ],
            "MIC": "7255cb07",  
            "MType": "UnconfirmedDataUp",
            "Major": "LoRaWANR1",
            "Modulation": "LORA", 
            "PolarizationInversion": false,    
            "SpreadingFactor": 12,                         
            "Timestamp": "2021-05-03T03:24:29Z"
            
        }
    }
}
```

### Uplink message example without gateway metadata


If you want to exclude the gateway metadata information from your uplink metadata, disable the **AddGwMetadata** parameter when you create the service profile. For information about disabling this parameter, see [Add service profiles](lorawan-define-profiles.md#lorawan-service-profiles).

In this case, you won't see the `Gateways` section in the uplink metadata, as illustrated in the following example.

```
{  
    "WirelessDeviceId": "0d9a439b-e77a-4573-a791-49d5c0f4db95",
    "PayloadData": "AAAAAAAA8=",
    "WirelessMetadata": {
        "LoRaWAN": {
            "ClassB": false,
            "CodeRate": "4/5",
            "DataRate": "1",
            "DevAddr": "01920f27",
            "DevEui": "ffffff10000163b0",
            "FCnt": 1,
            "FPort": 5,
            "Battery": 125,
            "Margin": -12,
            "Timestamp": "2021-04-29T05:19:43.646Z"
    }
  }
}
```

# Queue downlink messages to send to LoRaWAN devices
Queue LoRaWAN downlink messages

Cloud-hosted applications and other AWS services can send downlink messages to your wireless devices. Downlink messages are messages that are sent from AWS IoT Core for LoRaWAN to your wireless device. You can schedule and send downlink messages for each device that you've onboarded to AWS IoT Core for LoRaWAN.

If you have multiple devices for which you want to send a downlink message, you can use a multicast group. Devices in a multicast group share the same multicast address, which is then distributed to an entire group of recipient devices. For more information, see [Create multicast groups to send a downlink payload to multiple devices](lorawan-multicast-groups.md). 

## How a downlink message queue works


The device class of your LoRaWAN device determines how the messages in your queue are sent to the device. Class A devices send an uplink message to AWS IoT Core for LoRaWAN to indicate that the device is available to receive downlink messages. Class B devices can receive messages at regular downlink slots. Class C devices can receive downlink messages at any time. For more information about device classes, see [Device classes](lorawan-manage-end-devices.md#lorawan-device-classes).

The following shows how messages are queued and sent to your class A devices.

1. AWS IoT Core for LoRaWAN buffers the downlink message that you added to the queue with the frame port, payload data, and the acknowledge mode parameters that you specified by using the AWS IoT console or the AWS IoT Wireless API.

1. Your LoRaWAN device sends an uplink message to indicate that it's online and can start receiving downlink messages.

1. If you added more than one downlink message to the queue, AWS IoT Core for LoRaWAN sends the first downlink message in the queue to your device with the acknowledge (ACK) flag set.

1. Your device either sends an uplink message to AWS IoT Core for LoRaWAN immediately, or it sleeps until the next uplink message and includes the ACK flag in the message.

1. When AWS IoT Core for LoRaWAN receives the uplink message with the ACK flag, it clears the downlink message from the queue, indicating that your device has successfully received the downlink message. If the ACK flag is missing from the uplink message after checking three times, the message is discarded.

## Perform downlink queue operations by using the console


You can use the AWS Management Console to queue downlink messages and clear individual messages, or the entire queue, as needed. For class A devices, after an uplink is received from the device to indicate that it's online, the queued messages are then sent to the device. After the message is sent, it's automatically cleared from the queue.

**Queue downlink messages**  
To create a downlink message queue

1. Go to the [Devices hub of the AWS IoT console](https://console.aws.amazon.com/iot/home#/wireless/devices) and choose the device for which you want to queue downlink messages.

1. In the **Downlink messages** section of the device details page, choose **Queue downlink messages**.

1. Specify the following parameters to configure your downlink message:
   + **FPort**: Choose the frame port for the device to communicate with AWS IoT Core for LoRaWAN.
   + **Payload**: Specify the payload message that you want to send to your device. The maximum payload size is 242 bytes. If adaptive data rate (ADR) is enabled, AWS IoT Core for LoRaWAN uses it to choose the optimal data rate for your payload size. You can further optimize the data rate as needed.
   + **Acknowledge mode**: Confirm whether your device has received the downlink message. If a message requires this mode, you'll see an uplink message with the ACK flag in your data stream, and the message will be cleared from the queue.

1. To add your downlink message to the queue, choose **Submit**.

Your downlink message has now been added to the queue. If you don't see your message or you receive an error, you can troubleshoot the error as described in [Troubleshoot downlink message queue errors](#lorawan-downlink-queue-troubleshoot). 

**Note**  
After your downlink message has been added to the queue, you can no longer edit the parameters **FPort**, **Payload**, and **Acknowledge mode**. To send a downlink message with different values for these parameters, you can delete this message and queue a new downlink message with the updated parameter values.

The queue lists the downlink messages you've added. To see the payload for the uplink and downlink messages that are exchanged between your devices and AWS IoT Core for LoRaWAN, you can use network analyzer. For more information, see [Monitoring of LoRaWAN resources using network analyzer](network-analyzer-overview.md).

**List downlink message queue**  
The downlink message that you created is added to the queue. Each subsequent downlink message is added to the queue after this message. You can see a list of downlink messages in the **Downlink messages** section of the device details page. After an uplink is received, the messages are sent to the device. After a downlink message has been received by your device, it will be removed from the queue. The next message then moves up in the queue to be sent to your device.

**Delete individual downlink messages or clear entire queue**  
Each downlink message is cleared from the queue automatically after it's sent to your device. You can also delete individual messages or clear the entire downlink queue. These actions can't be undone.
+ If you find messages in the queue that you don't want to send, choose the messages and choose **Delete**.
+ If you don't want to send any messages from the queue to your device, you can clear the entire queue by choosing **Clear downlink queue**.

## Perform downlink queue operations by using the API


You can use the AWS IoT Wireless API to queue downlink messages and clear individual messages, or the entire queue, as needed.

**Queue downlink messages**  
To create a downlink message queue, use the [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_SendDataToWirelessDevice.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_SendDataToWirelessDevice.html) API operation or the [cli/latest/reference/iotwireless/send-data-to-wireless-device.html](cli/latest/reference/iotwireless/send-data-to-wireless-device.html) CLI command.

```
aws iotwireless send-data-to-wireless-device \
    --id "11aa5eae-2f56-4b8e-a023-b28d98494e49" \
    --transmit-mode "1" \
    --payload-data "SGVsbG8gVG8gRGV2c2lt" \
    --wireless-metadata LoRaWAN={FPort=1}
```

The output of running this command generates a `MessageId` for the downlink message. In some cases, even if you receive the `MessageId`, packets can get dropped. For more information about how you can resolve the error, see [Troubleshoot downlink message queue errors](#lorawan-downlink-queue-troubleshoot).

```
{
    MessageId: "6011dd36-0043d6eb-0072-0008"
}
```

**List downlink messages in the queue**  
To list all downlink messages in the queue, use the [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_ListQueuedMessages.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_ListQueuedMessages.html) API operation or the [https://docs.aws.amazon.com/cli/latest/reference/iotwireless/list-queued-messages.html](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/list-queued-messages.html) CLI command.

```
aws iotwireless list-queued-messages
```

By default, a maximum of 10 downlink messages are displayed when running this command.

**Remove individual downlink messages or clear entire queue**  
To remove individual messages from the queue or to clear the entire queue, use the [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_DeleteQueuedMessages.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_DeleteQueuedMessages.html) API operation or the [https://docs.aws.amazon.com/cli/latest/reference/iotwireless/delete-queued-messages.html](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/delete-queued-messages.html) CLI command.
+ To remove individual messages, provide the `messageID` for messages you want to remove for your wireless device, specified by the `wirelessDeviceId`.
+ To clear the entire downlink queue, specify `messageID` as `*` for your wireless device, specified by the `wirelessDeviceId`.

## Troubleshoot downlink message queue errors


Here are some things to check if you're not seeing the expected results:
+ 

**Downlink messages don't appear in the AWS IoT console**  
If you don't see your downlink message in the queue after adding it as described in [Perform downlink queue operations by using the console](#lorawan-downlink-queue-console), it might be because your device hasn't completed a process called *activation* or *join procedure*. This procedure is completed when your device onboards with AWS IoT Core for LoRaWAN. For more information, see [Add your wireless device specification to AWS IoT Core for LoRaWAN using the console](lorawan-end-devices-add.md#lorawan-end-device-spec-console).

  After onboarding your device to AWS IoT Core for LoRaWAN, you can monitor your device to check whether join and rejoin succeeded by using the network analyzer or Amazon CloudWatch. For more information, see [Monitoring tools](monitoring-cloudwatch.md#monitoring-tools).
+ 

**Missing downlink message packets when using the API**  
When you use the `SendDataToWirelessDevice` API operation, the API returns a unique `MessageId`. However, it can't confirm whether your LoRaWAN device has received the downlink message. The downlink packets can get dropped in cases such as when your device hasn't completed the join procedure. For more information about how to resolve this error, see the previous section.
+ 

**Missing ARN error when sending downlink message**  
When sending a downlink message to your device from the queue, you can receive a missing Amazon Resource Name (ARN) error. This error might occur because the destination hasn't been specified correctly for the device that's receiving the downlink message. To resolve this error, check the destination details for your device.

# Managing LoRaWAN traffic from public networks (Everynet)
Managing traffic from public LoRaWAN networks

You can connect your LoRaWAN devices to the cloud in minutes by using publicly available LoRaWAN networks. AWS IoT Core for LoRaWAN now supports Everynet’s network coverage in the US, UK, Ireland, and Spain. When using the public network, you'll be charged a public network connectivity charge for each device every month. The pricing applies to all AWS Regions where public network connectivity is offered. For information about pricing for this feature, see the [AWS IoT Core pricing page](https://aws.amazon.com//iot-core/pricing/).

**Important**  
The public network is operated and provided as a service directly by Everynet. Before using this feature, see the applicable [AWS Service Terms](https://aws.amazon.com/service-terms/). In addition, if you use a public network through AWS IoT Core for LoRaWAN, certain LoRaWAN device information such as `DevEUI` and `JoinEUI` will be replicated across regions where AWS IoT Core for LoRaWAN is available.

AWS IoT Core for LoRaWAN supports the public LoRaWAN network according to the LoRa Alliance specification for roaming, as described in [LoRaWAN Backend Interfaces 1.0 Specification](https://lora-alliance.org/wp-content/uploads/2020/11/lorawantm-backend-interfaces-v1.0.pdf). The public network capability can be used to connect your end devices that are outside the home network. To support this capability, AWS IoT Core for LoRaWAN partners with Everynet to offer extended radio coverage.

## Benefits of using a public LoRaWAN network


Your LoRaWAN devices can use a public network to connect to the cloud, which reduces the time to deployment, and reduces the time and cost that are required to maintain a private LoRaWAN network.

By using a public LoRaWAN network, you'll receive benefits such as coverage extension, running core without radio network, and coverage densification. This feature can be used to:
+ Provide coverage to devices when they move out of their home network, such as *Device A* in figure shown in the [Public LoRaWAN network support architecture](lorawan-roaming-works.md#lorawan-roaming-architecture) section.
+ Extend coverage to devices that don't have a LoRa gateway to connect to, such as *Device B* in figure shown in the [Public LoRaWAN network support architecture](lorawan-roaming-works.md#lorawan-roaming-architecture) section. The device can then use the gateway provided by the partner to connect to the home network.

Your LoRaWAN devices can use a public network to connect to the cloud using the roaming feature, which reduces the time to deployment, and reduces the time and cost that are required to maintain a private LoRaWAN network.

The following sections describe the public network support architecture, how public LoRaWAN network support works, and how to use this feature.

**Topics**
+ [

## Benefits of using a public LoRaWAN network
](#lorawan-roaming-benefits)
+ [

# How LoRaWAN public network support works
](lorawan-roaming-works.md)
+ [

# How to use AWS IoT Core for LoRaWAN public network support
](lorawan-roaming-use.md)

# How LoRaWAN public network support works
How LoRaWAN public network support works

AWS IoT Core for LoRaWAN supports the passive roaming feature, according to the LoRa Alliance specification. With passive roaming, the roaming process is entirely transparent to the end device. End devices that roam outside the home network can connect to gateways in that network and exchange uplink and downlink data using the application server. The devices stay connected to the home network throughout the entire roaming process.

**Note**  
AWS IoT Core for LoRaWAN supports only the stateless feature of passive roaming. Handover roaming is not supported. In handover roaming, your device will switch to a different carrier when it travels outside the home network.

**Topics**
+ [

## Public LoRaWAN network concepts
](#lorawan-roaming-concepts)
+ [

## Public LoRaWAN network support architecture
](#lorawan-roaming-architecture)

## Public LoRaWAN network concepts


The following concepts are used by the public network feature supported by AWS IoT Core for LoRaWAN.

**LoRaWAN network server (LNS)**  
An LNS is a standalone private server that can run on your premises or can be a cloud-based service. AWS IoT Core for LoRaWAN is an LNS that offers services on the cloud.

**Home network server (hNS)**  
The home network is the network that the device belongs to. The home network server (hNS) is an LNS where AWS IoT Core for LoRaWAN stores the provisioning data of the device, such as the `DevEUI`, `AppEUI`, and session keys. 

**Visited network server (vNS)**  
The visited network is the network that the device gets coverage from when it leaves the home network. The visited network server (vNS) is an LNS that has a business and technical agreement with the hNS for being able to serve the end device. AWS partner, Everynet, acts as the visited network to provide coverage.

**Serving network server (sNS)**  
The serving network server (sNS) is an LNS that handles the MAC commands for the device. There can be only one sNS for one LoRa session.

**Forwarding network server (fNS)**  
The forwarding network server (fNS) is an LNS that manages the radio gateways. There can be zero or more fNS involved in one LoRa session. This network server manages the forwarding of data packets that are received from the device to the home network.

## Public LoRaWAN network support architecture


The following architecture diagram shows how AWS IoT Core for LoRaWAN partners with Everynet to provide public network connectivity. In this case, *Device A* is connected to the hNS (home network server) provided by AWS IoT Core for LoRaWAN through a LoRa gateway. When Device A moves out of the home network, it enters a visited network, and is covered by the visited network server (vNS) provided by Everynet. The vNS also extends coverage to *Device B* which doesn't have a LoRa gateway to connect to.

You can view the public network coverage information in the AWS IoT console as described in the following section.

![\[Image showing how AWS IoT Core for LoRaWAN supports roaming to support devices that move out of home network, and to extend coverage to devices that don't have a gateway to connect to.\]](http://docs.aws.amazon.com/iot-wireless/latest/developerguide/images/iot-lorawan-roaming-architecture.png)


 AWS IoT Core for LoRaWAN uses a roaming hub functionality, in accordance with the [LoRa Alliance LoRaWAN Roaming Hub Technical Recommendation](https://lora-alliance.org/wp-content/uploads/2022/01/TR010-1.0.0-LoRaWAN-Roaming-Hub.pdf). The roaming hub provides an endpoint for Everynet to route the traffic received from the end device. In this case, Everynet acts as a forwarding network server (fNS) to forward the traffic received from the device. It uses an HTTP RESTful API, as defined by the LoRa Alliance specification.

**Note**  
If your device moves from its home network and enters a location where both your home network and Everynet can offer coverage, it uses first-come-first-serve policy to determine whether to connect to your LoRa gateway, or to Everynet's gateway.

When visiting a public network, the hNS and serving network server (sNS) are separated. Uplink and downlink packets are then exchanged between the sNS and hNS.

# How to use AWS IoT Core for LoRaWAN public network support
How to use LoRaWAN public network

To use Everynet's public network support, you enable certain roaming parameters when creating the service profile. In this beta release, these parameters are available when you use the AWS IoT Wireless API, or the AWS CLI. The following sections show the parameters you must enable, and how to enable public network using the AWS CLI.

**Note**  
You can enable public network support only when creating a new service profile. You can't update an existing profile to enable public network using these parameters.

**Topics**
+ [

## Roaming parameters
](#lorawan-roaming-parameters)
+ [

## Enable public network support for devices
](#lorawan-roaming-enable)
+ [

## View coverage information
](#lorawan-roaming-coverage)

## Roaming parameters


Specify the following parameters when creating a service profile for your device. Specify these parameters when adding a service profile from the [Profiles](https://console.aws.amazon.com/iot/home#/wireless/profiles) hub of the AWS IoT console, or using the AWS IoT Wireless API operation, [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CreateServiceProfile.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CreateServiceProfile.html), or the AWS CLI command, [https://docs.aws.amazon.com/cli/latest/reference/iotwireless/create-service-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/create-service-profile.html).

**Note**  
AWS IoT Core for LoRaWAN does not support handover roaming. When creating the service profile, you can't enable the `HrAllowed` parameter that specifies whether to use handover roaming.
+ Roaming activation allowed (`RaAllowed`): This parameter specifies whether to enable roaming activation. Roaming activation enables an end device to activate under the coverage of a vNS. When using the roaming feature, `RaAllowed` must be set to `true`.
+ Passive roaming allowed (`PrAllowed`): This parameter specifies whether to enable passive roaming. When using the roaming feature, `PrAllowed` must be set to `true`.

## Enable public network support for devices


To enable public LoRaWAN network support on your devices, run the following procedure.

**Note**  
You can enable the public network capability only for OTAA devices. This feature is not supported for devices that use ABP as the activation method.

1. 

**Create service profile with roaming parameters**

   Create a service profile by enabling the roaming parameters.
**Note**  
When you create a device profile for the device that you'll associate with this service profile, we recommend that you specify a large value for the `RxDelay1` parameter, at least greater than 2s.
   + 

**Using the AWS IoT console**  
Go to the [Profiles](https://console.aws.amazon.com/iot/home#/wireless/profiles) hub of the AWS IoT console and choose **Add service profile**. When creating the profile, choose **Enable public network**.
   + 

**Using the AWS IoT Wireless API**  
To enable roaming when creating a service profile, use the [CreateServiceProfile](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CreateServiceProfile.html) API operation or the [https://docs.aws.amazon.com/cli/latest/reference/iotwireless/create-service-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/create-service-profile.html) CLI command, as shown in example below.

     ```
     aws iotwireless create-service-profile \ 
         --region us-east-1 \
         --name roamingprofile1 \ 
         --lorawan '{"AddGwMetadata":true,"PrAllowed":true,"RaAllowed":true}'
     ```

     Running this command returns the ARN and ID of the service profile as output.

     ```
     {
         "Arn": "arn:aws:iotwireless:us-east-1:123456789012:ServiceProfile/12345678-a1b2-3c45-67d8-e90fa1b2c34d",
         "Id": "12345678-a1b2-3c45-67d8-e90fa1b2c34d"
     }
     ```

1. 

**Check roaming parameters in service profile**

   To check the roaming parameters that you specified, you can view the service profile in the console, or using the `get-service-profile` CLI command, as shown in example below.
   + 

**Using the AWS IoT console**  
Go to the [Profiles](https://console.aws.amazon.com/iot/home#/wireless/profiles) hub of the AWS IoT console and choose the profile that you created. In the **Profile configuration** tab of the details page, you'll see **RaAllowed** and **PrAllowed** set to `true`.
   + 

**Using the AWS IoT Wireless API**  
To view the roaming parameters that you enabled, use the [GetServiceProfile](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetServiceProfile.html) API operation or the [https://docs.aws.amazon.com/cli/latest/reference/iotwireless/get-service-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/get-service-profile.html) CLI command, as shown in example below.

     ```
     aws iotwireless get-service-profile \ 
         --region us-east-1 \ 
         --id 12345678-a1b2-3c45-67d8-e90fa1b2c34d
     ```

     Running this command returns the service profile details as output, including the values for roaming parameters, `RaAllowed` and `PrAllowed`.

     ```
     {
         "Arn": "arn:aws:iotwireless:us-east-1:123456789012:ServiceProfile/12345678-a1b2-3c45-67d8-e90fa1b2c34d",
         "Id": "12345678-a1b2-3c45-67d8-e90fa1b2c34d",
         "Name": "roamingprofile1"
         "LoRaWAN": {
             "UlRate": 60,
             "UlBucketSize": 4096,
             "DlRate": 60,
             "DlBucketSize": 4096,
             "AddGwMetadata": true,
             "DevStatusReqFreq": 24,
             "ReportDevStatusBattery": false,
             "ReportDevStatusMargin": false,
             "DrMin": 0,
             "DrMax": 15,
             "PrAllowed": true,
             "RaAllowed": true,
             "NwkGeoLoc": false,
             "TargetPer": 5,
             "MinGwDiversity": 1
         }
     }
     ```

1. 

**Attach service profile to devices**

   Attach the service profile that you created with the roaming parameters to your end devices. You can also create a device profile and add a destination for your wireless devices. You'll use this destination to route uplink messages that are sent from your device. For more information about creating device profiles and a destination, see [Add device profiles](lorawan-define-profiles.md#lorawan-device-profiles) and [Add destinations to AWS IoT Core for LoRaWAN](lorawan-create-destinations.md).
   + 

**Onboarding new devices**  
If you haven't already onboarded your devices, you specify this service profile to be used when adding your device to AWS IoT Core for LoRaWAN. The following command shows how you can use the `create-wireless-device` CLI command to add a device using the ID of the service profile that you created. For information about adding the service profile using the console, see [Add your wireless device specification to AWS IoT Core for LoRaWAN using the console](lorawan-end-devices-add.md#lorawan-end-device-spec-console).

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

     The following shows the contents of the file *`createdevice.json`*.

     **Contents of createdevice.json**

     ```
     {
         "Name": "DeviceA",  
         "Type": LoRaWAN,
         "DestinationName": "RoamingDestination1",
         "LoRaWAN": {
             "DeviceProfileId": "ab0c23d3-b001-45ef-6a01-2bc3de4f5333",
             "ServiceProfileId": "12345678-a1b2-3c45-67d8-e90fa1b2c34d",
             "OtaaV1_1": {
                 "AppKey": "3f4ca100e2fc675ea123f4eb12c4a012",
                 "JoinEui": "b4c231a359bc2e3d",
                 "NwkKey": "01c3f004a2d6efffe32c4eda14bcd2b4"
             },
             "DevEui": "ac12efc654d23fc2"
         },
     }
     ```

     The output of running this command produces the ARN and ID of the wireless device as output.

     ```
     {
         "Arn": "arn:aws:iotwireless:us-east-1:123456789012:WirelessDevice/1ffd32c8-8130-4194-96df-622f072a315f",
         "Id": "1ffd32c8-8130-4194-96df-622f072a315f"
     }
     ```
   + 

**Updating existing devices**  
If you have already onboarded your devices, you can update your existing wireless devices to use this service profile. The following command shows how you can use the `update-wireless-device` CLI command to update a device using the ID of the service profile that you created.

     ```
     aws iotwireless update-wireless-device \
         --id "1ffd32c8-8130-4194-96df-622f072a315f" \
         --service-profile-id "12345678-a1b2-3c45-67d8-e90fa1b2c34d" \ 
         --description "Using roaming service profile A"
     ```

     This command doesn't produce any output. You can use the `GetWirelessDevice` API or the `get-wireless-device` CLI command to get the updated information.

1. 

**Connect device to cloud using Everynet**

   As roaming has been enabled, your device must now perform a join to obtain a new `DevAddr`. If you're using OTAA, your LoRaWAN device sends a join request and the Network Server can allow the request. It can then connect to the AWS Cloud using the network coverage provided by Everynet. For instructions on how to perform the activation procedure or join for your device, see the device documentation.
**Note**  
You can enable the roaming capability and connect to the public network only for devices that use OTAA as the activation method. ABP devices aren't supported. For instructions on how to perform the activation procedure or join for your device, see the device documentation. See [Activation modes](lorawan-manage-end-devices.md#lorawan-activation-modes). 
To disable the roaming capability for your devices, you can disassociate the devices from this service profile, and then associate them with another service profile that has the roaming parameters set to `false`. After switching to this service profile, your devices must perform another join so that they don't continue running on the public network.

1. 

**Exchange uplink and downlink messages**

   After your device has joined to AWS IoT Core for LoRaWAN, you can start exchanging messages between your device and the Cloud.
   + 

**View uplink messages**  
When you send uplink messages from your devices, AWS IoT Core for LoRaWAN delivers these messages to your AWS account using the destination that you configured earlier. These messages will be sent from your device to the Cloud over Everynet's network.

     You can use either view the messages using the AWS IoT rule name or use the MQTT client to subscribe to the MQTT topic that was specified when creating the destination. For more information about the rule name and other destination details that you specify, see [Add a destination using the console](lorawan-create-destinations.md#lorawan-create-destination-console).

     For more information about viewing uplink message and the format, see [View format of uplink messages sent from LoRaWAN devices](lorawan-uplink-metadata-format.md).
   + 

**Send downlink messages**  
You can queue and send downlink messages to your devices from the console, or by using the AWS IoT Wireless API command, `SendDataToWirelessDevice`, or the AWS CLI command, `send-data-to-wireless-device`. For information about queuing and sending downlink messages, see [Queue downlink messages to send to LoRaWAN devices](lorawan-downlink-queue.md).

     The following code shows an example of how you can send a downlink message using the `send-data-to-wireless-device` CLI command. You specify the ID of the wireless device to receive the data, the payload, whether to use the acknowledge mode, and the wireless metadata.

     ```
     aws iotwireless send-data-to-wireless-device \
         --id "1ffd32c8-8130-4194-96df-622f072a315f" \
         --transmit-mode "1" \
         --payload-data "SGVsbG8gVG8gRGV2c2lt" \
         --wireless-metadata LoRaWAN={FPort=1}
     ```

     The output of running this command generates a `MessageId` for the downlink message.
**Note**  
In some cases, even if you receive the `MessageId`, packets can get dropped. For information about troubleshooting such scenarios and resolving them, see [Troubleshoot downlink message queue errors](lorawan-downlink-queue.md#lorawan-downlink-queue-troubleshoot).

     ```
     {
         MessageId: "6011dd36-0043d6eb-0072-0008"
     }
     ```

## View coverage information


After you've enabled the public network, you can view the network coverage information in the AWS IoT console. Go to the [https://console.aws.amazon.com/iot/home#/wireless/network-coverage](https://console.aws.amazon.com/iot/home#/wireless/network-coverage) hub of the AWS IoT console and then search for locations to see the coverage information of your devices on the map.

**Note**  
This feature uses the Amazon Location Service to display the coverage information of your devices on an Amazon Location map. Before using Amazon Location maps, review the Terms and Conditions for Amazon Location Service. Note that AWS may transmit your API queries to your chosen third party data provider, which may be outside of the AWS Region that you are currently using. For more information, see [AWS Service Terms](https://aws.amazon.com/service-terms/).