Getting started with the Arduino MKR WAN 1300
Minimal getting started examples to connect the Arduino MKR WAN 1300 to The Things Network
Make sure you have an updated version of Arduino IDE installed.
You could run these examples on the Arduino Web Editor also, but the screenshots are from the desktop client.
Install board definitions
Go to Tools
-> Boards
-> Board manager
, search for MKR
, and install the Arduino SAMD Boards
package.
Install LoRaWAN library
Go to Sketch
-> Include Library
-> Manage Libraries..
, search for MKRWAN
, and install it.
In order to connect, you will need to be in range of a gateway of The Things Network. Check the world map to see if your local community already has gateways, and if not, consider installing one!
While you're there, also make sure you have an account on The Things Network.
Always make sure you have the antenna plugged to your Arduino before powering it up.
In order to send messages to the network, you need to register it on The Things Network, but before we do that, we need to find out its Device EUI
(identifier):
Board
and Port
on the Arduino IDE menumkrwan_01_get_deveui
lora_band region
variable according to your region.Device EUI
, keep this at hand.Application
Device
giving it a ID of your liking and paste the Device EUI
that we got on Step 5.Once the device is registered on the network, we can start sending data:
mkrwan_02_hello_world
lora_band region
variable according to your region.arduino_secrets.h
), paste the appEui
and appKey
values for your device. You can copy & paste it verbatim from the bottom of the device page on The Things Network Console (section EXAMPLE CODE
).Data
tab of The Things Network Console.Q: Wait! Why do I see payload =
68 69
instead ofhi
?A: That's HEX for
hi
. That's because you should not be sending strings over LoRaWAN, you have to optimize the air time usage sending as much a compact payload as possible.
Check Working with Bytes for more details about optimizing your payload.
Now for a more complete application, let's build a GPS tracker node! For this example, you need to get a GPS module. I am using u-blox PAM-7Q but also tested it with the more widely available u-blox NEO series.
The wiring of the module is trivial:
Arduino pin | GPS pin |
---|---|
GND |
GND (3 ) |
VCC |
VCC (4 ) |
RX (13 ) |
TX (2 ) |
TX (14 ) |
RX (1 ) |
You will also need to install the TinyGPS++ library. Download it as ZIP, then go to Sketch
-> Include Library
-> Add .ZIP Library
and select it.
We will use a binary payload based on TTN Mapper reference, so we need to add a decoder
payload format function to The Things Network Console (as described in the documentation).
Go to the Applications
tab in The Things Network Console, select Payload Formats
and copy & paste the following decoder
function:
// Author:
// Copyright (c) 2016 JP Meijers
// Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
// https://github.com/jpmeijers/RN2483-Arduino-Library
function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var decoded = {};
// if (port === 1) decoded.led = bytes[0];
decoded.lat = ((bytes[0]<<16)>>>0) + ((bytes[1]<<8)>>>0) + bytes[2];
decoded.lat = (decoded.lat / 16777215.0 * 180) - 90;
decoded.lon = ((bytes[3]<<16)>>>0) + ((bytes[4]<<8)>>>0) + bytes[5];
decoded.lon = (decoded.lon / 16777215.0 * 360) - 180;
var altValue = ((bytes[6]<<8)>>>0) + bytes[7];
var sign = bytes[6] & (1 << 7);
if(sign)
{
decoded.alt = 0xFFFF0000 | altValue;
}
else
{
decoded.alt = altValue;
}
decoded.hdop = bytes[8] / 10.0;
return decoded;
}
We are all set to update our Arduino, the steps are almost identical to the previous example:
mkrwan_03_gps_tracker
lora_band region
variable according to your region.arduino_secrets.h
), paste the appEui
and appKey
values for your device. You can copy & paste it verbatim from the bottom of the device page on The Things Network Console (section EXAMPLE CODE
).Serial Monitor
to see the progress.Data
tab in the console to see GPS data coming in.Fantastic! And now, how do I see my GPS traces on a map like this?
Check this sample web app!
This content is licensed under the MIT License, see the LICENSE file for details.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Examples loosely based on Arduino MKRWAN library.
Check the reference documentation of the library for additional options.