Sending the data – Your first IoT deployment
At cloudsensing we want to make things simple for you. Today’s is the first post of the series Your first IoT deployment. We are going to work on sending data to the internet, in the IoT way.
The world of IoT is incredibly huge. So, instead of making this generic, we have preferred to go straight to the point. We will use specific hardware and networks, and try to show you how to get started in the matter of minutes.
Your first IoT deployment: sending the data
Firstly, let’s check what network we will be using. At cloudsensing we like LoRa, an LPWAN network that has a wide community behind it doing incredible things. Also, it is very fast to get started with LoRa, thanks to the open and community-backed TTN (The Things Network). Most likely you will be near a community gateway and be able to follow this tutorial without installing your own one. Check their gateways map to be sure about it.
Secondly, the hardware. Over the last year we have been working with an outstanding IoT hardware manufacturer: Pycom. Those guys have been doing an incredible job creating IoT development boards with which you can get started in just seconds. To be able to use the LoRa connectivity you will either need a LoPy or a FiPy. Choose the one that you like the most.
So, with both having Pycom hardware and being located near a TTN gateway, you can get started. Believe it or not, you are going to have data on the internet with an scalable network in just 20 minutes.
Let’s get to it.
Configuring the network
The first step is to configure your device in the network. We will be using TTN (The Things Network), an open LoRa network. To do so, head over to TTN Console (and create an account if you do not have one).
Once everything is set up, you will need to create a new application: specify for that the ID, a description and the default handler. That application is going to be in charge of managing your devices and decoding the data. You need to take note of the application EUI. Check out the screenshots below.
Preparing the hardware to send data
Now it is time to move to the hardware. We need to define it in the network through the application we just created before it is allowed to send data.
Using your LoRa enabled pycom development board, connect to it and access the REPL console (there are pretty good tutorials on the pycom docs website explaining the first steps with the boards). To define the hardware in TTN we will need its device EUI. You could just use a random one generated by the console, but it is preferred to use the MAC from the lora radio. Type the following commands to obtain it:
form network import LoRa
lora = LoRa(mode=LoRa.LORAWAN)
With this 8-byte address, head over to the TTN console again. Under the DEVICES tab, click register a device: define a name and input the LoRa MAC you just obtained as Device EUI. Once the device is created, you can access it and copy the App key.
At this point we have all the necessary information to put into the firmware.
Go to the LoRa examples on the Pycom documentation, and get the code for the OTAA activation one (click!).
In the firmware, you just need to replace the app_key and app_eui variables with the ones that you obtained from TTN. Save the code, flash it and voilà! As long as you are reachable by a gateway, you are already sending data to the internet through a LoRa network.
Check the results! And keep working on it
You can check real time the data you are sending, either in the Application view under the Data tab (you will see all the data from the registered devices in that app) or in the Device view (you will only see the data from your device).
Before we move forward and start forwarding and doing things with that data, you may want to better understand what have we done. Pycom and TTN documentation is really good on helping you every step of the way, and you may want to check the following topics:
- Different authentication methods: OTAA vs ABP. We used the first one, but also check out ABP.
- Payload formats. Now, we just send bytes, but you can compress your data in a custom way or through any other IoT standards. TTN supports CayenneLPP, so be sure to check out that one. It even has a python library for you to use with you Pycom devboards.
- Deploying your own gateways for TTN: collaborate with the open source community. Set up a gateway of your own and increase the coverage on your region.
Are you amazed about how easy it has been sending the data? In the following tutorials, our CEO and head of engineering Wladi will keep teaching you more about IoT deployments.
Keep tuned for the next posts in the series and become a master in IoT.