In the last couple of months I had the chance to play around with LoRaWAN. In case you have never heard of LoRaWAN, it is THE radio communication protocol for the Internet of Things (IoT). It is long range (thus LoRa) and consumes only little energy when transmitting. This guide will help you to get a Seeedstudio Seeeduino LoRa GPS to TheThingsNetwork.
TheThingsNetwork (TTN) is a community driven communication infrastructure currently using the LoRaWAN protocol. This means that instead of paying fees for your local Telecom provider you can connect your devices for free to the internet. Provided that there is already coverage of TTN in your area. This map can give you an indication if you already have coverage. Otherwise don’t worry, for little money you can become a infrastructure provider yourself. You can build a “real” multi-channel gateway (something like a WiFi access point) for about 200-300$. And a single channel gateway can be built for as little as USD $15 (watch this Video from my fellow countryman Andreas Spiess). But this post is not about the infrastructure, it is about getting one specific LoRa hardware connected and this is more complicated than you think (the first time).
Arduino IDE setup
This chapter is all about getting the programming environment ready for the Seeeduino. Since this might change you probably find most up-to-date information on the Seeeduino Wiki: http://wiki.seeed.cc/Seeeduino_LoRAWAN/. Here a few quick steps:
- Download the latest Arduino IDE: https://www.arduino.cc/en/main/software
- Go the preferences/settings and under “Additional Board Manager URLs” add the following URL: https://raw.githubusercontent.com/Seeed-Studio/Seeed_Platform/master/package_seeeduino_boards_index.json If you already have one add the new one separated by a comma
- Now head to Tools > Board > Boards Manager and install the Seeeduino SAMD board.
- On Windows you’ll have to install a Serial driver as well. On my Mac this wasn’t necessary
- Now select in Tools > Board the “Seeeduino LoRaWAN” board
- Under File > Examples > LoRaWAN select the OTAA sample
As mentioned earlier TheThingsNetwork is your telecom provider you are going to use in this setup. There might be other providers in your country. In Switzerland we have Swisscom LPN, Loriot.io (a cool Swiss startup with world wide infrastructure) and TTN. In this post we’re going to use TTN since it is free to use and relatively easy to setup.
LoRaWAN devices send with a broadcast, which means all LoRaWAN antennas from all providers are going to pick up your (encrypted) message. Only the provider with which the device is registered will forward the message to your application. The others will discard the message. The following steps show you how to register the Seeeduino with TTN. First create an account, then create an application and then register your device within this application:
- Go to https://www.thethingsnetwork.org/ and register an account
- Go to https://console.thethingsnetwork.org/ and select “Application”
- On the next screen click “+add application”
- In the next screen pick a meaning full name for your application in lowercase letters for Application ID and write something in Description. Under Handler Registration pick your region, for Europe I have picked ttn-handler-eu
- On the next screen click “register device”
- For “Device ID” pick a meaningful name in lowercase letters
- On the left side of the DevEUI field click on the arrow icons. The icon changes into a pen and this will cause the ID to be generated. This is necessary since the API doesn’t offer a way to read out the devices MAC address. See image below
- In App EUI pick the ID of the application we created earlier
Adapting & Running the Code
Now it’s time to adapt the OTAA code. Replace the line lora.setKey(..) with the values below. I copied here also the signature of the two methods so you know which value you have to put there. setId(NULL, DevEUI, AppEUI) and setKey(NULL, NULL, AppKey):
// void setId(char *DevAddr, char *DevEUI, char *AppEUI); lora.setId(NULL, "12409E2345695432", "70B3D57EF0006593"); // setKey(char *NwkSKey, char *AppSKey, char *AppKey); lora.setKey(NULL, NULL, "47BDA77B6D7B4DDA7DC182E54295FE4E");
Now make sure to select the Seeeduino under Tools > Port and upload the sketch. If you are not owning a LoRaWAN gateway yourself but you think that one should be close then remove obstacles between you and that gateway. LoRaWAN can penetrate walls but how deep into the house the signal is strong enough depends on many factors. Upload the code and open the serial monitor. If everything worked out well your output should look something like this:
+VER: 2.0.10 +ID: DevAddr, 26:01:3A:44 +ID: DevEui, 12:40:9E:23:45:69:54:32 +ID: AppEui, 70:B3:D5:7E:F0:00:65:93 +ID: DevEui, 12:40:9E:23:45:69:54:32 +ID: AppEui, 70:B3:D5:7E:+KEY: APPKEY 47 BD A7 7B 6D 7B 4D DA 7D C1 82 E5 42 95 FE 4E +MODE: LWOTAA +DR: EU868 +DR: DR0 +DR: EU868 DR0 SF12 BW125K +CH: 0,868100000,DR0:DR5 +CH: 1,868300000,DR0:DR5 +CH: 2,868500000,DR0:DR5 +RXWIN1: OFF; 3; 0,868100000; 1,868300000; 2,868500000; +RXWIN2: 869500000,DR3 +POWER: 20 +JOIN: Start +JOIN: NORMAL +JOIN: Network joined +JOIN: NetID 000013 DevAddr 26:01:21:52 +JOIN: Done +MSG: Start +MSG: TX "Hello World!" +MSG: Done
Now you can also go back to your TTN console (website) and see if the packages have arrived there.
Where to buy
You can buy the Seeeduino LoRaWAN with GPS module from Seeedstudio:
Seeedstudio LoRaWAN w/GPS
This post showed you how you can connect the Seeeduino LoRaWAN w/GPS to TheThingsNetwork. This is just half the rent. In one of my next posts I want to show you how you can use the GPS module on the device to send the Seeeduino’s location over LoRaWAN. And finally we also want to receive the data in our own application. So a future post will show you how to do that as well.
Did you like this post? Consider supporting me with a virtual coffee or beer.