0% found this document useful (0 votes)
52 views58 pages

Lesson 4 Getting Connected With LoRa

This document provides instructions on connecting a FiPy board to a LoRa network using The Things Network (TTN). It discusses: 1. What LoRa and LoRaWAN are and their key features like long range and low power communication. 2. The steps to register a device with TTN including getting the device EUI and creating an account and application on TTN. 3. The two connection methods for LoRaWAN - OTAA (Over the Air Authentication) and ABP (Activation By Personalization) and includes code examples for connecting via each. 4. How to register a LoRaWAN gateway with TTN by providing the gateway ID and configuring the location

Uploaded by

Andri Junaedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views58 pages

Lesson 4 Getting Connected With LoRa

This document provides instructions on connecting a FiPy board to a LoRa network using The Things Network (TTN). It discusses: 1. What LoRa and LoRaWAN are and their key features like long range and low power communication. 2. The steps to register a device with TTN including getting the device EUI and creating an account and application on TTN. 3. The two connection methods for LoRaWAN - OTAA (Over the Air Authentication) and ABP (Activation By Personalization) and includes code examples for connecting via each. 4. How to register a LoRaWAN gateway with TTN by providing the gateway ID and configuring the location

Uploaded by

Andri Junaedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Lesson 4: Getting connected

Lesson 4: Getting connected


with LoRa
with LoRa
Lesson Objectives
• To learn what LoRa is

• To understand what it does

• To understand the terms Over The Air Authentication, Authentication by


Personalisation and Node

• To connect the FiPy board to the LoRa network

• To set up an account on The Things Network (TTN)

27/04/2020 Created by Pycom for Education 2


Key point
You have to make sure that your Pycom device can connect to LoRa if this
lecture is to be helpful

27/04/2020 Created by Pycom for Education 3


LoRa – An introduction
• LoRa is short for Long Range radio
• It is derived from the chirp spread spectrum (CSS)
• LoRa is in the physical layer or layer 1 of the OSI model of computer networking

(Image source:https://upload.wikimedia.org/wikipedia/en/5/5a/LoRa_Module_with_antenna_and_SPI_wires_attached.jpg)

27/04/2020 Created by Pycom for Education 4


LoRa – An introduction
LoRaWAN
• Is the open specification protocol
based on LoRa technology
• It is the communication protocol and
system architecture for the network
• Supports both OTAA and ABP
connection methods, as well as
advanced features

(Image source:
https://www.thethingsnetwork.org/docs/lorawan/LoRaWAN-
Overview.png)

• 27/04/2020 Created by Pycom for Education 5


LoRa-MAC (Raw LoRa)
• In LoRa-MAC mode the LoRaWAN
layer is bypassed and the radio is used
directly
• The modules do not have to be
registered

(Image source:
https://www.researchgate.net/publication/332151302/figure/fig1/A
S:743250218450945@1554216069910/The-LoRaWAN-MAC-
protocol-stack-is-implemented-on-top-of-LoRa-modulation-
PHY-The.ppm)

https://docs.pycom.io/tutorials/lora/lora-mac/
• 27/04/2020 Created by Pycom for Education 6
Suitable Use-cases for LoRaWAN

1. Long range – up to several kilometres


2. Low power – can last years on a battery
3. Low cost
4. Low bandwidth - between 250bit/s and 11kbit/s in Europe using LoRa modulation
(depending on the spreading factor)
5. Wide coverage area
6. Secure - 128 bit end-to-end encryption

https://docs.pycom.io/tutorials/lora/lora-mac/
27/04/2020 Created by Pycom for Education 7
Before starting

When you are using LoRaWAN you only need to concern yourself with two
things:

• Your IoT devices

• The Internet service (‘platform’) your IoT devices communicate with

27/04/2020 Created by Pycom for Education 8


Before starting

If, as in this example, you are using The Things Network, please check their
coverage map (https://www.thethingsnetwork.org/map)

o This will show the gateways that are already set-up and available to be used
for free

27/04/2020 Created by Pycom for Education 9


Before starting

• Each gateway on TTN has a Gateway ID and a sample code that creates a
unique Gateway ID

o The sample code uses a unique identifier (MAC) that is built into the WiFi
network adaptor on all Pycom devices

27/04/2020 Created by Pycom for Education 10


Registering with LoRaWAN
1. Get your module's Device EUI
a) Use this code:

2. The output will be a hex string like this: 70B3D5499585FCA1

https://docs.pycom.io/gettingstarted/registration/lora/

27/04/2020 Created by Pycom for Education 11


Registering with LoRaWAN
3. Once you have the hex string, you will need to provide it to you LoRaWAN
network – so make a note of it

a) You need it to connect via Over The Air Activation (OTAA) or Activation by
Personalisation (ABP)

