Resource

From WiFi to LoRaWAN: A Step-by-Step Guide to Superior IoT Connectivity - Part 1

Published on 25 Jun, 2024 by Neil

Introduction

This blog post describes the steps taken to extend the connectivity of an existing product to include LoRaWAN. It will cover the hardware choice, LoRaWAN MAC library choice, integration to the hardware, initial testing and follow-up decisions based on lessons learned.

The Challenge

Green Custard were approached by a client who made extensive use of WiFi to provide connection between multiple sensors and finally a gateway to the wider Internet. This network topology was not reliable enough for the intended application and a more robust solution was required.

The Solution

LoRaWAN was chosen as a long-range, low-bandwidth alternative to WiFi. The number of gateways could be reduced dramatically as the coverage provided by LoRa is far greater than 2.45GHz WiFi.

A star topology (single gateway, many devices) would replace the device-to-device-to-gateway approach.

Low-cost, LoRaWAN-compatible hardware was selected and a library was ported that enabled connection to the AWS LPWAN services.

Range of LoRa vs WiFi

Many factors, including the transmission frequency, affect the propagation range of a radio frequency. Maximum range is achieved by line of sight when any material or object does not occlude the transmitting and receiving antennae i.e. when one antenna can be seen from the other.

Calculating the theoretical range is complex and involves factors such as the power radiated from the antenna, the sensitivity of the receiver, and the attenuation from intermediate objects. LoRa in the EU868 band (868MHz) will propagate further than WiFi at 2.45GHz for the same transmission power.

Copyright © MOKO LORA

From the diagram above, the trade off between range and data rate for WiFi and LoRa can be clearly seen.

Constraints

There were several constraints which had an impact on the choices of solutions available which included:

  • The case enclosure could not be changed, any changes to the main PCB had to fit within the current plastics and retain the same board outline. This included the placement of indicator LEDs, alignment with mode and select actuators. The original design supported a 2.45GHz WiFi module along with BLE capability which needed to be retained. An external RF antenna was used for Wifi, however, this would be incompatible with 868MHz LoRa. The original design uses a Particle.io P1 module. Development for this part is within an Arduino environment along with Arduino libraries. The P1 module was marked end-of-life by the manufacturer and any new development is to be based on the replacement P2 module. As the client had developed and tested an application based on the P1, it made sense to use the P2 module to reduce risk and development effort. https://docs.particle.io/reference/datasheets/wi-fi/p2-datasheet/

  • A runtime configuration file (stored on an SD card) is used to determine whether data is sent over the WiFi connection or over the LoRaWAN interface. The LoRaWAN device configuration parameters (DevEUI, AppKey) are also located on the SD card.

  • From the constraints described above, it was immediately apparent that the LoRa module needed to be small enough to fit within an unpopulated region of the PCB, to be mounted directly to the PCB where there was sufficient space above the board to not clash with the legacy plastics. It also required a U.FL connector for an external antenna as range was a key aspect of the RF performance. It was unlikely that a PCB antenna would provide the RF sensitivity required for the product use case.

LoRa Device Selection

The Semtech SX1262 is a sub-GHz radio transceiver developed for long-range wireless applications. The SX1262 can transmit up to +22dBm with highly efficient integrated power amplifiers. These devices support LoRa for LPWAN use cases and are highly configurable to meet different application requirements utilising the global LoRaWAN standard.

The SX1262 is designed to comply with the physical layer requirements of the LoRaWAN specification released by the LoRa Alliance. The radio is suitable for systems targeting compliance with radio regulations including but not limited to ETSI EN 300 220, FCC CFR 47 Part 15 with continuous frequency coverage from 150MHz to 960MHz allowing the support of all major sub-GHz ISM bands around the world. The Core1262-HF can be used from 868 to 960MHz.

The SX1262 is one of the most recent products added to Semtech's portfolio so it was an obvious choice as it is unlikely to go out of production soon and is established enough to be available to buy.

SX1262 Block Diagram

Copyright © Semtech Corporation

The MCU digital interface is over the SPI bus, the crystal oscillator is located on the module.

Waveshare Core1262-HF

Waveshare Electronics offers many LoRa solutions, including the Core1262-HF which covers the EU868 and US915 LoRa bands. This means that a single module can cover both the EU and US markets and the frequency band can be configured and selected at runtime.

The physical dimensions of the Core1262-HF are 22 x 19 x 3.27mm so it is a reasonably small module. It has castellated edge 0.1" pitch headers, with no underside components and can be directly soldered to the PCB. RF connection is via an IPEX socket which is equivalent to a U.FL connector.

Copyright © Waveshare Electronics

The interface to the SX1262 LoRa part is via SPI with several of the SX1262 IO lines brought out to the PCB headers. These will be described later. The price point is attractive and the author has had a positive experience working with Waveshare parts. They provide schematics, reference code and good product documentation via a wiki page. The build quality is good and previous builds using Waveshare parts have worked well.

Copyright © Waveshare Electronics

The ANT output (top left) is not required as the RF antenna is attached via the IPEX connector on the top side of the module.

LoRa Library selection

Writing a LoRaWAN MAC from scratch is not sensible. Semtech provide a reference written in C which has been ported to many platforms. It provides support for multiple Semtech chipsets and includes examples for using the part in a LoRa-only mode which is useful for checking register values as the part is configured.

Several potential LoRaWAN MAC ports were investigated before the final choice was made:

GitHub - mcci-catena/arduino-lorawan: User-friendly library for using arduino-lmic with The Things Network and other LoRaWAN® networks

GitHub - mcci-catena/arduino-lmic: LoraWAN-MAC-in-C library, adapted to run under the Arduino environment

No support for the sx1262 part. The radio layer was written to support the Semtech SX127x family which has a very different register map compared to the SX1262. The effort and risk to port this version of the MAC was deemed too high.

GitHub - LacunaSpace/basicmac: BasicMAC LoRaWAN stack that supports (but is not limited to) Arduino

Another port of the LoRa MAC in C (LMIC). This version has support for the SX1262 and has not received any recent maintenance.

GitHub - beegee-tokyo/SX126x-Arduino: Arduino library to use Semtech SX126x LoRa chips and modules to communicate

This version of the LoRaWAN MAC has support for the SX1262 part. It was chosen as the basis of the P2 to Core1262-HF integration. This library is maintained by an employee of RAKWireless, has recent updates and the radio layer (including the SX1262 driver) is cleanly written. This version became the basis of the P2 to Core1262-HF porting work.

Adding a Library to the build


This may appear to be a trivial step, but the Particle.io workbench requires a particular directory layout to allow for the toolchain to recurse and add a new library. This is outside of the scope of this post, further details can be found here: https://docs.particle.io/getting-started/device-os/firmware-libraries/

Once the library (in this context, the LoRaWAN MAC library) has been added and successfully compiled, the process of porting the HAL can begin.

Summary

In this first post, we have examined the expected benefits of using LoRaWAN, the choice of hardware and a description of the selected RF module. Finally a brief description of the LoRaWAN libraries available, the choice of a suitable LoRaWAN library and addition to an Arduino-compatible platform.

In the next post, we will describe the hardware configuration, bring-up and work done to provide LoRaWAN functionality.


Back to the list