techreview/techreview.latex

303 lines
14 KiB
Plaintext
Raw Normal View History

2019-11-03 20:36:14 -08:00
\documentclass[10pt, draftclsnofoot,onecolumn]{IEEEtran}
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist
\usepackage{todonotes}
\usepackage{caption}
\usepackage{pgfgantt}
\linespread{1}
\begin{document}
\title{Fenceless Grazing Tech Review - Danila Fedorin}
\author{Danila Fedorin, \and Matthew Sessions, \and Ryan Alder}
\maketitle
\begin{abstract}
2019-11-03 23:44:39 -08:00
The Fenceless Grazing Collar System aims to reduce the burden
on farmers caused by the need of constant manual herding of livestock.
The project will use LoRa wireless technology, and will prevent
animals from leaving prescribed grazing areas through the use of
an auditory or electrical stimulus. The project will additionally provide
data gathering features. As a member of the FGC team, I will be
responsible for creating the smart application that will be used
to control the wireless collars, as well as some supporting
software such as an HTTP API server.
2019-11-03 20:36:14 -08:00
\end{abstract}
\pagebreak
\tableofcontents
\pagebreak
\section{Role}
My role in this project is the development of the smart application which
will be used to control the Fenceless Grazing Collars in the field. This
includes the actual application, as well as the software to support
the app, such as a web server for authentication and data retrieval.
\section{Team Goal}
The goal of the Fenceless Grazing Collar (FGC) System is to reduce
the amount of manual labor required for keeping farm animals. The FGC system
does this by automating the process of keeping animals within their prescribed
grazing area through the use of GPS location tracking, as well as audio
and electric stimuli. Additionally, the FGC aims to provide information
about the behavior of the farm animals to their keepers, with the goal
of improving their understanding of the livestock.
\section{Responsibilities}
\subsection{Smart Device Application}
A major component of this project is the creation
of an application that is capable of adjusting
the settings of the wireless collar devices. This
section describes the components of this application.
\subsubsection{Platform}
2019-11-08 23:22:07 -08:00
The Android platform makes up more than half of the market share
in the United States \cite{android-share}, with a majority of the remaining share taken
2019-11-03 20:36:14 -08:00
up by Apple iOS. Because iOS requires an Apple device to perform
2019-11-08 23:22:07 -08:00
development, and because Android devices are
on average more than 50\% cheaper than iPhone devices \cite{iphone-price}, we will
2019-11-03 20:36:14 -08:00
use the Android platform for developing the mobile application
associated with this project.
2019-11-08 23:22:07 -08:00
% https://www.businessinsider.com/android-stops-us-market-share-decline-2013-5
2019-11-03 20:36:14 -08:00
% https://www.forbes.com/sites/amitchowdhry/2015/02/03/average-iphone-price-increases-to-687-and-android-decreases-to-254-says-report/#4d9d29a3539e
\subsubsection{Language}
2019-11-08 23:22:07 -08:00
There exists a variety of available technologies and techniques suitable
2019-11-03 20:36:14 -08:00
for creating an Android application. The most common way for developing
Android apps is using the Java programming language,
utilizing the standard Android tooling. Such tooling includes
the Android Studio Integrated Development Environment (IDE),
and the Gradle build system. However, since Android's creation,
multiple other ways of developing Android applications have been introduced. For
2019-11-08 23:22:07 -08:00
example, technologies such as the Ionic Framework \cite{ionic} and
React Native \cite{react-native} have been created, allowing for the creation
2019-11-03 20:36:14 -08:00
of Android applications using the JavaScript programming
language. More recently, Google announced that JetBrains' Kotlin
language will be made an official language of the Android
2019-11-08 23:22:07 -08:00
platform \cite{android-kotlin}.
2019-11-03 20:36:14 -08:00
%https://ionicframework.com/
%https://facebook.github.io/react-native/
%https://www.theverge.com/2017/5/17/15654988/google-jet-brains-kotlin-programming-language-android-development-io-2017
The use of JavaScript was ruled out due to its weak type system.
The language does not undergo a process called "type checking",
which means that certain bugs that can easily be detected
in other languages may go unnoticed in a JavaScript program
until they are observed in practice. Since this application
must reliably control the wireless collars, this is an
unnecessary risk.
The choice then remains between Java and Kotlin, both
official languages of the Android platform. For our
purpose, Kotlin has advantages over Java. First,
Kotlin has a stronger type system, which, as described
above, helps prevents certain bugs before they are
observed in practice. Second, while Kotlin has access
to all features of the Android platform that Java does,
it has significantly less "boilerplate" code. This will
help reduce the amount of code requiring maintenance,
and thus reduce the number of mechanical issues with the final code.
\subsubsection{Backwards Compatibility}
Because vendors can customize the Android operating system prior
to using it on their products, a variety of Android devices
run an "outdated" version of the Android platform, resulting
in a severe fragmentation of the overall codebase. Since maintaining
compatibility with every Android version on the market is not viable,
the project will focus on the version of Android supported by 95\%
of Android devices at the time the project implementation begins.
This will allow the project to target a majority of available
devices, while at the same time not being bogged down by the
compatibility requirements with very old version of Android.
\subsection{Data Storage}
Data storage is a major component of the fenceless grazing project.
It is important that the collars collect and store meaningful data
about the animals in the field, to be analyzed by the client.
\subsubsection{Type of Data Collected}
The data collected will consist of GPS coordinates of the animal,
taken every 15 seconds, as well as instances of the activation
of the collars' sound and shock features. This way, the client
can monitor the locations and habits of the animals, as well
2019-11-08 23:22:07 -08:00
as quantitatively assess the number of items that the animals
2019-11-03 20:36:14 -08:00
attempt to leave the prescribed area. Each data point will
be associated with the collar that produced it, such that
behaviors of individual animals can be easily analyzed.
\subsubsection{Storage Type}
An SQL database will be used for storing the data generated
2019-11-08 23:22:07 -08:00
by the collars. The technology chosen for this is MariaDB.
MariaDB \cite{mariadb} was chosen because of its permissive license
and compatibility with MySQL \cite{mysql}, another SQL dialect that is very
commonly used in the industry. There exist other technologies
for storage, such as MongoDB, which do not use the relational
model used by SQL-based databases. The advantage of NoSQL databases
is the ability to store data in arbitrary formats, without
specifying prior schema. On the other hand, SQL-based
systems (including MySQL and MariaDB) support concurrency,
which is much more useful for our project due to the future
need to scale the fenceless grazing system. Additionally,
we already know the format of our data, making the benefit
of flexible data storage irrelevant to our use case.
2019-11-03 20:36:14 -08:00
% https://mariadb.org/
% https://www.mysql.com/
\subsubsection{Storage Hardware}
Because MariaDB and MySQL require a server machine, a Linux machine
will be used to host the database. This machine will be
a Raspberry Pi, a small and low-power Linux single-board
computer. This computer not only has a full-featured
Debian Linux operating system, but also allows for the
addition of hardware components, which will be used
for communicating with collars in the field. Among the
2019-11-08 23:22:07 -08:00
hardware components compatible with the Raspberry Pi \cite{raspi} is a
2019-11-03 20:36:14 -08:00
LoRa shield, which allows the Pi to send and receive
LoRa signals. This is ideal since the server machine will also act as the LoRa
gateway, serving as the liaison between the collars
deployed in the field and the rest of the project.
2019-11-08 23:22:07 -08:00
Alternative implementations include an AVR-based microcontroller
equipped with ethernet and / or Bluetooth. Such a controller
would be integrated with a LoRa receiver and transmitter,
and programmed to send data to some other storage medium,
potentially a Virtual Private Server (VPS). This
implementation was dismissed due to the additional
complexity introduced by separating the LoRa receiver
and transmitter from the storage medium. This leaves
room for issues such as network errors between
LoRa and the SQL machine, which are entirely
avoided my using a Linux machine (Raspberry Pi) with support
for external hardware components (LoRa shield).
2019-11-03 20:36:14 -08:00
% https://www.raspberrypi.org/
\subsection{App API Server}
An API server is needed to allow users of the Android
smart application to interact with the fenceless collars
deployed on farm animals. Smartphones do not have
hardware that can communicate using the LoRa protocol,
which is used for collars. As such, an intermediate
device, a server that can communicate with both smartphones
and LoRa, must be used.
\subsubsection{Server Technology}
The server will run on the aforementioned Linux machine.
This is because it is rather expensive, in terms of both
price and complexity, to introduce two server machines
for the individual tasks of SQL data storage and smartphone
2019-11-08 23:22:07 -08:00
app support.
The server will use the Python \cite{python} programming
language, which is natively supported by the Raspberry Pi,
to host an HTTP(S) server on the local network. The
use of Python will allow for rapid development, and give
direct access to the server's LoRa hardware. While other
languages, such as Go, are also commonly used for API
implementations, they lack the first-class support that
Python receives from the Raspberry Pi project. Additionally,
Python is currently at the top of the popularity rankings
for programming languages, leading to increased access
to documentation and support.
2019-11-03 20:36:14 -08:00
2019-11-08 23:22:07 -08:00
The Gunicorn \cite{gunicorn} server will be used to expose the Python
2019-11-03 20:36:14 -08:00
application to the Android application clients. While
other web servers, such as Apache and nginx, are very
commonly deployed in production, Gunicorn has excellent
support for Python, which will allow the team to
quickly develop the HTTP application.
% https://www.python.org/
% https://gunicorn.org/
\subsubsection{Authentication}
The mobile app will use JSON web token (JWT)
to allow the mobile application to make multiple requests
2019-11-08 23:22:07 -08:00
without having to continuously provide a username
2019-11-03 20:36:14 -08:00
and password to the server. The idea of JWT is that
a JSON (JavaScript Object Notation) object, containing
session information (such as the identity of the current user),
is encrypted with information from the server. The encrypted
version of this object is then sent to the user, and can be
used as a "proof of identity". Since only the server can decrypt
the token, the user cannot deliberately make changes to it, preventing
security breaches. Once a user logs in, a JWT token will be generated,
2019-11-08 23:22:07 -08:00
containing the identity of the user and an expiration date, and
2019-11-03 20:36:14 -08:00
returned to the app. The app will then use the token for further
requests.
2019-11-08 23:22:07 -08:00
Cookie-based authentication systems were considered as an alternative;
This is commonly used in web applications, serving as a different
way to avoid authentication on every API or web request. However,
this approach will not generalize well. Using cookie or session-based
authentication requires more extensive bookkeeping on the client side, which
complicates the implementation of other clients. In the future, it is
likely that the smart application will be ported to other platforms,
including iOS and Web. To ease this expansion, the approach
requiring the least additional implementation overhead is preferred.
Because of this criterion, JWT-based authentication is better suited
for the API server.
2019-11-03 20:36:14 -08:00
\subsubsection{API}
There are several ways of communicating data to the mobile application
from the server. Because writing custom code to encode / decode data
send between the android application (client) and the server is
time consuming and prone to errors, priority is given to existing
encoding / decoding technologies. Of these technologies, Google's
2019-11-08 23:22:07 -08:00
ProtoBuf \cite{protobuf}, XML, and JSON are the most viable. JSON was chosen
2019-11-03 20:36:14 -08:00
for this project because of the ease with which it can be decoded,
as well as due to its compatibility with the JavaScript ecosystem.
Virtually every language (including Kotlin and Python) has support
for JSON decoding that is well-tested and supported. This makes
JSON the most standard choice for an interchange format.
The aforementioned HTTP server will thus provide a JSON API
to the client. During each HTTP requests, the client will
include a JWT token, and, once that token is verified, the server
will process the relevant information and return a JSON object
through HTTP containing the resulting data.
% https://developers.google.com/protocol-buffers
2019-11-08 23:22:07 -08:00
\pagebreak
\begin{thebibliography}{99}
\bibitem{android-share}Alex Cocotas, \textit{Android Bounces Back From U.S. Market Share Decline} \\
\texttt{https://www.businessinsider.com/android-stops-us-market-share-decline-2013-5}
\bibitem{iphone-price}Amit Chowdhry, \textit{Average iPhone Price Increases To $687 And Android Decreases To $254, Says Report} \\
\texttt{https://www.forbes.com/sites/amitchowdhry/2015/02/03/average-iphone-price-increases-to-687-and-android-decreases-to-254-says-report/\#437c18ac539e}
\bibitem{ionic}\textit{Ionic Framework} \\
\texttt{https://ionicframework.com/}
\bibitem{react-native}\textit{React Native} \\
\texttt{https://facebook.github.io/react-native/}
\bibitem{android-kotlin}Paul Miller, \textit{Google is adding Kotlin as an official programming language for Android development} \\
\texttt{https://www.theverge.com/2017/5/17/15654988/google-jet-brains-kotlin-programming-language-android-development-io-2017}
\bibitem{mariadb}\textit{MariaDB} \\
\texttt{https://mariadb.org/}
\bibitem{mysql}\textit{MySQL} \\
\texttt{https://www.mysql.com/}
\bibitem{raspi}\textit{Raspberry Pi} \\
\texttt{https://www.raspberrypi.org/}
\bibitem{python}\textit{Python} \\
\texttt{https://www.python.org/}
\bibitem{gunicorn}\textit{GUnicorn} \\
\texttt{https://gunicorn.org/}
\bibitem{protobuf}\textit{Protocol Buffer} \\
\texttt{https://developers.google.com/protocol-buffers}
\end{thebibliography}
2019-11-03 20:36:14 -08:00
\end{document}