Create rules to process LoRaWAN device messages - Amazon IoT Core
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Create rules to process LoRaWAN device messages

Amazon IoT rules send device messages to other services. Amazon IoT rules can also process the binary messages received from a LoRaWAN device to convert the messages to other formats that can make them easier for other services to use.

Amazon IoT Core for LoRaWAN destinations associate a wireless device with the rule that processes the device's message data to send to other services. The rule acts on the device's data as soon as Amazon IoT Core for LoRaWAN receives it. Amazon IoT Core for LoRaWAN destinations can be shared by all devices whose messages have the same data format and that send their data to the same service.

How Amazon IoT rules process device messages

How an Amazon IoT rule processes a device's message data depends on the service that will receive the data, the format of the device's message data, and the data format that the service requires. Typically, the rule calls an Amazon Lambda function to convert the device's message data to the format a service requires, and then sends the result to the service.

The following illustration shows how message data is secured and processed as it moves from the wireless device to an Amazon service.


                        Image showing how Amazon IoT Core for LoRaWAN data is passed from a wireless
                            device to Amazon IoT and other services.
  1. The LoRaWAN wireless device encrypts its binary messages using AES128 CTR mode before it transmits them.

  2. Amazon IoT Core for LoRaWAN decrypts the binary message and encodes the decrypted binary message payload as a base64 string.

  3. The resulting base64-encoded message is sent as a binary message payload (a message payload that is not formatted as a JSON document) to the Amazon IoT rule described in the destination assigned to the device.

  4. The Amazon IoT rule directs the message data to the service described in the rule's configuration.

The encrypted binary payload received from the wireless device is not altered or interpreted by Amazon IoT Core for LoRaWAN. The decrypted binary message payload is encoded only as a base64 string. For services to access the data elements in the binary message payload, the data elements must be parsed out of the payload by a function called by the rule. The base64-encoded message payload is an ASCII string, so it could be stored as such to be parsed later.

Create rules for LoRaWAN

Amazon IoT Core for LoRaWAN uses Amazon IoT rules to securely send device messages directly to other Amazon services without the need to use the message broker. By removing the message broker from the ingestion path, it reduces costs and optimizes the data flow.

For an Amazon IoT Core for LoRaWAN rule to send device messages to other Amazon services, it requires an Amazon IoT Core for LoRaWAN destination and an Amazon IoT rule assigned to that destination. The Amazon IoT rule must contain a SQL query statement and at least one rule action.

Typically, the Amazon IoT rule query statement consists of:

  • A SQL SELECT clause that selects and formats the data from the message payload

  • A topic filter (the FROM object in the rule query statement) that identifies the messages to use

  • An optional conditional statement (a SQL WHERE clause) that specifies conditions on which to act

Here is an example of a rule query statement:

SELECT temperature FROM iot/topic' WHERE temperature > 50

When building Amazon IoT rules to process payloads from LoRaWAN devices, you do not have to specify the FROM clause as part of the rule query object. The rule query statement must have the SQL SELECT clause and can optionally have the WHERE clause. If the query statement uses the FROM clause, it is ignored.

Here is an example of a rule query statement that can process payloads from LoRaWAN devices:

SELECT WirelessDeviceId, WirelessMetadata.LoRaWAN.FPort as FPort, WirelessMetadata.LoRaWAN.DevEui as DevEui, PayloadData

In this example, the PayloadData is a base64-encoded binary payload sent by your LoRaWAN device.

Here is an example rule query statement that can perform a binary decoding of the incoming payload and transform it into a different format such as JSON:

SELECT WirelessDeviceId, WirelessMetadata.LoRaWAN.FPort as FPort, WirelessMetadata.LoRaWAN.DevEui as DevEui, aws_lambda("arn:aws:lambda:<region>:<account>:function:<name>", { "PayloadData":PayloadData, "Fport": WirelessMetadata.LoRaWAN.FPort }) as decodingoutput

For more information on using the SELECT AND WHERE clauses, see Amazon IoT SQL reference

For information about Amazon IoT rules and how to create and use them, see Rules for Amazon IoT and Creating Amazon IoT rules to route device data to other services.

For information about creating and using Amazon IoT Core for LoRaWAN destinations, see Add destinations to Amazon IoT Core for LoRaWAN.

For information about using binary message payloads in a rule, see Working with binary payloads.

For more information about the data security and encryption used to protect the message payload on its journey, see Data protection in Amazon IoT Core.

For a reference architecture that shows a binary decoding and implementation example for IoT rules, see Amazon IoT Core for LoRaWAN Solution Samples on GitHub.