Seeeduino LoRa GPS: Getting Started with LoRaWAN (and TTN)

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:

  1. Download the latest Arduino IDE: https://www.arduino.cc/en/main/software
  2. 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
  3. Now head to Tools > Board > Boards Manager and install the Seeeduino SAMD board.
  4. On Windows you’ll have to install a Serial driver as well. On my Mac this wasn’t necessary
  5. Now select in Tools > Board the “Seeeduino LoRaWAN” board
  6. Under File > Examples > LoRaWAN select the OTAA sample

 

TheThingsNetwork setup

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:

  1. Go to https://www.thethingsnetwork.org/ and register an account
  2. Go to https://console.thethingsnetwork.org/ and select “Application”
  3. On the next screen click “+add application”
  4. 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
  5. On the next screen click “register device”
  6. For “Device ID” pick a meaningful name in lowercase letters
  7. 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
  8. 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

 

Summary

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.

Posted by Daniel Eichhorn

Daniel Eichhorn is a software engineer and an enthusiastic maker. He loves working on projects related to the Internet of Things, electronics, and embedded software. He owns two 3D printers: a Creality Ender 3 V2 and an Elegoo Mars 3. In 2018, he co-founded ThingPulse along with Marcel Stör. Together, they develop IoT hardware and distribute it to various locations around the world.

10 comments

  1. Thank you for the nice example! I don’t have LoRaWAN modules to test, but I found data logging to Google Spreadsheets is an interesting alternative of ThingSpeak. In fact, I managed to send ESP8266 DHT to data there. Regards.

  2. Thanks for this post. Is this possible to give an example how to send GPS data over TTN?

    Regards.

    • Yes, I will try to show the complete chain from node, ttn to Google sheet app. In my early tests I couldn’t get a fix for GPS even when being outside. I have to look into that…

  3. i have problem while doing this part

    // 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”);

    where should i find these values DevAddr , NwkSKey , AppSKey ???

  4. I just tried the sketch with your mods (with my proper keys and eui, that I masked here), but got this in the console:

    +VER: 2.0.10
    +ID: DevAddr, ******
    +ID: DevEui, ******
    +ID: AppEui, ******
    +ID: DevEui, ******
    +ID: AppEui, ******:+KEY: APPKEY ********
    +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: 0,868100000
    +RXWIN2: 869500000,DR3
    +LW: DC, OFF, 0
    +LW: ERROR(-2)
    +POWER: 20
    +JOIN: Start
    +JOIN: NORMAL
    +MSG: LoRaWAN modem is busy
    +JOIN: Join failed
    +JOIN: Done
    +MSG: Please join network first
    +MSG: Please join network first
    +MSG: Please join network first

    … and so on for the last message. Do you know why and how to fix this?

  5. Thank you for this post.
    I also receive the Please join network first-messages.
    Maybe you have a clue of what I’am doing wrong?

  6. Hi,
    Thank you for your work.
    I do have the same error message even with the 2.1.16 firmware version.
    Regards,
    Lionel

  7. Hi, to fix the ‘modem is busy’ message you need to set the timeout on the join command like this: `while(!lora.setOTAAJoin(JOIN, 60));`

    Cheers!

  8. Hello – it took me some time to bring my Seeeduino LoRaWan into the Things Network. I use the Activation Method ABP and European Frequenz Plan. Actually i have only a dragino one channel Gateway available. Also i have two Dragino Lora Shield v95 Nodes running. My Problem – the Dragino Lora Shield v95 Nodes are running on Port 1 both – the Seeeduino on Port 8 – and the bad News – after 10 Minutes the Seeeduino is never seen – Flash new – start new the Seeeduino and he works again for some minutes. What could be the reason ?

Leave a Reply to lwalter86Cancel reply