PC Pro

PAU L OCKENDEN This month, Paul begins a short series of articles looking at the potential uses of cheap, low-power, long-range communicat­ions via LoRa.

Paul begins a short series of articles looking at cheap, low-power, long-range communicat­ions using LoRa

- @PaulOckend­en

Over the next few issues I want to talk about LoRa communicat­ion. Short for “long range”, it’s a type of low-cost, low-power, extreme-range radio. I’ll go through some use cases later, but for now just imagine that you’re a farmer and your land stretches across a valley. Your farmhouse is on one side and you have a flock/herd/whatever of animals and a shelter on the other side, about 1km away. You want to know the temperatur­e in the shelter

(if it’s too cold, you’ll need to bring the animals back to the farm).

The first thing you might think of is some kind of Wi-Fi-based temperatur­e sensor, relaying back to the farm. Perhaps something like one of the Cricket boards I wrote about in 2020 ( see issue 312, p113); there’s more news about that towards the end of this column. Obviously, you can’t transmit a normal Wi-Fi signal across 1km, so you’ll need something like an Ubiquiti NanoBeam to create a pointto-point connection. There’s just one problem: the shelter doesn’t have any power. Any long-range Wi-Fi kit is likely to need mains power.

This is where LoRa comes in. A battery-powered sensor will easily cross that 1km valley, and as I’ll show when I come on to some of the kit that you might play with, there are relatively cheap sensors that will last for ten years on a single battery.

But I’m racing ahead of myself: let’s step back and look at the technology involved, whether that’s LoRa, LPWAN or LoRaWAN. I’ll start with LoRa. It’s the physical layer

– the radio signals that allow this long-distance transmissi­on – and it’s the fundamenta­l building block for everything else I’m going to write about. I’ll come back to how LoRa actually works shortly, because it’s fascinatin­g, but the key thing to know now is that LoRa can work below the noise floor. If you’ve ever done any RF comms theory, you’ll know that this is completely at odds with what you were taught. It’s usually accepted that the noise floor is the physical limit when it comes to signal sensitivit­y.

Imagine being in a large, crowded pub. You’re on one side of the room and there’s a couple arguing on the other side. If everyone in the pub is silent, you’ll hear the argument, but if all the other customers start talking loudly then the argument will get drowned out. That’s what it means by the signal getting lost below the noise floor. LoRa manages to punch its way through that: in my somewhat crude analogy, it means you’d still be able to hear what the argument is about despite the chatter. I’ll come on to how it does that shortly, but first let’s take a look at those other acronyms.

LoRaWAN is, as the name suggests, a LoRabased wide area network (WAN). Where LoRa provides the physical layer, LoRaWAN defines the protocol that sits on top that allows you to send data. It’s a point-tomultipoi­nt-based system, and this works both ways. For now, just think of several IoT-type sensors dotted around an area

along with a few base stations (“gateways” in LoRa parlance). The multipoint aspects means that one gateway can handle the traffic from many sensors, but likewise one sensor’s signal can be received by several different gateways.

LPWAN is simply a low-power wide area network, of which LoRaWAN is one of several. Other notable examples include Sigfox ( sigfox.com), which is a commercial offering including coverage, and an open standard called Weightless (I won’t point you to the special interest group’s website as it appears to have been hijacked). You’ll often see the term “oG” used for LPWAN providers.

I want to concentrat­e on LoRa and LoRaWAN in these articles as it’s probably the best-known LPWAN technology and, unlike Sigfox, it’s open for hobbyists and amateurs to have a play. Plus it has great support from big industry.

Chirpy chirpy cheep cheep

So, how does LoRa create viable signals whilst working below the noise floor? The first thing to note is that LoRa has a very low bandwidth. A typical sensor in the UK will work at around 868MHz, which is the same frequency used for products such as wireless headphones and video senders (both of which need plenty of bandwidth). With LoRa, you’re looking at data rates of between 250bits/sec and 11Kbits/sec. This low bandwidth is because of the type of modulation used. Typically, a radio signal will pulse on and off at its simplest, or vary the frequency around a fixed carrier (allowing multiple values to be encoded based on how far the signal has deviated from the central value). There are plenty of other techniques that are used to pack even more data into a given signal, but all of these things make the signal more fragile, as well as more susceptibl­e to interferen­ce and other environmen­tal factors.

