Memoria2017 AngelGuzman
Memoria2017 AngelGuzman
TELECOMMUNICATIONS ENGINEERING
Author
Angel Guzman-Martinez
Supervisors
Jorge Navarro-Ortiz
Sandra Sendra-Compte
Author
Angel Guzman-Martinez
Supervisors
Jorge Navarro-Ortiz
Sandra Sendra-Compte
Resumen
El Internet de las cosas es un tema candente hoy en dı́a que va tomando cada
vez más relevancia. Sin embargo, esto trae consigo una serie de problemas
que las redes convencionales no solventan correctamente, como el alcance y
la duración de las baterı́as de los dispositivos conectados a estas redes.
Como solución a estos problemas, surgen las redes de baja potencia.
Dichas redes están orientadas a proporcionar un mayor alcance con un menor
consumo, a cambio de una menor velocidad de transmisión. Por este motivo,
las redes de baja potencia son el candidato ideal para los dispositivos del
internet de las cosas. Una de estas redes de baja potencia es LoRaWAN,
que es en la que se basará este proyecto.
El objetivo de este proyecto es el desarrollo de dos dispositivos relaciona-
dos con LoRaWAN:
Angel Guzman-Martinez
Abstract
Nowadays, the Internet of Things (IoT) is a trending topic that is growing
in relevance every day. However, it brings out some problems that are not
properly solved by the conventional networks, such as the range and battery
life of the devices connected these networks.
The Low Power Wide Area Networks (LPWAN) appear as a solution
to these problems. These networks provide an improved range and less
power consumption, at the expense of the data rate. Thus, these low power
networks are the ideal candidate for the IoT devices. One of these low power
networks standards is called LoRaWAN, which is the one this project will
be based on.
The goal of this project is to develop two LoRaWAN related devices:
Informan:
Los directores:
Glossary 21
1 Introduction 23
1.1 Context and Motivation . . . . . . . . . . . . . . . . . . . . . 23
1.2 Goals and Reach of the Project . . . . . . . . . . . . . . . . . 23
1.3 LoRaWAN’s Current Situation . . . . . . . . . . . . . . . . . 24
1.4 Structure of the document . . . . . . . . . . . . . . . . . . . . 24
2 LoRaWAN Overview 27
2.1 LoRa Modulation . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.1.1 Direct Sequence Spread Spectrum (DSSS) . . . . . . . 27
2.1.2 LoRa Spread Spectrum . . . . . . . . . . . . . . . . . 28
2.1.3 Main Properties of LoRa Modulation . . . . . . . . . 30
2.1.4 Link Budget Example . . . . . . . . . . . . . . . . . . 31
2.2 LoRaWAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.2.1 Device Classes . . . . . . . . . . . . . . . . . . . . . . 33
2.2.2 Regional Parameters . . . . . . . . . . . . . . . . . . . 35
2.2.3 Security . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.3 The Things Network . . . . . . . . . . . . . . . . . . . . . . . 36
13
14 CONTENTS
4.1.3 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.1.4 Implementation . . . . . . . . . . . . . . . . . . . . . . 53
4.1.5 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.1.6 Documentation . . . . . . . . . . . . . . . . . . . . . . 53
4.2 Resources and Cost Estimate . . . . . . . . . . . . . . . . . . 53
4.2.1 Human Resources . . . . . . . . . . . . . . . . . . . . 53
4.2.2 Material Resources . . . . . . . . . . . . . . . . . . . . 54
4.3 Total Budget . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5 Requirement Specifications 57
5.1 Gateway . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.1.1 Functional Requirements . . . . . . . . . . . . . . . . 57
5.1.2 Non-Functional Requirements . . . . . . . . . . . . . . 57
5.2 Mote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.2.1 Function Requirements . . . . . . . . . . . . . . . . . 58
5.2.2 Non-Functional Requirements . . . . . . . . . . . . . . 58
5.3 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.3.1 Functional Requirements . . . . . . . . . . . . . . . . 59
5.3.2 Non-Functional Requirements . . . . . . . . . . . . . . 59
6 Design 61
6.1 Mote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6.1.1 Development Board . . . . . . . . . . . . . . . . . . . 61
6.1.2 Transceiver Module . . . . . . . . . . . . . . . . . . . 63
6.1.3 Antenna . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.2 Gateway . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
6.2.1 Embedded Linux Board . . . . . . . . . . . . . . . . . 64
6.2.2 Concentrator . . . . . . . . . . . . . . . . . . . . . . . 65
6.2.3 Antenna . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6.2.4 Enclosure . . . . . . . . . . . . . . . . . . . . . . . . . 66
7 Implementation 67
7.1 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
7.2 Mote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.2.1 Wiring . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.2.2 Software . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.3 Gateway . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.3.1 Wiring . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.3.2 Software . . . . . . . . . . . . . . . . . . . . . . . . . . 74
7.3.3 Registration . . . . . . . . . . . . . . . . . . . . . . . . 75
7.3.4 Enclosure . . . . . . . . . . . . . . . . . . . . . . . . . 76
7.3.5 Location . . . . . . . . . . . . . . . . . . . . . . . . . . 78
CONTENTS 15
9 Conclusions 97
9.1 LoRa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
9.2 LoRaWAN and TTN . . . . . . . . . . . . . . . . . . . . . . . 97
9.3 The Gateway . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
9.4 Low Cost Mote . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Appendices 101
17
18 LIST OF FIGURES
19
Glossary
BW Bandwidth.
DIY Do It Yourself.
DR Data Rate.
21
22 Glossary
NF Noise Figure.
SF Spreading Factor.
Introduction
23
24 1.3. LoRaWAN’s Current Situation
Figure 1.1: World market for Internet connected devices forecast [1].
LoRaWAN Overview
In this chapter, we will introduce the protocols and technologies that make
this project possible. Specifically:
LoRa stands for Long Range and is a Semtech proprietary spread spectrum
modulation. Its main selling point consists of being able to gain range at the
expense of data rate. What makes LoRa stand out from other modulation
methods is its unique spread spectrum technique, which provides robustness
against interferences and a very low minimum SNR for the receiver to be
able to demodulate the signal.
27
28 2.1. LoRa Modulation
2SF
Ts = seconds
BW
Lastly, the different spreading factors do not interfere with each other,
as they are orthogonal with each other. As a result, we can transmit several
signals over the same frequency range by using different spreading factors.
Constant Envelope
Similarly to FSK, LoRa is a constant envelope modulation scheme. This
means that the amplitude level of the signal is constant throughout its
length, therefore the data contained within the signal is not related to its am-
plitude level, making it robust against possible nonlinear distortion caused
by power amplifiers. As a result, we can use highly efficient non-linear power
amplifiers. For reference, non constant envelope signals require a fully linear
power amplifier, which is not ideal as this type of power amplifier tends to
be very inefficient.
Robustness
Due to its asynchronous nature, a LoRa signal is very resistant to both in-
band and out-of-band interference mechanisms. The LoRa symbol period
is longer than the usual short-duration burst of FHSS systems, providing
excellent immunity to interferences caused by Pulse Amplitude Modulation,
which consists of several pulses of short duration that vary in amplitude.
LoRaWAN Overview 31
Fading Resistant
Thanks to the chirp pulse being relatively broadband, the LoRa signal is
resistant to multipath and fading.
Doppler Resistant
The Doppler effect introduces a relatively negligible shift in the time axis of
the baseband signal, which makes LoRa ideal for mobile data communica-
tions.
Typically, we have to take into account the gain of the antennas and the loss
caused by the connectors, but we are going to ignore these factors to simplify
the example. It is also worth noting, when talking about LoRa modulation,
the main limiting factor is the SNR rather than the SIR. This is caused
by LoRa’s robustness against interference but very low power transmission,
making it vulnerable to noise.
Then we need to know the formula for the receiver sensitivity, which
specifies the minimum signal power in order to be demodulated by the re-
ceiver:
Where:
NF is the receiver noise figure (dB).
• SNR = -20.
• NF = 6dB.
• Bandwidth = 125kHz.
This means we can lose about 150dB between the transmitted signal and
the received signal and the receiver would still be able to demodulate it. In
fact, if we take the free space path loss formula:
Where:
We obtain that the signal could travel almost 800km and the receiver
would still manage to demodulate it. Obviously, this is too good to be
true, because in reality we do not work with free space and there are other
effects like multipath, Fresnel zones, fading, etc., that also affect our signal.
Nonetheless, this example showcases LoRa’s capabilities and why it is a
strong option for most of the low-power networks.
2.2 LoRaWAN
The following section is based on the LoRaWAN specification [2] and Re-
gional Parameters [7] defined by the LoRa Alliance 1 .
2.2.3 Security
This section will briefly explain the security fundamentals of LoRaWAN.
The main principle is that LoRaWAN makes use of three different 128
bits keys:
• Network session key. Derived from the Application Key. This key
is known by the network in order to prove and verify the integrity and
authenticity of the packets.
• Maximum of 30 seconds of uplink time on air, per day and per device.
For now, this policy is not enforced. In fact, we will most likely not
respect it while testing our devices. Nevertheless, it should be respected
after the testing phase is over.
Chapter 3
In this chapter we will present and analyze the different possibilities we have
to build a LoRaWAN gateway and a mote. This analysis will involve several
parameters such as hardware requirements, price and TTN support among
others, which will help us choose the best option for the project.
3.1 Gateways
This section will go through the different LoRaWAN gateways available and
compare their characteristics such as price, hardware requirements, software
requirements, LoRaWAN compatibility, etc. To be precise, we will study the
following gateway possibilities:
• Single-channel gateway.
39
40 3.1. Gateways
Hardware Requirements
In order to build this gateway we need the following items:
• Raspberry Pi (any model).
• Radio frequency transceiver.
• Antenna.
From this list we can see why this is the cheapest option, as it requires very
little hardware, at the cost of only being able to listen on a single channel.
Cost Estimate
Table 3.1 shows the estimated of the cost for each hardware component and
the total cost they add up to.
For a total cost of about 50 e, this is a very affordable gateway.
1
SX1272 used as reference.
2
3dBi and 868MHz antenna as reference.
State of the Art 41
Software
There is one repository with all the code needed for the gateway [12], which
consists of a C++ program you have to run as root in the Raspberry Pi
as well as some configurable parameters. Unfortunately, this repository is
deprecated and no longer up to date to use on TTN.
Supported Features
The following list contains the most important features that are fully devel-
oped for this type of gateway.
• Able to listen on configurable frequency.
• Spreading factors from SF7 to SF12.
• Status updates.
• Can forward to two routers.
Main Advantages
According to the previous points, these are the main advantages of the single
channel LoRaWAN gateway.
• Very cheap components.
• Easy to build.
• Great for getting started with LoRaWAN.
Final Notes
Due to its single channel nature, it has less than 2% of the capacity of a real
multi-channel gateway, in addition to not being supported by TTN and not
fully LoRaWAN compatible.
In conclusion, this type of gateway is best used for testing and educa-
tional purposes.
42 3.1. Gateways
Hardware Requirements
This is the hardware equipment needed to build the gateway:
• Embedded Linux board.
• Antenna.
Cost Estimate
Table 3.2 shows the cost estimate for the multi-channel DIY gateway.
3
Raspberry Pi 3 model B used as reference.
4
iC880A antenna as reference.
5
Double female jumper wire as the reference.
State of the Art 43
Software
Main Advantages
These are the main advantages of the DIY multi-channel LoRaWAN gate-
way:
Final Notes
Hardware Requirements
This gateway comes fully built as a pack. All the necessary equipment
needed for the set up is included in the package.
Cost Estimate
As mentioned before, the gateway is shipped as one pack, which costs 300 e.
Since we do not need anything else to set up the gateway, the price of the
pack accounts for the total cost associated to this gateway.
Software
Same as the hardware, the software comes already set up, meaning that we
do not have to run any script or implement any program in order for the
gateway to start working.
In addition, the only process required is the registration of the gateway
over TTN, unless we use a private LoRaWAN network which does not make
State of the Art 45
Main Advantages
These are the main advantages of The Things Gateway.
• Easy to install.
Final Notes
It is a great option if you do not have the time to build your own gateway. On
top of that, the registration process over TTN is very easy and intuitive even
for someone not familiar with LoRaWAN. Furthermore, being especially
designed for TTN ensures an smooth experience when using TTN’s backend.
Overall, an interesting choice for an easy to install and use gateway. It
is also the most expensive option, although not by a large margin.
• MultiTech Conduit.
• Lorrier LR2.
Although they would be valid options for our project, we will soon see
that their high price will be reason behind discarding them.
MultiTech Conduit
This gateway supports multiple protocols, so in order to use it for LoRa
we also have to buy the appropriate LoRa cards. This results in quite a
expensive LoRaWAN gateway. The price for the gateway itself is 442 e,
while the price for one LoRa card is 159 e. This gives us a price of 601 e,
which is almost double the price of The Things Gateway.
46 3.2. Motes
Lorrier LR2
The Lorrier gateway is fairly similar to the DIY multi-channel gateway, as
it is built using using an iC880A concentrator and a BeagleBone Green.
Moreover, it is designed to be an outdoors gateway, thus it is enclosed in an
IP66 metal case. Lastly, it has a price of 575 e, which is quite high but it
includes the price of the enclosure as well.
3.2 Motes
We will now go through the different possibilities for motes, and choose the
one that best suits our project.
Most importantly, we have to remember that we are looking for a low-
cost option, so price will be a very important factor when choosing the
mote.
Furthermore, similarly to the gateways we will only discuss the two main
types of LoRaWAN motes:
Hardware Requirements
These are the hardware pieces we need to build the mote:
• Antenna.
• Micro-USB cable.
• Breadboard or shell.
State of the Art 47
Table 3.3: Cost estimate for the ESP8266 chip based mote.
Cost Estimate
According to the hardware required, Table 4.4 shows the estimate of the
price for this mote.
At the expense of having to program it ourselves, this mote comes at
quite a low price.
Software
For this mote we have to implement the software ourselves, however it is easy
to find already programmed LoRaWAN examples made by the community.
These examples together with the LMIC-Arduino library, which contains all
the necessary functions to set up the LoRaWAN MAC, make the software
implementation much more manageable.
Main Advantages
Here we are going to list the strong points of this type of mote.
• Very affordable.
• Small size.
While it does not have many advantages, the very low price is what we
are looking for, which outweighs its disadvantages.
Final Notes
This is the mote we have chosen for the project, the main reason being its
price. Although we have to program it ourselves, the minimal hardware
requirements makes this mote the ideal candidate for the low-cost mote we
are looking for.
6
Board Wemos D1 Mini used as reference for the price.
7
Dragino LoRa BEE used as reference for the price.
48 3.2. Motes
Table 3.4: Cost estimate for the LoRaWAN certified chip based mote.
Hardware Requirements
Here is the list of the different hardware elements required for this type of
mote:
• LoRaWAN Chip.
• Antenna.
• Breadboard or shell.
Cost Estimate
Table 3.4 shows an estimate of the price based on the hardware requirements.
In summary, it is significantly more expensive than the previous option,
which makes it the main disadvantage for this type of mote.
Software
This type of motes come wit that a fully integrated LoRaWAN chip, meaning
we do not have to implement any kind of program ourselves. Moreover, some
chips may even include a text based interface for configuration purposes.
8
RN2483 used as reference for the price.
9
Dragino LoRa BEE used as reference for the price.
State of the Art 49
Main Advantages
The take away features of this type of mote.
Final Notes
In conclusion, the main strong point is the easy integration as counterpart
for the higher price. Therefore, it is very reasonable choice to minimize
development time. However, its higher price makes it unappealing for our
project, since we are committed to building a mote with very low budget.
Chapter 4
In this chapter we will first describe the different stages involved in the
development of this project, followed by a Gantt chart that shows the time
required for each one of them.
In addition, this chapter will also contain an estimate for the total cost
of the project, which be obtained by calculating four independent budgets:
Lastly, we will add those four budgets together to obtain the total esti-
mated cost for the project as a whole.
51
52 4.1. Development Stages
4.1.3 Design
Aiming to meet the previously defined specifications, we will work on choos-
ing the different hardware and software elements.
4.1.4 Implementation
Once the design phase is completed, we will proceed with its implementation.
4.1.5 Testing
Lastly, we are now able to test our devices and ascertain that they work as
we expected.
4.1.6 Documentation
This phase consists on the writing of this document and, although it is
placed as the last phase, is carried out in parallel alongside the rest of the
previous phases.
Gathering all of the previous data, we have presented the results in Table
4.2, where we obtain a total cost of 15,580 e.
General purpose
The items in this section will be used throughout the entirety of the project:
• Personal laptop.
The result from this category is shown in Table 4.3. From this table,
700 e is the total cost obtained.
Planning and Cost Estimate 55
Mote
The following list presents us with the required materials to build the low-
cost mote:
• Wemos D1 Mini.
• Micro-USB cable.
• Breadboard or shell.
Gateway
Here we list what we need to build the LoRaWAN gateway:
• iC880A concentrator.
• Antenna.
Table 4.5 shows the result for the cost of the gateway, with the total cost
being 249.65 e.
Concept Cost
Human 14,480 e
General purpose 87.74 e
Hardware mote 26.9 e
Hardware gateway 249.65 e
Total 14,844.29 e
Finally, from Table 4.6, the total cost estimated for this project is
14,844.29 e, FOURTEEN THOUSAND EIGHT HUNDRED AND FORTY
FOUR WITH TWENTY NINE EUROS.
1
Double male jumper wire used as reference.
2
Assuming we already have a laptop available, which is needed for setting up the
mote’s software.
3
Raspberry Pi 3 model B used as reference.
4
iC880A antenna used as reference.
5
Double female jumper wire used as reference.
6
Cost for the initial set up of the Raspberry Pi (Ethernet/HDMI cable, external key-
board...) not included.
Chapter 5
Requirement Specifications
This chapter will talk about the functional and non-functional requirements
the gateway and the mote have to fulfill in order for the project to be
considered successful.
Furthermore, we have to remember that the final destination of the data,
sent by the mote and forwarded by the gateway, is an application. Simi-
larly to the mote and the gateway, the application also has to meet some
requirements in order for us to recover useful information. Therefore, the
application requirements will also be described in this chapter.
5.1 Gateway
Here we define the requirements we aim to meet with the gateway once it is
working. Although some of the requirements are not fully necessary for the
gateway to work, all of them should be met for a quality experience when
using it.
• Able to forward the received packets over to TTN via either WiFi or
Ethernet, in order to reach the application.
• Wide coverage.
57
58 5.2. Mote
5.2 Mote
In this section we will list the requirements our mote should meet after the
implementation phase is done. Again, we do not have to meet all of them for
the mote to work, in fact it would be fine for testing purposes not to meet
some of them. However, we want to build a mote that closely resembles one
that would be used in a real scenario, hence why all of the requirements
should be met.
• Will have the option to change the spreading factor used, as to adapt
to different distances and data rates
5.3 Application
Lastly, here we list the requirements that the application must meet. More-
over, it is important that the application meets these basics requirements,
as that will help us perform the testing phase properly.
Design
This chapter will explain the process followed to design both the gateway
and the mote, describing the different hardware elements employed as well
as the reasoning behind them.
In addition, we have to keep in mind that the goal of this design process
is to build a mote and a gateway that meet the requirement specifications
defined for them in the previous chapter.
6.1 Mote
First, we will start with the design of the mote. Note that the design does
not include any type of sensor, as it is not needed to test that everything
works together. In the case we wanted to add a sensor, we would have to
perform the necessary wiring to the development board and adapt the code,
so that the payload contains the information gathered by the sensor.
These two boards are very cheap and they both come with the ESP12
chip, which contains the WiFi module ESP8266. However, this chip can be
programmed to work with LoRa so we can use it to implement the MAC
layer.
From this point and although both boards are very similar and cost
about the same price, we decided to go with the Wemos D1 Mini because
61
62 6.1. Mote
of its fairly smaller size: 34.2mm long and 25.6mm wide as opposed to the
49mm long and 24.5mm wide NodeMCU.
On a side note, we could have minimized the price even further if we just
chose to work with the ESP8266 chip by itself, but we felt the board was
already cheap enough, thus working with the chip by itself was not worth
the extra hassle.
This is the part in charge of taking the packets and modulate them using
LoRa. We have a few different options for it, Figure 6.3.
Firstly, since we are in Europe, we need a module that supports the
868MHz frequency range, so we have to discard both RFM96W and RFM98W.
Secondly, the difference in price between the modules is almost ne-
glectable, so we are looking for the one with the best performance. From
Figure 6.3 we can see that the module RFM95W supports all five spreading
factors and has the best estimated sensitivity, so it will be the one we choose.
Finally, now that we have decided that we will use the RFM95W module,
we need to find a chip with it. In our case we have found the chip SX1276,
by Semtech.
6.1.3 Antenna
An antenna is the last part we need to have a functional mote, whose func-
tions consist of transmitting and receiving the signal over the 868MHz fre-
quency range.
Since we need the chip SX1276, we have decided to use the transceiver
module LoRa BEE, which is based on said chip and it comes with an 868MHz
antenna, Figure 6.4.
With this final piece we now have all of the necessary hardware to build
our mote. From this point, we only have to properly wire the pieces together,
implement the MAC layer and we will have a working mote.
64 6.2. Gateway
6.2 Gateway
In the State of the Art chapter, we decided to build the DIY multi-channel
Raspberry Pi gateway and therefore we will need the following:
• Concentrator.
• Antenna.
In our case we will use the Raspberry Pi 3 model B, which is well over the
minimum requirements but it will help improve the overall performance of
the gateway.
6.2.2 Concentrator
6.2.3 Antenna
6.2.4 Enclosure
Since we want the gateway to be outside for maximum coverage, we need
to make sure it does not get damaged by the weather, birds, insects or
dust. However, Granada is not a very rainy city, thus we do not need an
extreme water proof enclosure. Nevertheless, it is important that we choose
the adequate level of protection according to our zone, as it is a big factor
in our gateway’s useful life and performance. Therefore and taking all of
those factors into account, we have chosen an IP54 enclosure:
1. The first number in IP54, 5, stands for the level of protection against
small objects. In this case, level 5 means complete protection against
contact and dust deposit.
Finally, we feel that this level of protection is enough for our zone. How-
ever, we should monitor the state of the gateway and make sure the enclosure
is working as intended.
Chapter 7
Implementation
This chapter will describe the steps followed to set up the mote, the gateway
and the application. Thus, it will include the process between having the
different hardware elements by themselves and everything working together
and fully operational.
Also, we have to set up the application before the mote, since we will
need some parameters from the application to implement the mote.
7.1 Application
Here we will go through the process of creating our application, which will
be linked to our mote in order to receive and decipher the packets. Since
we are making use of TTN, we have to create the application through their
website.
To start off, we need to register an account before we can create the
application. Then, after logging in with said account, we navigate to the
console of TTN: https://console.thethingsnetwork.org/, where we have the
option to either register a gateway or create an application. Right now we
want to create an application, so we click on ”Applications”. This will take
us to the application manager, but we do not have any applications yet so
we click on ”add application”.
When creating the application, we have to fill in some fields which will
help describe and identify our application. An example configuration is
shown in Figure 7.1.
At this point our application is ready, however we are not done yet
because we have to link at least one device to it. In order to link a device
we navigate to the ”Devices” tab and click on ”register device”. Here we
only have to fill in the ”Device ID” field, as the rest of the fields will be
generated automatically. Example configuration shown in Figure 7.2.
To wrap up, the last thing we have to do is enter the ”Settings” tab in
our device and change the ”Activation Method” from OTAA to ABP, as it
67
68 7.1. Application
will be the activation method that we will use on the mote. After this last
step, we have generated all the keys and parameters we will later need to
set up the mote.
Finally, as a suggestion and only during testing, we should disable the
”Frame Counter Checks” option, so that our application picks up all the
packets after we reset the transmission.
And that is it, we are done. Our application is ready to receive packets
from our mote through TTN.
7.2 Mote
In this section we will describe how to set up both the hardware and the
software for the mote. The goal here is to end up with a fully functional
transceiver capable of sending a customizable payload over the LoRa phys-
ical layer.
7.2.1 Wiring
Although we could start with the software first, we are going to begin build-
ing the mote by wiring the different pieces together.
First thing we have to do is identify the pins for both the Wemos and
LoRa BEE, Figures 7.3 and 7.4 respectively.
Secondly, now that we know the pins layout, we will connect the ground
and power pins, Table 7.1.
Then we will connect the serial peripheral interface bus, by connecting
the MISO, MOSI, SCK and SS pins together, Table 7.2.
Finally, we will connect the I2C bus, Table 7.3.
70 7.2. Mote
Now, we should have everything properly connected and waiting for the
software to be implemented. However, we encountered a problem during the
wiring process. The distance between the LoRa BEE pins is different from
the distance between the pins in the breadboard. Thus, we had to figure
out a different way to connect the wires. As a result, we ended up welding
the wires between the Wemos board and the LoRa BEE, Figure 7.5.
7.2.2 Software
First of all, we need to know what language we are going to use. The
Wemos D1 Mini development board supports Arduino, NodeMCU and Mi-
croPython. We are familiar with the Arduino language, thus it will be the
one will be using.
Secondly, it is not viable and out of the reach of this project to implement
the LoRaWAN MAC layer from scratch, therefore we will use the Arduino-
LMIC library [20] version 1.5, which is based on the LMIC library developed
by IBM for C language.
Once we have the library downloaded and added to Arduino we can start
our program but, again, we do not have to start from scratch as the library
also includes some LoRaWAN demo programs that we can use as a starting
point. To be specific, it comes with two LoRaWAN examples:
72 7.2. Mote
Either of the examples can be used as a valid starting point, but ABP
is slightly simpler to implement and the one we will use. Then, with our
Arduino sketch open, we have to configure some parameters:
Most of the parameters are located at the start of the sketch. The values
we need to use for the network session key, the application session key and
the device address were generated by the device we previously registered for
the application. Therefore, we have to go back to the TTN console and copy
those values into the Arduino sketch using the right hexadecimal format.
We can see an example configuration in Figure 7.6. Also, the entire
Arduino sketch is available in Appendix A at the end of this document.
As for the pin map, Figure 7.7 shows the Arduino code that corresponds
to the wiring configuration we did earlier. Also, when configuring the pin
map, we have to take a few things into consideration:
• The names on the left correspond to pins on the transceiver, while the
numbers refer to GPIO number on the Wemos side. For example, 15
means GPIO15 which corresponds to D8.
Implementation 73
• We do not need to specify the pins for the SPI bus, as they are always
the same.
Finally, once we are done configuring all the parameters, we verify the
sketch to make sure we have not made any mistakes, and then upload it
to the Wemos board. Once this is done, we will now have both end points
ready, the mote and the application, and at this point we are only missing
the gateway for a fully operational LoRaWAN.
7.3 Gateway
7.3.1 Wiring
Wiring the Raspberry to the concentrator is very similar to the wiring we
performed for the mote: we have to connect the 5V power input, ground and
the SPI bus. Therefore, in this case we will list all the connections directly
in Table 7.4.
74 7.3. Gateway
Table 7.4: Pin connections between the Raspberry Pi and the concentrator.
And that is it for the wiring between the Raspberry Pi and the concen-
trator, Figure 7.8. The next step will be to set up the software.
7.3.2 Software
The first thing we have to do is install an operative system in the Raspberry
Pi using the SD card. For this step we have chosen the Raspbian Jessie Lite
operative System.
Following the installation of the operative system, we need to enter the
following command:
Here we can enable the SPI (”Interfacing options”) and expand the file
system (”Advanced options”).
Now, we should make sure our system is up to date with the commands:
At this point, we can now install the software for the gateway. Thank-
fully, TTN provides us with a script that installs everything for us [14]. We
can make use of this script by typing these commands:
1 $ git clone -b spi https :// github . com / ttn - zh / ic880a - gateway . git ~/
ic880a - gateway
2 $ cd ~/ ic880a - gateway
3 $ sudo ./ install . sh spi
7.3.3 Registration
Next, we have to register our gateway on TTN before it is able to forward
packets to TTN. For this, we have to go again to the TTN console, click
76 7.3. Gateway
7.3.4 Enclosure
To wrap up, we are going to mount the gateway in the enclosure in order to
keep it safe from insects, birds, rain, etc. But before doing so, we have to
make two holes:
• One for the power supply. The gateway would not be able to do much
without a power supply.
Implementation 77
• Another one for the Ethernet cable. This one is optional, but in
case we need to reconfigure our gateway for whatever reason we will
not have to open the enclosure. Alternatively, we could set up the
”wpa supplicant” on the Raspberry Pi so we can access it via WiFi,
however the enclosure might weaken the WiFi signal to the point where
it barely reaches outside the enclosure.
As seen in Figure 7.8, the Ethernet cable barely fits in the enclosure and
thus, cannot be turned in order to connect it to the Raspberry Pi. Due to
this, we bought a right angle USB connector.
7.3.5 Location
Finally, we are going to place the gateway on high place so that it has better
reach. For this purpose, we have placed the gateway on the terrace of the
fifth floor of the school. Although we would like it to be even higher, the
gateway will stay there during all of the testing process.
Chapter 8
79
80 8.1. Sending Data to the Application
1 48 65 6 c 6 c 6 f 2 c 20 77 6 f 72 6 c 64 21
1 Hello , world !
8.2.1 Indoors
The indoors test will consist on transmitting packets with the mote during
10 minutes on each floor of the school, except for floor 2 which will be
explained on its own section. We will start on floor 5 and end on floor -1,
for a total of seven floors. Moreover, we will store the RSSI level of each
packet received during those 10 minutes. Lastly, these values will be used
to make an RSSI histogram for each floor.
However, we cannot work directly with the data received on the appli-
cation, unless we manually write down the values. Therefore, we use an
MQTT client, Mosquitto version 3.1 in our case, to store the data so that
we can work with it. By looking at the API provided by TTN, we use the
following command to store the data:
Where:
Once we have the data stored in a log file, we need to, somehow, store
the RSSI values in an array in Matlab. We also have to keep in mind that
we have stored much more data aside from the RSSI, such as SNR, airtime,
channel, etc. Example of log file in Figure 8.5.
The procedure to get the RSSI array in Matlab involves opening the log
file with excel in order to separate the different fields in different columns
and, once that is done, we can use Matlab to read a specific column of the
excel file to store it as an array. The code for the Matlab scripts can be
found in Appendix B at the end of this document.
Lastly, remember the gateway is located on the fifth floor, as we men-
tioned in the implementation chapter.
Floor 5
We start our test on floor 5, Figure 8.6. We can see that the most common
RSSI values are -57 and -60dBm with 11 and 9 appearances respectively.
These RSSI values are not that good considering we are almost next to
the gateway. This might be due to the location of the gateway, which is
placed right in front of the metallic grid that covers the entrance to the ter-
race. This grid might be deteriorating the received signal and thus, lowering
the RSSI level.
Floor 4
On floor 4, Figure 8.7, the most common RSSI values are -51 and -52dBm
with 14 and 13 appearances respectively, which are better values than on
floor 5.
These measurements were taken slightly closer to the gateway (on the
horizontal plane) than the ones taken on floor 5. That small deviation plus
the metallic grid not being directly in the way is what might be causing the
RSSI levels to better here than on floor 5.
Floor 3
On floor 3, Figure 8.8, the most common RSSI values are -81 and -79dBm
with 12 and 7 appearances respectively.
84 8.2. Gateway Coverage
Floor 2
On floor 2, Figure 8.9, the most common RSSI values are -90, -91, -97 and
-99dBm with 69, 58, 58 and 58 appearances respectively.
We have a larger sample size on this floor because one of my supervisors
has his office on this floor, so he was able to leave the mote sending packets
for about 2 hours. Additionally, the test for this floor was performed on a
different day than the rest of the floors.
We expected the histogram to be more similar to a Gaussian distribution
with this large sample size. However, that is not what happened as the there
are several RSSI levels evenly distributed. We think this is caused by the
channel hopping that occurs when using LoRaWAN, leading to different
RSSI levels for each channel.
Floor 1
On floor 1, Figure 8.10, the most common RSSI values are -81 and -87dBm
with 11 and 10 appearances respectively.
Although there are now four floors between us and the gateway, the
packets are still being received with acceptable RSSI levels. In fact, these
packets have a slightly better RSSI than the ones received from floor 2. We
86 8.2. Gateway Coverage
think this might be caused by the small sample size and the fact that the
measurements on floor 2 were taken on a different day.
Floor 0
On floor 0, Figure 8.11, the most common RSSI values are -87 and -84dBm
with 9 and 8 appearances respectively.
Despite being one floor below, we have about the same RSSI levels as on
floor 4. This might be due to sending the testing packets from a different
point on the floor, as I did not want to obstruct the stairs to the library on
floor 1. Therefore, I ended up taking the measurements on a different point
that was closer to the gateway on the horizontal plane.
Floor -1
On floor -1, Figure 8.12, the most common RSSI values are -101 and -97dBm
with 9 and 7 appearances respectively.
Finally, on the last floor, there are 6 floors between us and the gateway
and the packets are still being received just fine. We also have to keep in
mind that there is concrete between each floor.
88 8.2. Gateway Coverage
8.2.2 Outdoors
As the second part of this coverage test, we are going to perform it outside.
For this, we could use the same procedure we used for the indoors part,
however we found an application called ”TTN Mapper”, which will yield us
more elegant results.
For this part, all we need is a phone with and GPS receiver and Android
operative system (version 4.03 or higher), as well as a LoRaWAN transmit-
ter. Of course, the gateway has to be running too. To be more specific, we
used:
1. We open the application and link our mote to it, either manually or
by logging on our TTN account and selecting the device.
2. We plug in the mote and start transmitting, while keeping the phone
close to it.
Figure 8.13: Results of the outdoor coverage testing on the TTN Mapper
website [3].
Now, we can start moving around with the mote and the TTN Mapper
will display the position of our mote, by using the GPS of our phone, and
the RSSI level obtained from that position. Also, during this test we used
SF7 for several reason:
Once we are done mapping, we can see the results on Figures 8.13 and
8.14, obtained from the TTN Mapper website [3]. In these figures, the point
with the TTN symbol represents the position of our gateway.
The furthest point measured is about 550m away from the gateway and
was still received within the greater than -100dBm range.
Figure 8.14: Zoomed in results of the outdoor coverage testing on the TTN
Mapper website [3].
Testing and Results 91
Figure 8.17: Spectrum centered on 868MHz when packets are being trans-
mitted.
Testing and Results 93
Figure 8.18: USB Tester after measuring for 32 minutes during worst case
scenario.
1. First test will measure the mote during the worst case scenario. This
is, when the mote is transmitting every few seconds, limited only by
the duty cycle and using SF7.
2. Second test will repeat these measurements but for a more realistic
scenario. This is, when the mote transmits a packet every five minutes
in addition to disabling WiFi on the ESP8266, since we are not making
use of it.
Figure 8.19: USB Tester after measuring for one hour during realistic sce-
nario.
60
P owerW orstCase = 29 ∗ 10−3 ∗ 5.09 ∗ = 0.2768W (8.1)
32
From this result we can draw the conclusion that this mode is not rec-
ommended for a battery dependent mote, as it is slightly power intensive.
For reference, a 10,000mAh battery would only last for a little over a week.
Now that the WiFi module is turned off, we proceed to measure the
power consumed for one hour, Figure 8.19. For some reason the timer shows
49 minutes, but the actual measuring time was one hour.
60
P owerRealistic = 8 ∗ 10−3 ∗ 5.08 ∗ = 0.0406W (8.2)
60
Testing and Results 95
From these results, it is clear that in a realistic scenario and with some
optimizations, the power consumption is extremely low. Using the same
reference we used for the worst case scenario, a 10,000mAh battery would
last for about 52 days. Also, it is worth noting that we could reduce the
power consumption even further by doing the following:
• Working with the ESP12 chip by itself without the Wemos board.
• By using the Deep Sleep mode available on the ESP8266 chip, which
consumes about 60 µA [21], and activating it in between transmissions.
Chapter 9
Conclusions
In this final chapter, we will draw our conclusions based on what we have
learned throughout the whole process of carrying out this project.
9.1 LoRa
LoRa works really well despite the density of buildings surrounding the
gateway. Accordingly, we would expect LoRa to work even better on open
environments, so it is better suited for agricultural purposes.
Furthermore, it surpasses WiFi range without a doubt. For reference,
and average WiFi antenna might reach about 30 meters.
97
98 9.4. Low Cost Mote
top of that, the enclosure of our gateway is black. Right now the gateway is
not directly exposed to the sun most of the day and it reaches about 70o C
(measurement obtained from the Raspberry Pi). Therefore, if we want to
place it somewhere else, we have to be careful with the sun exposure.
All in all and despite that temperature issue, the gateway is working
extremely well while also being fairly simple to build.
99
100 BIBLIOGRAPHY
101
Appendix A
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright ( c ) 2015 Thomas Telkamp and Matthijs Kooijman
3 *
4 * Permission is hereby granted , free of charge , to anyone
5 * obtaining a copy of this document and accompanying files ,
6 * to do whatever they want with them without any restriction ,
7 * including , but not limited to , copying , modification and
redis tributi on .
8 * NO WARRANTY OF ANY KIND IS PROVIDED .
9 *
10 * This example uses ABP ( Activation - by - p e rs on al i sa ti on ) , where a
DevAddr and
11 * Session keys are preconfigured ( unlike OTAA , where a DevEUI and
12 * application key is configured , while the DevAddr and session keys
are
13 * assigned / generated in the over - the - air - activation procedure ) .
14 *
15 * Note : LoRaWAN per sub - band duty - cycle limitation is enforced (1% in
16 * g1 , 0.1% in g2 ) , but not the TTN fair usage policy .
17 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
18
19 # include < lmic .h >
20 # include < hal / hal .h >
21 # include < SPI .h >
22
23 // LoRaWAN NwkSKey , network session key
24 // This is the default Semtech key , which is used by the early
prototype TTN
25 // network .
26 static const PROGMEM u1_t NWKSKEY [16] = { 0 x55 , 0 xE5 , 0 xF4 , 0 xFE , 0 xDF
, 0 xB4 , 0 xD7 , 0 x43 , 0 xFD , 0 xD6 , 0 x65 , 0 xB3 , 0 xD9 , 0 xAE , 0 xD1 , 0 xAD
};
27
28 // LoRaWAN AppSKey , application session key
29 // This is the default Semtech key , which is used by the early
103
104
prototype TTN
30 // network .
31 static const u1_t PROGMEM APPSKEY [16] = { 0 xD9 , 0 x44 , 0 x61 , 0 x6B , 0 x0D
, 0 xC1 , 0 x42 , 0 x8A , 0 x97 , 0 x55 , 0 xF9 , 0 x7F , 0 x80 , 0 xFE , 0 x24 , 0 x70
};
32
33 // LoRaWAN end - device address ( DevAddr )
34 static const u4_t DEVADDR = 0 x260111CE ;
35
36 // These callbacks are only used in over - the - air activation , so they
are
37 // left empty here ( we cannot leave them out completely unless
38 // DISABLE_JOIN is set in config .h , otherwise the linker will complain
).
39 void os_getArtEui ( u1_t * buf ) { }
40 void os_getDevEui ( u1_t * buf ) { }
41 void os_getDevKey ( u1_t * buf ) { }
42
43 static uint8_t mydata [] = " Hello , world ! " ;
44 static osjob_t sendjob ;
45
46 // Schedule TX every this many seconds ( might become longer due to
duty
47 // cycle limitations ) .
48 const unsigned TX_INTERVAL = 6;
49
50 // Pin mapping
51 const lmic_pinmap lmic_pins = {
52 . nss = 15 ,
53 . rxtx = LMIC_UNUSED_PIN ,
54 . rst = LMIC_UNUSED_PIN ,
55 . dio = {4 , 5 , LM IC _ UN US ED _ PI N } ,
56 };
57
58 void onEvent ( ev_t ev ) {
59 Serial . print ( os_getTime () ) ;
60 Serial . print ( " : " ) ;
61 switch ( ev ) {
62 case E V_ SC AN _ TI ME OU T :
63 Serial . println ( F ( " E V _S CA N_ T IM EO UT " ) ) ;
64 break ;
65 case E V_ BE AC O N_ FO UN D :
66 Serial . println ( F ( " E V _B EA CO N _F OU ND " ) ) ;
67 break ;
68 case E V _ B E A C O N _ M I S S E D :
69 Serial . println ( F ( " E V _ B E A C O N_ M I S S E D " ) ) ;
70 break ;
71 case E V _ B E A C O N _ T R A C K E D :
72 Serial . println ( F ( " E V _ B E A C O N _ T R A C K E D " ) ) ;
73 break ;
74 case EV_JOINING :
75 Serial . println ( F ( " EV_JOINING " ) ) ;
76 break ;
77 case EV_JOINED :
78 Serial . println ( F ( " EV_JOINED " ) ) ;
79 break ;
80 case EV_RFU1 :
81 Serial . println ( F ( " EV_RFU1 " ) ) ;
82 break ;
83 case EV_JOIN _FAILED :
84 Serial . println ( F ( " EV_JO IN_FAIL ED " ) ) ;
85 break ;
Arduino Program for the Mote 105
86 case E V _ R E J O I N _ F A I L E D :
87 Serial . println ( F ( " E V _ R E J O I N _F A I L E D " ) ) ;
88 break ;
89 case EV_TXCOMPLETE :
90 Serial . println ( F ( " EV_TXCOMPLETE ( includes waiting for RX
windows ) " ) ) ;
91 if ( LMIC . txrxFlags & TXRX_ACK )
92 Serial . println ( F ( " Received ack " ) ) ;
93 if ( LMIC . dataLen ) {
94 Serial . println ( F ( " Received " ) ) ;
95 Serial . println ( LMIC . dataLen ) ;
96 Serial . println ( F ( " bytes of payload " ) ) ;
97 }
98 // Schedule next transmission
99 o s _ s e t T i m e d C a l l b a c k (& sendjob , os_getTime () + sec2osticks (
TX_INTERVAL ) , do_send ) ;
100 break ;
101 case EV_LOST_TSYNC :
102 Serial . println ( F ( " EV_LOST_TSYNC " ) ) ;
103 break ;
104 case EV_RESET :
105 Serial . println ( F ( " EV_RESET " ) ) ;
106 break ;
107 case EV_RXCOMPLETE :
108 // data received in ping slot
109 Serial . println ( F ( " EV_RXCOMPLETE " ) ) ;
110 break ;
111 case EV_LINK_DEAD :
112 Serial . println ( F ( " EV_LINK_DEAD " ) ) ;
113 break ;
114 case EV_LINK_ALIVE :
115 Serial . println ( F ( " EV_LINK_ALIVE " ) ) ;
116 break ;
117 default :
118 Serial . println ( F ( " Unknown event " ) ) ;
119 break ;
120 }
121 }
122
123 void do_send ( osjob_t * j ) {
124 // Check if there is not a current TX / RX job running
125 if ( LMIC . opmode & OP_TXRXPEND ) {
126 Serial . println ( F ( " OP_TXRXPEND , not sending " ) ) ;
127 } else {
128 // Prepare upstream data transmission at the next possible
time .
129 L MI C_ se t Tx Da ta 2 (1 , mydata , sizeof ( mydata ) -1 , 0) ;
130 Serial . println ( F ( " Packet queued " ) ) ;
131 }
132 // Next TX is scheduled after TX_COMPLETE event .
133 }
134
135 void setup () {
136 Serial . begin (115200) ;
137 Serial . println ( F ( " Starting " ) ) ;
138
139 # ifdef VCC_ENABLE
140 // For Pinoccio Scout boards
141 pinMode ( VCC_ENABLE , OUTPUT ) ;
142 digitalWrite ( VCC_ENABLE , HIGH ) ;
143 delay (1000) ;
144 # endif
106
145
146 // LMIC init
147 os_init () ;
148 // Reset the MAC state . Session and pending data transfers will be
discarded .
149 LMIC_reset () ;
150
151 // Set static session parameters . Instead of dynamically
establishing a session
152 // by joining the network , precomputed session parameters are be
provided .
153 # ifdef PROGMEM
154 // On AVR , these values are stored in flash and only copied to RAM
155 // once . Copy them to a temporary buffer here , LM IC _s e tS es si o n
will
156 // copy them into a buffer of its own again .
157 uint8_t appskey [ sizeof ( APPSKEY ) ];
158 uint8_t nwkskey [ sizeof ( NWKSKEY ) ];
159 memcpy_P ( appskey , APPSKEY , sizeof ( APPSKEY ) ) ;
160 memcpy_P ( nwkskey , NWKSKEY , sizeof ( NWKSKEY ) ) ;
161 L MI C_ se t Se ss io n (0 x1 , DEVADDR , nwkskey , appskey ) ;
162 # else
163 // If not running an AVR with PROGMEM , just use the arrays
directly
164 L MI C_ se t Se ss io n (0 x1 , DEVADDR , NWKSKEY , APPSKEY ) ;
165 # endif
166
167 # if defined ( CFG_eu868 )
168 // Set up the channels used by the Things Network , which
corresponds
169 // to the defaults of most gateways . Without this , only three base
170 // channels from the LoRaWAN specification are used , which
certainly
171 // works , so it is good for debugging , but can overload those
172 // frequencies , so be sure to configure the full frequency range
of
173 // your network here ( unless your network a utoconf igures them ) .
174 // Setting up channels should happen after LMIC_setSession , as
that
175 // configures the minimal channel set .
176 // NA - US channels 0 -71 are configured automatically
177 L M I C _ s e t u p C h a n n e l (0 , 868100000 , DR_RANGE_MAP ( DR_SF12 , DR_SF7 ) ,
BAND_CENTI ) ; // g - band
178 L M I C _ s e t u p C h a n n e l (1 , 868300000 , DR_RANGE_MAP ( DR_SF12 , DR_SF7B ) ,
BAND_CENTI ) ; // g - band
179 L M I C _ s e t u p C h a n n e l (2 , 868500000 , DR_RANGE_MAP ( DR_SF12 , DR_SF7 ) ,
BAND_CENTI ) ; // g - band
180 L M I C _ s e t u p C h a n n e l (3 , 867100000 , DR_RANGE_MAP ( DR_SF12 , DR_SF7 ) ,
BAND_CENTI ) ; // g - band
181 L M I C _ s e t u p C h a n n e l (4 , 867300000 , DR_RANGE_MAP ( DR_SF12 , DR_SF7 ) ,
BAND_CENTI ) ; // g - band
182 L M I C _ s e t u p C h a n n e l (5 , 867500000 , DR_RANGE_MAP ( DR_SF12 , DR_SF7 ) ,
BAND_CENTI ) ; // g - band
183 L M I C _ s e t u p C h a n n e l (6 , 867700000 , DR_RANGE_MAP ( DR_SF12 , DR_SF7 ) ,
BAND_CENTI ) ; // g - band
184 L M I C _ s e t u p C h a n n e l (7 , 867900000 , DR_RANGE_MAP ( DR_SF12 , DR_SF7 ) ,
BAND_CENTI ) ; // g - band
185 L M I C _ s e t u p C h a n n e l (8 , 868800000 , DR_RANGE_MAP ( DR_FSK , DR_FSK ) ,
BAND_MILLI ) ; // g2 - band
186 // TTN defines an additional channel at 869.525 Mhz using SF9 for
class B
187 // devices ’ ping slots . LMIC does not have an easy way to define
Arduino Program for the Mote 107
set this
188 // frequency and support for class B is spotty and untested , so
this
189 // frequency is not configured here .
190 # elif defined ( CFG_us915 )
191 // NA - US channels 0 -71 are configured automatically
192 // but only one group of 8 should ( a subband ) should be active
193 // TTN recommends the second sub band , 1 in a zero based count .
194 // https :// github . com / T h e T h i n g s N e t w o r k / gateway - conf / blob / master / US
- global_conf . json
195 L M I C _ s e l e c t S u b B a n d (1) ;
196 # endif
197
198 // Disable link check validation
199 L M I C _ s e t L i n k C h e c k M o d e (0) ;
200
201 // TTN uses SF9 for its RX2 window .
202 LMIC . dn2Dr = DR_SF9 ;
203
204 // Set data rate and transmit power for uplink ( note : txpow seems
to be ignored by the library )
205 L MI C_ se t Dr Tx po w ( DR_SF7 ,14) ;
206
207 // Start job
208 do_send (& sendjob ) ;
209 }
210
211 void loop () {
212 o s_ ru nl o op _o nc e () ;
213 }
Appendix B
These are the scripts used to make the histograms shown on the ”Testing
and Results” chapter. Note that for these scripts to work the excel file must
be located in the same folder as the script.
109
110 B.4. Floor 2 Histogram
These are the Matlab functions used to perform the Spectrum Analysis test
in the ”Testing and Results” chapter.
113
114 C.1. Function That Captures and Stores the Spectrum
22 if ( numvarargs == 1)
23 b S p e c t r u m A n a l i z e r = varargin {1};
24 elseif ( numvarargs == 2)
25 b S p e c t r u m A n a l i z e r = varargin {1};
26 gain = varargin {2};
27 end
28 end
29
30 disp ([ ’ c en te r Fr eq ue n cy : ’ num2str ( ce nt er F re qu en c y ) ...
31 ’ , samplingRate : ’ num2str ( samplingRate ) ...
32 ’ , noSamples : ’ num2str ( noSamples ) ...
33 ’ , b S p e c t r u m A n a l i z e r : ’ num2str ( b S p e c t r u m A n a l i z e r ) ...
34 ’ , gain : ’ num2str ( gain ) ]) ;
35
36 % co nn e ct ed Ra d io s = findsdru ;
37 % if ( co n ne ct ed R ad io s (1) . Status == ’ Success ’)
38
39 m as te rC l oc kR at e = 20 e6 ; % Default value
40 s am pl es P er Fr am e = 10000; % 4096; % Default value
41
42 % if ( co n ne ct ed R ad io s (1) . Platform == ’ B210 ’)
43 % ma s te rC lo c kR at e = 20 e6 ; % For B210
44 % end
45 d e c i m a t i o n F a c t or = m as t er Cl oc k Ra te / samplingRate ;
46
47 % radio = comm . SDRuReceiver (...
48 % ’ Platform ’ , c on n ec te dR a di os (1) . Platform , ...
49 % ’ SerialNum ’ , c o nn ec te d Ra di os (1) . SerialNum , ...
50 % ’ CenterFrequency ’ , centerFrequency , ...
51 % ’ MasterClockRate ’ , masterClockRate , ...
52 % ’ DecimationFactor ’ , decimationFactor , ...
53 % ’ SamplesPerFrame ’ , samplesPerFrame , ...
54 % ’ OutputDataType ’ , ’ double ’ , ...
55 % ’ Gain ’ , gain ) ;
56
57 radio = comm . SDRuReceiver (...
58 ’ Platform ’ , ’ B210 ’ , ...
59 ’ SerialNum ’ , ’ 30 B56E1 ’ , ...
60 ’ C en te rF r eq ue nc y ’ , centerFrequency , ...
61 ’ M as te rC l oc kR at e ’ , masterClockRate , ...
62 ’ D e c i m a t i o n F a c t o r ’ , decimationFactor , ...
63 ’ S am pl es P er Fr am e ’ , samplesPerFrame , ...
64 ’ OutputDa taType ’ , ’ double ’ , ...
65 ’ Gain ’ , gain ) ;
66
67 rxLog = dsp . SignalSink ;
68 if ( b S p e c t r u m A n a l i z e r )
69 h S p e c t r u m A n a l y z e r = dsp . S p e c t r u m A n a l y z e r (...
70 ’ Name ’ , ’ Spectrum ’ ,...
71 ’ Title ’ , [ ’ Spectrum centered
at ’ num2str ( floor ( c e nt er F re qu en c y /1 e5 ) /10) ’ MHz ’
] , ...
72 ’ SpectrumType ’ , ’ Power density ’ ,...
73 ’ FrequencySpan ’ , ’ Full ’ , ...
74 ’ SampleRate ’ , samplingRate , ...
75 ’ YLimits ’ , [ -110 , -50] ,...
76 ’ SpectralAverages ’, 50 , ...
77 ’ FrequencySpan ’ , ’ Start and stop
frequencies ’ , ...
78 ’ StartFre quency ’ , - samplingRate /2 , ...
79 ’ StopFrequency ’ , samplingRate /2 ,...
80 ’ Position ’ , figposition ([50 30
Matlab Functions Used for the Spectrum Analysis 115
30 40]) ) ;
81 end
82
83 totalFrames = ceil ( noSamples / s am pl es P er Fr am e ) ;
84 for counter = 1: totalFrames
85 [ rxSig , len ] = step ( radio ) ;
86 if ( len > 0)
87 rxLog ( rxSig ) ;
88 if ( b S p e c t r u m A n al i z e r )
89 % Display received frequency spectrum .
90 h S p e c t r u m A n a l y z e r ( rxSig ) ;
91 end
92 end
93
94 if ( mod ( counter , debugPeriod ) == 0)
95 disp ([ ’ captured ’ num2str ( counter ) ’ frames ( out of ’
num2str ( totalFrames ) ’) ... ’ ]) ;
96 end
97 end
98 % end
99
100 data = rxLog . Buffer ;
101 len = length ( data ) ;
102
103 % Release all System objects
104 release ( radio ) ;
105 clear radio ;
1 % Spectrum from data saved from a USPR ( tested with NI 2901 , i . e . B210
)
2 % Syntax : s p e c t r u m F r o m D a t a ( < samplingRate >)
3 % Example : s p e c t r u m F r om D a t a ( ’ lora868 . mat ’ , 2 e6 )
4 function s p e c t r um F r o m D a t a ( filename , samplingRate )
5 debugPeriod = 100; % Show a message every ’ debugPeriod ’ frames
6
7 load ( filename ) ;
8
9 s am pl es P er Fr am e = 4096;
10 datalength = length ( data ) ;
11 totalFrames = floor ( datalength / sa mp le s Pe rF ra m e ) ;
12
13 h S p e c t r u m A n a l y z e r = dsp . S p e c t r u m A n a l y z e r (...
14 ’ Name ’ , ’ Spectrum ’ ,...
15 ’ Title ’ , ’ Spectrum ’ , ...
16 ’ SpectrumType ’ , ’ Power density ’
,...
17 ’ FrequencySpan ’ , ’ Full ’ , ...
18 ’ SampleRate ’ , samplingRate ,
...
19 ’ YLimits ’ , [ -110 , -50] ,...
20 ’ SpectralAverages ’, 50 , ...
21 ’ FrequencySpan ’ , ’ Start and stop
frequencies ’ , ...
116 C.2. Function That Displays the Spectrum