PC Pro

PAU L OCKENDEN

The long battery life of LoraWAN sensors makes them ideal for long-term monitoring. Paul introduces the different types you can buy

- @PaulOckend­en

The extensive battery life of LoraWAN sensors makes them ideal for long-term monitoring. Paul introduces the different types you can buy.

Welcome to the next part of my series of articles on LoRa and LoRaWAN. As promised, I’m going to be looking at some of the better LoRaWAN sensors I’ve discovered and I’ll also guide you through connecting a sensor to The Things Network.

There’s a huge variety of sensors out there. For example, I’ve recently come across waste bin management sensors for those business-sized “dumpster” bins – they monitor how full the bin is, so that the company emptying them can optimise the lorry routes and avoid sending trucks to bins that are empty.

Another good example is a parking sensor that’s available from Bosch. No, not those things that incessantl­y beep when you’re trying to reverse into a space; these sensors are glued to the road and detect whether the space above is occupied or not. Take a look at the promo video on YouTube ( pcpro.link/321bosch).

These sensors are intended for car park management, but in the future I can imagine things such as this will be integrated into all on-street parking spaces. So, rather than driving around the streets trying to find somewhere to park, your car will direct you to the nearest empty space. As with those bin sensors, this is a perfect use for LoRaWAN technology.

There’s even a LoRaWAN rat trap on offer! Much like with the bin sensors, this is all about reducing site visits. Imagine you run a company of rat-catchers. It’s inefficien­t to send your staff out to clients to check their traps every few days when LoRaWAN-enabled rat traps mean you only need to send staff out when one of the critters has been caught.

Although these examples show the vast range of sensors available, I have to admit that I haven’t played with any of them. Mostly because I don’t own a refuse collection company, a multi-storey car park or a pest control agency. But there’s a number of sensors that I do have in my toy box, so let’s take a look at a few of them.

I’m going to start with something called The Things Node. As you might guess from the name, it’s a product from The Things Network. The Things Node is an odd, puck-like device: a multifunct­ional sensor that you can use for numerous purposes. It’s little bigger than a matchbox but has an IP54 casing, which means it’s fine for outdoor use. The “5” is the dust rating, and means it’s well protected, while the “4” is the liquid score and indicates that the device can cope with gentle spray from any direction. So, as long as you don’t fire a pressure washer at it or submerge it in deep water, it will cope just fine.

Inside The Things Node you’ll find three AAA batteries powering a SparkFun Pro Micro microcontr­oller interfaced to a Microchip LoRaWAN module. Accompanyi­ng these is a temperatur­e sensor, a light sensor, an accelerome­ter, a push-button and an RGB LED. As the Pro Micro is an Arduino-compatible board (based on the ATmega32U4) you can simply upload sketches to it in the normal way using the Arduino IDE.

As you have full control over the uploaded sketch, you can make changes to optimise the battery life. For example, if you aren’t interested in light levels, you can keep the

“Rather than driving around, your car will direct you to the nearest empty space”

illuminati­on sensor switched off, and not waste time reading, processing and transmitti­ng the readings .. The same goes for the accelerome­ter. And for maximum battery life it m makes sense to disable the LED th hat normally lights up every tiim et he device transmits. You can even disable the US B port, whichhwi ill ll save a bit more power. I do all of these tweaks with a couple of The Things Nodes I keep inside my fridge and freezer. They just sit there mostly sleeping, but every 30 minutes or so they sample the temperatur­e, transmit it to my LoRaWAN gateway and then go back to sleep again. The batteries seem to last forever.

The Things Node is great for general messing around and experiment­ing. You’ll remember last month I wrote about TTN Mapper, where a combinatio­n of a smartphone app and a LoRaWAN trigger allow you to map the range of The Things Network-connected LoRaWAN gateways. Well, The Things Node is perfect for this: I just put one in my pocket and go for a walk. You can either use the interrupt time to wake every 30 seconds or, easier still, use the accelerome­ter as a trigger and allow your walking movement to keep waking it up.

You can buy The Things Nodes from RS or Farnell/CPC for around £60, but you should keep an eye on eBay too. You’ll often see them listed there for stupidly high prices (for instance, as I write this there’s one on sale for an insane £137), but just occasional­ly they appear for sensible prices too. I’ve seen them go for around the £30 mark.

Although The Things Node has a built-in temperatur­e sensor, and it works well in my freezer, there are better options available. I particular­ly like a device called the Dragino LHT65, which is a temperatur­e and humidity sensor. There’s one in my bathroom, just sitting out of sight on top of a tall cupboard. It’s there so I can monitor that the bathroom fan is operating correctly and keeping the humidity low when someone has a shower. The great thing about the LHT65 is its battery life of around ten years, so it really is one of those set-and-forget devices. And, unlike The Things Node, there’s no USB port and no sketches, so it’s all set up and ready to go. There’s a serial interface, but you really don’t need to worry about that.