https://docs.pycom.io/gettingstarted/registration/lora/
27/04/2020 Created by Pycom for Education 12
Registering with TTN
To set up the gateway with The Things
Network (TTN)

1. Head to their website


2. Create a username and they'll need
your email address to verify with their
platform
3. Once an account has been registered,
the nano-gateway can then be
registered
4. Navigate to the TTN Console webpage

https://docs.pycom.io/gettingstarted/registration/lora/ttn/
27/04/2020 Created by Pycom for Education 13
Registering with TTN
5. Navigate to ‘Console’ under your 6. Under the application option, choose
account name ‘Add Application’

https://docs.pycom.io/gettingstarted/registration/lora/ttn/

• 27/04/2020 Created by Pycom for Education 14


Registering with TTN
7. Select ‘register device’ to add your 8.Create a unique Device-ID
device to the TTN application

https://docs.pycom.io/gettingstarted/registration/lora/ttn/

• 27/04/2020 Created by Pycom for Education 15


Registering with TTN
9. After you’ve registered, you’ll be taken to the device overview page. Go
to Settings and paste in your copied Device EUI

https://docs.pycom.io/gettingstarted/registration/lora/ttn/
27/04/2020 Created by Pycom for Education 16
Woo!
Connecting via OTAA
• OTAA stands for Over The Air Authentication

• The network will provide you with:

o An Application EUI

o An Application Key

https://docs.pycom.io/tutorials/lora/lorawan-otaa/

27/04/2020 Created by Pycom for Education 18


LoRaWAN with OTAA
• With this method, the FiPy sends a Join request to the LoRaWAN gateway

• If the keys are correct, the Gateway will reply to the FiPy with a join accept
message

• If the keys are incorrect, no response will be received and the has_joined()
method will always return to False

https://docs.pycom.io/tutorials/lora/lorawan-otaa/
27/04/2020 Created by Pycom for Education 19
Connecting via OTAA
Use this code to connect to the
network

https://docs.pycom.io/tutorials/lora/lorawan-otaa/
27/04/2020 Created by Pycom for Education 20
LoRaWAN with OTAA
This example attempts to get any
data received after sending the frame

https://docs.pycom.io/tutorials/lora/lorawan-otaa/
27/04/2020 Created by Pycom for Education 21
LoRaWAN with ABP
• APB stands for Authentication By Personalisation

• The network will provide you with:

o A Device Address

o A Network Session Key

o An Application Session Key

https://docs.pycom.io/tutorials/lora/lorawan-abp/

27/04/2020 Created by Pycom for Education 22


LoRaWAN with ABP
• The encryption keys are configured manually on the device

• Can start sending frames to the Gateway without needing a 'handshake'


procedure to exchange the keys

https://docs.pycom.io/tutorials/lora/lorawan-abp/
27/04/2020 Created by Pycom for Education 23
LoRaWAN with ABP
Use this code to connect to the network

https://docs.pycom.io/tutorials/lora/lorawan-abp/
27/04/2020 Created by Pycom for Education 24
LoRaWAN with ABP
This example attempts to get any
data received after sending the
frame