LoRa does the reverse of this: it exchanges data rate for robustness. It does this by using a modulation called chirp spread spectrum (or CSS, just to confuse any web developers out there). It’s extremely complex – far too complex for me to go into lots of detail here, but if you’re curious I suggest checking out the research paper at pcpro.link/318lora or the more accessible YouTube video at pcpro.link/318lora2.

While I can’t go into lots of detail about CSS, it’s worth having a stab at the basic concepts. There’s a core RF frequency for the signal, and just to make the example easy I’m going to say it’s 500kHz – please note that this isn’t a valid LoRa frequency, I’m using it purely to make the numbers simpler, and perhaps easier to visualise what’s going on.

There’s also a bandwidth, but it’s not to be confused with what we call bandwidth when it comes to broadband connection­s: here I’m talking about the actual width of the RF band. Let’s say it’s 200kHz.

With a centre frequency of 500kHz, this means the band runs from

400kHz to 600kHz. What LoRa uses is a combinatio­n of “upchirps” and “downchirps”. An upchirp is when the RF signal starts at 400kHz and sweeps across the band to end up at 600kHz, while a downchirp is the reverse. A LoRa signal usually consists of eight initial upchirps for LoRaWAN. This is called the preamble, which allows the receiving end to lock onto the signal. This is then followed by a set of downchirps used for synchronis­ation and then a series of upchirps that carry the data ( see image below).

The way that the data is encoded into the upchirps is by dividing the swing (from 400kHz to 600kHz in my artificial example) into a series of steps. For instance, one swing might be from 400kHz to 475kHz, and then it drops back to 400kHz again. The pattern ends up looking like a broken sawtooth and it’s these partial swings in frequency that encode the data.

There’s a heck of lot more to it than this, with error correction and other stuff thrown in to make the signal more robust, but this should give you a quick overview of how CSS signalling works.

Now, think back to my noisy pub analogy. Once everyone in the pub starts talking loudly you can’t hear the couple arguing on the other side of the room. But if they were singing instead of arguing, then there’s a good chance you’d be able to make out what tune it is despite all of the hubbub. That’s kind of what CSS is doing: the swings in signal are easier to detect than simple forms of modulation.

While I’m covering the physical radio layer of LoRa communicat­ion, one other thing I need to mention is the spreading factor (SF). You’ll usually see it written as SF7 for a spreading factor of seven, and for LoRaWANs the SF is usually between seven and 12. B asically, a lower SF means that more chirps are sent per second. It’s all about balancing time, distance and budget. With a low SF, the data is sent more quickly, but if you increase the SF you should be able to send the data over a bigger distance, albeit at the expense of slower transmissi­on and, as a result, increased battery drain.

What’s the frequency, Kenneth?

LoRaWAN operates in the licence-free industrial, scientific and medical

(ISM) bands, and the frequency used is different in every country. Most EU (and by associatio­n UK) kit works at 868MHz, but in the US it’s 915MHz and in most of Asia it’s 923MHz. If you’re deploying or selling kit worldwide, you need to pay careful attention to this, as indeed you need to if you’re ordering boards, sensors or antennae from overseas. Always make sure you’re getting the

“The swings in signal are easier to detect than simple forms of modulation”

868MHz variant (which is often referred to as EU868).

As well as having different frequencie­s available, some regions also have different power limits. For example, the EU (which the UK follows) sets a maximum power of 25mW for communicat­ion from a node to a network gateway, and there’s a limited duty cycle. The latter is slightly complicate­d because LoRaWAN uses several channels: there are 16 channels available at 868MHz, but most LoRaWAN setups use just eight of them. Each of the channels can have different duty cycle limits, but don’t worry about this as under normal circumstan­ces it won’t affect you.

I’m going to continue my exploratio­n of LoRa and LoRaWAN next month, but in the meantime, if you’ve got itchy feet then a good place to start is with a couple of cheap single-board computers with displays. I recommend the Heltec V2 LoRa developmen­t boards. They’re available on Amazon for around £20 each ( pcpro.link/318lora3), but you’ll find them much cheaper elsewhere, especially if you import them from the Far East. They don’t always have Heltec in the product listing but check the photos and look at the sticky-out bit on the right-hand side of the board and check that it says “V2” inside a black square. Oh, and make sure you order the EU 868MHz version.

Next, you’ll need to install the Arduino IDE ( arduino.cc/en/

software), which is available for Windows, Mac or Linux. Once you’ve done that, open the IDE, go into Preference­s and towards the bottom you’ll see a sec tion to load additional board managers. If you click the little square thing on the right, it will open up a window that allows you to add more than one. For now you need to link to the JSON package from https://resource.heltec. cn/download/package_heltec_ esp32_index.json, which adds the definition­s for several Heltec boards. Then go to Tools | Board | Boards Manager and search for Heltec ESP32 and click Install.

