Environmental Sensors using LoraWan
First off I purchased two of these units:
Wio-E5 units are very low power with a range of several miles. In fact they say it can reach 500 miles given the right environment say like the Spy Ballon for example.
Just like my previous cellular project it uses serial at 9600 to communicate with the unit. The Grove connector it came with is not very nice in that it's big and just a ribbon cable. Not very flexible.
I ended up cutting one end off and putting a 4 pin connector in its place. Plugs in very nicely.
The unit uses the AT command set to configure it and I was hoping to just do a Point to Point Lora network but that turned out to be more complicated than I thought. The units want to setup a Wan network and so you need a Gateway for it to relay the messages to the cloud. Well, that's not that much different than my Cellular project and the cost of Gateway is from $90 to $1000.
The cloud network that I can use is called The Things Network.
It's free to sign up just like the Blues network and they will collect your data for up to 24hours.
The data for Lora is in hex and the data must be less than 51 bytes in length. So no JSON data should be passed between the device and the network. The examples I saw just encode the hex values of the data and have it in the correct order so it can be decoded once it is received.
This turned out to be ok. I have Temperature, Humidity, Pressure, Voltage, and Current.
Float values are stored as 4 bytes just like integer values so I just converted those binary values to hex and sent them which takes only 20 bytes.
Now I have everything ready except for a Gateway. Most of the Gateways are out of stock or expensive.
I will have to wait to get one since there are no local gateways running near my location that I could hop onto. The LoraWan network is more of European thing at this point.
I was able to dummy up the two devices to do Point-to-Point. This at least allowed me to test sending and receiving the data. With LoraWan the data is encrypted from end to end and the Gateway just receive the packet of data and forewords it on to the cloud where it is decrypted using 128 bit AES. When you register the device it gives you a key that is entered into the device. The data is encrypted/decrypted with this key.
So just like the Blues network the data is encrypted but not guaranteed to make it.
Mike
Comments
Her is my setup for the Environment sensor which I just replaced the Blues Notecard with the Wio-E5 Lora board.
The code is pretty much the same I made the driver which is also mostly a full duplex serial driver
Bad new though, in my testing I found out that the Rev B board actually uses less power than the Rev C board in low power mode. Actually, it looks like it uses twice as much power as the Rev B. I went from 2ma to 5ma in low power mode.
So far this is a point to point configuration and I waiting on the Gateway device.
MIke
Finally got my point to point setup running. I ran out of P2's so I had to setup the receiver on a P1 instead. This led to coding changes as I moved the code over to the P1.
Wasted a day trying to track down a strange behavior that turn out to be a code conversion hick-up. While I was trying to decode the message that I got from the environment sensors I realized that I didn't have a date attached to the data. At first thought is to add the date on the receiver side since passing the year, month, day, hours, minutes and seconds seem like a lot of data.
I have a DS3231 clock module that I hooked up and used that to set the date on the P1. After looking at the code I realized that the date is just a long integer and could easily be passed along with the other data. So I moved the DS3231 to the sender side and added a small amount of code to send it along with the other data.
I did run into an issue with receiving the data which is less than a quarter mile away. The documentation says that should not be an issue. I moved that antenna into a more upright position and that seems to be working now. I may have to change the Spreading Factor.
The Spreading Factor changes the data rate at which the data is sent or basically the baud rate. The Spreading Factor ranges from 7 to 12 where 7 is 11k and 12 is 250 bits per second. I am using SF8 which is 3125 bits per second. Slowing down the bit rate can improve range as it leaves the signal in the air longer for the receiver to see it.
Receiving program:
I need to add an SD card to the picture so that I can record the environment data in a permanent file. This may be a problem as the program is getting close to the 32k limit. Would not be an issue for the P2 though.
Mike
I finally got the LoraWan gateway unit.
Setting up the gateway and devices requires a Network Engineering degree.
There are all these hex strings that need to be typed in and field values that don't match their names and passwords that are cryptic.
Figuring out where the data goes so you can see if you're actually making a connection with the cloud.
Join request that have to match your area, channels that match the gateway, encryption keys that match the cloud, and spread frequencies that match the data you want to send.
After several days of working on this I got everything working with the driver I put together. One of the problems is that the device uses AT commands which are very wordy and writing code that has to visit all these return types to determine if what is happening is what the text says. Using AT commands on a command line is nice since you can see what you're doing but converting that to a driver not so much.
Setting up the Blues Notecard is a breeze compared to this.
Now I have to figure out how to use the API's so I can get the environment data out of the cloud.
Mike
Here is the P1 version of the Lorawan environment sensor.
All the code just fits in the P1 and uses very little power.
40ma at 7volts when fully powered and only 12ma when in sleep mode. The WOIE5 unit is about 4ma when power and a few microamps when powered down. During transmitt it could be 100ma at 3.3v but only when sending the data.
At 12ma it should run for a couple of weeks using two 18650 batteries.
I'm using the Parallax Bosch BME680 board as the environment sensor using Bosches driver.
Here is the code to make it work:
Mike