The IoT revolution also depends on the spread of LPWAN (Low Power Wide Area Network) and the LoRaWAN protocol, defined by the “LoRa Alliance“. In more detail, LoRaWAN is a media access control (MAC) protocol for wide area networks. It is designed to allow low-powered devices to communicate with Internet-connected applications over long range wireless connections.

The TTN (The Things Network), a global community of people over 84 countries, is building a global Internet of Things data network based on LoraWAN. Tale a look at these terms to have a better overview of this technologies:

Node, End Device – an object with an embedded low-power communication device

– an object with an embedded low-power communication device Gateway – antennas that receive broadcasts from Nodes and send data back to Nodes

– antennas that receive broadcasts from Nodes and send data back to Nodes Network Server – route messages from Nodes to the right Application, and back.

– route messages from Nodes to the right Application, and back. Application Server – a piece of software, running on a server

– a piece of software, running on a server Uplink Message – a message from a Device to an Application

– a message from a Device to an Application Downlink Message – a message from an Application to a Device

In this tutorial, we’ll see how to create a LoraWAN network programmed in Python using Zerynth and connected to The Things Network. In particular, we’ll see how to:

Configure a Link Labs Gateway.

Gateway. Program a Node in Python using Zerynth. In this case, the node is a Flip&Click by Mikroelektronika (based on the microcontroller SAM3X by Microchip). The LoRa module is a “LoRa Click” by Mikroelektronika (based on the RN2483 chip by Microchip ).

(based on the microcontroller SAM3X by Microchip). The LoRa module is a “LoRa Click” by Mikroelektronika (based on the chip by ). Connect the node to TTN (The Things Network) Console.

Required Material

LoraWAN Gateway . In this case, we’ve used a Link Labs BS-8, an industrial-grade IoT/M2M gateway for use with LoRa networks. It’s capable of supporting thousands of endpoints with 8 simultaneous receive channels.



. In this case, we’ve used a Link Labs BS-8, an industrial-grade IoT/M2M gateway for use with LoRa networks. It’s capable of supporting thousands of endpoints with 8 simultaneous receive channels. LoraWAN endpoints . In this case, we’ve used Flip&Click as MCU board and a LoRa Click, that carries Microchip’s RN2483 fully certified LoRa Sub-GHz, 433/868 MHz European R&TTE Directive Assessed Radio Modem. Two antenna connectors allow you to choose which of the two frequency bands will be employed. In the figure below is also present a Temp&Hum Click (not necessary for this tutorial).



. In this case, we’ve used Flip&Click as MCU board and a LoRa Click, that carries Microchip’s RN2483 fully certified LoRa Sub-GHz, 433/868 MHz European R&TTE Directive Assessed Radio Modem. Two antenna connectors allow you to choose which of the two frequency bands will be employed. In the figure below is also present a Temp&Hum Click (not necessary for this tutorial). Zerynth Studio : our professional IDE that provides a platform for developing your Python or hybrid C/Python code and managing your boards. It includes a compiler, debugger and an editor, alongside tutorials and example projects for an easy learning experience.

: our professional IDE that provides a platform for developing your Python or hybrid C/Python code and managing your boards. It includes a compiler, debugger and an editor, alongside tutorials and example projects for an easy learning experience. TTN (The Things Network) Console: you need to create/register an account entering a username and an email address.

Link Labs LoraWAN Gateway configuration

Turn on the gateway: connect the antennas and apply power. Connect a PC: wait a minute for the gateway to bootstrap, then connect a PC to the local Ethernet jack (the middle one) using an Ethernet cable. Navigate to the local webpage: on the connected PC, open a browser and navigate to 192.168.3.3. Log in using username “admin” and password “password.” The local webpage provides an interface to view the status of the gateway and to connect it to the Internet. To connect using WiFi select the Enabled checkbox in the Wireless tab of the local webpage. Then select a Wifi network from the SSID drop-down listbox and enter the password in the SHARED KEY editbox and click Submit. After a few moments, the Wireless tab updates with the connection information.

Follow the official Link Labs guide for more detailed info.

Connecting the LoraWAN gateway to The Things Network

The first step is to get the root password, so you can install whatever packages are needed. To get the root password you have to send your gateway ID, which is accessible on the local web page, at community@link-labs.com, as reported in this thread on the TTN forum.

Once you have the root password, access to the gateway through ssh protocol and follow this guide to setup and configure the router to auto connect to TTN.

Now you have to register your gateway to TTN, following this link.

LoraWAN Node configuration

First of all, you have to build an Application through the TTN console. So, go to the Application page and clicking on “add application” a new page, similar to the one below, will open.

Enter a unique Application ID as well as a Description & Handler Registration.

Then, to send data up to the new Application you just registered, you need to register your LoraWAN nodes.

To do this, navigate to the “Devices” tab on the Application home page and click the “Register Device” button.

In the Register Device panel, you’ll need to complete the forms for the Device ID and the Device EUI, that must consist of exactly 8 bytes, given in hexadecimal. You can get this code directly from your board, following the instructions below.

Programming the LoraWAN Node in Python using Zerynth

It’s time to use Zerynth to program your board in Python and get the needed Device EUI of you LoraWAN module. In particular, we’ll use the Zerynth library for the RN2483 LoraWAN chip, mounted on the LoRa Click by Mikroelektronika.

Once you have installed Zerynth Studio and created a Zerynth user, you can clone the example “get ui“. You can find the example in the “Examples Browser” panel or you can use the “Quick Search” feature, searching for “rn2483”.

Once you have cloned the example, uplink the code to your board. As you can see below, the Python script is very very simple.