LoRa IIoT Gateway Using Raspberry Pi
LoRa IIoT Gateway Using Raspberry Pi
5259
Authorized licensed use limited to: Cornell University Library. Downloaded on September 12,2020 at 10:33:38 UTC from IEEE Xplore. Restrictions apply.
2 System Layout MCU(microcontroller) interfaces with RF transceiver
module through SPI protocol and runs many software
Fig. 1 below provides a high-level overview of LoRa functions such as sampling the data from external sensor,
application architecture. sending control signal to external actuator, formatting the
sensor data into LoRa protocol’s payload format and
scheduling of LoRa messages to gateway. For
accomplishing the above-mentioned functions, there are a lot
suitable and cheaper microprocessors to choose from, for
example ST Micro series Cortex-M0 MCU STM32F030F4 .
RF transceiver converts the data from MCU with SPI
interface and protocol to an analog radio signal by
modulating it onto an RF carrier frequency. It also receives
incoming RF radio messages, performs demodulation,
converts the analog signals back to digital and forwards the
incoming radio messages to the MCU. The module
Fig. 1: The overview of LoRa application architecture
composed of Semtech SX1276 ultra long range spread
spectrum wireless transceiver is intended for applications
LoRa based application consists of end devices, gateway over a wide frequency range for example 433MHz ISM band
and network server or cloud-hosted web application. On the in China. It is very suitable for our project [12]. End Devices
middle of the diagram is proposed gateway that comprise of is available peripheral I/O interfaces include UART and I2C
Raspberry Pi mini-computer and LoRa add-on board. On the through that communications with external equipment for
left half of the diagram depicts one or more LoRa completing tasks such as viewing or setting parameters, etc.
end-devices. The right half of the diagram depicts the It can be a standalone transmitter/receiver, or as part of a
interaction with a cloud-hosted web application using the more complex IoT system.
RESTful APIs cloud platform and MQTT protocol [16] 3.2 Gateway Hardware Implementation
[17][18]. Data and useful information are accessible to
authorized users through desktop, web application and Fig. 3 below is a schematic block diagram for LoRa
mobile APP. The network topology between end devices and gateway.
gateway is star structure. End devices and gateways are
connected wirelessly using LoRa communication. Gateways
and network servers are connected using IP backhaul
connections typically Ethernet or 4G with communication
such as RESTful HTTP and MQTT protocol. In the basic
architecture of above, the proposal gateway is key
component that acting as only bidirectional relay, or protocol
converter, with the cloud-hosted web application being
responsible for decoding the packets sent by the end devices
and generating the packets that should be sent back to end Fig. 3: Block diagram of the proposal gateway
devices.
3 Implementation Details On the left half of the diagram is a Raspberry Pi board and
the right half of the diagram is a LoRa module. Raspberry Pi
Key components and flows are described at a high level uses its GPIO to interface the LoRa module.
below. Fig. 4 below shows hardware Implementation of proposed
3.1 LoRa End Devices system.
5260
Authorized licensed use limited to: Cornell University Library. Downloaded on September 12,2020 at 10:33:38 UTC from IEEE Xplore. Restrictions apply.
It mainly comprises Raspberry Pi (RPi) board (top of Fig. a number between 6 and 12 and this parameter is relevant in
4) and LoRa add-on board (bottom of Fig. 4). Raspberry Pi the spread spectrum technique [1][12].
board is mode 3B+ that supports gigabit RJ-45 Ethernet, In the reality application deploy, it should be determined
dual-band 802.11ac wireless LAN, Bluetooth 4.2, external according to the specific situation. In fact, there is a
USB devices and much more. Based on a 1.4GHz 64-bit compromise between the distance range and the transmission
quad-core ARM Cortex-A53 CPU and 1GB LPDDR2 speed. For example, the spreading factor has significant
SRAM, this board provides an effective platform for impact on the network coverage. It requires the gateway and
exploring more complex local-processing end-devices to agree on using a single spreading factor for
capabilities[13][14][15]. communication. Moreover, the longer range of the higher
LoRa add-on board is a RPi expansion board based on spreading factors (SF10, SF11, SF12) compared to the lower
Semtech SX1268 [12]. It covers 433MHz frequency band spreading factors (SF7, SF8, SF9) increases the possibility of
and allows data transmission up to 5km through UART serial collisions [12].
port. It also has many excellent characteristics such as higher
4.3 Sending Data to End Devices
rate, longer communication distance, lower consumption,
better safety and anti-interference. It is very suitable for We design the DATA command to send data from
various industrial control applications. proposal gateway to end devices or any other LoRa equipped
The Raspberry Pi 3B+ has two UART controllers named device. The packet structure of this command is shown in
mini UART and pl011UART that can be used for UART Table 1.
serial interface. In this project, the mini UART used for Table 1: The Structure of DATA Command
communication with LoRa add-on board is mapped to TXD
Field of packet Value Description
(GPIO 14) and RXD (GPIO 15) on 40PIN GPIO extension STX ASCII character 0×02 Start of Header
header. Meaning DATA
The RPi 3 is external powered using a micro-USB cable command DATA command
which is connected to a 5V power supply that is rated to Number
deliver a current of at least 2,500 mA for system stability and between 1 and Each end device
Serial ID 255. 0 for uniquely
reliability. broadcast
The antenna is a key component for reaching the message.
maximum distance in the wireless communication between Number of bytes [1
The number of bytes
end devices and the gateway. In this project, the external [1-200] between this field
byte] and CR+LF
antenna is used to extend the communication range of the
system. Data to send
CR+LF ASCII 0x0D and Carry return + line
4 Protocol Design and Software Implementation characters 0x0A feed
The normal topology for this system is a star: all the end 2 hexadecimal bytes
CRC16 code [2 bytes] CRC between STX
devices transmit towards a central gateway. The and CR+LF
communication between gateway and end devices uses a ETX ASCII character 0×03 End of Transmission
protocol designed for the specific use. The proposal gateway
implements a simple link protocol.
As defined in Table 1, the frame of a command example
4.1 Communications Setup will be: [STX] DATA 01020102[CR+LF]2A31[ETX]
The same command in hexadecimal format:
Raspberry Pi uses the mini UART to communication with
02 44 41 54 41 01 02 01 02 0D 0A 7A 05 03
LoRa add-on board. The UART communication parameters
The gateway supports two types of transmission named
are set as follows:
Unicast and Broadcast (Serial ID is 0 shown in Table 1).
z Baudrate: 11520
Unicast is used to send a packet to one specific end device in
z 8 Data bits
a network through its device address (Serial ID). In the
z No parity
Unicast process, we adopt a timeout mechanism to prevent a
z 1 Stop bit
permanent wait for a packet to return. In addition, if the
4.2 Setup Configuration Parameters of LoRA Module gateway does not receive the ACK confirmation message
within the specified time interval, it will resend the packet up
In order to configure the LoRA module, several
to three times or until the ACK is received.
parameters are available for the customization of the LoRa
Compared with Unicast, the disposal mechanism of
modulation include frequency, BW (Bandwidth), CR
Broadcast is simpler. Broadcast is used to send a packet to all
(coding rate) and SF (Spreading factor) and much more.
end devices in a network and any end device within range
Among these parameters, frequency is set to fixed value
will accept the packet. Broadcast just sends a packet and no
433MHz. The 433MHz ISM bands is application free
ACK confirmation or retry is required.
transmitting and receiving frequency in China, which can be
directly deployed and not requiring a license. BW only can 4.4 Data Frame Structure from End Device to
be chosen among 3 options: 125 kHz, 250 kHz or 500 Gateway
kHz.CR is a number 4/N and N is between 5 and 8. It denotes
The framework shown in Table 2 is designed in order to
that every 4 useful bits are going to be encoded by 5, 6, 7 or 8
create sensor data frames of end device with a specific
transmission bits depending on its value. SF can choose from
5261
Authorized licensed use limited to: Cornell University Library. Downloaded on September 12,2020 at 10:33:38 UTC from IEEE Xplore. Restrictions apply.
format with short payload size using low bit-rate protocols.
The frame is composed of two different parts: header and The section on the left half of the diagram is used to define
payload. the main parameters of LoRa Module such as various
configurations include BW (Bandwidth), CR (coding rate)
and SF (Spreading factor) .
Table 2: The Structure of Data Frame The section on the right half of the diagram is used to
Header payload. define some major settings of MQTT protocol such as
STX STX
Number of bytes Serial ID Sensor_1 Sensor_2 Ă Sensor_n
remote server information and specific communication
STX
parameters like QoS [17][18].
The screenshot in Fig. 6 below shows some settings
The structure fields are described below: between gateway and end devices.
Start Delimiter [3 bytes]: It is composed of three STX
ASCII character (Hexadecimal value is 0×02). This is a
3-byte field and it is necessary to identify each frame
starting.
Number of bytes [1 byte]: This field specifies the number
of bytes between this field and the end of the payload.
Serial ID [1 byte]: This is a one byte field which identifies
each end device uniquely.
PAYLOAD˖This part is composed of several sensor data.
All data sent in these fields correspond to a predefined sensor
data type.
The sensor field consists of four bytes correspond to the
single sensor value. For example the remote tank level sensor
is a float number, the sensor field for 5.9m will be set as
follows shown in Table 3.
Fig.6: Shows some settings between gateway and end devices
Table 3: Simple Sensor Field via IE browser on PC
Sensor field 1
Byte 1 Byte 2 Byte3 Byte4 The gateway software usually polls the sensor data
0x9A 0x99 0xA9 0x40 periodically and allows user to easily configure the polling
interval for each end device.
5262
Authorized licensed use limited to: Cornell University Library. Downloaded on September 12,2020 at 10:33:38 UTC from IEEE Xplore. Restrictions apply.
real industry standard LoRaWAN-compatible multichannel [7] ZHANG MinˈZHOU ZhipingˈDesign of remote monitoring
gateway. Our future work will focus on expanding single system based on Lo ˮ a, Transducer and Microsystem
channel to LoRaWAN-compatible multichannel by choosing Technologies,2019,38(07):95-98.
more expensive RF chipsets such as SX1301/SX1278 [8] WUJin, ZHAOXin liang, ZHAOJun, Modulation and
instead of SX1272/SX1276 in hardware design and adopting demodulation of LoRa internet of things technology,
Computer Engineering and Design, 2019,40(03):617-622.
full-featured LoRaWAN protocol in software[12][19], and
[9] LoRa gateway. www.dragino.com
then, this kind of improved gateway can handle data coming [10] LoRa gateway. www.libelium.com
from many end devices simultaneously. In return, this will [11] LoRa gateway.
give end users greater flexibility in deploying applications https://www.cisco.com/c/en/us/products/routers/wirelessgate
that best suit their specific business. way-lorawan/index.html
[12] SX1276/77/78/79 WIRELESS, SENSING & TIMING
References DATASHEET Rev. 4 Available:
[1] LoRa Alliance. White Paper: A Technical Overview of Lora https://cdn-shop.adafruit.com/product-files/3179/sx1276_77
and Lorawan; The LoRa Alliance: San Ramon, CA, USA, _78_79.pdf [Accessed July. 9, 2019]
2015. [13] http://www.raspberrypi.org, About raspberry Pi.
[2] CHEN Xiaosong, Design and Implementation of Lo ˮ a [14] Matt Richardson, Shawn Wallace, Getting Started with
Low-cost Full-duplex Gateway, Radio Communications Raspberry Pi, 2nd Edition, Published by Maker Media,Inc.,
Technology,2019,45(02):206-209. USA, 2014. Book ISBN: 978-1-457-18612-7
[3] Wei Yuantong, Dai yawen, Design of Industrial Monitoring [15] Gay, W. W.: Raspberry Pi System Software Reference,
ad hoc Network Protocol System Based on LoRa, Computer Springer Science+Business Media, New York, 2014
Measurement & Contro, 2019,27(02):225-228. [16] L. Richardson, M. Amundsen, RESTful Web APIs. O’Reilly
[4] QIAO Haiye, Design of equipment protection system based Media, 2013.
on lora communication technology, Automation & [17] MQTT, Documentation: Protocol Specifications, MQTT.
Instrumentation, 2019(08):73-75+79. [Online]. Available: http://mqtt.org/documentation.
[Accessed July. 17, 2019]
[5] ZHAO Er-gangˈGUO Tian-yongˈDesign of Encrypted
[18] MQTT protocol specification. [Online]
Wireless Communication System Based on LoRa Technology,
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-o
Automation & Instrumentation,2019,34(11):1-4+8.
s.pdf. [Accessed July. 12, 2019]
[6] Li Da,Yang Zhen, Design of LoRaWAN Integrated Gateway
[19] Semtech SX1301,Digital Baseband Chip for outdoor
System Based on Embedded Linux, Microcontrollers &
LoRaWAN? macro
Embedded Systemsˈ2019,19(07):10-14.
gateways,https://www.semtech.com/products/wireless-rf/lora
-gateways/SX1301
5263
Authorized licensed use limited to: Cornell University Library. Downloaded on September 12,2020 at 10:33:38 UTC from IEEE Xplore. Restrictions apply.