I find LoRa very annoying to work with, partly as it's so low-level, which really isn't my background, partly because the docs are all over the place. But nevertheless I love the idea of very low powered devices sending tiny pieces of data a long way, so I have persevered.

Tarim and I have been very slowly working on a project to put LoRa gateways on the tower block sites in Bristol that Bristol Wireless used to use and still have permission to use. We're going to do a Dorkbot Bristol talk in May about it - the Bristol Wireless bit is a great story of DIY wifi networks (Tarim) and then there's all the fun with getting extremely frustrated with using LoRa and The Things Network (me).

Basically there's two says of using these little devices. One is to have them speak directly to each other. Richard's been having fun with these cute little fellas, which have GPS, an e-ink screen and a battery:

Meanwhile I've been trying various gateways and devices to go with them in order to access The Things Network (TTN), which is basically a way of aggregating data from a bunch of devices to somewhere else, via gateways which talk LoRa and also are connected to the internet. The gateways pass the packets on. The devices - "nodes" - (typically an ESP32 with some other bits, e.g. a sensor) talk to gateways.

My current mental model is this:

  • A device sends out TTN-type packets - any gateway in range will pick them up and forward them
  • You make a TTN application, register the device with the application then you see data coming in, if you've done your config right. If.

This means that you don't need to have your own gateway necessarily, but if there are none near you - or your packets are not arriving - debugging is impossible without a gateway.

So, Tarim and I were trying out an old Pi hat he had hanging round which appeared to work, but we couldn't see on the gateway whether or what packets were arriving. Jonty (I think?) recommended the LR1302, which comes with GPS, so I bought one of those and followed the instructions with a Pi3. There is a small error in the config file in github - a missing zero on ttyS0 and I needed to do chmod a+x reset_lgw.sh but otherwise it all worked and I could see packets and stats on packets coming through.

The breakthrough this weekend has been finding a decent ESP32-compatible library to put on the nodes. TTN has multiple versions of its protocol and many many libraries do not specify which version to use, so it's trial and error or searching for help in forums for similar issues - and because there are so many possible devices you could buy it's very hard to pin down where the error is coming from. Each version of the protocol has a different number and type of mysterious numbers that you have to make up or generate and they can be hex or not, LSB or MSB, and many of the libraries just don't tell you what they need. It has been an extremely frustrating experience.

Anyway, Richard found RadioLib which works with the latest version of the TTN protocol (1.1.0), has great instructions(🙀) and worked nicely with my TTGO LORA32 (I have an older version of this) and Heltec Wireless Stick (an older version of this) ESP32s.

Using an Arduino IDE setup with the usual json for ESP32s https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json additional boards in settings, then having loaded the esp32 espressif boards from the boards menu, which I keep forgetting to do:

For the TTGO I added #define ARDUINO_TTGO_LORA32_V1 to config.h and ran it as a TTGO LoRa32-OLED board.

For the Heltec I tried #define ARDUINO_heltec_wifi_kit_32_V2, and still with the same TTGO LoRa32-OLED board it worked.

The code in those images is just RadioLib loaded from the library menu - I used

examples-> Radiolib -> LoraWan -> Lorawan_starter

as the instructions tell you to. The instructions are very good (for once) on the mysterious codes and their format too, but for the avoidance of doubt the appKey and nwkKey are in MSB format. If your board isn't in config.h you just need to know some pin numbers, but I've not figured out how to work out what those are yet.

There are still 2 puzzles I have (probably many more)

  • Why isn't my gateway detecting device-to-device packets like those Richard was sending with his devices? are they filtered out somewhere?
  • What is the difference between OTAA activation and ABP activation? (see below for Microbit fun with those)

Last bit - I thought it'd be nice to try a microbit board with LoRa. There's one available, some nice instructions too, but, feh, I cannot get it reliably to work. (It uses TTN protocol 1.0.2 just in case you were wondering, and also ABP. But whether either of those is the issue I have no idea).