How To Build a LoRaWAN Network and Connect It to a Server

Want to create a LoRaWAN network? This guide shows how to set up the gateway and connect it to the TTN server. Find out more!
How To Build A LoRaWAN Network And Connect It To A Server
Table of Contents

Want to create a LoRaWAN network? This guide shows how to set up the gateway and connect it to the TTN server. Find out more!

LoRaWAN (Long Range Wireless Area Network) is the most typical LPWAN (Low Power Wide Area Network) IoT protocol due to its broad coverage and low-cost chipsets. One LoRaWAN gateway can cover up to 20-30km in rural areas and a few kilometers in dense, urban areas under the right conditions. If you want to build this network for your project, I will show you how to do it. Let’s get started!

What Are LoRa and LoRaWAN?

LoRa (Long Range) is a proprietary long-range, low-power radio modulation technique that manipulates radio waves to encode data using Chirp Spread Spectrum Technology.

On the other hand, LoRaWAN is a low-power wide-area network protocol built above the LoRa modulation technique. The protocol connects devices to the internet and handles communication between the gateways and end nodes.

In other words, LoRaWAN is the MAC (Media Access Control) software layer that controls the operation of the LoRa hardware physical layer.

LoRaWAN Network Architecture

A LoRaWAN network consists of these four primary components.

%E8%80%8C%E6%88%91%E5%8D%B4
LoRaWAN network architecture
  • End Nodes: Edge devices and sensors fall in this category. They send or receive LoRa-modulated data wirelessly to and from the gateway.
  • Gateways: Lora cellular gateway collect data from various end nodes and send them to the network server. Also, they operate in reverse, sending data from the network server to the nodes. Gateways are at the heart of LoRaWAN IoT architecture because they are the backbone of the network’s star topology.
  • Network Server: The network server software manages the LoRaWAN network, with functions like data exchange, sensor authorization, and more.
  • Application Server: These servers host the software responsible for processing application data securely.

LoRaWAN Network Server Providers

Dusun’s IoT platform integrates with the industry-leading LoRaWAN network servers to ease the development work. Some of the leading LoRaWAN network service providers include:

Loriot

Loriot is a powerful LoRaWAN network server that promises scalability, security, and interoperability with all IoT platforms. The user-friendly provider offers managed/ unmanaged deployments and has a software suite for assisting users manage their networks.

ThingsBoard

ThingsBoard is an open-source IoT platform offering solutions for data collection, visualization & processing, and device management. It provides on-premise and cloud deployments, plus a combination of fault tolerance, scalability, and performance to ensure zero data loss.

Helium

Operated by a blockchain network, Helium creates a decentralized wireless architecture for powering IoT devices. It is the world’s first peer-to-peer LoRaWAN network server and earns peers HNT crypto rewards for providing coverage.

ChirpStack

ChirpStack is also an open-source LoRaWAN network server. It provides a web interface for managing the gateways and nodes and connects to the devices using TLS and MQTT. Also, you can extend or integrate ChirpStack using a gRPC-based API.

AWS

AWS is well-known for providing cloud services, and one of them is the IoT network server. You can create a private LoRaWAN network using AWS IoT core by linking your end nodes and AWS LoRaWAN gateways to the cloud.

Senet

Like AWS, Senet provides managed network services on the cloud (Network-as-a-Service), resulting in highly scalable IoT deployments. The platform’s developer portal enables users to test end nodes, validate sensor functions, and test gateways. 

MachineQ

MachineQ offers fully integrated and custom IoT platforms to suit the needs of different developers. The company’s LoRaWAN stack also features a join algorithm for rapid device onboarding and flexible parameters for connectivity configuration to support re-joining.

The Things Network

The Things Network is an IoT global cooperative ecosystem available in 152 countries. It consists of the Things stack, a flexible set of network components with the following servers.

  • Network server
  • Identity server
  • Gateway server
  • Join server
  • Application server

It provides the option of managed network services or self-hosting and has other features, such as:

  • Firm updates over the air
  • Clock syncing in the application layer
  • Supporting class A, B, and C devices
  • Transporting split data blocks

How To Build a LoRaWAN Network and Connect It to a Server

Since the TTN is widely available and more comprehensive, I will use it to show you how to build a LoRaWAN network. Here we go!

Overview: What You Will Build

If you recall, a LoRaWAN network has four components. I will show you how to build the end node, then use one of Dusun’s LoRaWAN gateways to connect to the network and application server. You can use public roaming networks if they are available in your country.

The LoRaWAN network is similar to connecting your smartphone (end node) to the internet (network & application servers) via cell towers (gateways). However, you don’t pay for telco charges with LoRaWAN. LTE for smartphones is faster than LoRaWAN and operates in real-time. But the latter has long-range and low-power advantages.

