0% found this document useful (0 votes)
21 views

LoRa IIoT Gateway Using Raspberry Pi

Uploaded by

amal.es23
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

LoRa IIoT Gateway Using Raspberry Pi

Uploaded by

amal.es23
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Proceedings of the 39th Chinese Control Conference

July 27-29, 2020, Shenyang, China

Design and Implementation of Cloud-based Single-channel LoRa IIoT


Gateway Using Raspberry Pi
Changqing Sun, Fuquan Zheng, Guangxu Zhou, Kun Guo
Institute of Automation, Qilu University of Technology (Shandong Academy of Sciences)
Shandong Provincial Key Laboratory of Automotive Electronics Technology
Abstract: With the emergence of industry 4.0 and Internet of things (IOT), more and more practical requirements need seamless
connection from the smallest sensor to enterprise level systems and other systems with simple, convenient, reliable and economic
approach. LoRa is a low-power wide area network (LPWAN) solution specifically designed for IoT devices that send and receive
small amounts of data over a range of many kilometers with minimal power consumption. At the system architecture level, Lora
is considered as a physical layer technology based on OSI model, mainly based on Chirp spread-spectrum(CSS) technology.
LoRa is resulted in a robust and reliable technology compared to other standardized wireless solutions such as Zigbee , Bluetooth,
WiFi, and 3G/4G cellular. In this paper, we have designed a single-channel LoRa gateway for Industrial IoT cloud applications
using inexpensive single-board computer naming Raspberry Pi plus a LoRa add-on board with the necessary integrated circuits
for wireless data communication. The system adopting the LoRa LPWAN technology consists of end devices, gateways, and
cloud IoT services. The proposal gateway sends and receives LoRa messages to and from end devices and communicates with
upstream cloud application servers through HTTP RESTful protocol and IoT-standard MQTT protocol, according to different
data types and specific functional requirements. Unlike other ready-to-use LoRa gateways available on the market in which these
gateways simply pass all the original LoRa packets back and forth between and network server over the air called “packet
forwarding” mode, the proposal gateway contains smart-agent managing connectivity to devices, coordinating polling
mechanism, decoding the packets, passing periodically the unified data to the public or private cloud service applications. Aside
based on the embedded web server, the configuration of the gateway is carried out through the web page with desktop or mobile
application and it can be updated anytime& anywhere when necessary. The proposal gateway is built cloud ready and can easily
integrate with existing networks and enables low-cost, long range communication capability for a multitude of industry
applications with minimum effort.
Key Words: LoRa, LoRaWAN, gateway, Industrial Internet of Things (IoT), Raspberry Pi


technology based on the OSI model. The network commonly


1 Introduction consists of end devices, gateways (sometimes called
More and more things in our world are getting connected concentrators) and application servers or cloud services. The
to the internetˈcreating what's popularly called The Internet key component is the gateway, which is responsible for
of Things˄IoT˅. For different communication technologies collecting information and preprocessing from sensors and
with low power consumption, many wireless IoT sending it to the data center [2]. Depending on the size and
communication have been proposed and deployed. These complexity of specific IoT project in the real world, the
standardized communication technologies include Bluetooth, general architecture is to deploy IoT gateway devices or
ZigBee, Wi-Fi, or cellular(3G/4G). Comprehensive sensor hub to collect data from many sensor nodes and then
consideration of primary factors such as communication forward that data on to an upstream data collection system
coverage, low power consumption, link budget and others, such as private or public IoT cloud applications[3] [4].
these technologies are not quite suitable for some IoT To solve these problemsˈmany works have been done in
applications requiring long-range communication channels previous years on enabling direct integration of LoRa end
with low data rates and power consumption optimized. LoRa device data into private or public IoT cloud applications[5]-
is a low-power wide area network solution specifically [8] . Also, there are hundreds of ready-to-use LoRa gateways
designed for IOT devices that send and receive small available on the market [9][10][11].But by whatever way,
amounts of data over a range of many kilometers with there are some shortages and deficiencies in structure and
minimal power consumption. design of these gateways. Most of these gateways or
It operates on the unlicensed 433-, 868- or 915-MHz ISM convertors tend to be 'dumb' gateways. They don't do
(Industrial Scientific Medical) bands, depending on the anything other than forward data on to the data center or an
region in which it is deployed. It uses the technology known upstream collector. In comparison with the afore-mentioned
as chirp spread spectrum (CSS) across a wide bandwidth to methods and products, in this paper we propose a prototype
provide resilience to deliver interference or signal noise. The gateway using cheap Raspberry Pi single-board computer
long-distance and low-power characteristics of LoRa make it and a simple LoRa add-on board for wireless data
an interesting candidate for industrial applications. LoRa communication [14][12]. Powered by the MQTT messaging
networks are considered low-power wide area networks protocol and other cloud connectivity capabilities [17], the
(LPWANs) [1]. LoRa is considered as a physical layer gateway polls and preprocess LoRa-based sensor data
periodically. It is especially suitable for a variety of
*
This work was supported by Key research and development (R&D) industrial real-time data acquisition and remote monitoring
plan of Shandong Province (No. 2019GGX101058), Major scientific and applications using cloud-based technology and services.
technological innovation projects of Shandong Province (No.
2019JZZY020810, No. 2019JZZY010448).

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.

Fig. 2 below is a schematic block diagram for LoRa end


device. A typical LoRa end device will have some or all of
the components and functions shown in the diagram.

Fig. 4: Implementation hardware of proposed gateway. (A) LoRa


add-on board(top); (B) external antenna connector; (C) LoRa
module; (D) 40 pin GPIO connector; (E) Raspberry Pi 3B+
board(bottom); (F) power input; (G) RJ-45 Ethernet connector
Fig. 2: Basic LoRa end device block diagram

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.

4.5 Built-in Web Server Design 5 Conclusions


We use the Flask framework based Python template In this paper, we propose a prototype of LoRa-based IoT
engine to set up a web server for parameter gateway using inexpensive credit-sized mini-computer
configuration[].Related tasks can be easily accomplished Raspberry Pi and a plug-in printed circuit board with the
through PC , Smartphone APP or browser such as Microsoft necessary integrated circuits for data processing. The
Internet Explorer using HTTP protocol. Example of relevant hardware composition and software design are
configuration parameter setting user interface is shown in clearly described in detail. The system consists of devices or
Fig. 5. nodes, gateways, and cloud services. The communications
protocol used between the devices and the gateways is LoRa
with incredible performance compared to other competing
technologies, and between the gateways and the cloud
services is TCP/IP using wired or wireless network. The
proposal gateway is suitable for building long-range
communication channels with low data rates in wide array of
applications such as machine condition monitoring and
manufacturing automation application. It also can be used to
replace some parts of new or existing solutions that require
wireless connectivity and IoT cloud applications. With
sample implementation based on the proposal gateway, the
results mainly come from the good quality of the system
design, the distance between end devices and gateway we
achieved is up to 5 km because the lora module works well.
Nevertheless, with some minor problems were
encountered in this project, and the proposal gateway was
(A) (B) designed just only from the beginning as a LoRa-based IoT
applications. Furthermore, the gateway must provide
Fig. 5: Screenshots of Smartphone APP (A) Basic configuration extensive and comprehensive protocol support. After all, the
for LoRa Module; (B) Main MQTT parameters and attributes
single-channel LoRa gateway is some limited compared to a
settings

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.

You might also like