summaryrefslogtreecommitdiff
path: root/text/vysledky.tex
blob: c94f8ce5d61c5431f92d2176d81a7721c26e151b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
\chapter{Practical demonstration}

For practical demonstration of an IoT device with 4G/5G connectivity, a 4G development kit nRF9160 DK was selected. Demonstration of 5G connectivity could not be made due to a delay with delivery of the ordered Quectel module.

Practical demonstration of an IoT device with LTE-M connectivity was made on an example of a combined burglary and fire alarm system with 4 sensors, transferring data to a remote cloud server via MQTT protocol, simulating a data transfer to a central security panel.

\section{Hardware}

nRF9160 DK development kit was adapted with an add-on board made from a universal line PCB with headers compatible to Arduino Uno form-factor fitting to nRF9160 DK headers. The add-on PCB contained connections for four sensors:

\begin{itemize}
	\item Hall effect sensor Texas Instruments DRV5033 \cite{haldatasheet}, with open-drain output (for pulled-up digital input) pulled down by an external magnetic field and simulating door/window switch, connected to GPIO pin P0.19.
	\item analog thermometer Texas Instruments LM35 \cite{tempdatasheet}, with an analog output linearly corresponding to 10 mV for each oC above 0 oC, connected to GPIO pin P0.17.
	\item passive infrared (PIR) motion sensor Hadson Technology HC-SR501 \cite{pirdatasheet} with digital output (3,3 VDC output reduced to 3 VDC level by a voltage divider), connected to GPIO pin P0.16.
	\item sensor for combustible gases Pololu MQ-2 \cite{gasdatasheet}, with an analog ouput reduced by a voltage divider to avoid exceeding 3 VDC threshold, connected to GPIO pin P0.18.
\end{itemize}

\begin{figure}[!h]
  \begin{center}
	  \includegraphics[width=0.5\textwidth]{obrazky/ezsschema.png}
  \end{center}
	\caption[Overview of security and fire alarm]{Overview of security and fire alarm board}
	\label{fig:ezsschema}
\end{figure}

\begin{figure}[!h]
  \begin{center}
	  \includegraphics[width=0.5\textwidth]{obrazky/ezspcb.png}
  \end{center}
	\caption[Schematic of security and fire demo]{Schematic of security and fire alarm demo}
	\label{fig:ezspcb}
\end{figure}


\begin{figure}[!h]
  \begin{center}
	  \includegraphics[width=0.9\textwidth]{obrazky/pcbphoto.jpg}
  \end{center}
	\caption[PCB schematic of alarm demo board]{PCB schematic for alarm demo}
	\label{fig:ezsreal}
\end{figure}

\newpage

\section{Firmware tools}

nRF Connect SDK was used as a software platform for the demo application. nRF Connect SDK is a unified software development kit for building products based on all Nordic nRF Series wireless devices. It integrates the Zephyr RTOS and wide range of samples, application protocols, protocol stacks, libraries and hardware drivers  \cite{zephyrpp}.

It offers a single code base for all Nordic devices and software components. It simplifies porting modules, libraries and drivers from one application to another, thus reducing development time. nRF Connect SDK is publicly available under OpenSource license, offers source code management with Git and has free nRF Connect for Visual Studio Code IDE support. Zephyr RTOS furthemore provides extensive amount of libraries including standardized access to basic peripheries, IP stack and MQTT library \cite{nrfsdk}.

MQTT is a lightweight, publish-subscribe protocol that enables efficient and reliable communication between devices in the IoT domain. MQTT is based on a broker-client architecture, where a broker is a server that receives and routes messages from multiple clients, and a client is any device that can publish or subscribe to a topic. A topic is a hierarchical identifier that defines the content and scope of a message\cite{mqtt}.

This firmware is based on nRF Connect SDK example named Simple MQTT\cite{nrfmqtt}.

\section{Firmware outline}

\subsection{LTE network connection}

First task for the demo firmware is an establishment of a connection to LTE network. This is mostly handled by function \texttt{modem\_configure()}, which turns off power saving modes for better responsivity and calls HAL function \texttt{lte\_lc\_init\_and\_connect()}.

\texttt{lte\_lc\_init\_and\_connect()} takes all modem settings from text config files transferred to macros by Kconfig. This ilustrates a possibility of cross-platform or regionally independent application, where only the config files for given platform or region are needed to be changed.

\subsection{ADC configuration}
When connection with LTE network is successfully established, ADC is configured. Two analog input channels are used in this demo - AIN4 on P0.17 pin connected to LM35 temperature sensor and AIN5 on P0.18 connected to MQ-2 combustible gas sensor. For both channels, \texttt{adc\_channel\_cfg} structs are initialized and channels are set to 10bit resolution, internal 0.6 V reference voltage and 1/2 divider using \texttt{adc\_channel\_cfg()}, setting channels voltage range to 1.2 V. Both channels (if they are enabled by the button configuration) are then sampled in set interval using a custom fuction \texttt{adc\_sample()} and printed to USB serial.

\subsection{Digital inputs and outputs}
For ease of implementation, digital sensors on GPIO pins P0.16 (DRV5033) and P0.19 (PIR) were added to the device tree as additional development kit buttons. This avoided the need for their own separate initialization and reading codes.

These digital input sensors are then processed as buttons using callback handler \texttt{button\_handler()}. This function is called with bitmasks \texttt{button\_states} and \texttt{has\_changed}, making it ease to figure state change for these two sensors.

Two buttons and two switchers are used for optionally disabling the corresponsing sensors. This is executed in \texttt{button\_handler()}.

Four on-board LEDs are used for local signalization of status of PIR sensor (LED1) and Hall effect sensor (LED2), as well as over-threshold values of temperature (LED3) and combustible gas (LED4) sensors.

\subsection{MQTT}

Communication with MQTT server is done by zephyr/net/mqtt.h library. Connection with the server is attempted after LTE and sensors setup with function \texttt{mqtt\_connect()}.
Publishing of message is achieved by function \texttt{mqtt\_publish()} upon a digital sensor is activated or analog sensor exceeds the set threshold value. Example of the MQTT communication sent to a virtual server is shown in figure \ref{fig:mqttcom}.

\begin{figure}[!h]
  \begin{center}
    \includegraphics[width=0.2\textwidth]{obrazky/mqttcom.png}
  \end{center}
	\caption[Demo MQTT communication]{Sample of resulting MQTT communication}
	\label{fig:mqttcom}
\end{figure}