Lesson 4 Getting Connected With LoRa
Lesson 4 Getting Connected With LoRa
(Image source:https://upload.wikimedia.org/wikipedia/en/5/5a/LoRa_Module_with_antenna_and_SPI_wires_attached.jpg)
(Image source:
https://www.thethingsnetwork.org/docs/lorawan/LoRaWAN-
Overview.png)
(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
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:
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
• 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
https://docs.pycom.io/gettingstarted/registration/lora/
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)
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/
https://docs.pycom.io/gettingstarted/registration/lora/ttn/
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
o An Application EUI
o An Application Key
https://docs.pycom.io/tutorials/lora/lorawan-otaa/
• 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
o A Device Address
https://docs.pycom.io/tutorials/lora/lorawan-abp/
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/
https://docs.pycom.io/gettingstarted/registration/lora/ttn/
https://docs.pycom.io/gettingstarted/registration/lora/ttn/
• 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/
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
https://docs.pycom.io/tutorials/lora/lora
wan-nano-gateway/
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/
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
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
https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
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/
https://docs.pycom.io/tut
orials/lora/lorawan-nano-
gateway/
27/04/2020 Created by Pycom for Education 44
Configuring your node(s) -ABP
https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
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
https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
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/
https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
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/
https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
https://docs.pycom.io/tutorials/lora/lorawan-
nano-gateway/
• 27/04/2020 Created by Pycom for Education 53
TTN Applications – HTTP request integration
https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
https://docs.pycom.io/tutorials/lora/lorawan-nano-gateway/
https://docs.pycom.io/tutorials/lora/lorawan-
nano-gateway/
27/04/2020 Created by Pycom for Education 57
And you're set with LoRa!