One final step is to add the library files. Head to Sketch | Include Library | Manage

Libraries, again search for Heltec ESP32 and then install it. It’s a faff, but you’re now ready to go.

If you head to File | Examples and dig around in the Heltec section, you should find two sketches: “OLED_LoRa_Sender” and “OLED_LoRa_Receiver”.

Upload these to the two boards you’ve bought. You’ll need to change the code to set the correct band in both sketches (use 868E6) and, in the sender sketch, scroll down quite a bit to find a line that starts “LoRa. setTxPower” and change the first parameter to 20 if it isn’t already.

Next, make sure you’ve plugged the antenna into each board (never power them up with the antenna disconnect­ed) and upload the sketches. You now have two boards, one sending LoRaWAN packets

(which consist of the text “hello” plus a counter), the other end receiving.

You’re now ready to do distance tests. You should be able to reach 1km or more if you have clear line of sight. Don’t forget that obstacles such as windows will degrade the signal, so ideally you’ll want the boards to be outdoors with the antennae pointed in the same direction.

I normally have the sender board powered by a laptop or PSU, and then walk around with the receiver connected to a mobile battery pack. Just be aware that many power bricks will automatica­lly power down after a few seconds because of the low power draw. It’s a pain. But I’ve discovered that many (not all) of the power bricks made by Zendure have a special feature called X-Mode that sets the device into an always-on mode. The power brick I use is a SuperTank, which is a bit big and a bit expensive, but many of the smaller/cheaper Zendure models also support X-Mode – just check the specs.

When you’ve found the maximum distance, you can start playing with different spreading factors. You’ll need to add something such as “LoRa. set Spreading Factor (12);” to both the sending and receiving sketches. Try various values between seven and 12 – you’ll notice that you don’t always get the results that you’d expect, such are the problems with working in the noise floor. A lot can depend on environmen­tal issues.

Anyway, more LoRa and LoRaWAN next month.

Cricketing news

There was lots of nice feedback about the column a few months back ( see issue 312, p113) where I mentioned the low-cost Cricket IoT board – the one with the lightning-fast response times and long battery life, even though it uses Wi-Fi. Well, I have two pieces of news for you.

Firstly, there’s a new version of the Cricket board out. Confusingl­y, it’s called V1.0, so don’t get confused by the ordering pages thinking you’re getting the old version. It’s now fully shielded (there’s a tin cover on the PCB) and, as a result of this and other things, the Cricket board has RoHS 3, CE and FCC certificat­ion. With the new version you no longer need to use the Things On Edge portal for configurat­ion tasks – it can all be done locally and there’s a captive portal so you don’t have to fiddle around using apps. The board supports over-the-air firmware updates, and best of all there’s an extra digital input enabled. So lots of really useful updates there, but lucki ly th e price hasn’t increased.

The second bit of news is that Things On Edge is offering PC Pro readers a 30% discount on all orders. Just use the discount code PCPRO at the checkout – you can order as many boards as you’d like for this reduced price. But hurry, the code will only work during the month or so that this issue of the magazine is on sale. You can order via thingsoned­ge.com.

“Obstacles such as windows will degrade the signal, so you’ll want the boards to be outdoors”

 ?? @PaulOckend­en ?? Paul owns an agency that helps businesses exploit the web, from sales to marketing
@PaulOckend­en Paul owns an agency that helps businesses exploit the web, from sales to marketing
 ??  ?? BELOW The LoRa Alliance non-profit looks after the LoRaWAN standards
BELOW The LoRa Alliance non-profit looks after the LoRaWAN standards
 ??  ?? BELOW A LoRaWAN of eight upchirps, two downchirps and then the encoded signal
BELOW A LoRaWAN of eight upchirps, two downchirps and then the encoded signal
 ??  ?? ABOVE The complex ins and outs of LoRa modulation can make your head chirp
ABOVE The complex ins and outs of LoRa modulation can make your head chirp
 ??  ?? ABOVE LoRa signals use a gliding frequency that’s actually more like singing than chirps
ABOVE LoRa signals use a gliding frequency that’s actually more like singing than chirps
 ??  ?? BELOW The new V1.0 version of the Cricket board includes some useful updates
BELOW The new V1.0 version of the Cricket board includes some useful updates

Newspapers in English

Newspapers from United Kingdom