Talking MQTT

mqttmessages.PNG

Ha! Today has been a good day. I’ve got my Air Quality sensor talking MQTT to the Connected Humber server and sending messages. This has been a bit of an adventure, mainly because I had to mess around with the libraries for the Heltec device that I’m using.

Anyhoo, I’m now sending messages over both LoRa and MQTT at the same time. Go me. Now I just need to add some configuration options and I think we might actually have a product here.

Incidentally, I’m using a Windows app called MQTTBox to view the messages on the server and post test messages to my sensor. Works rather nicely. And free.

Build another LoRa Node in a Day

 Everyone looking happy at the start

Everyone looking happy at the start

In July we held a “Build a LoRa node” workshop at c4di. It was great fun for us, and those who took part. Today we did it again. I turned up, fresh from my media appearance and helped Robin set things up. As before, the aim was to get attendees to build a working LoRa node and finish up with a device sending environmental data to the cloud.

Everybody succeeded. It was great to watch them all convert a “bag of bits” into a working sensor node and then watch as they saw their readings appearing in their browsers.

We run the events when we get eight or nine people together who want to have a go. They are hosted in the lovely environment of the c4di and we only charge you for the parts that you take away. If you want to come along to our next one, just send me an email or a direct message on twitter and I’ll add you to the list.

Connecting a ZPH01 Dust Sensor to Python

42748138105_eeba4d99fa_z.jpg

I've just noticed that one of the wires came of the connector while I was taking the photograph. Oh well.

Anyhoo, some time back I got a dust particle sensor to play with. Air quality is a big thing, but one that we don't have much information about at the moment. An air quality measurement device is also a perfect application for LoRa. Sensors can gather data and then send summaries over the network. As part of ConnectedHumber initiative (of which much more later) we're designing an air quality sensor with the intention of deploying some city wide.

As a start I've connected the sensor to my PC and written a little Python script that gets the readings from it. You can find the script on GitHub here, in the unlikely event that you've got a sensor just like mine.

To connect the sensor to my PC I just used a standard USB to serial adaptor, the kind of thing you use to program Arduino Pro-Mini devices. I connected all the signal pins, and also took the mode pin to ground, so that the sensor will output serial data rather than pulses. 

The sensor works fine, although I've no real idea what any of the numbers mean at the moment. The next step is to get one into a case with a Wemos or LoRa device connected to it. 

LoRa Build a Node Workshop at c4di

LoRa-7.JPG

We've just had a bunch of folks around to build some LoRa nodes. Robin had put together some kits and we came up with a set of instructions. By the end of the day we expected our attendees to have their LoRa nodes sampling temperature, air pressure and humidity and maybe even be viewing the values on The Things Network website. 

Well, we got that and more. One person had the information going into Microsoft Power BI and was using Machine Learning to predict future room temperatures. Another used If This Then That to tweet temperature readings to his phone. Others left with plans to install LoRa gateways and sprinkle LoRa powered sensors all over their properties.

Very successful, in spite of the fact that we were soldering surface mount components and some folks hadn't soldered since they were 14, or even at all. Thanks for coming folks and being so determined. At some points during workshop you could have heard a pin (or other tiny component) drop. 

LoRa-6.JPG

We're doing another one in September, ping me an email if you want to get your name on the list. You can find our notes and sample programs here.

If you want to play with LoRa (and anything else that takes your fancy) take a look at the Humber Health Care Challenge. We'll make sure we've got some LoRa kits available there for people to have a go with this technology. 

 Mightier Than sword or pen?

Mightier Than sword or pen?

LoRa at Humber Street Gallery

42481462384_0f1278dc08_z.jpg

Today finds us at Humber Street Gallery. We're looking for locations for a LoRa gateway for the area. They've got a lovely rooftop bar which looks perfect, and has some amazing views. Of course, I happened to have my camera with me. 

29328214468_1cd44eefd8_z.jpg

We were telling the folks at the gallery about LoRa and we're going to go back and find out a bit more about the possibility of LoRa enabled artworks. Could lead to some interesting discussions. 

Tell LoRa I love her.

42287009134_1bed6ef887_z.jpg

Gotta love the post title. But I do quite like LoRa. We're doing some exciting things with LoRa nodes over the next few weeks and so I thought I'd build a node of my own. I used a kit that Robin put together and had a node on the air within a couple of hours. The node just sends temperature, atmospheric pressure and humidity up to a Things Network server, but it does do that. And I can get the data into a Python program (other programming languages are available) amongst other places. And it was genuinely fun and easy to do. 

