2a. Connect a Marvin Device

Learn how to connect your Marvin device to KPN Things!

Marvin is the fastest start with LoRa and the Internet of Things. It’s the perfect introduction to IoT for your organization, and is also used in education. Marvin uses its LoRa connectivity to connect to the internet from anywhere in the world where there is LoRa coverage.

Setup your Marvin

This part of the getting started is based on the Getting Started by the IoT Academy.

Setup your Arduino environment

  • Download the Arduino IDE and follow the installer. We'll use it later on to program the Marvin.

  • Connect your Marvin to your computer.

Test your Marvin device

We will now test whether the Marvin device is working by letting a LED blink.

  • Download blinky.ino and open it in the Arduino IDE, or copy-paste the code into an empty Arduino IDE sketch.

  • From the Tools menu, under Board, select Arduino Leonardo

  • Also from the Tools menu, under Port, make sure the correct COM port is selected. If you have multiple options, select the one stating Arduino Leonardo. If non of your ports is labelled that way, disconnect your Marvin, reopen the menu, check which COM port disappeared, reconnect the Marvin and choose the previously identified COM port.

  • From the Sketch menu, click Upload to send the software to the Marvin. If all went well it will say Uploading complete in the bottom of the Arduino IDE and the second LED on the Marvin board will blink!

Test the LoRa module on the Marvin

The LoRa connectivity on your Marvin device is managed by the Microchip RN2483 module. With the following steps we check whether this module works correctly.

  • Download MarvinMultiSerial.ino and open it in the Arduino IDE, or copy-paste the code into an empty Arduino IDE sketch. With this program we can communicate directly with the LoRa module.

  • Upload the sketch to your Marvin.

  • Meanwhile, from the Tools menu, open the Serial Monitor

  • In the Serial Monitor, set the baudrate to 57600 baud (same as detailed in the sketch) and select Both NL & CR (#1 in the screenshot below).

Now you can directly speak to the LoRa module and get a response! #2 in the screenshot above shows you where to enter commands you want to send, and #3 highlights where answers from the module will be shown.

  • If you for instance send sys get ver, the module will return its firmware version back. This will be 1.0.1 with some historic date.

  • Now execute the command sys get hweui to retrieve the DevEUI that is stored in the module. Store the value in a text file. You'll need it when adding the device to KPN Things.

Possible other commands can be find in the module data sheet or in one of the many examples by others.

Register your Marvin to KPN Things

Open the KPN Things Portal

Open the KPN Things Portal. Go to the All Devices page and click on Add new Device.

Fill in your device information

  1. Select the Own LoRa device (preset connectivity) device type

  2. Enter a name for your Marvin device

  3. Click Add Device to continue

Provide Network Information

  1. DevEUI: the value you retrieved from the LoRa module in the step Test the LoRa module on the Marvin.

  2. AppEUI: you can use the following value: 0059AC00000FFFFF

  3. AppKey: Every device should have its own unique AppKey, since it is the root security key of your device. You can generate a unique AppKey here: https://www.loratools.nl/#/keys​

Store these three values somewhere, because you will be needing them to program your device later on.

4. Click Add Network Info to save the network information and then Finish to continue.

Check your newly created Device

You are now on the Device Detail Page. In the Status panel you will see the LoRa Connectivity status. This can temporarily be Pending creation, but if you refresh the page it should switch to Active. This means your device is correctly registered to the network.

If the LoRa Connectivity sticks to Pending creation, you could try to delete the device and provision again (Restart at step Register your Marvin to KPN Things).

If the Network Status ended up in Failed, something has gone wrong. Most likely the DevEUI is already registered through another application like Thingpark or the LoRa Developer Portal. Please make sure you remove the device registration from the other application and re-add the device in the Things Portal. For more information consult our FAQ.

Program your device to send a LoRa message

Download the ThingsML library

  • From the Tools menu in your Arduino IDE click on Manage Libraries...

  • Now, in the Library Manager, search for ThingsML and click Install. When the installation is finished, click Close.

Make a sketch

From the File menu, click on Examples.

  • Now find ThingsML, then select marvin, and within that choose marvin_example, as such:

  • A sketch will open. Now update the values for the variables DevEUI, AppEUI, and AppKey in the code with the values you entered earlier in the Portal.

Run the sketch

  • Upload the sketch to your Marvin and open the Serial Monitor. You will see a lot of commands being send to the LoRa module to configure it and to join the network. At some point you will see the following:

> mac join otaa
< ok

This means your Marvin is trying to join the network. After some seconds the following line will appear

< accepted

This means the device has joined our network!

If you see denied instead of accepted , move closer to your window or walk out into the garden to improve reception from the LoRa network. Then disconnect and reconnect the Marvin to your computer. You probably need some more coverage to be able to join the network.

After joining, your Marvin will send a message every 30 seconds containing an empty temperature measurement in ThingsML format. For more information on ThingsML, read on here.

Check incoming data in the Portal

Now your Marvin has joined and is sending data, you could visit the Data History tab on your Device Detail Page in the Portal. You should see your Join request and Join accept appear like in the screenshot below and at this point you will see more data as well. Learn more about LoRa data history.