https://docs.pycom.io/tutorials/lora/lorawan-abp/
27/04/2020 Created by Pycom for Education 25
It’s now time to Register a gateway with TTN
Registering A gateway with TTN
5. Inside the TTN Console, there are • 6. Please verify that the location and
two options. country specific frequency is correct,
a) Applications otherwise you will not be able to
connect to TTN
b) Gateways – Select Register
Gateway

https://docs.pycom.io/gettingstarted/registration/lora/ttn/
• 27/04/2020 Created by Pycom for Education 27
Registering a gateway with TTN
Verify that the location and
country specific frequency
is correct otherwise you will
not be able to connect to
TTN

https://docs.pycom.io/gettingsta
rted/registration/lora/ttn/

27/04/2020 Created by Pycom for Education 28


Registering A Gateway with TTN
7. The Gateway EUI should match your Gateway ID from the config.py file

https://docs.pycom.io/gettingstarted/registration/lora/ttn/

27/04/2020 Created by Pycom for Education 29


Registering A gateway with TTN
8. Once these settings have been
applied, click Register Gateway.

a) A 'Gateway Overview' page will


appear, with the configuration
settings showing.

https://docs.pycom.io/gettingstarted/registration/lora/ttn/

• 27/04/2020 Created by Pycom for Education 30


The Gateway should now be
configured!
LoRaWAN Nano-Gateway
Nano-Gateway

• The Nano-Gateway code is split into 3 files, main.py, config.py and


nanogateway.py

• It’s best to use the latest code from GitHub, so click here and unzip the
downloaded file

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 32


LoRaWAN Nano-Gateway
Main (main.py)

• This file runs at boot

• It calls the library and config.py files


to initialise the nano-gateway.

https://docs.pycom.io/tutorials/lora/lora
wan-nano-gateway/
27/04/2020 Created by Pycom for Education 33
LoRaWAN Nano-Gateway
Configuration (config.py)
• Contains settings for the server and
network it is connecting to.
• Please change the WIFI_SSID and
the WIFI_PASS variables to match
your desired WiFi network

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
• 27/04/2020 Created by Pycom for Education 34
LoRaWAN Nano-Gateway
Library (nanogateway.py) code continued

27/04/2020 Created by Pycom for Education 35


LoRaWAN Nano-Gateway
Library (nanogateway.py)
• The nano-gateway controls all of the
packet generation and forwarding
for the LoRa data.
• This does not require any user
configuration and the latest version
of this code should be downloaded
from here

https://docs.pycom.io/tutorials/lora/lora
wan-nano-gateway/

• 27/04/2020 Created by Pycom for Education 36


LoRaWAN Nano-Gateway
Gateway ID
• Most LoRaWAN network servers expect a Gateway ID in the form of a unique
64-bit hexadecimal number (called a EUI-64)

• The result will be something like


b'240ac4FFFE008d88' where 240ac4FFFE008d88 is your Gateway ID to be
used in your network provider configuration.

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
27/04/2020 Created by Pycom for Education 37
LoRa-MAC Nano-Gateway
Gateway Code
• The code shows how to allow a raw
LoRa connection between two FiPys
(nodes) to a single FiPy acting as a
Nano-Gateway

https://docs.pycom.io/tutorials/lora/l
ora-mac-nano-gateway/

• 27/04/2020 Created by Pycom for Education 38


LoRa-MAC Nano-Gateway
The Node

The node is always sending


packages and waiting for the
ack from the gateway

https://docs.pycom.io/tutorials/lora/lora-
mac-nano-gateway/
• 27/04/2020 Created by Pycom for Education 39
LoRa-MAC Nano-Gateway
To adapt to user specific needs:

• Put a max waiting time for the ack to arrive and resend the package or

mark it as invalid

• Increase the package size changing the _LORA_PKG_FORMATto BH%ds