To celebrate I've designed and printed a box to hold the node. It's far too big at the moment. I used to have a thing where I'd make the boxes exactly the same size as the components and then find I had no way to actually get the components in, and put them together. This box won't win any prizes for compactness, but it will let me carry the node around and see just how many places pick up the signal. When I've got a bit more experience with the technology I'll post some How-Tos and other stuff. This really is great fun. 

41195262710_c38fd104cb_z.jpg

Kickstarting Hull's Smart City

 Paul Foster taking networks. 

Paul Foster taking networks. 

Well, that was fun. And exhausting. We did two Smart City events in one day. The morning event was all about getting people together to build a network, and the afternoon was all about the tech of LoRa. 

Both events had awesome attendance, lots of sensible discussion, and we even managed to fit in a bit of planning. As far as I'm concerned, the outcomes are:

  • We are going to get Lora gateways to cover the area as a first step towards building the Smart City infrastructure. There are already some commercial/proprietary LoRa gateways opening up in the region which would be a fantastic platform for industry strength applications, but from a community perspective an open one based on The Things Network would make a very good start. If you're not sure what LoRa is, read the attached slide deck....
  • We are going to start up a community effort building LoRa network devices. Lots of people seem quite keen on this. Once we've got the bits together we'll set up a happy afternoon where we'll build some network endpoints and get them going. Then we can start looking at using the devices to solve problems. 
  • We are going to set up a "Smart City Steering Group" to get all the interested parties together, share what we are all doing and try to put together a strategy that will start with LoRa and move on to consider other technologies including how to make some of the data gathered into open data. 

If you want to see my slides, which tell you all about LoRa, you can find them here.

I'm really excited about this. I think it could be the start of something not small. If you didn't make the events, but you want to get involved, feel free to contact me directly (put a comment on this post or message me via Twitter or email me or stand on a corner and shout loudly). 

Kickstart Hull's Smart City - free event Wed. 21st Feb

On 21st of February we'll be Kickstarting Hull's Smart City at the c4di. You're invited. You're especially invited if you're a developer wanting to get into city wide networking, a student looking for a new field to get your teeth into or someone who wants to do some good with technology. 

We'll be describing our plans for building a community to work with the latest low powered networking technology and use it to build solutions for local people. It's going to be great fun. 

The event is free, we'll have lots of expertise and maybe even biscuits. You can sign up here

Lora at the c4di Hardware Group

38814376694_f400e0798e_z.jpg

