“Wireless Made Easy!" - Adding BLE features & provisioning to an existing LoRaWAN Application
This sample code demonstrates how to provision & control a LoRaWAN end-device over a BLE connection between Smartphone App and a RN4870/71 module.
For more information on Microchip ATSAMR34 LoRa SiP and RN4870/71 BLUETOOTH 5 certified module, visit Microchip webpages:
https://www.microchip.com/design-centers/wireless-connectivity/low-power-wide-area-networks/lora-technology/sam-r34-r35 https://www.microchip.com/wwwproducts/en/rn4870 https://www.microchip.com/wwwproducts/en/rn4871
The ATSAMR34 Xplained Pro evaluation kit (DM320111) is a hardware platform used to evaluate the ATSAMR34 Low Power LoRa® Sub-GHz SiP. It is supported by Atmel Studio 7.0 IDE and a collection of sample codes are available from Advanced Software Framework (ASFv3) since the 3.44.0 release. The Xplained Pro MCU series evaluation kit includes an on-board Embedded Debugger (EDBG), and no external tools are necessary to program or debug the ATSAMR34. The kit offers a set of features that enable the user to get started with the ATSAMR34 Low Power LoRa® Sub-GHz SiP peripherals right away, and to understand how to integrate the device in your own design. The ATSAMR34 Xplained Pro kit contains the following items:
- One ATSAMR34 Xplained Pro
- One external antenna
https://www.microchip.com/DevelopmentTools/ProductDetails/dm320111
The RN-4871-PICtail is a development board based on the ultra-compact Bluetooth 5 Low Energy RN4871 module. The RN4871 uses a simple ASCII command interface over the UART.
https://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/RN-4871-PICTAIL
Alternatively, you can use a RN4870 or RN4871 click board from Mikroe.
https://www.mikroe.com/rn4870-click https://www.mikroe.com/rn4871-click
And use mikroBUS Xplained-Pro board (ATMBUSADAPTER-XPRO).
https://www.microchip.com/Developmenttools/ProductDetails/ATMBUSADAPTER-XPRO
-
Download and install Atmel Studio 7.0 IDE.
https://www.microchip.com/mplab/avr-support/atmel-studio-7 -
Open Atmel Studio 7.0 IDE.
-
Then, you need Advanced Software Framework (ASFv3) v3.45.0 release or upper release.
Install ASFv3 as an extension to Atmel Studio from the menu: Tools -> Extensions and Updates … -
Once the installation is complete, you must restart Atmel Studio.
-
Download and install a serial terminal program like Tera Term.
https://osdn.net/projects/ttssh2/releases/
Note: ASFv3 is an MCU software library providing a large collection of embedded software for AVR® and SAM flash MCUs and Wireless devices. ASFv3 is configured by the ASF Wizard in Atmel Studio 7.0 (installed as an extension to Studio). ASFv3 is also available as a standalone (.zip) with the same content as Studio extension (https://www.microchip.com/mplab/avr-support/advanced-software-framework).
Important: Until the next Atmel Studio IDE release, you have to manually install the Device Part Pack for developing with SAMR34/R35 on Atmel Studio 7.0 IDE. (all products released in between IDE releases of Atmel Studio should be manually added by user to develop applications).
- Go to Tools -> Device Pack Manager
- Check for Updates
- Search for SAMR34 and click install
- Repeat the same for SAMR35
- Restart Atmel Studio 7.0 IDE
To demonstrate BLE applications as well as LoRaWAN end-device provisioning, follow the connection below :
- In order to connect in LoRaWAN, you will need to be in range of your gateway. If you don’t have gateway, check the world map (https://www.thethingsnetwork.org/map) to see if your local community has gateway deployed around your location.
- Plug the antennas and always make sure you have the antennas plugged to your boards before powering it up.
- Connect the ATSAMR34-Xpro board to the PC through the micro-USB cables.
USB cable must be connected to the EDBG USB connectors of the ATSAMR34 kit.
The USB ports powers the board. - Connect the FTDI cable the host PC. A COM port will be mounted. This port mounted will be used to communicate with the kit.
- Launch Tera Term program and configure the serial ports mounted with: 115200 bps, 8/N/1
This demo requires:
Microchip Bluetooth Data (MBD) Apps for mobile:
https://play.google.com/store/apps/details?id=com.microchip.bluetooth.data&hl=en
https://apps.apple.com/us/app/microchip-bluetooth-data/id1319166097
Microchip Bluetooth Smart Data
https://apps.apple.com/fr/app/bluetooth-smart-data/id1004033562
or
BLE Terminal:
https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en
https://apps.apple.com/fr/app/ble-terminal-hm-10/id1398703795
This demo is using QRbot apps to scan a QR code. This QRcode contains the LoRaWAN provisioning information.
https://play.google.com/store/apps/details?id=net.qrbot&hl=en
https://apps.apple.com/cy/app/qrbot/id1048473097
- Log in to your TTN account
- Go to the Console
- Create an Application and note the AppEUI generated by TTN
- From the application created, add a Device
- For the DevEUI, use the MAC address written in the back of the SAMR34 Xplained Pro board.
- Let TTN generate the AppKey
When the device is created, note carrefully the OTAA credentials (DevEUI, AppEUI, AppKey). You will needed later to generate the QR Code.
You have done the provisioning of the end-device within the TTN Console.
A QR Code will be used to provision the LoRaWAN OTAA parameters (DevEUI, AppEUI, AppKey) over BLE.
To be recognized by the SAMR34 sample application, the QR code must contains a string of characters which respect the following format:
Create your own QR Code from: https://www.unitag.io/qrcode
- As QR Code Type: select Other and Text
- In the textbox, type your own string of characters with the help of your OTAA credentials
- Click confirm to generate your own QR Code
You can download and print your QR Code.
From your smartphone, Open the QRbot apps and scan your QR Code.
You should retrieve the "mac set otaa" command with your credentials. Copy the text.
This project integrates the Microchip LoRaWAN Stack (MLS) Software API which provide an interface to the different software modules.
This application is based on LoRaWAN Mote Application generated from ASFv3 and already contains drivers required to interface the RN4870/71 module.
It implements the Transparent UART service. This service exposes the characteristics to transfer serial data on both direction.
From the menu, you have the choice of the application:
- Start Atmel Studio 7 IDE
- Open this project
- From the Atmel Studio menu, go to: Build -> Build Solution
- Flash the firmware on the ATSAMR34 Xplained Pro board
- To get console logs through EDBG interface, open a Tera Term session with 115200 bps 8N1 configuration.
- Reset the board
- The application will start and should expose a menu if the interface with RN4870/71 module is correct
Try to initialize BLE device ...
===============================================
Menu: select a BLE application from the list
===============================================
1) Serial bridge
2) Beacon mode - https://www.microchip.com URL
3) Transparent chat mode
4) Scan mode
5) Search mode
6) Search and connect
7) Sleep mode
8) Wake-up
9) LoRaWAN provisioning
-----------------------------------------------
>>
- From here, simply select a BLE application you want to be executed
- And follow the instructions displayed on the console
- From here, the SAMR34 will automatically send a Join Request message to activate the device within the LoRaWAN nettwork
- If the activation succeed, you will be notified by a "Joining Successful" message on the BLE apps
- Go back to the TTN Console, and observe the Application Data of your device
- You should see the Join procedure
- Go back to the TTN Console and observe the data received in HEX