Skip to content

Commit 9e0efa3

Browse files
committed
Update tutorial content
1 parent 23a3c35 commit 9e0efa3

File tree

4 files changed

+101
-6
lines changed

4 files changed

+101
-6
lines changed

content/hardware/04.pro/carriers/portenta-max-carrier/tutorials/mc-ard-lora/content.md

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ You can use several Arduino libraries with the CMWX1ZZABZ-078 LoRaWAN® module f
8181

8282
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:
8383

84-
![Library Manager in the Arduino IDE 2.](assets/mc_ard_ttn_library.png)
84+
![Library Manager in the Arduino IDE 2.](assets/mc_ard_ttn_library.png)
8585

8686
***Currently, there are two versions of the MKRWAN library. We recommend using the MKRWAN_v1 library since MKRWAN_v2 library is still in beta.***
8787

@@ -144,30 +144,125 @@ Now, let's use the `DevEUI` number from your Portenta Max Carrier to create an a
144144

145145
### 3. Creating an Application in TTN
146146

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**.
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, click on **Create an application**. If you already created an application, click on **Go to applications**.
148+
149+
![TTN console welcome page.](assets/mc_ard_ttn_console_1.png)
148150

149151
Now click in **Create an application**. You will need to add the following information:
150152

151153
* **Owner**: the person or organization that owns the application.
152154
* **Application ID**: a unique identifier for your application (must be lowercase and without spaces).
153155

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.
156+
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.
157+
158+
![Application dashboard in TTN.](assets/mc_ard_ttn_console_2.png)
159+
160+
Now, scroll to **End devices** in the left toolbar and then click on **Add end device**; a registration page for end devices will open.
155161

156-
On the registration page click on **Manually**, now you will have to add the following information for your Portenta Max Carrier:
162+
![Registering an end device in TTN.](assets/mc_ard_ttn_console_3.png)
163+
164+
On the registration page click on **Manually**; you will have to add the following information for your Portenta Max Carrier:
157165

158166
* **Frequency plan**: choose a region according to your country.
159167
* **LoRaWAN version**: 1.0.2.
160168
* **Regional Parameters version**: 1.0.2.
161169
* **Activation mode**: Over the air activation (OTAA).
162-
* **DevEUI**: fill it with the `DevEUI` number of your Portenta Max Carier.
170+
* **DevEUI**: fill it with the `DevEUI` number of your Portenta Max Carier you found before.
163171
* **AppEUI**: fill it with zeros or enter your own.
164172
* **AppKey**: generate one or enter your own.
165173
* **Device ID**: must be lowercase and without spaces.
166174

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.
175+
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. You are going to use some of this information with your Portenta Max Carrier to send information to TTN.
168176

169177
### 4. Sending a Message to an Application in TTN
170178

179+
Now, let's start sending information to TTN. The following sketch let's you send information to TTN using your Portenta Max Carrier LoRaWAN® module; Over the Air (OTAA) device activation method is used to join TTN:
180+
181+
```arduino
182+
#define PORTENTA_CARRIER
183+
#include <MKRWAN.h>
184+
185+
_lora_band region = US915;
186+
187+
LoRaModem modem(Serial1);
188+
189+
String appEui;
190+
String appKey;
191+
192+
void setup() {
193+
Serial.begin(115200);
194+
while (!Serial);
195+
Serial.println(F("LoRaWAN + Portenta Max Carrier (OTAA)"));
196+
197+
if (!modem.begin(region)) {
198+
Serial.println(F("- Failed to start module!"));
199+
while (1) {}
200+
};
201+
202+
Serial.print(F("- Your module version is: "));
203+
Serial.println(modem.version());
204+
205+
if (modem.version() != ARDUINO_FW_VERSION) {
206+
Serial.println(F("- Please make sure that the latest module firmware is installed."));
207+
Serial.println(F("- To perform a firmware update, use the 'MKRWANFWUpdate_standalone.ino' example sketch."));
208+
}
209+
210+
Serial.print(F("- Your device EUI is: "));
211+
Serial.println(modem.deviceEUI());
212+
213+
// To use predfined setting for OTAA or use a custom setting
214+
int mode = 0;
215+
while (mode != 1 && mode != 2) {
216+
Serial.println(F("- Use predefined AppEUI & AppKey settings? (1) Yes | (2) No"));
217+
while (!Serial.available());
218+
mode = Serial.readStringUntil('\n').toInt();
219+
}
220+
221+
if (mode == 2) {
222+
Serial.println(F("- Enter your AppEUI"));
223+
while (!Serial.available());
224+
appEui = Serial.readStringUntil('\n');
225+
226+
Serial.println(F("- Enter your AppKey"));
227+
while (!Serial.available());
228+
appKey = Serial.readStringUntil('\n');
229+
} else if (mode == 1) {
230+
Serial.println(F("- Using predefined settings"));
231+
}
232+
233+
appKey.trim();
234+
appEui.trim();
235+
236+
int connected = modem.joinOTAA(appEui, appKey);
237+
238+
if (!connected) {
239+
Serial.println("- Something went wrong; are you indoor? Move near a window and retry...");
240+
while (1) {}
241+
}
242+
243+
delay(5000);
244+
245+
// Sending packet
246+
int err;
247+
modem.setPort(3);
248+
modem.beginPacket();
249+
modem.print("HeLoRA world!");
250+
err = modem.endPacket(true);
251+
if (err > 0) {
252+
Serial.println("- Message sent correctly!");
253+
} else {
254+
Serial.println("- Error sending message :(");
255+
}
256+
}
257+
258+
void loop() {
259+
while (modem.available()) {
260+
Serial.write(modem.read());
261+
}
262+
modem.poll();
263+
}
264+
```
265+
171266
## Conclusion
172267

173268
### Next Steps

0 commit comments

Comments
 (0)