Getting into LoraWan with the things netwrok (part 1)


Lora is a wonderful technology that will be - without any doubt - the future supporting network technlogy of the "internet of things"... , but I'll write a more "business" article on my other blog, let's dive in the tech...

After spending quite an amount of time playing with LoraWan with a Chip from my friends at the
ABINC (brazilian association of IoT)

Here is my learnings from LoRa / LoraWan


LoraWan is a layer of protocols over Lora radio technology. It enable sync of packets to a gateway who will in turn transfer them to the IP network.

A tipical architecture of an app based on Lora integrates nodes, (IoT devices), connected over LoRa protocol to a Gateway, that transfer packets to one or many network servers, who finally send the data to the Application layer (distributed web app).

It is still not easy to connect a Lora Chip directly to the network, as it requires quite some work of syncing and it can get quite complex if there is more than a single node.

Some chips manufacturers have developped "all-in-one" chips that can handle lora communication as well as Gateway connection / transmission.

Here in brazil I am testing the Microchip RN2903. (915Mhz Lorawan chip.)
My friend Vidal from ABINC has made an arduino Shield to make the connection easier.




1) Checking if the Gateway is connected

Look for your Gateway euid from the status page:

http://staging.thethingsnetwork.org/gatewaystatus/

https://thethingsnetwork.org/api/v0/gateways/EUID_number/

2) Registering your App with "ttnctl"

The things network developped a backend tool to manage and create "apps", it is called
ttnctl, it is a script that enables you to create and manage your app.

The quick start info to use ttnctl is available from:
http://staging.thethingsnetwork.org/wiki/Backend/ttnctl/QuickStart

To check "online" if things are working you can use:

https://staging.thethingsnetwork.org/applications

another way to access, via REST api, although I am not sure if this will stay online long:
https://thethingsnetwork.org/api/v0/

3) Differences between OTAA and ABP

LoRa devices need to be activated in the network to be able to communicate with the correct Application Server. Futhermore, LoRa data packets are encrypted with AES-128 be default on the device.

According to the LoraWan specifications (LoraAlliance site), there are two ways of "activating" a new node to a LoraWan network.

https://www.lora-alliance.org/portals/0/specs/LoRaWAN%20Specification%201R0.pdf#page=30

After activation, some data are stored into the node:
devAddr (device address)
appEUI (app id)

NwkSKey (network session key)
AppSKey (app session key)

For over-the-air activation, end-devices must follow a join procedure prior to participating in 35 data exchanges with the network server. An end-device has to go through a new join 36 procedure every time it has lost the session context information.

ABP (Activation by personalisation):

With Activation by Personalisation (ABP) a 32-bit device address (7-bit network identifier plus 25-bit network address), along with the network and application session keys, are manually configured.

ABP is great for prototyping and suited to smaller networks. Whereas OTAA will allow for a greater degree of flexibility, e.g. in addressing, and should provide increased security and ability to scale.

4) Check your gateway

For the Communication to happen you need to configure your Gateway:

here are some information about Gateway setup:

https://staging.thethingsnetwork.org/wiki/Backend/Connect/Gateway

- check that it is well connected to your local network (either by DHCP or by fixed address)
- check that the "server IP" address is properly configured as well as the proper ports
- check that other configurations items are properly working


Important: Check that your gateway is communicating on the same channels as you are using from your Lora Chip. Make sure you desactivates all the channels that are not being used, on the Gateway site as well as on the Chip site, otherwise the Lora communication will fail.


Others topics....

--> Serial connection

The first problem I faced is that I discovered that the Arduino script on thethingsnetwork used 2 serial ports, one for Arduino -> LoraWan communication, the other from "serial debugging".

The script was originally made for Arduino Leonardo and it has 2 pair of pins for Serial communication while the Uno has only one.

I discovered a library that can emulate other Serial ports, to enable working with more than one.

#include "SoftwareSerial.h"

then you can create a new serial connection as :
SoftwareSerial loraSerial(2,3); // RX, TX

then:
loraSerial.begin(57600);
and use it as a tipical serial connection.


--> Publish and get data with Nodered (a visual nodejs tool to connect IoT devices)
Very good step by step documentation here
https://github.com/TheThingsNetwork/examples/tree/master/workshops/TheThingsUno


Commentaires