Before setting up all the roles, all of the participants including the professor or the laboratory technician must have a TTN account.
Administrator
The course professor or the laboratory technician should be set as the owner of the gateway or be the only collaborator with full access to all the features (presented in Figure 3.7).
Students
Depending on the goal of the lab session the administrator has to add each student´s account as a collaborator and give the desired permissions. Recommend permissions are:
Gateway location: View the exact location of the gateway
Gateway messages: View the traffic that occurs on the gateway
With these permissions, the student can see the incoming and outgoing traffic that goes through the Gateway and analyse the packets and every parameter that was shown in section 4.1.1.
Each student can create his/her own application or also the professor or the laboratory technician can create a unique application and assign collaborators to it. The second option is recommended when the number of end-devices is limited because each of the student can access the same device by being a collaborator of the application the device is registered to. The permissions that can be managed at the moment of the creation of a collaborator can be seen in Figure 3.8. The recommended permissions are:
Devices: View edit and add devices of the application
Settings: Manage the application settings and access keys
With these permissions the student can register an end-device and analyse uplink and downlink traffic and analyse the packets and every parameter that was shown in section 4.1.2. Furthermore, the student can send downlink messages and integrate other third party APIs.
CONCLUSIONS
In this master thesis, the LPWAN paradigm for the IoT connectivity has been introduced and in a more in-depth explanation LoRa technology has been described, which is a solution based on long-range, low-power consumption, radio links, that can have numerous transmission parameter combinations. A LoRaWAN environment has been developed with educational purposes where a student can learn the basic LoRa/LoRaWAN concepts in a practical matter. The student can benefit from a step by step guide where various parameters can be managed and analysed such as:
How to activate a gateway.
How to activate an end-device.
How to send Uplink/Downlink packet.
How to decode a LoRa packet.
How to analyse a LoRa packet.
Time and trace analysis.
Check link parameters and status.
Analysis of the SF impact
LoRa modulation is a physical layer whose main advantages are: high tolerance to interference thanks to the use of the spread spectrum modulation, long range transmissions in the order of kilometres, very low power consumption, years of lifetime with battery use.
LoRaWAN on the other hand is a network protocol that uses the LoRa modulation to communicate and manage LoRa devices, that are composed of mainly two parts, gateways and end-devices.
Analysing the different network servers that exist, the chosen network server is TTN NS. One of the main reasons for this was that the Gateway used for this project is not compatible for the moment with any server except for The Things Network Server. Apart from this reason, also the TTN server has some other features that its competitors are not yet fulfilling as it is the case of integrations with other services. TTN offers a wide spectrum of integrations with different third party developers.
One of the issues with TTN NS and all the other servers analysed is that setting up a network and understanding all the features that LoRa can be complicated for a person that doesn’t have a solid knowledge of LoRaWAN. The main objective of this thesis helps in this situation due to the fact that besides setting up a practical LoRaWAN scenario it is intended to be taken as a step by step guide for a better understanding of how LoRaWAN technology works.
A practical LoRaWAN scenario was developed in two ways: one using The Things network resources and another one setting up a private environment, the two of them gave similar results because for now TTN is in charge of the account
servers and the gateway has to register in this server in order to start forwarding packets.
Future Works
LoRaWAN is a wide topic and different lines of work can be followed using the present work due to the fact that this master thesis is the basis for building a bigger LoRa network. The gateway is capable of connecting thousands of devices at the same time.
Future works can integrate different APIs to solve all kinds of needs. Also later this year TTN is releasing a new firmware version for the gateway and a new network server where more features are going to be implemented such as running a full private environment.
Another future work item is analysing the security of LoRaWAN links and compare the security level between OTAA and ABP.
Sustainability considerations
LoRaWAN is intended for large networks where a lot of devices are connected to a single gateway within a radius of up to 10 km. For this reason, the end-devices that are spread need to be cheap from an economic point of view. Regarding the energy consumption, the majority of end-devices will run on batteries with very small power consumption, with the battery lasting for years.
However, it must be taken into account the radiofrequency regulations which state that the maximum transmitted power an emitter can use when communicating is 25 mW. And that the maximum ratio of time on the air is 1% per hour.
Ethical Considerations
This project contributes to upcoming students, who can benefit from learning LoRa/LoRaWAN technology in a practical and guided way. Due to the fact that nowadays, and probably in the future, this technology is very relevant in the IoT area.
ACRONYMS
ABP Activation by Personalization ADR Adaptive Data Rate
BW Bandwidth
CF Carrier Frequency
CLI Command Line Interface CRC Cyclic Redundancy Check CSS Chip Spread Spectrum IOT Internet of Things
LPWAN Low Power Wide Area Network LoRa Long Range
LoRaWAN Long Range Wide Area Network
LR-WPANs Low-Rate Wireless Personal Area Networks MAC Medium Access Control
NS Network Server
OSI Open Systems Interconnection OTAA Over the Air Activation
RFID Radio Frequency ID
RSSI Received Signal Strength Indicator SF Spreading Factor
SNR Signal-to-noise ratio TP Transmission Power TTN The Things Network UNB Ultra Narrow Band
REFERENCES
[1] D. Evans, “The internet of things: How the next evolution of the internet is changing everything,” CISCO white Pap., vol. 1, no. 2011, pp. 1–11, 2011. [2] L. Vangelista, A. Zanella, and M. Zorzi, “Long-range IoT technologies: The dawn of LoRa,” in Future Access Enablers of Ubiquitous and Intelligent Infrastructures, 2015, pp. 51–58.
[3] A. Augustin, J. Yi, T. Clausen, and W. M. Townsley, “A study of LoRa: Long range & low power networks for the internet of things,” Sensors, vol. 16, no. 9, p. 1466, 2016.
[4] M. Centenaro, L. Vangelista, A. Zanella, and M. Zorzi, “Long-range communications in unlicensed bands: the rising stars in the IoT and smart city scenarios,” IEEE Wirel. Commun., vol. 23, no. 5, pp. 60–67, 2016. [5] I. 802 W. Group and others, “IEEE Standard for Local and Metropolitan
Area Networks—Part 15.4: Low-Rate Wireless Personal Area Networks (LR-WPANs),” IEEE Std, vol. 802, pp. 4–2011, 2011.
[6] The Bluetooth Special Interest Group, “Bluetooth 5 Bluetooth Technology Website,” Technical Spec for Bluetooth 5, 2018. .
[7] E. Khorov, A. Lyakhov, A. Krotov, and A. Guschin, “A survey on IEEE 802.11 ah: An enabling networking technology for smart cities,” Comput. Commun., vol. 58, pp. 53–69, 2015.
[8] U. Raza, P. Kulkarni, and M. Sooriyabandara, “Low power wide area networks: An overview,” IEEE Commun. Surv. Tutorials, vol. 19, no. 2, pp. 855–873, 2017.
[9] N. Sornin, M. Luis, T. Eirich, T. Kramp, and O. Hersent, “Lorawan specification,” LoRa alliance, 2015.
[10] M. Bor and U. Roedig, “LoRa transmission parameter selection,” 2017. [11] Semtech, “LoRa Modulation Basics v2,” 2015.
[12] J. Haxhibeqiri, E. De Poorter, I. Moerman, and J. Hoebeke, “A survey of lorawan for iot: From technology to application,” Sensors, vol. 18, no. 11, p. 3995, 2018.
[13] T. M. Workgroup, “Technical Overview of LoRa and LoRaWAN,” 2015. [14] TTN, “LoRaWAN Duty-Cycle.” [Online]. Available:
https://www.thethingsnetwork.org/docs/lorawan/duty-cycle.html.
[15] TTN, “TTN LoRaWAN Documentation.” [Online]. Available: https://www.thethingsnetwork.org/docs/lorawan/.
http://www.dragino.com/products/module/item/102-lora-shield.html.
[17] RSComponents, “TTN Gateway V1.” [Online]. Available: https://uk.rs- online.com/web/p/wifi-routers/1359783/.
[18] TTN, “The Things Gateway.”
[19] T. COSTACHIOIU, “Hands-on: The Things Network Gateway,” Hands-on: The Things Network Gateway, 2018. [Online]. Available: https://electronza.com/review-ttn-things-network-gateway/.
[20] LoRaServer, “LoRa Server, open-source.” . [21] TTN, “The Things Network.”
[22] T. T. Network, “The Things Network Learn,” Learn LoRaWAN. [Online]. Available: https://www.thethingsnetwork.org/docs/gateways/.
[23] “MQQT ORG.”
[24] L. Foundation, “Node.js.” [Online]. Available: https://nodejs.org/es/about/. [25] IBM, “IBM LMIC Framework.” [Online]. Available:
https://www.arduinolibraries.info/libraries/ibm-lmic-framework. [26] H. Visser, “Setting up a Private Routing Environment.”
ANNEXES
ANNEX 1
The following are the steps to create a Private Back-End
First it is necessary to have a working directory created where all the network components are going to be installed in the case of the project the directory is
~/ttn.
Discovery Server
The first step is to create a configuration file (ttn.yml) under
~/ttn/discovery/ttn.yml. Configuration File: id: mynetwork-discovery tls: true key-dir: discovery/ auth-servers: ttn-account-v2: "https://account.thethingsnetwork.org" local: "file://discovery/server.pub" discovery: master-auth-servers: - ttn-account-v2 - local
This configuration creates a discovery server called "mynetwork-discovery". The server will use TLS and get its keys from ./discovery. It uses the public TTN account server and a local certificate for authentication, and both "account servers" are seen as "master servers".
When the configuration file ready now it is necessary to generate public/private keypair for the Discovery server:
$ ttn discovery gen-keypair --config ./discovery/ttn.yml
Since TLS is used, it is necessary to create a certificate for localhost:
$ ttn discovery gen-cert localhost --config ./discovery/ttn.yml
To continue with the next steps, the discovery server needs to be running, to start the network server it’s necessary to run the following command line:
Access Tokens
In order for the router, broker and handler to authenticate with the discovery server Access tokens are needed, these access tokens have to be created in order to build a private network.
ttn discovery authorize router mynetwork-router --config ./discovery/ttn.yml
This step has to be replicated in order to get all the access tokens for each part: router, broker, handler and network server.
Router
The second step is to configure a router, for this we have to create another configuration file ~/ttn/router/ttn.yml.
id: mynetwork-router tls: true key-dir: router/ auth-servers: ttn-account-v2: "https://account.thethingsnetwork.org" discovery-address: "localhost:1900"
auth-token: THE DISCOVERY ACCESS TOKEN THAT YOU GENERATED FOR THE **ROUTER**
router:
server-address-announce: localhost skip-verify-gateway-token: true
This configuration creates a router called "mynetwork-router". The server will use TLS and get its keys from ./router. It uses the public TTN account server for authentication. It connects to the discovery server on localhost and uses the access token, that was generated in the previous step, to authenticate with the discovery server.
Just like with the discovery server, a public/private keypair and a TLS certificate need to be generated:
ttn router gen-keypair --config ./router/ttn.yml ttn router gen-cert --config ./router/ttn.yml
The TLS certificate that was generated for the discovery server is not going to be trusted by the OS and it needs to be appended to a ca.cert file in the router directory:
This step has to be replicated when setting up the broker and handler also. Network Server
The third step is to configure a network, for this the creation of a configuration file is needed ~/ttn/networkserver/ttn.yml. id: mynetwork-networkserver tls: true key-dir: networkserver/ auth-servers: ttn-account-v2: "https://account.thethingsnetwork.org"
The public/private keypair and TLS certificate have to be generated:
ttn networkserver gen-keypair --config ./networkserver/ttn.yml ttn networkserver gen-cert --config ./networkserver/ttn.yml
Broker
Similar to previous steps a configuration file is needed ~/ttn/broker/ttn.yml.
id: mynetwork-broker tls: true key-dir: broker/ auth-servers: ttn-account-v2: "https://account.thethingsnetwork.org" discovery-address: "localhost:1900"
auth-token: THE DISCOVERY ACCESS TOKEN THAT YOU GENERATED FOR THE **BROKER**
broker:
server-address-announce: localhost
networkserver-cert: broker/networkserver.cert
networkserver-token: THE NETWORKSERVER ACCESS TOKEN THAT YOU GENERATED
The public/private keypair and TLS certificate have to be generated:
ttn broker gen-keypair --config ./broker/ttn.yml ttn broker gen-cert --config ./broker/ttn.yml
Now a device address prefix needs to be set, TTN has a reserved prefix for private network which is 26000000/20. This prefix allows to issue 4096 distinct addresses to devices a private network.
ttn broker register-prefix 26000000/20 --config ./broker/ttn.yml
Handler
The configuration for the Handler will be stored in ~/ttn/handler/ttn.yml.
id: mynetwork-handler tls: true key-dir: handler/ auth-servers: ttn-account-v2: "https://account.thethingsnetwork.org" discovery-address: "localhost:1900"
auth-token: THE DISCOVERY ACCESS TOKEN THAT YOU GENERATED FOR THE **HANDLER**
handler:
server-address-announce: localhost broker-id: mynetwork-broker
mqtt-address: localhost:1883
Starting Everything
The final step is to start everything in separate tabs:
ttn router --config router/ttn.yml
ttn networkserver --config networkserver/ttn.yml ttn broker --config broker/ttn.yml
ttn handler --config handler/ttn.yml
gateway-connector-bridge --root-ca-file "bridge/ca.cert" --ttn-router "localhost:1900/mynetwork-router"
After everything is started the network can be managed with the line command “ttnctl”.
Annex 2
The following annex is the Arduino code for an end-device with ABP activation, the explanation is giving in a form of comments in the code.
This code is capable of sending uplink messages as well receiving downlink messages coming from TTN that can be seen in the Arduino serial monitor. It can also allow ACKs as it can be observed in
// Libraries needed for the code #include <lmic.h>
#include <hal/hal.h> #include <SPI.h>
// LoRaWAN NwkSKey, obtained from the TTN page in the device section
static const PROGMEM u1_t NWKSKEY[16] = { 0x95, 0xFE, 0xA2, 0x7F, 0x1F, 0xA6, 0x46, 0xE6, 0x45, 0xCC, 0x0A, 0xEB, 0xE7, 0x1F, 0xD0, 0x3D };
// LoRaWAN AppSKey, obtained from the TTN page in the device section
static const u1_t PROGMEM APPSKEY[16] ={ 0xA2, 0xE9, 0xAD, 0x13, 0xF5, 0xBA, 0x03, 0x14, 0x92, 0xAE, 0xE1, 0x6A, 0xCB, 0x35, 0x97, 0x4D };
// LoRaWAN end-device address (DevAddr), obtained from the TTN page in the device section
static const u4_t DEVADDR = 0x260117DC;
// Time analysis variable declaration unsigned long startTime;
unsigned long RTT; unsigned long endTime;
// These callbacks are only used in over-the-air activation, so they are // left empty here (we cannot leave them out completely unless
// DISABLE_JOIN is set in config.h, otherwise the linker will complain). void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { } void os_getDevKey (u1_t* buf) { }
//Payload to be sent
static uint8_t mydata[] = "22222"; static osjob_t initjob,sendjob,blinkjob;
// Schedule TX every this many seconds (might become longer due to duty // cycle limitations).
const unsigned TX_INTERVAL = 10; //for SF 7 //const unsigned TX_INTERVAL = 30; //for SF 9 //const unsigned TX_INTERVAL = 240; //for SF 12
// Pin mapping
const lmic_pinmap lmic_pins = { .nss = 10, .rxtx = LMIC_UNUSED_PIN, .rst = 9, .dio = {2, 6, 7}, }; void do_send(osjob_t* j){
// Check if there is not a current TX/RX job running if (LMIC.opmode & OP_TXRXPEND) {
Serial.println("OP_TXRXPEND, not sending"); } else {
// Prepare upstream data transmission at the next possible time by setting // the 4th parameter to one ACK is required
LMIC_setTxData2(1, mydata, sizeof(mydata), 0); Serial.println("Packet queued");
Serial.println(LMIC.freq);
startTime=millis(); // START TIMING PROCESS FOR RTT }
// Next TX is scheduled after TX_COMPLETE event. }
void onEvent (ev_t ev) {
Serial.print(os_getTime()); Serial.print(": ");
Serial.println(ev); switch(ev) {
Serial.println("EV_SCAN_TIMEOUT"); break; case EV_BEACON_FOUND: Serial.println("EV_BEACON_FOUND"); break; case EV_BEACON_MISSED: Serial.println("EV_BEACON_MISSED"); break; case EV_BEACON_TRACKED: Serial.println("EV_BEACON_TRACKED"); break; case EV_JOINING: Serial.println("EV_JOINING"); break; case EV_JOINED: Serial.println("EV_JOINED"); break; case EV_RFU1: Serial.println("EV_RFU1"); break; case EV_JOIN_FAILED: Serial.println("EV_JOIN_FAILED"); break; case EV_REJOIN_FAILED: Serial.println("EV_REJOIN_FAILED"); break; case EV_TXCOMPLETE:
Serial.println("EV_TXCOMPLETE (includes waiting for RX windows)");
////////////////RTT CALCULATION/////////////////////////////// endTime=millis(); // END TIMING THE RTT
RTT=endTime-startTime; // RTT CALCULATION Serial.print("RTT: "); // PRINT THE RTT Serial.println(RTT);
/////////////////////////////////////////////////////////////
//////// CODE TO RECEIVE PACKETS FROM TTN///////////////// if(LMIC.dataLen) {
// data received in rx slot after tx Serial.print("Data Received: ");
Serial.write(LMIC.frame+LMIC.dataBeg, LMIC.dataLen); Serial.println();
}
///////////////////////////////////////////////////////////////// // Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send); break; case EV_LOST_TSYNC: Serial.println("EV_LOST_TSYNC"); break; case EV_RESET: Serial.println("EV_RESET"); break; case EV_RXCOMPLETE:
// data received in ping slot Serial.println("EV_RXCOMPLETE"); break; case EV_LINK_DEAD: Serial.println("EV_LINK_DEAD"); break; case EV_LINK_ALIVE: Serial.println("EV_LINK_ALIVE"); break; default: Serial.println("Unknown event"); break; } } void setup() { Serial.begin(9600); while(!Serial); Serial.println("Starting"); #ifdef VCC_ENABLE
// For Pinoccio Scout boards pinMode(VCC_ENABLE, OUTPUT); digitalWrite(VCC_ENABLE, HIGH); delay(1000);
// LMIC init os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
//LMIC_setClockError(MAX_CLOCK_ERROR * 1/100);
// Set static session parameters. Instead of dynamically establishing a session
// by joining the network, precomputed session parameters are be provided.
#ifdef PROGMEM
// On AVR, these values are stored in flash and only copied to RAM // once. Copy them to a temporary buffer here, LMIC_setSession will // copy them into a buffer of its own again.
uint8_t appskey[sizeof(APPSKEY)]; uint8_t nwkskey[sizeof(NWKSKEY)];
memcpy_P(appskey, APPSKEY, sizeof(APPSKEY)); memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY)); LMIC_setSession (0x1, DEVADDR, nwkskey, appskey); #else
// If not running an AVR with PROGMEM, just use the arrays directly LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
#endif
// Disable link check validation 0 Enabled 1 LMIC_setLinkCheckMode(0);
LMIC_setAdrMode(0);
// TTN uses SF9 for its RX2 window. LMIC.dn2Dr = DR_SF9;
// Set data rate and transmit power LMIC_setDrTxpow(DR_SF7,14); // Start job do_send(&sendjob); } void loop() { os_runloop_once(); }
Annex 3
The script for Node.js in order to decode a LoRaWAN packet has to be ran in the CLI:
Node >> END
const lorapacket = require('lora-packet');
const nwkSKey = new Buffer('C15C54812EC31DEA211AE337CEC598F2', 'hex'); const appSKey = new Buffer('55B9D78BCF4D70D868DE98749DBFAD09', 'hex'); const data = new Buffer('40F7120126807300011C526EBAF83712C796', 'hex');
const packet = lorapacket.fromWire(data); console.log(packet.toString());
const valid = lorapacket.verifyMIC(packet, nwkSKey); console.log('MIC: ' + (valid ? 'OK' : 'FAIL'));
const payload = lorapacket.decrypt(packet, appSKey, nwkSKey); console.log('Payload: ' + payload.toString());
Annex 4
RTT in ms obtained for each case and statistical parameters
SF7 payload 24 bytes SF7 payload 51 bytes SF9 payload 51 bytes SF12 payload 51 bytes 1106 1148 22818 236541 1107 1148 22816 236538 1107 11410 22816 483131 1107 1147 22814 236538 1107 1148 22814 236541 1108 1148 22814 236538 1106 21809 22813 236538 7273 8429 22814 236538 1108 8304 22815 236537 1107 1148 22812 236537 1106 1147 22815 236537 1107 1147 22814 236537 7273 1148 22816 236537 7275 11411 22813 236537 7273 1147 22814 236537 1106 1147 22814 236537 1106 1147 22813 236536 1107 1149 22814 236537 1107 1147 22814 236536 1107 1147 22813 236537 1106 1148 22815 236536 1107 1148 22814 236537 1107 1146 22815 236537 1107 1148 22814 236537 1106 1148 22814 236537 1106 11410 22814 236537 1107 1147 22814 236537 1107 1148 22814 236537 1106 1148 22812 236537 1106 1147 22814 236537 1107 1148 22812 236537 1108 1148 22813 236537 1106 1147 22814 236537 1106 1147 22814 236536 1107 1148 22814 236536 1107 1147 22813 236537 1106 1147 55681 236537 7275 1148 22813 236537 1107 1148 22812 236537