https://docs.pycom.io/tutorials/lora/lora-mac-nano-gateway/
27/04/2020 Created by Pycom for Education 40
Node to Node
How to connect two Pycom LoRa capable modules (nodes) via raw LoRa
Node A Node B

https://docs.pycom.io/tutorials/lora/module-module/
27/04/2020 Created by Pycom for Education 41
Configuring your node(s)
You have to configure your node(s) to use the nano-gateway so that TTN
applications can be built

There are two methods of connecting FiPy devices to the nano-gateway:


• Over The Air Activation (OTAA)
• Activation by Personalisation (ABP)

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 42


Configuring your node(s) - OTAA

When the FiPy connects to an application (via TTN) using OTAA, the network
configuration is derived automatically during a handshake between the FiPy and
the network

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 43


Configuring your node(s) - OTAA

https://docs.pycom.io/tut
orials/lora/lorawan-nano-
gateway/
27/04/2020 Created by Pycom for Education 44
Configuring your node(s) -ABP

Activation by Personalisation – ABP


• Using ABP join mode requires the user to define the listed values and input
them into both the FiPy and the TTN Application

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 45


Configuring your node(s) - ABP

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
27/04/2020 Created by Pycom for Education 46
TTN Applications

• Now that the gateway and nodes have been setup, a TTN application can be
built

• The example that follows demonstrates an HTTP request integration

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 47


TTN Applications – HTTP request integration
Registering an Application
1. Select the Applications tab at the
top of the TTN console. This will
bring up a screen for registering
applications.
2. Click register and a new page

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
• 27/04/2020 Created by Pycom for Education 48
TTN Applications – HTTP request integration
Registering an Application
3. Enter a unique Application ID as well as a Description and Handler
Registration

4.The FiPy nodes must be registered to send data up to the new application

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 49


TTN Applications – HTTP request integration
Registering devices
1. To connect nodes to the nano-gateway, devices need to be added to the
application
2. To do this, navigate to the Devices tab on the Application home page
3. Click the Register Device button

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 50


TTN Applications – HTTP request integration

4. In the Register Device panel, complete the forms for Device ID and Device
EUI

5. Once the device has been added, change the Activation Method between
OTAA and ABP depending on the user preference
a) This option can be found under the Settings tab

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 51


TTN Applications – HTTP request integration

Adding Application Integrations


• Data is now arriving on the TTN backend
• TTN can be managed, so where the data is delivered can be controlled

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 52


TTN Applications – HTTP request integration
Adding Application Integrations
1. Use the Integrations tab within
the new application's settings
2. Click Add Integration and a
screen with four different options
will appear

https://docs.pycom.io/tutorials/lora/lorawan-
nano-gateway/
• 27/04/2020 Created by Pycom for Education 53
TTN Applications – HTTP request integration

1. Click HTTP Integration to connect


up to an endpoint that can receive
the data
2. For testing, a website called
RequestBin can be used to receive
the data that TTN forwards (via POST
request)

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

27/04/2020 Created by Pycom for Education 54


TTN Applications – HTTP request intergration
3. Navigate to RequestBin and click 4. Copy the URL that is generated and
Create a RequestBin paste this into the URL form under the
Application Settings

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

• 27/04/2020 Created by Pycom for Education 55


TTN Applications – HTTP request intergration
6. This is the address that TTN will
forward data onto.

a) As soon as a FiPy starts


sending messages, TTN will
forward these onto
RequestBin and they will
appear at the unique
RequestBin URL

https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/

• 27/04/2020 Created by Pycom for Education 56


RN2483 to FiPy
This example shows how to send data between a Microchip RN2483 and a FiPy
via raw LoRa
RN2483
FiPy

https://docs.pycom.io/tutorials/lora/lorawan-
nano-gateway/
27/04/2020 Created by Pycom for Education 57
And you're set with LoRa!

You might also like