Thing Board PDF
Thing Board PDF
Thing Board PDF
University Centre-Hämeenlinna
Smart Services Research Unit
Project developed under the exchange program PROPICIE 13th ed., in cooperation
nd
between the Brazilian institution Federal Institute of Santa Catarina - IFSC a
the Finnish institution Häme University of Applied Sciences - HAMK.
Advisors:
Joni Kukkamäki (HAMK)
Robson Costa (IFSC)
Vilson Heck Júnior (IFSC)
Authors:
Eduardo Natan Bitencourt
Willian Pereira dos Anjos
1. TABLE OF CONTENTS
Introduction 4
Objectives 6
Theoretical Approach 7
IoT Architectures 7
IoT Platforms 9
IoT protocols 9
MQTT 10
HTTP 11
CoAP 12
OPC-UA 13
Comparison 15
Microcontrollers 16
Telemetry data 18
Cloud platforms (Azure) 19
NoSQL databases 20
Cassandra database 20
Containers and Docker 22
Methodology and Research 25
IoT Platforms comparison survey 25
Thingsboard 27
Licenses 27
Installation (cloud/own server) 28
Architecture 29
Modules (protocols and databases) 30
External connection (in/out, APIs) 30
Analyzing/visualizing tools 31
Pros/Cons 32
Wemos D1 Mini Pro 32
DTH 11 33
PlatformIO 34
Experimental Procedures and Results 36
Installation of the Thingsboard Platform (Azure) 36
Using Docker 37
Configuration of Thingsboard (Creating users, devices and dashboards) 42
Getting temperature and humidity from devices 43
Using MQTT 44
3
Using HTTP 45
Monitoring and managing the Thingsboard database 45
Thingsboard Rest API 48
Embedding widget and dashboard to an external web page. 49
Rules, Alarms and Plugins. Firing alert Emails. 50
Thingsboard Gateway 52
MQTT External Broker 53
OPC-UA 54
Integrating Thingsboard with Yepzon Asset (industrial tracker) 55
Conclusion 58
Acknowledgments 60
References 61
Appendices 64
4
2. Introduction
3. Objectives
Main Objective:
Conduct a study to validate a centralized management infrastructure for IoT
environments, projects and devices through an open source platform for educational and
research purposes.
Specific Objectives:
● Analyze the open source IoT platforms already available on the market, conduct a
comparative study in order to identify its advantages and limitations in relation to
the characteristics desired for the execution of the project.
● Study of IoT communication protocols: MQTT, HTTP, COAP, OPC-UA;
● Study of Devices, Microcontrollers, Sensors and Actuators used in Iot Projects;
● Study of NoSQL databases for IoT: Cassandra;
● Install the platform with NoSQL database Cassandra;
● Study of Containers and Docker;
● Install the platform with Docker;
● Configure the platform: Customers, Users, Rules, Plugins, Devices;
● Make a practical implementation testing the communication of the IoT platform and
the protocols previously highlighted;
● Validation of real-time data visualization tools and widgets provided by the
platform;
7
4. Theoretical Approach
To understand the purpose and the project as a whole is necessary to know some
theoretical concepts about technologies and approaches used in this paper.
First, we will dive into IoT architecture and software platforms for visualization and
management of IoT environments and understand which problems they intend to solve.
Furthermore, the main principles of the project are described, like IoT protocols,
microcontrollers, NoSQL databases, among others.
A brief introduction to the five layers of IoT system architecture is as follows [5]:
8
● Middleware Layer: The devices over the IoT implement different types of
services. Each device connects and communicates with only those other devices
which implement the same service type. This layer is responsible for service
management and has links to the database. It receives information from the
Network layer and stores in the database. It performs information processing and
ubiquitous computation and takes automatic decisions based on the results.
● Business layer: Also named as management layer manages all layers, activities,
and service of IoT. It incorporates certain graphs, flowcharts, and models based
on the data acquired from the application layer. This layer is capable of making
effective decisions for big data analysis.
It is a fact that IoT protocol world is complicated due to legacy protocols, emerging
technologies, different layering methodologies and many use cases. There are hundreds
of protocols and just a few standards to organize its layers and formats, as shown on
Section 4.1 the five-layer architecture is a good approach for this paper's purpose.
In this project context, the most important layer is the application layer, where we
can find the data protocols, since this paper focuses on data
visualization\storage\management. The most common protocols used in this layer are:
MQTT; CoAP; HTTP; OPC-UA* (OPC-UA is not a stand-alone protocol, more on that on
Sections 4.2.4 and 4.2.5).
4.3.1. MQTT
4.3.2. HTTP
The W3C Foundation, the official maintainer of HTTP, affirms “The HTTP protocol
is a request/response protocol. A client sends a request to the server in the form of a
request method, URI, and protocol version, followed by a MIME-like message containing
request modifiers, client information, and possible body content over a connection with a
server. The server responds with a status line, including the message's protocol version
and a success or error code, followed by a MIME-like message containing server
information, entity meta information and possible entity-body content.” [9].
This protocol, used as IoT protocol, is exploited to exchange data between
applications/devices and to integrate applications belonging to different domains. HTTP
uses client/server paradigm. HTTP is widely used not only in the IoT ecosystem, but in
almost every web based application in the world.
For devices used in the IoT world, it is difficult to implement the old HTTP protocol
due to various reasons. The main reason is the fact that IoT is made up of unseen
devices that require very little interaction. IoT devices consume very little power and
frequently have poor network connectivity. Accordingly, HTTP is too heavy to be a good
fit for these devices. An HTTP request requires a minimum of nine TCP packets, even
more when one considers packet loss from poor connectivity, and plain text headers can
12
get very verbose. And even with all this overhead HTTP doesn't guarantee message
delivery [10]. The HTTP overhead also adds to IoT operating expenses. The current
costs of wireless connectivity are exorbitant. Bandwidth conservation is especially
important with enterprise customers that often have hundreds of thousands or millions of
devices deployed.
4.3.3. CoAP
COAP stands for Constrained Application Protocol. This protocol was designed by
IETF. It is an M2M protocol, defined by RFC7252, and it is a web transfer protocol. This
protocol is very similar to HTTP and it uses the document transfer paradigm. Moreover, it
uses the request/response model and supports built-in service discovery. Respect to
HTTP protocol, COAP is lightweight with smaller packets. COAP uses UDP as the
underlying network protocol. “COAP is basically a client-server IoT protocol where the
client makes a request and the server sends back a response as it happens in HTTP.
The methods used by COAP are the same used by HTTP” [11].
Conceptually, CoAP is compatible with HTTP except that it's designed for devices
with constrained resources like sensors and microcontrollers that have restricted
memory and bandwidth capabilities. It's designed to support RESTful architecture, so it
13
supports the four main methods (GET, POST, PUT and DELETE) and can identify
resources by a URL [12].
Therefore, CoAP could be considered a non-official version of HTTP for IoT
contexts. One could think of CoAP logically as using a two-layer approach, a CoAP
messaging layer used to deal with UDP and the asynchronous nature of the interactions,
and the request/response interactions using Method and Response Codes (see Figure 4)
[13].
4.3.4. OPC-UA
OPC-UA is not a protocol, but a whole architecture where data protocol is only part
of the topics addressed.
OPC Unified Architecture (OPC UA) is the current OPC Foundation technology for
secure, reliable and interoperable transport of raw data and pre-processed information
from the shop floor into production planning systems Definition of OPC specifications
started to simplify and to standardise data exchange between software applications in
industrial environment [14]. To facilitate this information exchange OPC UA specifies the
following: The information model to represent structure, behaviour and semantics; The
message model to interact between applications; The communication model to transfer
14
The client part of OPC-UA is the endpoints application. It uses the OPC UA Client
API to send and receive OPC UA Service requests and responses to the OPC UA
Server.
In Figure 6 an expanded architecture is shown making all the OPC-UA server
components visible.
● Real Objects: Are physical or software objects that are accessible by the OPC UA
Server application or that it maintains internally. Examples include physical
devices and diagnostics counters.
● OPC UA Server application: The OPC UA Server application is the code that
implements the function of the Server. It uses the OPC UA Server API to send and
receive OPC UA Messages from OPC UA Clients.
● OPC UA AddressSpace: AddressSpace is modeled as a set of Nodes accessible
by clients using OPC UA Services (interfaces and methods). Nodes in
AddressSpace are used to represent real objects, their definitions and their
references to each other.
● MonitoredItems: Entities in the Server created by the Client that monitor
AddressSpace Nodes and their real-world counterparts. When they detect a data
change or an event/alarm occurrence, they generate a Notification that is
transferred to the Client by a Subscription.
● Subscriptions: A Subscription is an endpoint in the Server that publishes
Notifications to Clients. Clients control the rate at which publishing occurs by
sending Publish Messages.
The OPC UA specifications are layered to isolate the core design from the
underlying computing technology and network transport. This allows OPC UA to be
mapped to future technologies as necessary, without negating the basic design [14].
For transportation and data formats, OPC-UA is able to use a couple of different
technologies, and this creates some sort of freedom for developers to create whichever
combination they need.
For data encoding: XML or UA Binary.
For transporting data: TCP or SOAP Web services over HTTP.
4.3.5. Comparison
in several different contexts and applications. Also, since CoAP is an HTTP with a
smaller overhead, this comparison will be restricted to CoAP and MQTT.
4.4. Microcontrollers
● All computers have a CPU (central processing unit) that executes programs.
● The CPU loads the program from somewhere. On your desktop machine, the
browser program is loaded from the hard disk.
● The computer has some RAM (random-access memory) where it can store
"variables."
● The computer has some input and output devices so it can talk to people. On your
desktop machine, the keyboard and mouse are input devices and the monitor and
printer are output devices. A hard disk is an I/O device that handles both input and
output.
17
add the heat naturally generated by the engine, the temperature can go as high as
150 or 180 degrees F (65-80 C) in the engine compartment. On the other hand, a
microcontroller embedded inside a VCR hasn't been ruggedized at all.
development project. Once the project is released, however, telemetry is what you are
looking for to enable automatic collection of data from real-world use. Telemetry is what
makes it possible to collect all that raw data that becomes valuable, actionable analytics.
One of the main benefits from telemetry is to be able to monitor the state of an
object or environment when you can not be physically present. Telemetry is an incredibly
valuable tool for ongoing performance monitoring and management. [16]
Cloud is an abstract virtual environment where programs and data are stored.
Cloud computing power is provided by data centers, which can contain systems for data
storage and many servers that have the ability to manage almost any software, and
customers pay flexibly according to the resources used, based on a monthly fee. Also in
Cloud Computing users do not need to buy software or maintain expensive servers and
devices for data storage, this leads to significant reduction of expenses, office space, and
internal staff for IT support and increase of data security. This solution was made to users
that need an efficient and adaptable infrastructure for the purpose of their business. This
involves a non-stop running service, available from anywhere in the world. [17].
There are many options for cloud computing platforms available on the market.
Windows Azure is the Microsoft solution that appeared in 2009 and contains the following
components:
● Windows Azure: Provides a platform for running Windows applications and storing
their data in the clouds. Windows Azure runs on a large number of servers in
Microsoft data centers, which are connected into a unified whole by Windows
Azure Fabric. Windows-based computing and storage services for cloud
applications are built on top of this fabric.
● SQL Azure: Provides data services in a cloud based on SQL Server. Although the
eventual goal of SQL Azure includes a range of data-oriented capabilities,
including data synchronization and reporting, the first SQL Azure component to
appear is SQL Azure Database, which provides a cloud-based database
management system (DBMS).
20
● (i) Key-value stores: data is stored as key-pairs values. These systems are similar
to dictionaries, where data is addressed by a single key. Values are isolated and
independent from another, and relationships are handled by the application logic.
● (ii) Column family database: it defines the data structure as a predefined set of
columns. The super columns and column family structures can be considered the
database schema.
● (iii) Document-based storage: a document store uses the concept of key-value
store. The documents are collections of attributes and values, where an attribute
can be multivalued. Each document contains an ID key, which is unique within a
collection and identifies document.
● (iv) Graph databases: graphs are used to represent schemas. A graph database
works with three abstractions: node, relationships between nodes, and key value
pairs that can attach to nodes and relationships.
For developers and administrators coming from the relational world, the
Cassandra data model can be very difficult to understand initially. Some terms, such as
“keyspace,” are completely new, and some, such as “column,” exist in both worlds but
have different meanings [20].
Cassandra defines a column family as a logical division that associates similar
data. For example, we might have a User column family, a Hotel column family, an
Address Book column family, and so on. In this way, a column family is somewhat
analogous to a table in the relational world. Putting this all together, we have the basic
Cassandra data structures: the column, which is a name/value pair (and a client-supplied
timestamp of when it was last updated), and a column family, which is a container for
rows that have similar, but not identical, column sets. The row keys are a reference to an
entity stored in the database, analogous to the basic row in SQL.
22
With a container-oriented approach, you can eliminate most of the issues that
arise when having inconsistent environmental setups and the problems that come with
them. The bottom line is that when running an app or service inside a container you avoid
issues that come with inconsistent environments.
Another important benefit when using containers is the ability to quickly instance
any container. For instance, that allows to scale-up fast by instantly instancing a specific
short-term task in the form of a container. From an application point of view, instantiating
an image (the container), should be treated in a similar way than instantiating a process
(like a service or web app), although when running multiple instances of the same image
across multiple host servers, you typically want each container (image instance) to run in
a different host server/VM in different fault domains, for reliability.
In short and as the main takeaways, the main benefits provided by containers are
isolation, portability, agility, scalability and control across the entire application lifecycle
workflow. But the most important benefit is the isolation provided between Dev and Ops.
Following these characteristics, the container concept is an excellent option to use
24
in applications that need to run on more than one cloud, applications that use
microservices and applications that benefit from DevOps. [23]
25
As this paper's main goal was the validation of an IoT platform as a tool to make
IoT data visualization\storage\management easier and more efficiently, first a comparison
study was executed in order to compare the pros and cons of several IoT platforms
available in the market. In this manner, the tool that seemed most appropriate for the
purpose of the project was chosen.
Subsequently, tests and validations were conducted with the platform, for that, a
microcontroller with a DTH sensor was used in order to simulate a real IoT device. The
objective was to test how the platform behaves, working directly with different protocols
and data transmission methods.
Other aspects of the platform were validated as well, like data storage,
visualization tools, integration with different databases and cloud services, alarm engines
and user management between others, all of these tests are described in Section 6.
To be able to understand these tests it is necessary to learn how to use properly
all of these technologies and approaches used during this project.
To choose the ideal IoT Platform, it was necessary to compare the main platforms
available on the market. The defined parameters to choose the platform was:
● Open Source;
● Support to install on cloud or own server;
● Variety of protocols;
● API support (External integrations);
● Analyzing and Visualization tools.
There is a limited quantity of Open Source IoT Platforms available on the market.
The following table was created based on this study [24] to hint the main features of each
open source platform found:
IoT Software Device Integration Security Protocols for Analytics Support for DB
Platform management data collection visualizations
26
ThingsBoard Yes REST Industry HTTP, MQTT, Real time Yes PostgreSQL,
APIs, standard OPC-UA, CoAP analytics(Ap Cassandra,
MQTT APIs encryption and Node-red ache Spark, HSQLDB
algorithms (SSL) Kafka)
and device
credentials types
(X.509
certificates and
access tokens)
Kaa IoT Yes Portable Link Encryption MQTT, CoAP, Real time Yes (Doesn't MongoDB,
Platform SDK (SSL), RSA key XMPP, TCP, IoT Data have own Cassandra,
available to 2048 bits, AES HTTP, WiFi, Analytics dashboards) Hadoop,
integrate key 256 bits Ethernet, and Oracle
any Zigbee Visualization NoSQL
particular with Kaa,
platform, Apache
REST API Cassandra
and Apache
Zeppelin
WSo2 Yes REST APIs Link Encryption HTTP, WSO2 Yes, WSO2 Yes Oracle,
(SSL) and basic ESB, MQTT Data PostgreSQL,
authentication Analytics MySQL, or
Server MS SQL
Site Where Yes REST API, Link Encryption MQTT, AMQP, Real-time No MongoDB,
Mule (SSL), Spring Stomp, analytics HBase ,
AnyPoint, Security WebSockets, (Apache InfluxDB
and more and direct Spark)
socket
connections
DeviceHive *Unknown REST API, Basic REST API, Real-time Yes (Doesn't PostgreSQL,
MQTT APIs Authentication WebSockets or analytics have own SAP Hana
using JSON MQTT (Apache dashboards) DB
Web Tokens Spark)
(JWT)
Thinger.io Yes REST APIs Link Encryption MQTT, CoAP Yes No MongoDB
(SSL/TLS) and and HTTP
basic
authentication
From the nine platforms, only four have support for visualizations, ThingsBoard,
Kaa IoT, WSo2, and DeviceHive. This support applies the capacity to see data on
dashboards, an important prerequisite. Comparing the tools only ThingsBoard and WSo2
27
have your own dashboard creation and management, the other tools use external tools to
be able to generate dashboards.
Comparing ThingsBoard and WSo2 is important to highlight the fact that the first
one has the better adaptability to the main protocols of IoT, including OPC-UA.
ThingsBoard presented a better usability and features compared with other open
source tools, so it was the IoT platform selected. Following this, we started with the study
of the platform.
5.2. Thingsboard
5.2.1. Licenses
ThingsBoard has two versions, the Community Edition and the Professional
Edition. The first one is open source and provides device management, data collection,
processing and visualization.
28
Figure 10. Comparison matrix between the two versions of thingsboard. [25]
ThingsBoard is designed to run and utilize the majority of hardware, from local
Raspberry PI to powerful servers on the cloud. Ways to set up a ThingsBoard cluster
include:
● Windows - install Thingsboard cluster on any pre-existing machines running
Windows.
● Linux (Ubuntu & CentOS) - install ThingsBoard cluster on any pre-existing
machines running Linux.
● Raspberry Pi 3 Model B (Raspbian Jessie) - install Cassandra and Thingboard
server on a Raspberry Pi 3 Model B.
● Docker (Linux or Mac OS) - install a single-node ThingsBoard cluster on your
Linux or Mac OS machine for development and testing.
● Docker (Windows) - install a single-node ThingsBoard cluster on your Windows
machine for development and testing.
29
● AWC EC2 installation using AMIs - install a single-node ThingsBoard cluster using
public AWS AMI.
5.2.3. Architecture
The general architecture of thingsboard is structured as the figure 11 shows:
● Device Application
● Rule Engine
● Core Services
Management of entities.
30
○ OPC-UA : ThingsBoard does not have native support and server nodes to
integrate OPC-UA devices. The ThingsBoard IoT gateway can be used for
this purpose.
○ CoAP: CoAP protocol is UDP based, but similar to HTTP it uses the
request/response model. CoAP observes options that allow users to
subscribe to resources and receive notifications on resource changes.
ThingsBoard server nodes act as a CoAP Server that supports both regular
and observed requests.
● Databases:
5.2.7. Pros/Cons
Cons: Most of Platform Integrations features are in the PE version (Azure, IBM
Watson, AWS IoT and etc); Most of customizable features are in the PE version; Small
Community; A lot of features still in development mode.
It is a great platform, the documentation is quite complete and it has a lot of
features. Although, if we need to make often integrations with third-party systems and
cloud services, the PE version should suit better.
For the tests and integration with ThingsBoard, the Wemos D1 Mini Pro board was
used, with the board we could test multiple protocols, such as MQTT, CoAP and HTTP
33
and see how the ThingsBoard platform receives, manage, store and show the values
received.
The Wemos D1 Mini Pro is a mini Wi-Fi board with 16MB flash, external antenna
connector and built-in ceramic antenna based on ESP-8266EX. The Wemos D1 Mini Pro
board is a suitable board for use in IoT (internet of things) projects and development of
electronic projects in general. It has 11 digital I / O pins, 1 analog input pin, 16MB flash
memory and supports interrupts, PWM, I2C and one-wire. Communication with the
computer and power is done by the micro-USB connector [26].
ESP-8266EX offers a complete and self-contained Wi-Fi networking solution; it
can be used to host the application or to offload WiFi networking functions from another
application processor. When ESP8266EX hosts the application, it boots up directly from
an external flash. In has integrated cache to improve the performance of the system in
such applications [27].
Since Wemos is based on ESP-8266EX microcontrollers, Arduino libraries, tools
and codes can be used without a problem.
5.4. DTH 11
As data examples, humidity and temperature were used, the data for these values
were read by a DTH 11 sensor.
34
These sensors are very basic and slow, but are great for hobbyists who want to do
some basic data logging. The DHT sensors are made of two parts, a capacitive humidity
sensor and a thermistor. There is also a very basic chip inside that does some analog to
digital conversion and spits out a digital signal with the temperature and humidity. The
digital signal is fairly easy to read using any microcontroller [28].
Its specifications are: Ultra low cost ; 3 to 5V power and I/O ; 2.5mA max current
use during conversion (while requesting data) ; Good for 20-80% humidity readings with
5% accuracy ; Good for 0-50°C temperature readings ±2°C accuracy ; No more than 1
Hz sampling rate (once every second) ; Body size 15.5mm x 12mm x 5.5mm 4 pins with
0.1" spacing.
5.5. PlatformIO
PIC32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32,
Teensy, TI MSP430, TI Tiva, WIZNet W7500.
And the following Frameworks: Arduino, ARTIK SDK, CMSIS, Energia, ESP-IDF,
libOpenCM3, mbed, Pumbaa, Simba, SPL, STM32Cube, WiringPi [29].
PlatformIO was used in this project to code for Wemos D1 board.
All the tests, procedures, approaches and results executed in this project are
going to be presented in this section. Since this paper proposes the validation, study and
tests of an IoT platform it is difficult to separate the results from the procedures, once that
our results are the success or failure of the tests itself.
An Ubuntu server 16.04.4 LTS virtual machine was installed in Azure Cloud
Service, in this server the Thingsboard cluster was installed and configured.
First, we created a resource in Azure Portal, this resource was the ubuntu server,
the Standard D1 v2 (1 vcpus, 3.5 GB memory) machine was chosen.
Once the virtual machine was up and running, we accessed it through SSH, using
the admin user and password.
Once the server is properly configured, the Thingsboard cluster can be installed;
for that, we need to install Cassandra, Thingsboard and Cassandra-Web.
In order to install Cassandra the following link was used
https://www.rosehosting.com/blog/how-to-install-apache-cassandra-on-ubuntu-16-04/.
To install Thingsboard the https://thingsboard.io/docs/user-guide/install/linux/
tutorial was used, during the installation we chose the external database configuration
37
As mentioned in Section 4.8 Docker is a project and application that provides the
containerization concept, where it is possible to run applications as portable,
self-sufficient and on any cloud or on-premises. The task consisted of using the Docker
on Azure and installing ThingsBoard in this environment. Then after, it makes possible to
generate a docker image with all the settings to possibly run it on any server.
It was identified in many forms to do it, as many problems too, which will be
described below.
Problem: To install the Docker CE for Azure within a Linux VM a Service Principal is
needed. The Service Principal generates an AD App ID; AD App Secret; AD Tenant.
All three pieces of informations are required for the setup of Docker CE.
Error: Running the Service Principal shows the Insufficient privileges to complete an
operational error.
38
Tutorial Link:
https://cloudify.co/2016/11/22/step-by-step-guide-deploying-docker-swarm-with-azure
-container-service.html
Error: When deploying the Azure Container service: The subscription is not
registered to use namespace “Microsoft.ContainerService”.
Cause: These errors show for one of three reasons: The resource provider has not
been registered for your subscription; The API version not supported for the resource
type; Location not supported for the resource type.
Workarounds:
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-r
egister-provider-errors
First try:
Steps:
1. It was installed by adding a new resource, searchin as ‘Docker CE’.
2. It was chosen as a virtual machine with HDD disc type with 3.5 GB of
memory.
Error: “The resource operation completed with terminal provisioning state ‘Failed’.
(Code: ResourceDeploymentFailure)
- OS Provisioning failed for VM ‘thingsboarddocker’ due to an internal error.
(Code: OSProvisioningInternalError)”.
Second try:
Steps:
1. It was installed by adding a new resource, searchin as ‘Docker CE’.
2. It was chosen as a virtual machine with HDD disc type with 4 GB of
memory.
Error cause: “A provisioning failure happens when the OS image fails to load either
due to incorrect preparatory steps or because of selecting the wrong settings during
the image capture from the portal.”.
Problem: It was not possible to access the ThingsBoard portal through a server
inside the VM on Azure. Maybe an IP and port configuration is necessary to use it.
This line is responsible for creating a container with Ubuntu and connecting the
mainly ThingsBoard ports with the container host ports. That will generate the
container with an Ubuntu SO and open it to be able to prepare all the environment
to support the ThingsBoard application within.
● apt-get update
● add-apt-repository ppa:webupd8team/java
Add a new repository to make it possible to install the Java JDK, a prerequisite for
ThingsBoard installation.
● apt-get update
● add-apt-repository ppa:webupd8team/java
Observations: It was not possible to install Cassandra in this environment. It only
worked installing without an external database installation.
42
Thingsboard has three levels of users: Admin, Tenant and Customer users, more
on this here: https://thingsboard.io/docs/user-guide/ui/users/.
Since we installed using the option --loadDemo, a lot of demo data has already
been created, like some demo accounts, devices, dashboards, rules, plugins and alarms.
In the first test a device was created, called DTH 11 DEMO DEVICE, once the
device is created, we could get its access token and id, those attributes are going to be
used to send the data to the platform (Section 6.3). After this dashboard was created, this
dashboard shows the humidity and temperature charts and values, in real time
visualization.
In this dashboard, a gpio (General Purpose Input/Output) control was also created
in order to control the LED available in the device.
All these steps were based on this tutorial:
https://thingsboard.io/docs/samples/esp8266/temperature/.
The circuit was created with the board Wemos D1 (Section 5.3) and DTH sensor
(Section 5.4). The purpose of this circuit was to simulate a real IoT device that would
keep uploading data to the platform every second, this data was temperature and
humidity. Also, a LED was used as an actuator, in order to validate the capability of
sending commands from Thingsboard to devices, for example switching a LED on and
off, the circuit schema can be seen in figure 22 and the real device in figure 23.
The program uploaded to the board was developed using platformIO IDE (Section
5.5).
44
Figure 22. IoT device scheme that reads temperature and humidity.
Arduino Libraries which are going to be used in the project, this can be done easily with
platformIO IDE. The libraries required are:
● ArduinoJson: Used to work with Json data format.
● PubSubClient: MQTT library that contains all the necessary methods and functions
for publishing data to a subscriber through an MQTT broker.
● ESP8266Wifi: This is used to connect the Wemos board in some WIFI network.
To make the integration between the device and the Thingsboard platform, 3
attributes are important, the server address (address were thingsboard is running), the
device ID (Id that can be copied from Thingsboard platform by just clicking into the device
that was created in Section 6.2) and the device access Token (Define the device Token
that we will use, copy the token from Thingsboard device panel).
The Wemos complete code for this project can be seen in the Appendices Section,
this test was executed based on this Thingsboard tutorial:
https://thingsboard.io/docs/samples/esp8266/temperature/.
Thingsboard does not allow database management through its graphical interface,
so we need to connect directly with the database service that has been used with the
platform. In this case, we are using NoSQL Cassandra for performance purposes. The
Thingsboard Cassandra database can be accessed with two different ways:
● Alternative 1: The server and the Cassandra instance can be accessed through
SSH. Command (mac or linux): sudo ssh useradm@thingsboardserveraddress.
Once accessing the server, just use the command “cqlsh”. This will open the cql
terminal, which you can use to make queries and operations in the Cassandra
cluster.
● Alternative 2: There is an UI tool called Cassandra Web
(https://github.com/avalanche123/cassandra-web), where cql commands and
queries can be executed, with this tool we can see the tables, rows, keyspaces
and the whole DB in an easier way. Note: The Cassandra Web may not work
properly when dealing with a large amount of data if any issue appears, test
accessing Cassandra through SSH (first alternative).
The same query, but it returns the last 1 month of temperature data from a
device:
48
The same query, but it returns the last 10 minutes of temperature data from a
device:
SELECT * FROM thingsboard.ts_kv_cf WHERE entity_id =
f35bcef0-3ef5-11e8-8fd0-cb746776d0c2 and key = 'temperature' and ts >=
timeAgoMinsOrDaysOrMonths(10,null,null) ALLOW FILTERING;
This new function allow us to execute clean routines in the database, for instance,
if we want to erase the last seven days of data, we can execute:
DELETE FROM thingsboard.ts_kv_cf WHERE entity_id =
f35bcef0-3ef5-11e8-8fd0-cb746776d0c2 and key = 'temperature' and partition IN
(1525132800000, 1522540800000,1525132800000) and entity_type = 'DEVICE'
and ts >= timeAgoMinsOrDaysOrMonths(null,7,null);
If we want to keep just the last 7 days of data and erase everything else:
DELETE FROM thingsboard.ts_kv_cf WHERE entity_id =
f35bcef0-3ef5-11e8-8fd0-cb746776d0c2 and key = 'temperature' and partition IN
(1525132800000, 1522540800000, 1525132800000) and entity_type = 'DEVICE'
and ts <= timeAgoMinsOrDaysOrMonths(null,7,null);
Note: the partition and the entity_type must be used to delete actions on
Cassandra (because they form the primary key of the entity). To see all the partitions and
be able to use them in the IN clause, you need to query the ts_kv_partitions_cf table. For
that, use the Cassandra Web (serveraddress:3000), go to thingsboard/ts_kv_partitions_cf
and then copy all the partitions of the values that you want to delete, for example,
humidity and then put them inside the IN clause.
49
Thingsboard can act as a web services RESTful and this allows us to make REST
calls and get the data back from the platform, this would be great if we want to use all the
data collected by the platform in a machine learning algorithm for example.
To make requests, some authentications are needed. Below the steps are
described if one wants to use the Rest API functions in Thingsboard.
Once those steps are finished, we are able to make some requests examples, for
instance, fetch list of latest values for particular entity type and entity id using GET
request:
curl -v -X GET
http://serveraddress:8080/api/plugins/telemetry/DEVICE/ac8e6020-ae99-11e6-b9b
d-2b15845ada4e/values/timeseries?keys=humidity,temperature \
--header "Content-Type:application/json" \
--header "Bearer X-Authorization: $JWT_TOKEN (The token generated)"
This will return the Json body with all the data requested. This request example
was executed through curl tool, but other solutions can be applied as well, such as
postman (https://www.getpostman.com/) or any other tool to make RESTful requests.
It is possible to show dashboards from thingsboard into an external web page. The
process consists of one embedded html (thingsboard dashboard) that will be displayed in
an iframe tag (external page).
In order to do that, enter in Thingsboard with a Tenant account, go to devices and
select the device related to the dashboard that is going to be shown in the HTML page
and make the device public, by clicking on the icon right at the bottom of the device card.
After that, do the same with the device’s dashboard, this will generate a link, copy this
link and paste inside an iframe tag, then the tag can be displayed anywhere inside an
HTML page, the figure 24 shows the process.
Figure 24. Making device and dashboard public in order to make them visible in an external web page.
Figure 25. Rule being configured and email alarm being received.
through external MQTT broker or OPC-UA server. Devices that support other protocols
may be connected to gateway by implementing custom extensions [31].
Thingsboard IoT Gateway provides following features:
● OPC-UA extension to collect data from devices that are connected to OPC-UA
servers.
● MQTT extension to collect data that is published to external MQTT brokers.
● Persistence of collected data to guarantee data delivery in case of network and
hardware failures.
● Automatic reconnecting to Thingsboard clusters.
● Simple yet powerful mapping of incoming data and messages in a unified format.
The Mosquitto MQTT broker was used to test the MQTT external broker
connection through ThingsBoard IoT Gateway and ThingsBoard. Mosquitto is an open
source (EPL/EDL licensed) message broker that implements the MQTT protocol versions
3.1 and 3.1.1. Mosquitto is lightweight and is suitable for use on all devices from low
power single board computers to full servers [32]. It was installed and configured based
on this tutorial http://www.steves-internet-guide.com/install-mosquitto-broker/.
Both Mosquitto and ThingsBoard Gateway use the same port (1883) for MQTT
service by default. So to test it in the same host was necessary to change the Mosquitto
running port to 1884. The following command was used:
● mosquitto -p 1884
54
6.8.2. OPC-UA
For the OPC-UA example the KEPServerEX for Windows was installed on a
Windows machine. KEPServerEX is a connectivity platform that provides a single source
of industrial automation data to all of your applications. The platform design allows users
to connect, manage, monitor and control diverse automation devices and software
applications through a user interface [57]. After the installation of this server, the sample
OPC-UA tag values of it were transformed into ThingsBoard attributes and telemetry. In
that manner it was possible to visualize data using the ThingsBoard widgets. Those steps
were done using the ThingsBoard documentation tutorial
https://thingsboard.io/docs/iot-gateway/getting-started/#step-9-connect-to-external-opc-u
a-server.
Observations: It was identified a problem to map all the telemetry device fields between
the KEPServer and ThingsBoard, where only the ‘Tag1’ attribute was mapped.
55
Yepzon Asset is an industrial tracker for cargo and asset management. It has its
own platform for visualization and management of devices and data, but is limited when
compared to Thingsboard, so a good approach is to integrate these two products.
Yepzon provides an integration API using RESTful methods, which can be used to
get the data that the tracker sent to the platform.
Thingsboard provides map widgets for location, route and tracking visualization, so
what needs to be done is get the data from Yepzon through their API and show the data
in the map widgets.
In order to do that, the map/latest values widget needs to be created in one
dashboard. When creating the Widget Thingsboard will ask for the datasource for the
map, there are 2 options that can be chosen, from a device and from a javascript
function, since there is no device for Yepzon because the data are pulled directly from
their platform, the function option needs to choose. In this function the Yepzon API is
going to be used for making the requests, each function will return one attribute from
Yepzon’s platform. Figure 26 shows the function used to pull latitude from the platform.
Figure 26. Creating the javascript function to get Latitude from Yepzon Asset Device.
56
In order to show the last location of the tracker, latitude and longitude attributes
are enough, but Yepzon provides temperature and humidity values as well, and these
values can be shown in the map marker description, so to get these values, the same
function can be used, just the return value needs to be changed to desirable attributes.
7. Conclusion
Comparing the IoT Platforms, choosing the best option, studying, resuming your
features and implanting some device solutions on it, made it possible to begin the
validation of the ThingsBoard platform as a solution for an academic IoT environment.
As shown it was possible to implement the tool on a cloud or on-premises server. There
were a great variety of ways to deploy it, which showed that it is a tool with great
adaptability.
The big quantity of IoT protocols that ThingsBoard supports and how easy it was
to integrate with the developed solutions showed the great potential of this platform. The
main integrations using HTTP, CoAP, and MQTT have worked well. Unfortunately, the
OPC-UA implantation was not done in a real scenario, with a real OPC-UA device and
server, but only the fact to support this and more other protocols through the
ThingsBoard Gateway application maintains the ThingsBoard ahead of its rival platforms.
Around the data management the application worked well, storing data from
devices with a NoSQL solution like Cassandra. The limitation here is that the platform
does not have specific functions to manage the device's data, therefore some analytics
and data management needs to be made independent from ThingsBoard.
The power of its visualization tools was proved as well. The platform has a vast
quantity of widgets, which could be customized or new widgets could be created through
HTML, CSS, and Javascript. It is possible to show the dashboards on a website through
a responsive iFrame that works well on both computer and mobile screens.
Customization and the possibility of managing actions and events interconnected
with the telemetry data of devices through the ThingsBoard Web UI showed it
promissory. With it, it is possible to create rules, alarms and send emails based on
specific data from a device.
About user and environment management, it was possible to use the platform to
create users hierarchically that would help to implant the tool in employees, teachers, and
students in academic contexts.
As described in Section 6.1.1, there were problems with the installation on Azure
using Docker tool, more with Docker than the ThingsBoard platform, that required more
59
study. More special attention to integrating an OPC-UA real solution needs to be made
as well. An adequate tool to do analytics work on specific data by the ThingsBoard DB
needs to be seen. And to finalize, it needs to be implanted in a real server with many
users, and devices, to validate the error handling, outliers and possible issues that can
occur in some specific cases.
60
8. Acknowledgments
We would like to thank all the hospitality and support which we were received by
our project coordinator Joni Kukkamäki, who helped us greatly with our introduction,
adaptation, and follow-up both in the research project and in our stay in Hämeenlinna.
To Juha-Matti Torkkel for all the support and suggestions related to our research
project.
To our project coordinator in Brazil Robson Costa for all the support, clarifications
and ideas that helped us in the development of this paper.
To our another project coordinator in Brazil Vilson Heck Júnior for all the support
with the beginning studies around this exchange program.
To all the Smart Services unit servers and colleagues who welcomed us with arms
wide open and were always willing to help us with anything.
To HAMK and all its really welcoming structure, for all the support of laboratories
and equipment needed for the project to be successfully developed.
And last but not least, to IFSC and this great project that gave us the opportunity
to develop this exchange program.
61
9. References
[1] ZANELLA, A. et al. Internet of things for smart cities. IEEE Internet of Things Journal,
v. 1, n. 1, p. 22–32, Feb 2014. ISSN 2327-4662.
[2] ATZORI, L.; IERA, A.; MORABITO, G. The internet of things: A survey. Computer
Networks, v. 54, n. 15, p. 2787 – 2805, 2010. ISSN 1389-1286. Available at:
<http://www.sciencedirect.com/science/article/pii/S1389128610001568>.
[3] GARTNER. Gartner Says 8.4 Billion Connected "Things"Will Be in Use in 2017, Up 31
Percent From 2016. 2017. Available at: <https://www.gartner.com/newsroom/id/
3598917>.
[5] KHAN, S. U.; ZAHEER, R.; KHAN, S. Future internet: The internet of things
architecture, possible applications and key challenges. International Conference on
Frontiers of Information Technology (FIT), v. 10, p. 257–260, 2012.
[7] MQTT Essentials Part 3: Client, Broker and Connection Establishment, 2015.
[Online]. Available at:
<https://www.hivemq.com/blog/mqtt-essentials-part-3-client-broker-connection-establish
ment>. [Accessed 24 April 2018].
[8] MQTT Protocol Tutorial: Step by step guide, Mosquitto and MQTT Security. [Online].
Available at: <https://www.survivingwithandroid.com/2016/10/mqtt-protocol-tutorial.html>.
[Accessed 24 April 2018].
[9] W3C. Hypertext Transfer Protocol – HTTP/1.1, 1999. [Online]. Available at:
<https://www.w3.org/Protocols/rfc2616/rfc2616-sec1.html#sec1>. [Accessed 24 April
2018].
[10] KELLOGG, T. Why HTTP won’t work for IoT, 2014. [Online]. Available at:
<https://www.edn.com/electronics-blogs/eye-on-iot-/4437056/Why-HTTP-Won-t-Work-for
-IoT>. [Accessed 7 May 2018].
62
[11] IoT protocols List: IoT data and network protocols in 2018, 2018. [Online]. Available
at: <https://www.survivingwithandroid.com/2016/08/iot-protocols-list.html>. [Accessed 24
April 2018].
[12] MINERVA, R.; BIRU, A.; ROTONDI, D. Towards a definition of the internet of things
(iot). IEEE Internet Initiative, n. 1, May 2015.
[13] SHELBY, Z.; HARTKE, K.; BORMANN, C. Rfc7252 the constrained application
protocol (coap). Internet Engineering Task Force (IETF), 2014. ISSN 2070-1721.
Available at: <https://tools.ietf.org/pdf/rfc7252.pdf>.
[14] OPC Foundation, “OPC Unified Architecture Specification”, Parts 1–11, 2009.
[Online]. Available at: <www.opcfoundation.org>. [Accessed 24 April 2018].
[18] J. Gong, P. Yue, H. Zhou, "Geoprocessing in the Microsoft Cloud computing platform
- Azure", Commission IV, WG IV/4 , 2010. Available at:
<http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.221.9206&rep=rep1&type=pd
f>
[19] R. Hecht and S. Jablonski, “NoSQL evaluation: a use case oriented survey,” in
Proceedings of the International Conference on Cloud and Service Computing (CSC ’11),
pp. 336–341, December 2011.
[21] E. Hewitt, “Cassandra: The Definitive Guide” O`Reilly Media, Inc. 2011.
63
[22] Flow.ci. Introduction to Containers: Concept, Pros and Cons, Orchestration, Docker,
and Other Alternatives, 2016 [Online]. Available at:
<https://medium.com/flow-ci/introduction-to-containers-concept-pros-and-cons-orchestrati
on-docker-and-other-alternatives-9a2f1b61132c>. [Accessed 26 April 2018].
[23] Linthicum, D. Three apps in which Docker containers really shine, 2015 [Online].
Available at:
<https://searchitoperations.techtarget.com/tip/Three-apps-in-which-Docker-containers-re
ally-shine>. [Accessed 26 April 2018].
[24] H2S Media Team. 9 Best & Top Open source IoT Platforms To Develop the IOT
Projects, 2017 [Online]. Available at:
<https://www.how2shout.com/tools/best-opensource-iot-platforms-develop-iot-projects.ht
ml>. [Accessed 26 April 2018].
[26] Wemos Documentation V1.1.0 (current version), 2018 [Online]. Available at:
<https://wiki.wemos.cc/products:d1:d1_mini_pro> [Accessed 26 April 2018].
[27] ESP8266EX Datasheet Version 4.3, Espressif Systems IOT Team, 2015, [Online].
Available at: <http://img.filipeflop.com/files/download/Datasheet-ESP8266EX-v4.3.pdf>.
[Accessed 26 April 2018].
[28] DHT11, DHT22 and AM2302 Sensors Adafruit Industries, 2018 [Online]. Available
at: <https://cdn-learn.adafruit.com/downloads/pdf/dht.pdf>. [Accessed 26 April 2018].
[30] G2 Crowd. Best IoT Management Software, 2018. [Online]. Available at:
<https://www.g2crowd.com/categories/iot-management>. [Accessed 26 April 2018].
10. Appendices
10.1. MQTT wemos code. The full PlatformIO project can be downloaded here
https://bit.ly/2si8V4c
#include <Arduino.h>
#include <ArduinoJson.h>
#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#include "DHT.h"
#define WIFI_AP "AlykkaatPalvelut"
#define WIFI_PASSWORD "DigiHiki2017"
#define DHTPIN D4 // Digital PIN used to read DTH values
// Digital PINs used to receive controls from thingsboard (ex, Leds, Motors)
#define GPIO6_PIN 6
#define GPIO7_PIN 7
#define GPIO6 12
#define GPIO7 13
#define DHTTYPE DHT11 // Define the type of the DHT
DHT dht(DHTPIN, DHTTYPE); // Sets up the DHT ;
char deviceId[] = "f35bcef0-3ef5-11e8-8fd0-cb746776d0c2";
char thingsboardServer[] = "52.178.138.16"; // Define the thingsboard server
Address
int mqttPort = 1884; // The default is 1883 but in some cases it migh be required
to change the port
int readingTries = 0; // Number of times that wemos will try to recollect the
data in case of a failure;
#define TOKEN "DHT11_DEMO_TOKEN" // Define the device Token wich we will use
(copy the token from thingsboard device panel)
WiFiClient wifiClient;
PubSubClient client(wifiClient); // MQTT Client;
//Control variables
int status = WL_IDLE_STATUS;
unsigned long lastSend;
boolean gpioState[] = {false, false};
//This method will read the data from the sensor and will send it to thingsboard
server through MQTT
void getAndSendTemperatureAndHumidityData()
{
//Serial.println("Collecting temperature data.");
65
//This method will read the status from the GPIO pins (HIGH -1 LOW - 0) and will
return a String with the values
String get_gpio_status() {
// Prepare gpios JSON payload string
StaticJsonBuffer<200> jsonBuffer;
66
// The callback for when a PUBLISH message is received from the server. (Method
used just in the GPIO control part)
void on_message(const char* topic, byte* payload, unsigned int length) {
Serial.println("On message");
char json[length + 1];
strncpy (json, (char*)payload, length);
json[length] = '\0';
Serial.print("Topic: ");
Serial.println(topic);
Serial.print("Message: ");
Serial.println(json);
// Decode JSON request
StaticJsonBuffer<200> jsonBuffer;
JsonObject& data = jsonBuffer.parseObject((char*)json);
if (!data.success())
{
67
Serial.println("parseObject() failed");
return;
}
// Check request method
String methodName = String((const char*)data["method"]);
if (methodName.equals("getGpioStatus")) {
// Reply with GPIO status
String responseTopic = String(topic);
responseTopic.replace("request", "response");
client.publish(responseTopic.c_str(), get_gpio_status().c_str());
} else if (methodName.equals("setGpioStatus")) {
// Update GPIO status and reply
set_gpio_status(data["params"]["pin"], data["params"]["enabled"]);
String responseTopic = String(topic);
responseTopic.replace("request", "response");
client.publish(responseTopic.c_str(), get_gpio_status().c_str());
client.publish("v1/devices/me/attributes", get_gpio_status().c_str());
}
}
void InitWiFi()
{
Serial.println("Connecting to AP ...");
// attempt to connect to WiFi network
WiFi.begin(WIFI_AP, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to AP");
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
status = WiFi.status();
if ( status != WL_CONNECTED) {
WiFi.begin(WIFI_AP, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
68
Serial.println("Connected to AP");
}
Serial.print("Connecting to ThingsBoard node ...");
// Attempt to connect (clientId, username, password)
if ( client.connect(deviceId, TOKEN, NULL) ) {
Serial.println( "[DONE]" );
client.subscribe("v1/devices/me/rpc/request/+");
// Sending current GPIO status
Serial.println("Sending current GPIO status ...");
client.publish("v1/devices/me/attributes", get_gpio_status().c_str());
} else {
Serial.print( "[FAILED] [ rc = " );
Serial.print( client.state() );
Serial.println( " : retrying in 5 seconds]" );
// Wait 5 seconds before retrying
delay( 5000 );
}
}
}
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
pinMode(GPIO6, OUTPUT);
pinMode(GPIO7, OUTPUT);
dht.begin();
delay(10);
InitWiFi();
client.setServer( thingsboardServer, mqttPort );
client.setCallback(on_message);
lastSend = 0;
}
void loop() {
if ( !client.connected() ) {
reconnect();
}
getAndSendTemperatureAndHumidityData();
lastSend = millis();
}
}
client.loop();
}
10.2. HTTP wemos code. The full PlatformIO project can be downloaded here
https://bit.ly/2LC0MjJ
#include <Arduino.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include "DHT.h"
#define WIFI_AP "AlykkaatPalvelut"
#define WIFI_PASSWORD "DigiHiki2017"
#define DHTPIN D4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
HTTPClient http;
char thingsboardServer[] =
"http://192.168.1.102:8080/api/v1/DHT11_DEMO_TOKEN/telemetry";
#define TOKEN "DHT11_DEMO_TOKEN"
WiFiClient wifiClient;
void getAndSendTemperatureAndHumidityData()
{
Serial.println("Collecting temperature data.");
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
if(WiFi.status()== WL_CONNECTED){
// Just debug messages
// Serial.print( "Sending temperature and humidity : [" );
// Serial.print( temperature ); Serial.print( "," );
// Serial.print( humidity );
// Serial.print( "] -> " );
void InitWiFi()
{
Serial.println("Connecting to AP ...");
// attempt to connect to WiFi network
WiFi.begin(WIFI_AP, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to AP");
}
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
delay(10);
InitWiFi();
void loop() {
if ( millis() - lastSend > 1000 ) { // Update and send only after 1 seconds
getAndSendTemperatureAndHumidityData();
lastSend = millis();
}
}