This guide introduces the steps to take in purpose of connecting Milesight IoT LoRa end-devices to AWS IoT Core for LoRaWAN. If you don’t have an AWS account, refer to the instructions in the guide here.
The high-level steps to get started with AWS IoT Core for LoRaWAN are as follows:
- Add UG6x on AWS IoT Link
- Add the end-device
These steps are detailed below. For additional help, refer to the AWS LoRaWAN developer guide.
Once setup is completed, provisioned devices can join the network and start to send messages. Messages from devices can then be received by AWS IoT Core for LoRaWAN and forwarded to the IoT Rules Engine.
- An AWS account
- LoRaWAN gateway (e.g., UG6x) that’s already connected to AWS IoT for LoRaWAN
- Milesight LoRaWAN end device whose frequency plan matches the gateway’s LoRaWAN region
- MAC Version. This must be one of the following that are supported on AWS (By default, AM100/EM300/EM500/UC500 series of endpoint devices abide v1.1, UC11 uses v1.0.2.)
- Activation method to use (By default, all Milesight IoT endpoint devices use OTAA v1.0.x.)
- OTAA v1.0.x or OTAA v1.1.
- ABP v1.0.x or ABP v1.1.
- Copy the following information from device’s payload structure on Milesight IoT document center:
- For OTAA v1.0.x devices: DevEUI, AppKey, AppEUI
- For OTAA v1.1 devices: DevEUI, AppKey, NwkKey, JoinEUI
- For ABP v1.0.x devices: DevEUI, DevAddr, NwkSkey, AppSkey
- For ABP v1.1 devices: DevEUI, DevAddr, NwkSEnckey, FNwkSIntKey, SNwkSIntKey, AppSKey
AWS IoT Core for LoRaWAN supports device profiles and service profiles. Device profiles contain the communication and protocol parameter values the device needs to communicate with the network server. Service profiles describe the communication parameters the device needs to communicate with the application server.
Some pre-defined profiles are available for device and service profiles. Before proceeding, verify that these profile settings match the devices you will be setting up to work with AWS IoT Core for LoRaWAN.
- Navigate to the AWS IoT console. In the navigation pane, choose Wireless connectivity.
- In the navigation pane, choose Profiles
- In the Device Profiles section, there are some pre-defined profiles listed.
- Check each of the profiles to determine if one of them will work for you. If not, select Add device profile and set up the parameters as needed. For example:
- MacVersion 1.0.3
- RegParamsRevision Regional Parameters v1.0.2rB
- MaxEirp 10
- MaxDutyCycle 10
- RfRegion US915
- SupportsJoin true
- In the Service Profiles section, there are some pre-defined profiles listed. Check each of the profiles to determine if one of them will work for you. If not, select Add service profile and set up the parameters as needed. Proceed only if you have a device and service profile that will work for you.
Since most LoRaWAN devices don't send data to AWS IoT Core for LoRaWAN in a format that can be consumed by AWS services, traffic must firstly be sent to a Destination. A Destination represents the AWS IoT rule that processes a device's data for use by AWS services. This AWS IoT rule contains the SQL statement that selects the device's data and the topic rule actions that send the result of the SQL statement to the services that will use it. For more information on Destinations, refer to the AWS LoRaWAN developer guide.
- Navigate to Wireless Connectivity -> Destination page, choose Add destination.
- Under Destination details enter ProcessLoRa as the Destination name, and an appropriate description under Destination description – optional.
NOTE: The Destination name can be anything. For getting started and consistency, choose ProcessLoRa for the first integration with AWS IoT Core for LoRaWAN.
- For Rule name enter LoRaWANRouting. Ignore the section Rules configuration – Optional for now.
- In the Permissions section select the IAM role you had created earlier from the drop-down.
- Choose Add Destination. You will see a message “Destination added”, indicating the destination has been successfully added.
Now register an endpoint device with AWS IoT Core for LoRaWAN as follows:
- Go to the AWS IoT console.
- Select Wireless connectivity in the navigation panel on the left.
- Select Devices
- Choose Add wireless device
- On the Add device page, select the LoRaWAN specification version in the drop-down under Wireless device specification. By default, AM100/EM300/EM500/UC500 series of endpoint devices abide v1.1, UC11 uses v1.0.2. You can also change this parameter in ToolBox.
- Under LoRaWAN specification and wireless device configuration, enter the DevEUI and confirm it in the Confirm DevEUI
- Enter the remaining fields as per the OTAA/ABP choice you made above.
- Enter a name for your device in the Wireless device name – optional
- In the Profiles section, under Wireless device profile, find a drop-down option that corresponds to your device and region.
NOTE: Compare your device details to ensure the device profile is correct. If there are no valid default options, you will have to create a new profile (see the section Verify Profiles).
- Choose Next
- Choose the destination you created earlier (ProcessLoRa) from the drop-down under Choose destination.
- Choose Add device
- You will see a message saying “Wireless device added”, indicating that your device has been set up successfully.
Create the lambda function to process device messages processed by the destination rule.
- Go to the AWS Lambda console.
- Click on Functions in the navigation pane.
- Click on Create function.
- Select Author from scratch. Under Basic information, enter the function name “am100decoder” for instance and choose Node.js 12.x. from the drop-down under Runtime.
- Click on Create function.
- Click the function you created, Under Code tab, follow the guide of README from this link to make the index.js code.
- Once the code has been pasted, choose Deploy to deploy the lambda code.
After deploying the code, you need to change the lambda role policy permission as following steps:
- Navigate to Configuration -> Permissions tab of the lambda function
- Under Execution role, click on the Role name to go to the IAM Roles page
- On the Permissions tab, find the policy name and click on it
- Choose Edit policy, and choose the JSON tab
- Append the following to the Statement section of the policy to allow publishing to AWS IoT.
- Choose Review Policy, then Save changes.
After saving the policy, go back to AWS Lambda page to create a test event that will allow you to test the functionality of the lambda function.
- Under Test tab, select New event
- Enter a name for the test event under Event name
- Copy the following AM107 sample payload and paste in the area under Event name:
- Click Save changes to save the event.
- Navigate to the AWS IoT Core console, choose Test on the navigation pane, and select MQTT client.
- Configure the MQTT client to subscribe to “#” (all topics)
- Click on Test in the Lambda function page to generate the test event you just created
- Verify the published data in the AWS IoT Core MQTT Test client.