Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Low Cost LoRa GW Step by Step PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 64

Low-cost LoRa gateway:

a step-by-step tutorial

Prof. Congduc Pham


http://www.univ-pau.fr/~cpham
Université de Pau, France
Contents

q We will show how to build a low-cost LoRa


gateway to collect data from end-devices
q Configuration and update procedures will also
be shown
q The device part will be shown in a separate
tutorial
q The hardware platform is a Raspberry PI. RPI
1B/B+, 2B and 3B have been successfully tested
q Let’s get started…

2
Assembling the hardware

3
Get the Raspberry

You can use Raspberry 1 model B or B+ or Raspberry 2 model B or Raspberry 3 model B.


The most important usefull feature is the Ethernet interface for easy Internet connection.
You can use WiFi to get Internet connection by adding a WiFi USB dongle. With the
Raspberry 3, WiFi and Bluetooth are embedded on the board.
4
Now the radio module (1)

GND

CS

I
MOS
O
MIS
CLK
VCC

If you go for the inAir9 from Modtronix, then the header pins can come fully assembled.
Take the 6mm header pins to have enough length to connect F/F breadboard cables
(left). Connect the SPI pins with the F/F cables. Try to use different colors. I use the
following colors: MOSI (blue), MISO (green), CS (white), CLK (orange). Then connect
also the VCC (red) and the GND (black or any other dark color) of the radio board.
5
Now the radio module (2)

GND
MIS
O
MOS
I
CLK

CS
VCC

If you take the HopeRF RFM 92W/95W you will need


the adaptor breakout and you have to go though some
delicate but simple soldering tasks! It is not difficult but
you have to trained a bit before! Then, like for the
inAir9, use F/F breadboard cable to connect the SPI
pins, using different colors as explained previously.

6
Connecting the radio
module (1)

GND

CS

MOSI
MISO
CLK
VCC

Depending on the model, you can have the « short » or the « long » GPIO interface. However,
the SPI pins are at the same location therefore it does not change the way you connect the
radio module if you take pin 1 as the reference. Connect the SPI pins (MOSI, MISO, CLK, CS)
of the radio to the corresponding pins on the RPI. Note that CS goes to CE0_N on the RPI.

7
Connecting the radio
module (2)

GND

CS

RT
It is strongly advised
to also connect the
RESET pin (RT) to
the RPI's #11 pin

I
MOS
O
MIS
CLK
VCC (GPIO17)
8
Put it in a box

You can have a more integrated version, with a box for outdoor usage and PoE
splitter to power the Raspberry with the Ethernet cable. See how we also use a
DC-DC converter to get the 5V for the RPI.
9
Antennas for gateway

q Antennas for gateways can be placed on a


building, at a high location.
q You can easily use ground plane or sleeve
dipole antenna. More complex high gain
antenna or a directional Yagi antenna can be
purchased depending on your budget and
whether the device deployment allows it.

10
Simple ¼ wave ground
plane antenna

q The ground plane antenna can be made with 5 pieces of


¼ wave wires. ¼ wave in 868MHz is about 8.2cm.

q You can buy a 3m RG58 cable with an SMA-male at one


end and a male N-connector at the other end. Or build
your own cable.
11
Getting, compiling &
installing the software

12
Flashing the OS
http://cpham.perso.univ-pau.fr/LORA/WAZIUP/raspberrypi-jessie-WAZIUP-demo.dmg.zip

q An SD card image with a Raspberry Raspbian


Jessie version is provided.
q You will need an 8GB SD card. Be careful, some
SD cards will not work. This one has been
successfully tested. It has to be class 10.
q Look at
https://www.raspberrypi.org/documentation/inst
allation/installing-images/ to see the procedure
depending on your OS. 7948206080 bytes should
be written, otherwise you may have a problem.
q Once flashed, insert the SD card and power-up
the Raspberry-based gateway.
13
SSH to the gateway

q The Raspbian image sets the Raspberry for DHCP


on wired Ethernet and as a WiFi access point.
q If you connected the gateway to your LAN or
laptop using wired Ethernet then the gateway
will be assigned an IP address. Use this address to
connect with SSH to the gateway
q Use ssh pi@rpi_addr, where rpi_addr is the IP
address assigned to the gateway
q Login password is loragateway if you installed
from the SD card image
q However, using the built-in WiFi access point is
easier as shown in the next slide
14
SSH to the gateway with
WiFi

q The gateway is also configured as a WiFi access


