LoRa is a radio technology for low power long range communication, typically kilometers. It is designed for small data packets and uses certain license-free frequency bands: 433, 868, 915-925 MHz depending on your region. It can be used peer-to-peer to exchange packets, or with LoRaWAN, a protocol on top of the LoRa technology which defines rules for data transmission and formats. I had experimented a bit with peer-to-peer LoRa few years ago, but as LoRaWAN seems to be gaining traction, i created a LoRaWAN prototype module for Industruino. This allows such node to be deployed in any LoRaWAN network, private or public. I chose to join The Things Network (TTN) because that seems well documented for experiments, and has built a nice worldwide community network.

TTN Mapper site shows TTN LoRaWAN gateways in Hong Kong (Jan 2022)

Note: yes i had a look at the Helium network, but having to pay even to join the network as a data-only hotspot shows how much of a Ponzi scheme this is.

The frequency to be used by LoRaWAN devices depends on the country. For Hong Kong, it is the AS923-1 frequency plan (923-925MHz). This means i should use a LoRa gateway and radio modules marked 915MHz. The regional differences are a bit annoying; you need different hardware for EU868, US915, CN470. It seems there is a plan to also enable 2.4GHz which would allow for the same hardware to be used around the world.

Another important note when using the TTN is that the regions are not integrated yet. When we register gateways and end devices in the TTN console we need to pick a cluster (EU, US, AU) and this is important because gateways will not forward packets of end devices configured in a different cluster. For Hong Kong and Asia, we are advised to use the Australian cluster, au1.

There was no TTN coverage yet in my village, so i installed an indoor LoRaWAN gateway, a Dragino LPS8. It is fairly easy to update the firmware, configure it for the AS923 frequency plan, and as a TTN Basic Station pointing to the TTN au1 server.

For LoRa radio modules there is a choice between basic radio modules with SPI such as this Dragino LoRa Bee, and more sophisticated modules with an embedded LoRaWAN stack and Serial communication with AT commands, such as this SeeedStudio LoRa-E5 module. The latter one reminded me too much of the early days ESP8266 wifi module and AT trouble, so i chose the basic LoRa radio, built around the SX1276/8 chip. That means the LoRaWAN stack has to run on the microcontoller. The common library for this seems to be MCCI’s Arduino-LMIC. It is well documented, and to make the ttn-otaa.ino example work, i only had to modify 2 lines in the project_config/lmic_project_config.h

  #define CFG_as923 1
  #define CFG_sx1276_radio 1

Of course i also needed to create an end device in the TTN console, and copy the DEVEUI and APPKEY.

I tried using an Arduino UNO first, but it did not compile because insufficient memory. It is probably possible to make it work by stripping some components off the library, but i was happy to switch to an ESP32 which has plenty of memory, and an easy to use low-power deep sleep. This is my first prototype on a breadboard; note that the Dragino LoRaBEE has 2.0mm headers; i needed to add an XBee style adapter to plug it into the breadboard.

These is the pin map in the sketch:

// LoRa BEE Pin mapping
const lmic_pinmap lmic_pins = {
  .nss = 5,
  .rxtx = LMIC_UNUSED_PIN,
  .rst = 14,
  .dio = {4, 17, LMIC_UNUSED_PIN},

The first application i have in mind is an ultrasonic distance sensor to measure water levels in nearby streams, so i designed a simple PCB with a Ra-01H module, with a spiral antenna. I decided not to use SMT components to keep it simple. More about this sensor later.

To get an idea about the range of my gateway, i used an Android app developed by TTN Mapper that allows to link it to an end device to record range measurements into a database for plotting on the TTN Mapper interactive map using the ‘Advanced maps’ and my gateway ID ‘cassiopeia-lps8’.

On my LoRaWAN node, i used the ttn-otaa.ino example sketch, slightly modified:

  • send every 10 seconds
  • ADR switched off
  • force SF7

My indoor gateway is positioned on the top floor, about 7m above ground, near windows to the East and South. At this time, i’m only using the standard antenna; i may upgrade it later to a larger outdoor one. However, even with the small indoor antenna, and forcing the node to SF7, it worked up to a distance of around 500m in the North and South directions, probably due to terrain and buildings in the other directions.

Looking at my gateway live data in the TTN console, and i see incoming messages from my own node DevAddr 260D9B01 which belongs to NetID 0x13 = TTN as expected, but i also see messages with a DevAddr belonging NetID 0x00 (private/experimental). I assume this is a private network, probably the Hong Kong government’s GWIN.

More news soon on the sensor node.

Getting started with LoRaWAN

Leave a Reply

Your email address will not be published. Required fields are marked *