In the previous tutorial, we covered the setup of your Arduino MKR WAN. This included installing the Arduino IDE, connecting the board to your computer, and downloading and installing the necessary boards and drivers. In the second part of this tutorial, we will create and activate an account on The Things Network (TTN), add your Arduino MKR WAN to the account, and send a test message to TTN.
Ensure your device remains connected to the computer. Upload the sketch named FirstConfiguration from the MKRWAN library. Navigate to File > Examples > MKRWAN > FirstConfiguration to find it.
Upload the sketch to your device and then open the serial monitor, as previously done for the firmware update sketch. The serial monitor should display the Device EUI.
Copy the device EUI from the serial monitor and paste into any convenient text editor such as Notepad. You will need this EUI to register your device with The Things Network.
Registering a device (such as your MKR WAN 1300) with The Things Network is a two-stage process. Firstly, you have to set up an ‘Application’, and then you add ‘Devices’ to your application. If you wanted to, you could add several devices to one application. I have just added one device to one application for simplicity.
Once you have clicked the ‘Create an application’ button, (or ‘Go to applications’ button), you will arrive at the Applications landing page. Click the blue ‘Add application’ (it may say ‘Create application’) button to start the process.
Boards 2, 3, 4 and 5 are ones I did earlier (there is no Board 1). You will now be taken to this page.
The ‘Owner’ field is automatically filled in based on the username you used when you registered (this field may be missing if you already have previous applications).
The ‘Application ID’ is the unique name that you give your application. You can call it anything, provided you only use lowercase letters, numbers and dashes (-)
You can type anything into the ‘Application name’ field. You are not limited to lowercase letters, numbers and dashes (-).
The ‘Description’ field is optional.
When done, click the blue ‘Create application’ button. You will then be taken to the application landing page.
Select the end device
Select Brand ‘Arduino SA’, then select Model ‘Arduino MKR WAN 1310’ (which works the same as the 1300). Select the newest Hardware Version (click on the dropdown and select the highest number) and the newest Firmware version. This should hopefully match the firmware version you previously updated using the MKRWANFWUpdate_standalone sketch.
Then select the Profile (Region). If you are in Europe, select EU_863_870. The numbers represent the frequency range in MHz that LoRa radio is permitted to use in Europe. The range is different in other parts of the world, so if you are in the US or in Australia, select your local version.
Enter registration data
Frequency plan – select the recommended option for your region.
AppEUI – click the ‘Fill with zeros’ button. (This is now called the JoinEUI. You can manually fill this field with zeros, just keep typing zeros until the box is full, then click ‘Confirm’.)
DevEUI – this is the ID that copied from the serial monitor when we ran the FirstConfiguration sketch. Copy it (from wherever you have saved it) and paste it into the box. The ID will be split into pairs of numbers and letters as you do so (do not select ‘Generate’).
AppKey – click the ‘Generate’ button.
End Device ID – this is created automatically from the DevEUI you just added. Note: this is no longer automatic, you have to type in your own AppKey. I am using the same format as the form originally used, that is to type ‘eui’ followed by a dash ‘-‘ and then the DevEUI, for example: ‘eui-a8610a3230228616’.
When you have finished, click the blue ‘Register end device’ button.
After pressing the Register button, your board will show up on the Device Overview page. You can now see all the information needed to complete the Arduino setup.
You have now registered your device with The Things Network. The next step is to connect your device and upload some data.
To do this, we need to open the Arduino FirstConfiguration sketch again.
To be safe, reset your board. An easy way to do this is to just unplug the MKR WAN 1300 and then plug it back into your computer. Upload the FirstConfiguration sketch and open the Serial Monitor again.
Once the program starts, it will start asking questions in the serial monitor. The first one is 'are we are using OTAA or ABP'. We will use OTAA (Over The Air Authentication), so we can enter a '1' in the monitor and hit 'send'.
If things don’t go according to plan, you will see this.
If you see the ‘Something went wrong’ message, first check you are within range of a TTN gateway, as was explained in the opening paragraphs of this article (click here to check). If you are, then try this:
Let us assume that you have now managed to connect your device. The message you have just sent (known as a 'payload') just says 'HelLora world!', coded in HEX (hexadecimal code, set to base 16 rather than decimal 10). This can be seen in the 'Live data' tab in the 'End device' overview (you can also click on ‘Live data’ in the left-hand navigation panel).
Here we can view any incoming data from our device. If the message was sent successfully, it will appear here. Any unsuccessful attempts to connect will also be listed here, with a lightning icon next to it.
The HEX code has been circled in red. If you hover your mouse over this code fragment, you will see the full message (payload). This should be 48654C6F524120776F726C6421. You may also see a ‘copy to clipboard’ icon to the right of the payload, which enables you to copy the message.
You can translate this by typing this string of letters and numbers into a HEX code translator, such as this one. Try it with the code above.
You will see that it has translated the string into ‘HeLoRa world!’.
We have successfully connected your device to The Things Network and transmitted some test data. To gather meaningful data, the next step involves integrating a sensor with the MKR WAN so that we can take some actual measurements. Click here for the next steps.