point with address 192.168.200.1
q Select the WAZIUP_PI_GW_xxxxxxxxxx WiFi
q WiFi password is loragateway You can use an Android
q Then ssh pi@192.168.200.1 smartphone or tablet to connect
to the gateway with the JuiceSSH
q Login password is loragateway app! See next slide.

15
Using Android
smartphone or tablet

q Use an Android smartphone or tablet with


JuiceSSH to connect to the gateway

16
Gateway's simple
command interface
q Once logged on the
gateway, you may directly
enter in a simple command
interface
q This command interface
consists in a cmd.sh shell
script
q In image versions after May
2017, this script is launched
when you log into the
gateway with ssh
q If this happens, select Q and
RETURN to quit this interface
q You should be in the
lora_gateway folder
17
Full update of GW
software from github

The software should be installed in a lora_gateway folder. Delete any previous folder.
> rm -rf lora_gateway
then
> mkdir lora_gateway
> git clone https://github.com/CongducPham/LowCostLoRaGw.git
> cp -r LowCostLoRaGw/gw_full_latest/* lora_gateway/
or
> svn checkout https://github.com/CongducPham/LowCostLoRaGw/trunk/gw_full_latest lora_gateway

18
… and compiling the GW
software
> cd lora_gateway
> make lora_gateway
g++ -DRASPBERRY -DIS_RCV_GATEWAY -c lora_gateway.cpp -o lora_gateway.o
g++ -c arduPi.cpp -o arduPi.o
g++ -c SX1272.cpp -o SX1272.o
g++ -lrt -lpthread lora_gateway.o arduPi.o SX1272.o -o lora_gateway

Edit radio.makefile for PABOOST setting. If inAir9B,


RFM92W/FM95W, NiceRF1272, uncomment:
CFLAGS=-DPABOOST
If inAir9/inAir4, Libelium SX1272, leave commented:
#CFLAGS=-DPABOOST

If you have a RPI 2 or RPI3, then type:

> make lora_gateway_pi2

19
Use a script to update
the gateway

q Alternatively, the gateway can also be updated


to the latest version with the update_gw.sh
script.
q The first step is to get the latest version of the
update script
> cd
> svn checkout https://github.com/CongducPham/LowCostLoRaGw/trunk/gw_full_latest/scripts
> cd scripts
> ll
total 48
-rw-r--r-- 1 pi pi 3561 May 10 17:31 bashrc.sh
-rwxr-xr-x 1 pi pi 10562 May 10 17:31 config_gw.sh
-rw-r--r-- 1 pi pi 230 May 10 17:31 interfaces_ap
-rwxr-xr-x 1 pi pi 99 May 10 17:31 mnt-dropbox
-rwxr-xr-x 1 pi pi 610 May 10 17:31 mongodb_repair.sh
-rwxr-xr-x 1 pi pi 816 May 10 17:31 start_access_point.sh
-rwxr-xr-x 1 pi pi 57 May 10 17:31 start_gw.sh
-rwxr-xr-x 1 pi pi 673 May 10 17:31 stop_access_point.sh
-rwxr-xr-x 1 pi pi 37 May 10 17:31 unmnt-dropbox
-rwxr-xr-x 1 pi pi 1537 May 10 17:31 update_gw.sh

20
Updating the gateway
software

q Then type the following commands


q cd
q cp lora_gateway/scripts/update_gw.sh .
q rm –rf lora_gateway
q ./update_gw.sh
q Removing any previous lora_gateway folder triggers a full
update
q The gateway will obtain the latest distribution from our
github repository and will create a new lora_gateway
folder
q Next periodic updates without deleting the existing
lora_gateway folder, i.e. preserving existing configuration
files, will be presented later on

21
Configuring the gateway
(1)

q First, get the hardware address of the gateway


q ifconfig

q Go into the scripts folder in the newly created


lora_gateway folder
q And run the config_gw.sh script by providing the last 5
bytes of the hardware address, in capital
q ./config_gw.sh 27EB795C47
q Then follow the instructions as shown in the next slides

22
Configuring the gateway
(2)
********************************************
*** compile lora_gateway executable Y/N *** Enter Y
********************************************

********************************************************
*** create log symb link to ~/Dropbox/LoRa-test Y/N *** Enter Y
********************************************************

***********************************
*** configure hostapd.conf Y/N *** Enter Y
***********************************

****************************************************************
*** configure a newly installed hostapd/dnsmasq package Y/N *** Enter N
****************************************************************

*********************************************
*** configure bluetooth network name Y/N *** Enter N
*********************************************

**********************************
*** install DHT22 support Y/N *** Enter Y
**********************************

23
Configuring the gateway
(3)
***************************************
*** edit gateway_conf.json now? Y/N *** Enter N
***************************************

*************************************
*** activate DHT22 MongoDB Y/N/Q *** Enter Q
*************************************

*********************************************************
*** edit LoRa data MongoDB local storage option? Y/N *** Enter N
*********************************************************

*******************************
*** run gateway at boot Y/N *** Enter Y
*******************************

**********************************************
*** check configuration (recommended) Y/N *** Enter N
**********************************************

*******************
*** reboot Y/N *** Enter N
*******************
24
Start the command
interface

> ./cmd.sh

As you can see, the gateway id


shown by the command
interface is now correct

25
Periodic update
procedure
q The latest command
interface has built-in
update procedure
q You can use option U to
update from repository
and still keep all your
configuration files:
gateway_conf.json,
clouds.json and key*
q You can also install a single
file with option V that will
prompt for a URL
q You can enter a URL that
has been provided by
some administrator
q Example in the next slide
26
Download and install a
file (1)

q With option V, you can enter an URL that points


to a file. The file will be downloaded and
installed in the lora_gateway folder.
Enter your choice:
V
----------------------------------------------------------------------
BEGIN OUTPUT
Download and install a file
Enter the URL of the file:
https://www.dropbox.com/s/mcmg4yeksr340c2/example-install-file.txt

27
Download and install a
file (2)

q This feature is very usefull for end-users to simply update


some files on the gateway.
q An administrator can write appropriate configuration files
for the end-user and generate an URL to this file (with
Dropbox for instance)
q The URL can be either be sent by mail or SMS to the end-
user.
q The end-user has to simply log into the gateway (using an
Android smartphone or tablet connecting to the
gateway's WiFi) and select option V to enter the URL.
q The end-user will then just reboot the gateway with option
R for the new configuration to run.

28
Download and install a
file (3)

q System files can also be installed with option W


that will prompt for a command
Enter your choice:
W
----------------------------------------------------------------------
BEGIN OUTPUT
Run a command
Enter the command to run:
sudo wget –O /etc/test.txt https://www.dropbox.com/s/mcmg4yeksr340c2/example-install-file.txt

q Here, the previous example file will be installed in


/etc under the name test.txt
q Like previously, the exact command can be sent
to the end-user
29
Our Low-Cost gateway
architecture
Most of user or post- user/app-
Kept as simple

high-level lang.
application specific processing specific
as possible

e.g. python
logics is done here!
We provide some
basic features, up to lora_gateway program
you to enhance them
stdout stdout
radio post
bridge processing Long-range radio lib
program stdin

Raspbian

30
Post-processing block
stdout stdout
radio post
bridge processing
program stdin

post-processing
Handle AES
LoRaWAN
encryption
downlink decryption
interoperability
data

Incoming data
Monitor
parsing block

Handle data Monitor


from other gateway
radio interfaces temperature

user/app-specific

cloud_script_1 cloud_script_2 cloud_script_n


Starting the basic
gateway

T/23
> sudo ./lora_gateway
Node 10
Power ON: state 0
Default sync word: 0x12
LoRa mode: 1
Setting mode: state 0 Node 3
Channel CH_10_868: state 0
Set LoRa Power to M: state 0
Get Preamble Length: state 0
Preamble Length: 8
LoRa addr 1 : state 0
SX1272/76 configured as LR-BS. Waiting RF input for transparent RF-serial bridge
--- rxlora. dst=1 type=0x10 src=10 seq=0 len=4 SNR=9 RSSIpkt=-54
^p1,16,10,0,4,9,-54
^r125,5,12
^t2016-02-25T01:51:11.058
T/23
--- rxlora. dst=1 type=0x10 src=3 seq=0 len=4 SNR=8 RSSIpkt=-54
^p1,16,3,0,4,8,-54
^r125,5,12
^t2016-02-25T01:53:13.067
H/85

32
Post-processing
received data
> sudo ./lora_gateway | python ./post_processing_gw.py
Power ON: state 0
Default sync word: 0x12 All lines that are not prefixed by specific
LoRa mode: 1 character sequence are displayed
Setting mode: state 0 unchanged
Channel CH_10_868: state 0
Set LoRa Power to M: state 0
Get Preamble Length: state 0 ^p provides information on the last received
Preamble Length: 8 packet: dst, type, src, seq, len, SNR & RSSI
LoRa addr 1 : state 0
SX1272/76 configured as LR-BS. Waiting RF input for transparent RF-serial bridge
--- rxlora. dst=1 type=0x10(DATA) src=10 seq=0 len=4 SNR=9 RSSIpkt=-54
Rcv ctrl packet info 1,16,10,0,4,9,-54
(dst=1 type=0x10 src=10 seq=0 len=4 SNR=9 RSSI=-54) ^r provides radio information on the last
rcv ctrl radio info (^r): 125,5,12 received packet: bw, cr & sf
splitted in: [125, 5, 12]
(BW=500 CR=5 SF=12)
rcv timestamp (^t): 2016-02-25T01:53:13.067
^t provides timestamp information on
got first framing byte
the last received packet
--> got data prefix
T/23

Pre-defined sequences inserted by the gateway or the end-device allow for information
exchanged between the gateway and the post-processing program
33
Gateway to cloud

Data received at the gateway can be pushed to IoT clouds. We provide python script examples
for many IoT cloud platforms. Most of clouds with REST API can be easily integrated.

34
Log received messages
using cloud services
\!T/23
Node 10

SX1272/76 configured as LR-BS. Waiting RF input for transparent RF-serial bridge


--- rxlora. dst=1 type=0x10 src=10 seq=0 len=6 SNR=9 RSSIpkt=-54
Rcv ctrl packet info 1,16,10,0,6,9,-54
(dst=1 type=0x10(DATA) src=10 seq=0 len=6 SNR=9 RSSI=-54)
rcv ctrl radio info (^r): 125,5,12
splitted in: [125, 5, 12]
(BW=500 CR=5 SF=12)
\$ or \! before the data indicates that the data
rcv timestamp (^t): 2016-02-25T01:53:13.067
should be logged on a file or a cloud. It is up
got first framing byte
to the end-device to decide which option
--> got data prefix
number of enabled clouds is 1
--> cloud[0]
uploading with python CloudThingSpeak.py
ThingSpeak: uploading
rcv msg to log (\!) on ThingSpeak ( default , 4 ): 23
ThingSpeak: will issue curl cmd
curl -s -k -X POST --data field4=23 https://api.thingspeak.com/[…]
ThingSpeak: returned code from server is 156
--> cloud end

35
Using

q A message starting with ’\$’ is logged in a file


‘telemetry.log’ in a folder shared through
Dropbox (if enabled)
(src=10 seq=0 len=6 SNR=9 RSSI=-54) 2015-11-04T10:14:30.328413> T/23
(src=10 seq=1 len=8 SNR=8 RSSI=-54) 2015-11-04T10:14:37.443350> T/23.2
(src=10 seq=2 len=6 SNR=8 RSSI=-53) 2015-11-04T10:16:23.343657> T/24
...

\$T/23
Node 10

36
Using

q A message starting with ’\!’ is uploaded on a


cloud, e.g. ThingSpeak

\!##T/23

Node 10

\!write_key#field_index#T/23

37
Using ------------

38
Using

39
Configuring data
management

q For WAZIUP, received data from devices will be


uploaded to the WAZIUP Orion data platform.
Therefore clouds.json file should be set as
follows:

q Modify clouds.json accordingly


q CloudWAZIUP.py script will use information from
key_WAZIUP.py to configure data management
for each organization
q Therefore we need to configure this file for each
organization
40
key_WAZIUP.py
####################################################
#server: CAUTION must exist
waziup_server="http://broker.waziup.io/v2"

#project name
project_name="waziup"

#your organization: CHANGE HERE


#choose one of the following: "DEF", "UPPA", "EGM", "IT21", "CREATENET", "CTIC", "UI", "ISPACE",
"UGB", "WOELAB", "FARMERLINE", "C4A", "PUBD"
organization_name="DEF"
You need to change the
#service tree: CHANGE HERE at your convenience
#should start with / organization_name.
#service_tree='/LIUPPA/T2I/CPHAM'
service_tree=''
service_tree is optional
#sensor name: CHANGE HERE but maybe better to leave it as Sensor
#the final name will contain the sensor address
sensor_name=organization_name+"_Sensor"

#service path: DO NOT CHANGE HERE


service_path='/'+organization_name+service_tree

#SUMMARY
#the entity name will then be sensor_name+scr_addr, e.g. "UPPA_Sensor2"
#the Fiware-ServicePath will be service_path which is based on both organization_name and
service_tree, e.g. "/UPPA/LIUPPA/T2I/CPHAM"
#the Fiware-Service will be project_name, e.g. "waziup"

source_list=[]

41
Editing key_WAZIUP_WS.py

Use nano to edit the file:

> nano key_WAZIUP.py

Then CTRL-O + RETURN to save

CTRL-X to quit

42
clouds.json

For each cloud, you have to


provide a script and the launcher
program (e.g. python)

Enabled clouds will be called by


the post-processing stage

43
Rebooting the gateway

q Your gateway is now updated and configured


q You can now reboot the gateway. To do so, just
type:
q sudo shutdown –r now
q Or run ./cmd.sh and chose option R
q Once the gateway has rebooted, check the
WiFi SSID which now should meet your gateway's
id
q Try to avoid unplugging power cable to
shutdown your gateway. Log into the gateway
and select option S instead.
q Your gateway is now ready to be deployed
44
Gateway web admin
interface (1)

q A gateway web admin interface has been


added to the latest version
q To install the web admin interface, check if you
have the gw_web_admin folder in your
lora_gateway folder
q If you don't, then update to the latest version
q Then, go into gw_web_admin and run the
install.sh script
q cd gw_web_admin
q ./install.sh
q Answer Y to " install from local version Y/N"

45
Gateway web admin
interface (2)

q http://192.168.200.1/admin

46
Web admin features

q Currently, you can use the web admin to:


q Easily reboot and shutdown your gateway
• Be carefull, if you shut down the gateway, you need to physically access
the gateway to power it it on again
q Change LoRa mode and frequency
q Update your gateway
q Change the WiFi SSID and password
q Enable/Disable local AES decryption
q Enable/Disable ThingSpeak and WAZIUP Orion cloud
q For ThingSpeak, you can specify a new write key
q For WAZIUP Orion, you can specify the project name, the
organization name and the service tree
• Fiware-service=project_name
• sensor_name=organization_name+"_Sensor"
• Fiware-servicePath='/'+organization_name+service_tree
• See slide 41

47
Default configuration

\!##TC/18.5

The default configuration in the Arduino_LoRa_temp example is:

Send packets to the gateway (one or many if in range)


LoRa mode 1 & Node short address is 6

The default gateway configuration is also LoRa mode 1

48
Write your own cloud
script

q Use our templates to write your own cloud script


q CloudMongoDB.py, CloudThingSpeak.py,
CloudFireBase.py, CloudGroveStreams.py,
CloudWAZIUP.py
q A cloud script is called with 5 arguments

These parameters are passed to the script. It is up to the cloud script to use these parameters or not.
49
Standalone gateway

50
Connect to the embedded
web server

q On the WiFi interface


q Gateway address is 192.168.200.1
q On the Ethernet interface
q Gateway address is the IP address assigned by the
DHCP server (of your LAN or laptop)
q Choose any of these solutions and open a web
browser to enter the gateway IP address in the
URL bar
q http://192.168.200.1

51
Data from the local web
server

52
Visualize it on your
smartphone!

q Don’t forget to join the


WAZIUP_PI_GW_xxxxxxxxxx WiFi

53
Running the gateway
without internet access

54
Improving casing and
adding PoE to gateway

55
Overview of the parts

56
Fixing the Raspberry to
the case

57
Prepare the DC Step-
Down (LM2596)
It is advised to connect the
DC plugs before soldering

Solder to the IN part of the


step-down module

Cut a USB cable, keeping


the micro-USB side

Solder to the OUT part of


the step-down module

58
Setting the step-down
module

Use for instance a 9v, 12v


or 18V AC-DC adaptor,
connect to the IN plug,
then check the output
voltage with a voltmeter
and turn the regulation
screw until output is about Then fix the module to the
5.1v. case

59
Installing the PoE injector and
water-resistant ethernet plug

60
Connect the radio
module

Like previously shown

GND

CS

RT
It is strongly advised
to also connect the
RESET pin (RT) to
the RPI's #11 pin

I
MOS
O
MIS
CLK
VCC
(GPIO17)

61
Install fixing parts of
the case

These parts of course


depends on the case that
you have.

Here we use the


GentleBOX JE-200 case
from MHzShop.

62
Fixing the antenna cable

Look at the Antenna


tutorial to see how an
antenna cable can be
made to adapt both the
cable length and the
antenna connectors

63
Connecting and powering
your gateway

64

You might also like