Although it works well as a standalone device, there’s also a 3.5mm socket where you can plug in external sensors. An external DS18B20 temperatur­e sensor ships in the box, but a plug-in illuminati­on sensor is also available (based on the BH1750), along with a flexible five-wire interface that you can use for various analogue and binary measuremen­t tasks. The binary input can be used either as a counting sensor or as an interrupt trigger, meaning there’s loads of flexibilit­y on offer here.

Again, as with all things LoRaWAN, you’ll see stupid variations in price so it pays to shop around. Either mouser.co.uk or

robotshop.com usually have the best prices for this one – expect to pay around £30 to 35. It’s worth noting that Mouser often lists Dragino devices as “Seed Studio”, but they’re proper Dragino devices and arrive in the correct packaging.

Dragino is a manufactur­er that I have a lot of time for. It’s a Chinese company that has a wide range of good quality products available for sensible prices. There’s excellent support too, inEEngl li ishh,wi it th ha greatt w i k i . I e s p e c i a l l yy l i k e t h e c o m p a n y ’ s entry on debuggging LoRaWAN communicat­ion, which you’ll find at

p c p r o . l i nk / 3 2 1 dd ragino.

I us et woo thee rD ra gino sensors extensivel­y: the door sensor, LDS01, and the water lea ak sensor orLWL 01. They’ re bothqui it es mall, are inexpensiv­e (around £10 to £15) and use CR2032coin­c el ll batteries. That battery will last around a year in the door sensor, while the water leak sensor should last two years or more – and you can increase this considerab­ly by disabling the daily heartbeat “ping” so that it only transmits when there really is a leak.

If you have places that are susceptibl­e to plumbing leaks, such as under a boxed-in bath, in the loft, beneath a hot water tank or inside a ceiling void, just chuck one of these devices in before you seal everything up. It’s a real no-brainer as long as you tweak them for maximum battery life. I’ve also found that the door sensors seem far more reliable than the various Z-Wave and Zigbee sensors I’ve written about in this column before. Oh, and I discovered that you can use the water leak sensor as a binary sensor if you connect it to a device with volt-free outputs. So it’s useful for monitoring things such as burglar alarms and is an extremely cheap way of doing so.

A quick technical note: The Things Network is currently transition­ing from The Things Stack, its network server, from v2 to v3. Older gateways still run v2, but The Things Network is encouragin­g people to upgrade. There’s just one problem: some older nodes don’t play nicely with the v3 stack yet, and this includes some of the Dragino devices above. In particular, you’ll find that they’re able to join the network properly but then data gets lost. Firmware upgrades will address this soon (with any l luck kb bytthh et t ii mee you read this ), but in theme anti mme there’ s a simple fix th a at you can do to cur et hep problem. The magi cc that you need is this s command, wwhich you will n need to send u using the internal s serial port:

“I can monitor that the bathroom fan is operating and keeping the humidity low”

Between The Things Network v2 and v3, the RX1 delay changed from one to five seconds, and various node manufactur­ers will need to catch up. This change was done to make things more robust: it gives more latitude when part of the connection has a long round-trip, perhaps via a satellite broadband link.

I’d be tempted to stick with v2 until all of these problems have been ironed out.

Gluing it all together

Let’s take a look how to connect a device to The Things Network. I’m going to assume that you’ve got a gateway nearby, either your own device or someone else’s that’s within range. The only extra hardware we’re going to need for this is The Things Node and three AAA batteries.

The first thing you need to know is that every The Things Node – indeed every bit of LoRaWAN kit – has an internal ID. It’s known as the DevEUI, often shortened to EUI, and it’s a 64-bit globally unique identifier assigned by the manufactur­er. Now, with most manufactur­ers it’s either printed on the box or written on the sensor itself, but The Things Node isn’t quite so user-friendly – you need to connect a micro-USB cable to it to read the EUI. But don’t worry, this is quite simple to do.

So, assuming you have the Arduino IDE set up, go to Sketch | Include library | Manage libraries and search for “TheThings” in the box at the top right. You’ll want to install as a minimum “TheThingsN­etwork” and “TheThingsN­ode”. You also need to add support for the SparkFun board inside The Things Node. First, go to Preference­s. Towards the bottom, you’ll see an entry for the “Additional Boards Manager URL”. Click the box to the right of this and it will open up a multi-line editor. Now add the following entry:

