You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/01.mkr/01.boards/mkr-wan-1310/tutorials/the-things-network/the-things-network.md
+35-27Lines changed: 35 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -3,12 +3,12 @@ title: 'Connecting MKR WAN 1310 to The Things Network (TTN)'
3
3
difficulty: intermediate
4
4
compatible-products: [mkr-wan-1310]
5
5
description: 'Learn how to set up an account on The Things Network (TTN) and test if your board can connect to it.'
6
-
tags:
6
+
tags:
7
7
- IoT
8
8
- LoRa®
9
9
- The Things Network
10
10
author: 'Karl Söderby'
11
-
libraries:
11
+
libraries:
12
12
- name: MKRWAN
13
13
url: https://www.arduino.cc/en/Reference/MKRWAN
14
14
hardware:
@@ -20,7 +20,7 @@ software:
20
20
- web-editor
21
21
---
22
22
23
-
## Introduction
23
+
## Introduction
24
24
25
25
In this tutorial, we will go through how to set up the MKR WAN 1310 board to work with The Things Network (TTN).
26
26
@@ -55,11 +55,11 @@ LoRaWAN®, stands for **Long Range Wide Area Network**, which is becoming increa
55
55
- LoRa® which stands for Long Range
56
56
- LP WAN which stands for Low Power Wide Area Network
57
57
58
-
LoRa® devices come with lower data rates, with longer intervals than i.e. a device connected through WiFi. This is due to the low-power consumption and long range that LoRa® technology puts emphasis on.
58
+
LoRa® devices come with lower data rates, with longer intervals than i.e. a device connected through WiFi. This is due to the low-power consumption and long range that LoRa® technology puts emphasis on.
59
59
60
60
While the data rate may be a restriction, let’s have a look at some of the amazing features LoRa® technology comes with:
61
61
62
-
-**Long range:** Up to 5km in an urban setting, 10km in suburban and up to 80km un-disrupted.
62
+
-**Long range:** Up to 5km in an urban setting, 10km in suburban and up to 80km un-disrupted.
63
63
64
64
-**Power consumption:** Our latest addition, the MKR WAN 1310, can now have as low power consumption as 104uA, when configured properly.
65
65
@@ -73,9 +73,9 @@ In this tutorial, we will be covering the basics of setting up a MKRWAN series d
73
73
74
74
## Step by Step
75
75
76
-
The aim with this tutorial is to achieve a connection between a MKR WAN 1310 board and The Things Network (TTN). First, we will need to retrieve our device's Extended Unique Identifier (EUI). Then, we will create an account at [The Things Network](https://console.cloud.thethings.network/), connect to a gateway in range and send a message through the gateway to the TTN service.
76
+
The aim with this tutorial is to achieve a connection between a MKR WAN 1310 board and The Things Network (TTN). First, we will need to retrieve our device's Extended Unique Identifier (EUI). Then, we will create an account at [The Things Network](https://console.cloud.thethings.network/), connect to a gateway in range and send a message through the gateway to the TTN service.
77
77
78
-
**1.** First, let's make sure we have the drivers installed. If we are using the Web Editor, we do not need to install anything. If we are using an offline editor, we need to install it manually. This can be done by navigating to **Tools > Board > Board Manager...**. Here we need to look for the **Arduino SAMD boards (32-bits ARM Cortex M0+)** and install it.
78
+
**1.** First, let's make sure we have the drivers installed. If we are using the Web Editor, we do not need to install anything. If we are using an offline editor, we need to install it manually. This can be done by navigating to **Tools > Board > Board Manager...**. Here we need to look for the **Arduino SAMD boards (32-bits ARM Cortex M0+)** and install it.
79
79
80
80
**2.** Now, we need to install the library needed. If we are using the Web Editor, there is no need to install anything. If we are using an offline editor, simply go to **Tools > Manage libraries..**, and search for **MKRWAN** and install it.
81
81
@@ -89,11 +89,11 @@ Copy and paste the code into the editor, and upload it to the board. Once we hav
89
89
90
90
We will need to copy and save the device EUI, as we are going to use it in the TTN service.
91
91
92
-
Now, we will need to create and activate an account at [thethingsnetwork](https://console.cloud.thethings.network/).
92
+
Now, we will need to create and activate an account at [thethingsnetwork](https://console.cloud.thethings.network/).
93
93
94
94
Once we have activated our account, go to the [TTN landing page](https://console.cloud.thethings.network/), first select your region and log in, then you will be taken to the landing page. Here, we will click the **"Create an application"** button, or **"Go to applications"** if you already have one created.
95
95
96
-

96
+

97
97
98
98
Here we need to fill in a unique name for our **application**. In this tutorial, we used **ard-lora-test**. When we have filled this in, we can click on the **"Create application"** button.
99
99
@@ -103,13 +103,18 @@ We have now created the application, and will move on to registering our device.
103
103
104
104

105
105
106
-
On the registration page, first we have to fill in information about our board. Select brand, **Arduino SA**, and then model, **Arduino MKR WAN 1310**, a MKR WAN 1300 will also work with this selection. Hardware and Firmware versions will automatically select the newest ones. Then set your preferred region.
106
+
On the registration page, first we have to fill in information about our board. Select brand, **Arduino SA**, and then model, **Arduino MKR WAN 1310** (a MKR WAN 1300 will also work with this selection). Hardware and Firmware versions will automatically select the newest ones. Then set your preferred region.
107
107
108
108

109
109
110
-
In the second step of registering the device, fill in **End device ID** and **EUI**. You can click the generate button next to the AppKey field to generate an app key for this device. Similarly, you can press the button next to the AppEUI field to make it all zeros, or enter your own AppEUI.
110
+
In the second step of registering the device, select the frequency plan for your region,
111
+
fill in **End device ID** and **DevEUI**. You can click the generate button next to the **AppKey** field to generate an app key for this device. Similarly, you can press the button next to the **AppEUI** field to make it all zeros, or enter your own AppEUI.
111
112
112
-
**Note**: The Device ID must be lowercase and without spaces. The **EUI** should be copied from the Serial Monitor.
113
+
**Note**: The **End device ID** must be lowercase and without spaces. The **DevEUI** should be copied from the Serial Monitor.
114
+
115
+
**Note**: The Frequency Plan used in Australia by **The Things Network** is
116
+
**"Australia 915-928 MHz, FSB 2 (used by TTN)"**. The other plans are included in
117
+
the list for LoRaWAN deployments using other LoRaWAN radio networks.
113
118
114
119

115
120
@@ -119,6 +124,10 @@ In our device overview, we can now see three rows: Device EUI, Application EUI a
119
124
120
125

121
126
127
+
**Note**: For devices using the **AU_915_928** band plan, an additional
128
+
configuration step is required. In settings for the end device, under
129
+
**General Settings**, expand the **Network Layer** options and change **Regional Parameters version** to **"RP001 Regional Parameters 1.0.2 revision B"**. Click **Save changes** to commit the new setting. Without this change, the device will be unable to complete it's registration to the TTN LoRaWAN network and will not be able to transmit data.
130
+
122
131
Now, we need to open the **FirstConfiguration** sketch again. To be safe, reset your board and open the Serial Monitor again. Once the program starts, it will start asking questions in the Serial Monitor. The first one is if we are using OTAA or ABP. We will use OTAA, so we can enter a **"1"** in the monitor and hit **"send"**.
123
132
124
133

@@ -127,61 +136,60 @@ Now it will proceed to ask for our **APP EUI** and **APP KEY**. Simply copy thes
127
136
128
137

129
138
130
-
This can be quite a time-consuming process, and will most likely involve more than one attempt. There are two possible outcomes: either it successfully connects, or it fails.
139
+
This can be quite a time-consuming process, and will most likely involve more than one attempt. There are two possible outcomes: either it successfully connects, or it fails.
131
140
132
141
### If Connection Fails
133
142
134
143
If the connection fails, we will see the message:
135
144
136
145
```
137
146
Something went wrong; are you indoor? Move near a window and retry
138
-
```
147
+
```
139
148
140
-
This means we have not been able to connect to TTN.
149
+
This means we have not been able to connect to TTN.
141
150
142
151

143
152
144
153
The most common issue is that the device cannot connect to a TTN gateway. Again, it is a good idea to check if we have coverage in the area we are conducting this tutorial, by checking out [this map](https://www.thethingsnetwork.org/map).
145
154
146
-
If we are within good range of a gateway, we should also try to move our device and antenna to a window, and even hold it out the window and move it around. This has proven successful on numerous accounts, as the signal can travel less obstructed.
155
+
If we are within good range of a gateway, we should also try to move our device and antenna to a window, and even hold it out the window and move it around. This has proven successful on numerous accounts, as the signal can travel less obstructed.
147
156
148
157
### If Connection Is Successful
149
158
150
-
If it succeeds, the Serial Monitor will print:
159
+
If it succeeds, the Serial Monitor will print:
151
160
152
161
```
153
162
Message sent correctly!
154
163
```
155
164
156
-
This means we have successfully been able to both connect, and send a payload to TTN.
165
+
This means we have successfully been able to both connect, and send a payload to TTN.
The payload contains a very simple message: `HelLora world!`, coded in HEX. This can be seen in the **"Live data"** tab in the **"End device"** overview. Here we can view any incoming data from our device. If the messaged was sent successfully, it will appear here. Any unsuccessful attempts to connect will also be listed here, with a **lightning** icon next to it.
161
170
162
171

163
172
164
-
As the payload comes in a HEX format, we will need to decode it. This can be done by using a Hex code translator, such as [this one](https://www.qbit.it/lab/hextext.php). We can also automate it directly in the TTC console, by navigating to our application overview, and to the **Payload formatters > Uplink**.
173
+
As the payload comes in a HEX format, we will need to decode it. This can be done by using a Hex code translator, such as [this one](https://www.qbit.it/lab/hextext.php). We can also automate it directly in the TTC console, by navigating to our application overview, and to the **Payload formatters > Uplink**.
165
174
166
-
Here, we can enter a custom code, that will convert the incoming data in HEX format to a simple text format. Below is an example written in `JavaScript`.
175
+
Here, we can enter a custom code, that will convert the incoming data in HEX format to a simple text format. Below is an example written in `JavaScript`.
167
176
168
177
```javascript
169
178
functionDecoder(bytes, port) {
170
-
var result ="";
171
-
for (var i =0; i <bytes.length; i++) {
172
-
result +=String.fromCharCode(parseInt(bytes[i]));
173
-
}
179
+
var result ="";
180
+
for (var i =0; i <bytes.length; i++) {
181
+
result +=String.fromCharCode(parseInt(bytes[i]));
182
+
}
174
183
return { payload: result, };
175
184
}
176
185
```
177
186
178
187
***For further instructions on how to use formatters, please refer to [The Things Stack's documentation on formatters](https://www.thethingsindustries.com/docs/integrations/payload-formatters/).***
179
188
180
-
This will decode the incoming message and add the text "payload: yourmessage" at the end of the incoming payloads. That way, we do not need to manually translate it each time we get a new message.
189
+
This will decode the incoming message and add the text "payload: yourmessage" at the end of the incoming payloads. That way, we do not need to manually translate it each time we get a new message.
181
190
182
191
## Conclusion
183
192
184
193
In this tutorial, we have looked at how to connect our MKR WAN 1310 board to the The Things Network (TTN). We have retrieved the device EUI, used it to register the device in the TTN console, and programmed the board using the data provided by TTN.
185
194
186
-
As long as we are in range of a TTN gateway, we can now send data over the LoRa® network which can be viewed from anywhere in the world (as long as we have an Internet connection).
187
-
195
+
As long as we are in range of a TTN gateway, we can now send data over the LoRa® network which can be viewed from anywhere in the world (as long as we have an Internet connection).
0 commit comments