|
| 1 | +--- |
| 2 | +title: 'Connecting the Portenta Max Carrier to The Things Network Using LoRaWAN®' |
| 3 | +description: 'This tutorial explains how to connect your Portenta Max Carrier to the Things Network(TTN) using the carrier's LoRa® connectivity feature.' |
| 4 | +coverImage: assets/ |
| 5 | +difficulty: Intermediate |
| 6 | +tags: |
| 7 | + - IoT |
| 8 | + - LoRa |
| 9 | +author: 'Taddy Chung, José Bagur' |
| 10 | +libraries: |
| 11 | + - name: MKRWAN |
| 12 | +hardware: |
| 13 | + - hardware/04.pro/boards/portenta-h7 |
| 14 | +software: |
| 15 | + - ide-v1 |
| 16 | + - ide-v2 |
| 17 | +--- |
| 18 | + |
| 19 | +## Overview |
| 20 | + |
| 21 | +This tutorial explains how to connect your Arduino® Max Carrier, with an [Arduino® Portena H7](https://store.arduino.cc/products/portenta-h7), to The Things Network (TTN) using its LoRaWAN® connectivity feature. The article will focus on achieving communication between the Max Carrier and an application on TTN. |
| 22 | + |
| 23 | +## Goals |
| 24 | + |
| 25 | +* Enable LoRaWAN® connectivity on the Arduino® Portenta Max Carrier. |
| 26 | +* Establish a connection between the Arduino® Portenta Max Carrier and TTN. |
| 27 | + |
| 28 | + |
| 29 | +### Required Hardware and Software |
| 30 | + |
| 31 | +- [Arduino® Portena H7](https://store.arduino.cc/products/portenta-h7). |
| 32 | +- Arduino® Portenta Max Carrier. |
| 33 | +- 868-915 MHz antenna with SMA connector. |
| 34 | +- USB-C cable (either USB-A to USB-C or USB-C to USB-C). |
| 35 | +- [Arduino IDE 2.0](https://www.arduino.cc/en/software). |
| 36 | +- [MKRWAN library](https://github.com/arduino-libraries/MKRWAN). |
| 37 | +- An active account in [TTN](https://www.thethingsnetwork.org/). |
| 38 | + |
| 39 | +## The Arduino® Portenta Max Carrier LoRaWAN® Connectivity Feature |
| 40 | + |
| 41 | +The Arduino® Portenta Max Carrier provides you with an unlimited range of applications, from robotics and medical devices to industrial or automotive applications; the Max Carrier possibilities are endless. One feature that boosts Portenta's Max Carrier possibilities is its onboard LoRaWAN® communications module, the [CMWX1ZZABZ-078](https://www.murata.com/products/connectivitymodule/lpwa/overview/lineup/type-abz-078) from Murata®. LoRaWAN® is a Low Power Wide Area Network (LPWAN) designed to connect low power devices to the Internet. It was developed to meet and fulfill Internet of Things (IoT) devices' requirements, such as low-power consumption and low data throughput. |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +***For more in-depth information about LoRa® and LoRaWAN®, please read [The Arduino Guide to LoRa® and LoRaWAN®](https://docs.arduino.cc/learn/communication/lorawan-101).*** |
| 46 | + |
| 47 | +## Connecting to TTN |
| 48 | + |
| 49 | +Let's start sending data to TTN using the Portenta Max Carrier LoRaWAN® module. As stated before, to do this, you will need a TTN account and to be in the range of a public TTN gateway. You can check the [world map](https://www.thethingsnetwork.org/map) of public gateways connected to TTN and see if your region already has a gateway installed. If not, consider installing one! |
| 50 | + |
| 51 | +To connect your Portenta Max Carrier to TTN, we must follow these steps: |
| 52 | + |
| 53 | +1. Hardware setup. |
| 54 | +2. Software setup. |
| 55 | +3. Arduino® Portenta Max Carrier provisioning. |
| 56 | +4. Create an application in TTN. |
| 57 | +5. Send a message to a TTN application. |
| 58 | + |
| 59 | +Let's start! |
| 60 | + |
| 61 | + |
| 62 | +### 1. Setting up the Hardware |
| 63 | + |
| 64 | +Begin by attaching the Arduino® Portenta H7 board to the high-density connectors of the Arduino® Portenta Max Carrier, as shown in the image below: |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +To power the CMWX1ZZABZ-078 LoRaWAN® module of the Portenta Max Carrier, you can use the **DC power jack** (with a 4.5V to 36V external DC power supply) of the Portenta Max Carrier or a **18650 3.7V Li-Ion battery**, connected to the Portenta Max Carrier battery clips; you can power the module also directly from the USB-C connector of the Portenta H7 board. **Also, do not forget to attach a LoRa® antenna to the SMA connector (J9) in the Max Carrier**. |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +***Using the LoRaWAN® module of the Portenta Max Carrier without an antenna may damage it. Please, do not forget to connect a suitable antenna to the dedicated SMA connector (J9) on the Max Carrier board.*** |
| 73 | + |
| 74 | +Now you can connect the Portenta H7 board to your computer using a USB-C cable. **Don't forget to change the position of the BOOT DIP switch** (SW1), **from BOOT SEL to BOO**T; otherwise, you are not going to be able to program your Portenta H7 board when attached to the Max Carrier. |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +### 2. Setting up the Software |
| 79 | + |
| 80 | +You can use several Arduino libraries with the CMWX1ZZABZ-078 LoRaWAN® module from Murata®; we recommend the [MKRWAN library](https://github.com/arduino-libraries/MKRWAN), developed by the Arduino Team. The MKRWAN library provides you the APIs to communicate with LoRa® and LoRaWAN networks® using the CMWX1ZZABZ-078 module. You can use this library in the Arduino IDE, both [online](https://create.arduino.cc/editor) and [offline](https://www.arduino.cc/en/software). |
| 81 | + |
| 82 | + If you are using the online IDE, you don't need to do anything; the library is already installed and ready to be used. If you are using the offline IDE, you must install the library **manually**. Installing the library can be done quickly by navigating to **Tools > Manage Libraries...** and then in the **Library Manager** search for **MKRWAN** library by Arduino; remember to install the latest version of the libraries. You can also access the Library Manager using the left toolbar of the IDE, as shown in the image below: |
| 83 | + |
| 84 | +  |
| 85 | + |
| 86 | +***Currently, there are two versions of the MKRWAN library. We recommend using the MKRWAN_v1 library since MKRWAN_v2 library is still in beta.*** |
| 87 | + |
| 88 | +To use the MKRWAN library with the Portenta Max Carrier, you must define `PORTENTA_CARRIER` before the library inclusion, as shown below: |
| 89 | + |
| 90 | +```arduino |
| 91 | +#define PORTENTA_CARRIER |
| 92 | +#include <MKRWAN.h> |
| 93 | +``` |
| 94 | + |
| 95 | +#### 2.1 Updating the LoRaWAN® Module Firmware |
| 96 | + |
| 97 | +The LoRaWAN® module firmware of the Portenta Max Carrier **must be updated** before its first use. This can be done using the example sketch `MKRWANFWUpdate_standalone` of the MKRWAN library. You can open this example by navigating to **Files > Examples MKRWAN**; before uploading the sketch into the Portenta H7 board, open the `MKRWANFWUpdate_standalone.ino` file and define `PORTENTA_CARRIER` before the library inclusion, as shown in the image below: |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +Upload the sketch, open the Serial Monitor and wait for the firmware update to finish. You should see a confirmation message when the process is done as shown in the image below: |
| 102 | + |
| 103 | + |
| 104 | +### 3. Provisioning the Arduino® Portenta Max Carrier |
| 105 | + |
| 106 | +Device provisioning is a process comparable to bank card numbering. Let's think about bank cards; bank cards numbers start with a six-digit vendor ID number that indicates who allocated and controls the card's security; the remaining digits are unique numbers associated with a specific card. Devices with LoRa® and LoRaWAN® capabilities have a similar system; the Join Server Unique Identifier (usually referred to as `JoinEUI`) is a number that manages the security and authorizes the device in a network, while the **Device Unique Identifier** (usually referred to as `DevEUI`) is a unique number that identifies the device. The `JoinEUI` and `DevEUI` numbers, are required to send information to TTN; the `JoinEUI` number is provided by the network (in this case TTN) while the `DevEUI` is provided by the manufacturer of the device's LoRa® module. |
| 107 | + |
| 108 | +The following sketch let's you find out what is the `DevEUI` of your Portenta Max Carrier: |
| 109 | + |
| 110 | +```arduino |
| 111 | +#define PORTENTA_CARRIER |
| 112 | +#include <MKRWAN.h> |
| 113 | +
|
| 114 | +_lora_band region = US915; |
| 115 | +
|
| 116 | +LoRaModem modem(Serial1); |
| 117 | +
|
| 118 | +void setup() { |
| 119 | + Serial.begin(115200); |
| 120 | + while(!Serial1); |
| 121 | +
|
| 122 | + if(!modem.begin(region)) { |
| 123 | + Serial.println("Failed to start the module..."); |
| 124 | + while(1) {} |
| 125 | + } |
| 126 | +
|
| 127 | + Serial.print("Your Portenta Max Carrier DevEUI is: ");V |
| 128 | + Serial.println(modem.deviceEUI()); |
| 129 | +} |
| 130 | +
|
| 131 | +void loop() { |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +The only line you may need to change before uploading the code is the one that sets the frequency: |
| 136 | + |
| 137 | +```arduino |
| 138 | +_lora_band region = US915; |
| 139 | +``` |
| 140 | + |
| 141 | +Set the frequency designator according to your country if needed. You can find more information about frequency plans definitions used in TTN [here](https://www.thethingsnetwork.org/docs/lorawan/frequency-plans/). After you upload the sketch into your Portenta H7 board, you should see the Portenta Max Carrier `DevEUI` in the Serial Monitor as shown below: |
| 142 | + |
| 143 | +Now, let's use the `DevEUI` number from your Portenta Max Carrier to create an application in TTN. |
| 144 | + |
| 145 | +### 3. Creating an Application in TTN |
| 146 | + |
| 147 | +To send information to TTN, first we need to create an application and register a device with it. Navigate to TTN portal and sign in; after signing in, clik on **Create an application**. If you already created an aplication, clik on **Go to applications**. |
| 148 | + |
| 149 | +Now click in **Create an application**. You will need to add the following information: |
| 150 | + |
| 151 | +* **Owner**: the person or organization that owns the application. |
| 152 | +* **Application ID**: a unique identifier for your application (must be lowercase and without spaces). |
| 153 | + |
| 154 | +Complete both fields and click on **Create application**. Now you will be redirected to the application dashboard that shows information of the newly created application. Now, scroll to **End devices** in the left toolbar and then click on **Add end device**; a registration page for end devices will open. |
| 155 | + |
| 156 | +On the registration page click on **Manually**, now you will have to add the following information for your Portenta Max Carrier: |
| 157 | + |
| 158 | +* **Frequency plan**: choose a region according to your country. |
| 159 | +* **LoRaWAN version**: 1.0.2. |
| 160 | +* **Regional Parameters version**: 1.0.2. |
| 161 | +* **Activation mode**: Over the air activation (OTAA). |
| 162 | +* **DevEUI**: fill it with the `DevEUI` number of your Portenta Max Carier. |
| 163 | +* **AppEUI**: fill it with zeros or enter your own. |
| 164 | +* **AppKey**: generate one or enter your own. |
| 165 | +* **Device ID**: must be lowercase and without spaces. |
| 166 | + |
| 167 | +Click on **Register end device**, this will take you to a Device Overview page where you will see all the information related to the device. We are going to use some of this information with your Portenta Max Carrier. |
| 168 | + |
| 169 | +### 4. Sending a Message to an Application in TTN |
| 170 | + |
| 171 | +## Conclusion |
| 172 | + |
| 173 | +### Next Steps |
| 174 | + |
| 175 | +## Troubleshooting |
| 176 | + |
0 commit comments