What You Need

  • Arduino microcontroller (Pro mini or Nano)
  • RFM95 or RA-07H module
  • Antenna (optional)
  • Sensor, such as DHT11 (although not necessary at this moment)
  • Dusun gateway (or you can use a public gateway that is within range)
  • Computer
  • Jumper wires

Building the Node

The end node requires a microcontroller to function as the brain and a LoRa module for wireless connectivity to the gateway.

image 12
The Arduino Pro Mini

I will use the Arduino Pro Mini and the RFM95 LoRaWAN module, which can transmit using the 863 to 870 MHz frequency band for Europe and 902 to 928 MHz for North America. You can learn more about these LoRaWAN frequency bands here.

Connect the pins as shown in this table.

Arduino Pro MiniRFM95
2DIO0
3DIO1
5Reset
10NSS
11MOSI
12MISO
13SCK
VCC3.3V
GNDGND

The node setup also needs an antenna to transmit and receive the radio waves. Some RFM95 modules come with copper coil antennas. If yours does not have one, solder an 8-9 cm wire to its ANT pin. This component is essential, so don’t power up the module before hooking up the lora gateway antenna if the module does not have it. You could destroy it.

LoRaWAN Gateway

You can use any of Dusun’s indoor or outdoor gateways. They are easy to set up, but you should check the user manual to see if the device needs any configuration before connecting the node and linking it to TTN.

The Dusun DSGW-014 (an outdoor gateway)

Remember, different zones/continents have specific roaming LoRaWAN network frequency ranges. If using a private gateway, configure it to operate within the frequency range in your region.

Creating an Application in TTN

The next step involves connecting to the TTN. But first, you need to register. Select your gateway or device’s location (country), and TTN will recommend the most suitable cluster. 

Next, go to the applications page to register your device on the network. Add a new application, then fill in the details, including the application ID. Click the “Add Application” button, and you’ll get an overview of your application.

After that, click the “Devices” menu, then add an end node by clicking the “Register Device” button on the top right corner of the webpage.

Enter the device EUI, app key, and app EUI, then click register to get a device overview.

After that, select the activation method, which determines the level of trust and security between the end node and the LoRaWAN gateway. Two connection modes exist for these devices: Activation By Personalization (ABP) and Over The Air Activation (OTAA). The difference between them lies in the implementation ease and security criteria.

image 11

LoRaWAN architecture with OTAA connection mode

OTAA is the preferred activation/connection mode because it is secure. It requires a handshake (two-way) communication procedure with the gateway to exchange keys.

However, ABP is faster and easier to use. It does not require the handshake procedure and enables manual encryption key configuration. So I will use ABP.

Edit the Code

The code for connecting the end node to the TTN server via the gateway is already in GitHub. You don’t have to rewrite it. Just some minor edits, and you’ll be ready to roll. Open the Arduino IDE, paste the code, then go to lines 10, 11, and 12.

From the TTN device overview page, copy the network session key, application session key, and device address. Paste this data into the respective fields in the code.

And you must begin the device address with 0x in the code. For instance, if the address is 260112BE, replace it in the code as 0x260112BE.

Results

Connect the Arduino Pro Mini to your computer and upload the code. If the connection is successful, the status on the device page on TTN should change from “never seen” to a number that counts upward in seconds.

At this point, the network is running, and you can connect sensors (such as the DHT11 temperature and humidity sensor) to the Arduino board.

image
wikipedia

The DHT11 sensor

This unit will form part of the end node and send the secure payload to the server. But you must set the payload formatter to decode the incoming raw data.

For instance, you need to use Javascript to convert the raw data from the sensor and gateway to the network server.

Let’s say you use a DHT11 sensor. The uplink payload data can be something like 3C0119. This Javascript code can decode the data.

ArzSVLbqar2SiiFN6evYftzfOIkf8JNs9tuR z3zTDjVwltk8KB9DppY8u1NhQn4Ys Q8VFW3rL44wc807deLqHuZF88yYTwJeWV5FLFJ9 NZkioDpOFQP76

The result will be {field1: 60, field2: 28.1}, implying the humidity is 60% and the temperature is 28.1°C.

Potential Issues That Can Affect the Network

  • Wrong keys or in the incorrect order
  • A fault with the RFM95 module or its connection with Arduino
  • No gateway within reach. Although a single gateway can cover a few km in urban areas and up to 30 km in rural areas, these are best-case scenarios under the right conditions. So I recommend buying a Dusun gateway to avoid this problem.

Free vs. Premium Network Providers

It is vital to note that The Things Network community edition is free to use and does not make money from its users. And as you know, there is always a catch with free things. In this case, the network server can have significant downtimes. Therefore, you should not deploy commercial projects using this TTN network server.