We had a great hardware meetup tonight. I showed off a bit of the latest Hull Pixelbot scripting stuff (once I'd got it to work - note to self - don't turn up with a machine and think you can install the software and it will just work. Doesn't happen). 

Then we talked a bit about Lora (or low powered radio to you). I've blogged a bit about this in the past but now we want to take things a bit further, and get going making Lora stuff. We've got all kinds of plans, none of them involving world domination. At least that's what we're saying for now. 

Anyhoo, expect to hear more about our Lora plans in the not too distant future. It looks like a great technology to get in on the ground floor of. If you fancy getting involved you should come along to our next meetup and utter the magic phrase "I fancy getting involved". You can sign up for the next meetup here

Single Channel Lora

38153290726_273a32593b_z.jpg

I'm learning more about the Lora network. Lora links tiny, low powered, devices to an application. The devices talk to a Lora "gateway". The idea is that any device can talk to any gateway. Lora networks use different radio channels to pass data, and the node can select any data channel to send any particular message. Nodes usually cycle through the available channels.

A "proper" Lora gateway will listen on 8 channels at the same time. However, my tiny (and cheap) |Lora gateway from Dragino only listens on one channel.  This means that under normal circumstances I only receive one message in 8 on my gateway. Which is a bit of a limitation. 

Fortunately for me there is a way you can restrict a node to only using one channel. I found a forum post here which tells you how to do it. This is not something I'd advise anyone to do, because it is not in the spirit of the way that Lora works by spreading messages round different channels. However, I've made a script (called naughty) which does this, and it works fine. 

The really good news for us is that Hull centre is now served by a proper Lora gateway so if I use my Lora nodes in Hull they just work. 

Things Network Frame Counter

Frame Counter Checks.PNG

I'm getting the hang of Lora networks. And by that I mean "Spending quite a lot of time figuring out why things don't work when they really should".

Today I found out about Frame Counter Checks. Each Lora packet contains a frame counter value. This is set by the node when the packet is sent into the network. The Things Network likes it if the frame counters in packets always get bigger. This makes it slightly more difficult for someone to spoof messages into the network. 

Trouble is, if you're using a very simple node you'll find that the frame counter is reset to zero by the software each time you start the device. Which means that The Things Network will reject packets from the device until it seems a frame counter bigger than the one it's seen so far. 

Unless you know this, you'll spend ages trying to figure out why something that worked yesterday has suddenly failed. 

There's an option for the device settings for your application in the Things Network which turns off Frame Counter checks, which you can see above.

In a proper application you'd either save the frame counter in eeprom each time you've used it, or do something clever with the date and time to generate a frame counter value which is always bigger than the last one. 

Lora Node Live

packet.PNG

Well, I've sent and received my first Lora packet sent from a node into a gateway. It turned out to be quite easy to set up. First you create an application, then you create a device, then you take the key data of the device web page and paste it into your node program. Then it works. 

Now I need to work out how to take the data off the server at the things network and do something with it. 

Great fun.

Learning about Lora

23578631578_beed38ee27_z.jpg

I don't know much about Lora networks. But I know more now that I did this time last week. Which is a good trajectory I suppose. Here are some things I know now.

  1. Lora is low-power, long-range. But very low data rates (just hundreds of bytes a second, if that). 
  2. Lora works. As I write this I've got a tiny Lora node sending lumps of data across Cottingham, where they are being received.
  3. You can get Lora devices for very low prices. I'm paying around 12 pounds for a node with a rather fancy OLED display, but you can get the interface chips for a round a third of that. 
  4. Frequency is important. In the EU you should get devices that work on 868Mhz, in the US go for 915MHz. There's another frequency, 433Mhz that you can use in the EU, but it might not work as well because this frequency is also used by radio amateurs and whatnot. 
  5. If you want to just use Lora to link a few devices that are a long way apart (up to a KM or so) then you can buy devices like mine and just use them. 
  6. Lora nodes in a proper Lora network talk to a gateway device that takes their messages, assembles them into lumps of JSON and sends them over the internet to a central server which makes them available to your application. You can buy gateways, or you can make tiny ones of your own. (That's what I'm trying to do at the moment)
  7. Lora uses a range of radio channels which are grouped around the working frequency of the particular node. A proper gateway implements a bunch of channels (usually 8) and cost at least 150 pounds, but you don't need one of these to start with. A single channel gateway will work fine for up to 50 or so nodes.
  8. You can register your gateway on the things network. This acts as the server in my description and allows other people can find and use it, and also lets your cloud service capture data and send commands to nodes. Commands are sent to nodes after the node has sent a message to the gateway. This saves power (and makes the networking easier) but it does mean that you can't just tell a node something, you have to wait until it reports in and then send a message. The node will listen for a while after it has sent a message. There are versions of Lora that allow messages to be sent to the node at any time, or in designated time slots, but these aren't in common use yet.  
  9. You create applications on the things network. An application is associated with one or more Lora powered nodes which use keys to authenticate their messages. You can bake the key into the node and use activation by personalisation (ABP)  or use over the air authentication (OTAA). OTAA is more secure, but not many devices (and certainly not simple gateways) do this. 
  10. Anyone can hear your Lora transmissions. The Lora standard offers proper end to end encryption but this doesn't seem to be available in devices just yet. 
  11. Andreas Spiess (aka 'The Guy with the Swiss Accent') has made some splendid videos that describe the technology. Great to watch during the lunch hour. 
  12. Lora is a great solution but I'm not completely sure what the problem is. But I'm still going to play with it. 

Lora Networking Hardware

Had a rush of blood to the head today and ordered a complete Lora networking kit from Tindie. Only slightly more expensive than a video game and a lot more fun. I'm going to set up a test Lora network in Cottingham for folks to connect their sensors. It's only a single channel gateway (hey - I'm not made of money) but it should be good for up to fifty sensors or so. . 

Then we can work out what to use it for......

The Lure of Lora

heltec.JPG

I was on AliExpress the other day, always an expensive experience, and I happened upon some boards from Heltec that offer an ESP32 (the upgrade of the ESP8266), a tiny OLED display and, most interesting, a connection to the Lora network. I've been meaning to spend some time playing with Lora for a while. It offers low power networking with a range that can go up into kilometres. At first I ordered one, and then it occurred to me that a network with only one node isn't really a network, so I got a couple more. 

They arrived on Friday the 13th last week and, much to my surprise given the date, they worked first time. I downloaded the sample programs, added them to my Arduino IDE installation and in no time at all I had two of the devices talking to each other.

Later on I discovered that I have been a little unlucky/stupid in that I've bought versions that work on the 433 MHz radio band, which is not the frequency that works the best for these devices. For the UK I should have bought the version that supports the 868 Mhz band that is used in Europe

Never mind. I can still use them, but I'll get more interference because this band is used by radio amateurs, car keys and building alarms etc. I'm looking forward to finding out more about how the network can be used.