What if you could collect data about the physical world, from almost anywhere in the world, for really short money? There’s a relatively new networking technology that enables you to do just that, called LoRaWAN. This specification defines a low power, wide area networking protocol engineered to connect wireless, battery-powered IoT devices to the internet over long distances. How long? Up to a few kilometers from the nearest gateway. The catch? This protocol only supports very low data transmission rates. However, most IoT applications don’t require a lot of bandwidth, and the tradeoff for long distance wireless communication is perfectly acceptable.
One implementation of this protocol that has taken off over the last couple of years is the Helium network. This network is made up of a distributed collection of privately owned and operated LoRaWAN gateways and network servers. The gateways, which are like wireless access points but for the LoRaWAN protocol, are actually blockchain crypto miners (in most cases). These gateways mine Helium’s HNT cryptocurrency for their operators, which is what incentivizes people to operate these gateways in the first place. You can read more about the Helium network here and see the map of over 700,000 gateways (at the time of this writing) around the world here. While there are other public and private LoRaWAN networks, most notably The Things Network, I’m currently using the Helium network simply because it has the best coverage in my area.
In part one of this two-part series of posts, I’ll show you how to join an Arduino MKRWAN 1300 microcontroller to the Helium network and send a basic message. I definitely encountered a few speed bumps trying to get it working, so I’ll touch on those as well as some important concepts you’ll need to understand if you want to try this yourself.
- Sign into the Helium Console: This is pretty self explanatory – head over to the Helium Console and sign up. When you create your Helium account, you’ll receive an initial 10,000 credits for free. For each message you send to Helium from an end device, you’ll consume a credit. You can purchase additional credits if/when your initial 10,000 run out using a credit card under the “Data Credits” tab in the console.
- Make sure you are within reasonable range of a Helium Gateway: Check out the Helium Explorer to find a gateway near you. Note that if you don’t have one near you, you’ll either need to move your device closer to one or get one and configure it (I’ll cover this in my next post). Even if you are within a mile or so of a Helium Gateway, you may still run into connection issues. I’ll cover troubleshooting further down this post.
Configuring the Arduino
After unboxing, make sure to remove the black foam protective piece from the bottom end of the Arduino pins and attach the antenna. Note that not removing the foam can mess with the device communication. Walk through the first few steps outlined in this tutorial by Arduino until you have the device EUI of your MKRWAN device. With the device EUI in your clipboard, sign into the Helium console and follow this documentation to add the device.
Next, create a copy of the LoraSendAndReceive.ino example code, replace the contents with the code below, and modify the associated arduino_secrets.h file with the “SECRET_APP_EUI” and “SECRET_APP_KEY” that were generated in the Helium console for your device. This code is mostly the same as the LoraSendAndReceive.ino example with just a few modifications which I’ll outline below:
This first modification is in lines 9-12 where we import some libraries for the CayenneLPP protocol and JSON formatting. Further down the code in lines 83-87, we use those libraries to format the data we’re sending in the CayenneLPP format. This converts the message we input on the serial monitor to a CayenneLPP temperature format. In a later post, I’ll outline how we take this formatted data and send it to the Cayenne MyDevices platform for visualization. On lines 40-46, we disable all radio channels with the exception of Channel 1. I’m not sure why, but this seems to be required for the Helium network (thank you to hpssjellis on Github for outlining this here). Finally, on line 50, I set the devices to communicate as class C. The LoRaWAN protocol specifies three device class types – A, B, and C. These classes define the intervals at which the device transmits and listens. I set my device to class C for testing purposes, but do note that this setting uses much more energy than class A as it basically tells the device to listen continually. The Things Network does a great job explaining the different devices classes here.
Joining the Helium Network
Now that you’ve got the code, what should you expect when you run it? If the device is within range of a functioning Helium Gateway, the device should return “Enter a message to send to network” in the serial monitor after 30-60 seconds. If you see this, it means that a Helium server received the “Join” message via your device and the device received an “Accept” message back from Helium. In other words, the device successfully joined the Helium network. The device will perform this join handshake each time it powers on. You can see these messages in the Helium console.
If instead you see “Something went wrong; are you indoor? Move near a window and retry”, that means the join was unsuccessful. Work through these steps below to troubleshoot:
- Try it again… sometimes the device times out before receiving the join accept message back from network. Give it a few tries before moving on.
- Relocate. Start by moving your device closer to the nearest gateway if you are located more than a few hundred feet away from it. If you are less than 10 feet away from it, try moving further away – you could be too close. Finally, try moving closer to a different gateway. Some of the gateways shown in the Helium Explorer have a “This gateway is relayed…” message on them. Make sure you are not using a relayed gateway.
- Adjust Device Profile Settings. Within the Helium Console there is a “Profiles” tab. You can create device profiles that turn on/off ADR and set the Rx (receive) Delay. You might need to adjust these settings which you can read more about here.
If at this point you still can’t get the device to join, you may want to obtain your own gateway. I ended up purchasing a Dragino LPS-08 gateway and configuring it for the Helium network using this guide from Helium.
When prompted for a message in the Arduino IDE serial monitor, enter a number (i.e. 20) and hit enter. You should then see two new device messages in Helium console – “Uplink” and “Acknowledge”. The “Uplink” message is what contains your “payload”, which in this case is the CayenneLPP-formatted message you typed in the serial monitor.
In Part 2 of this series, I’ll show you how we configure a decoder for the CayenneLPP protocol and send it to MyDevices Cayenne for visualization. Stay tuned!