The service is ideal for development, prototyping, and learning, but a reliable paid network is better for commercial deployments. Even TTN has a premium network server that offers better service.

Private vs. Public LoRaWAN Network

What you have built using the steps described above is a public network because several users share the network server. Also, it requires an internet connection.

A private LoRaWAN network requires IoT sensors, just like the public type. However, the network infrastructure must also be personal. So you should have a personal LoRaWAN gateway and network server.

You can place the gateways indoors or outdoors to provide enough coverage for the sensor/end node positions. Gateways operate like Wi-Fi routers, so install them at a reasonable height to cover the maximum range.

Although gateways are the backbone of the LoRaWAN network’s star topology, they operate under the network server in terms of management. Network servers have the following roles.

  • Managing several gateways
  • Permit nodes and actuators in the network
  • Managing payloads (uplink and downlink)
  • Ensure proper data transmission without duplication

How To Build a Private LoRaWAN Network

The gateway can double up as the network server for data delivery to applications if you build a small private LoRaWAN network with a single antenna.

But if you want to build a LoRaWAN network with more than one gateway, you should deploy a private network server to control the devices.

Also, you must ensure the deployed gateways provide the required range to transmit and receive data from the nodes.

Keep in mind that the communication between the gateways and nodes uses the LoRaWAN protocol. On the other hand, the data transmission between the network server and the gateway requires interfaces like web sockets, MQTT, and web services.

Lastly, you will need IoT platform applications for processing data from the gateways and allowing users to monitor and control the actuators and systems remotely.

Read More: How to Build a Private LoRaWAN Network

How To Switch From Public to Private LoRaWAN

Public LoRaWAN networks require the following.

  • Shared gateways
  • Internet connectivity
  • Subscription to a network service provider for sensor/device registration

These network service providers also offer end-user applications for managing LoRaWAN nodes.

Switching to a private network can have several advantages, such as improved security and better coverage, especially indoors.

To switch, you will acquire and set up LoRaWAN gateways, network servers, and IoT application platforms. Instead of going through the tedious task of setting up and integrating all three, you can get all-in-one solutions.

Most manufacturers customize these IoT application gateways for specific applications and systems, such as home assistants. However, Dusun’s gateways can accommodate third-party applications, making them versatile and flexible.

Cost of Setting Up a Private LoRaWAN Network

Whether you are setting up a private or public LoRaWAN network, the cost of the end nodes is constant because you must develop these components.

However, you can use shared gateways and network servers in a public LoRaWAN network, so the costs are lower when setting up. Subscription costs are also cheap and can be free if you use free community projects like TTN.

Deploying a private LoRaWAN network is costlier because you need to buy more hardware. The gateways must provide sufficient coverage, meaning you might need several for indoor and outdoor use.

Buying an all-in-one gateway, network server, and IoT platform application device is cheaper than setting up the three independently. So we will consider using this hardware as the most significant expense.

Contact Dusun to get a quote for their IoT app gateways. If you like getting technical, they also offer IoT programmable gateways. These are more flexible, have open APIs, and support multiple programming languages, such as Java, Python, C, C++, and Node JS.

Advantages of a Private LoRaWAN Network

  • Secure (minimizes the risk of data breaches and eavesdropping)
  • Offer better control of specific applications, including customization

Advantages of a Public LoRaWAN Network

  • Cheaper setup/installation cost
  • Links you to a large community of users
  • Established providers can provide reliable network server infrastructure

LoRaWAN Applications

  • Logistics/Transport (fleet monitoring)
  • Smart healthcare (fitness/health monitoring)
  • Smart agriculture (sunlight exposure measurement, grow lighting)
  • Smart environments (radiation leak detections, air quality monitoring, etc.)
  • Public safety solutions (wearables like ID badges with panic buttons for sending SOS signals)
  • Smart buildings (water metering, room occupancy, motion detection, CO2 level monitoring, etc.)
  • Smart cities (parking meters, air quality control, waste management, street lighting, public transit, etc.)

Wrapping Up

In conclusion, LoRaWAN networks are critical for supporting IoT. And you can build one using the steps I have explained above. Try to weigh the options between deploying a public or private LoRaWAN network by considering your requirements first.

For more information, visit Dusun Solutions to get a sneak peek of other ideas you can try to implement using your LoRaWAN IoT network.

Leave a Reply

Looking For An IoT Device Supplier For Your Projects?

CONTACT US

    This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    IoT Gateways for Recommendation

    CONTACT US

      This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

      Welcome to DusunIoT

      Hi there 👋 Is there anything we can help you with today? Please fill in the form below for the team to follow up if you become disconnected.

        Download

          This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

          Ultimate IoT White Paper for Developer Gateway

          DusunIoT Distributor Program

            This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

              This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.