https://raw. githubuser­content.com/ sparkfun/Arduino_Boards/ master/IDE_Board_ Manager/package_ sparkfun_index.json

Then navigate to Tools | Board | Boards manager and search for “SparkFun” and install the “SparkFun AVR Boards”. Now make sure that in the Tools menu you have the SparkFun Pro Micro board selected and on the line below that the processor is the 3.3V version, not the 5V.

That’s it: you’re all set up to load sketches to The Things Node. What you need to do is unscrew the back and connect a micro-USB cable to the socket that you’ll see beside the battery holder. Plug the other end of the lead into your computer. You don’t need to insert any batteries at this point as the USB lead will power it.

Next, go to File | Examples and then scroll right down to “TheThingsN­ode” and open a sketch called “DeviceInfo”. Look for the text “REPLACE_ME” and replace it with “TTN_FP_EU868” copied from the line above. Compile and upload this using the arrow button towards the top of the window – it might take a few seconds – and then open the Serial Monitor via the spyglass icon in the top-right of the window. Every few seconds you should see a load of text, part of which is the EUI. Write that down. In fact, write it in marker pen on the inside of the back cover of the node so that you never have to do this again.

The next step is to create an account on The Things Network at account.thethingsn­etwork.org/ register. Once you’ve done that and logged in to the console, click on Applicatio­ns | Add applicatio­n. The “Applicatio­n ID” is a unique name that’s all lowercase and without spaces, although you can use dashes and underscore­s. You can call it whatever you like. Add a descriptio­n but leave the “Applicatio­n EUI” blank as this will be assigned by The Things Network. For the handler at the bottom, use “ttn-handler-eu”. Then click the “Add applicatio­n” button.

Now we add the device. In the applicatio­n, click the “Register device” link. The “Device ID” is like the Applicatio­n ID – something you make up, all lowercase. Next, the Device EUI is the long hex string that we extracted just now. Leave the “App key” blank as it will be autogenera­ted and click Register.

Your Node will still be running the DeviceInfo sketch at this point, so go back to the Arduino IDE and go to File | Examples | TheThingsN­ode and open the Basic sketch. A few lines down, you’ll see the frequency plan; make sure it’s set to “TTN_FP_ EU868”. Above that, you’ll see two lines for “AppEUI” and “AppKey”.

It’s easy to copy those from the device page of the The Things Network console. Switch back to the browser window, scroll down to the bottom and you’ll see “Example code”. Click the copy icon, which is on the right. Then go back to the Arduino IDE and paste in the data, replacing the zero examples that are there. Then compile and upload as before.

Switch back to the The Things Network console, scroll up a bit and you should see the status icon turn from yellow to green. There will also be a counter showing when the last data was received. Congratula­tions!

I know last month I said that this column would be the final one in the series, but there are a couple of things I still need to cover – decoding the data we’ve just uploaded and then extracting that data to use in other systems – so more next time.

“Write the EUI on the inside of the back cover of the node so you never have to do this again”

 ?? @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 Bosch produces a LoRaWAN sensor that detects empty parking spaces
BELOW Bosch produces a LoRaWAN sensor that detects empty parking spaces
 ??  ?? BELOW The Dragino LHT65 is a long-lasting temperatur­e and hhumidityi­di sensor
O l d - t i m e r s l ii k e m e a l w a y s smile when we see AT c o m ma n ds ; t h i s i ss t h e H a y e s c o m ma n d s e t t h a t f i rr s t a p p e ar e d i n t he d i al - u p m o d e mss t h a t w e o n c e u s e d t o a c c e s s t h e i nn t e r n e t . AT+CCRX1DELAY=5
BELOW The Dragino LHT65 is a long-lasting temperatur­e and hhumidityi­di sensor O l d - t i m e r s l ii k e m e a l w a y s smile when we see AT c o m ma n ds ; t h i s i ss t h e H a y e s c o m ma n d s e t t h a t f i rr s t a p p e ar e d i n t he d i al - u p m o d e mss t h a t w e o n c e u s e d t o a c c e s s t h e i nn t e r n e t . AT+CCRX1DELAY=5
 ??  ?? ABOVE The Things Node is an excellent introducti­on to the world of LoRaWAN
ABOVE The Things Node is an excellent introducti­on to the world of LoRaWAN
 ??  ?? ABOVE Don’t forget to set the frequency plan before compiling the DeviceInfo sketch
ABOVE Don’t forget to set the frequency plan before compiling the DeviceInfo sketch
 ??  ?? BELOW The Things Network is controlled via the web browserbas­ed console
BELOW The Things Network is controlled via the web browserbas­ed console

Newspapers in English

Newspapers from United Kingdom