Acquisition and management of data using Sentilo

May 13, 2019 by
Acquisition and management of data using Sentilo
Boot & Work Corp. S.L., Support Team

Index

1. Introduction
2. Requirements
4. Description
5. Sentilo client library for Arduino
    5.1 Install
    5.2 Usage
6. Sketch

Introduction


Sentilo is the result of a project conceived by the city council of Barcelona in 2012 to define the strategy and actions necessary to achieve a global positioning of Barcelona as a reference in the field of smart cities.

It is a free and open source platform for interconnection between sensors and actuators designed to fit into Smart City architecture in any city that seeks easy interoperability and great openness.


The architecture of Sentilo has the following parts:

    - A front-end for message processing, with a REST API.

    - A web administration console to configure the system and manage the catalog

    - A memory database

    - A NoSQL database, in order to achieve a more flexible and scalable system

    - A universal viewer from a website where to publish the data

    - A statistics module that records and displays the basic performance indicators of the platform.

    - A set of agents for the exploitation of databases and for processing the internal codes.

Sentilo in Barcelona: 

The city of Barcelona is using Sentilo as the middleware that interconnects the sensor and actuator loads deployed throughout the city with the applications that supervise and control them. As of 2016, up to 3,200,000 records per day are recorded, with peaks of 2000 registers per second and the structure consists of 1800 sensors, in a total of 14000 parameters to be treated.


Requirements


Ethernet PLC:      Ethernet PLC          

Sentilo Arduino Client Library:             Sentilo Arduino Client Github Library  

 

Description

The structure of the Sentilo platform consists of several components that provide the services.

In order to operate the platform, it uses the following components:


- Publication/subscription server for communication with sensors and actuators and also, to be able to subscribe the actuators to alerts.

It is based on Redis, a non-relational database engine in memory, based on storage in dictionary-type tables and designed to act as a data structure server.

The subscription allows you to listen to a channel and the publication allows you to send messages through the channel. The format used by the platform to send the messages will be JSON (JavaScript Object Notation).


-  NoSQL Database (Not Only Structured Query Language) MongoDB, to have a more efficient and elastic database.
MongoDB is an open source software for the creation and management of document-oriented, scalable and high-performance databases.

-  MySQL database manager, relational database management system, which uses the SQL language. The platform is used to be able to export the data of the events to external relational databases.


-     Tomcat Web Server to host the Web Catalog application. It provides an environment for Java coding to be executed in cooperation with a stand-alone web server that allows a high level of traffic and high availability.



Structure of the Sentilo platform


Sentilo client library for Arduino

Install


Download and unzip the file to ~/Documents/Arduino/libraries where ~/Documents/Arduino is your sketchbook directory.

> cd ~/Documents/Arduino
> mkdir libraries
> cd libraries
> copy the file contents here

You can import the /release/sentilo-client-arduino.zip library file form the Arduino IDE > Program > Include library > Add .ZIP Library.


Usage

Include

You need to have the Ethernet2 library already included.

#include <Ethernet2.h>
#include <SPI.h>
#include "SentiloClient.h"

Run the sample code

In the Arduino IDE, navigate to File > Examples > sentilo-client-arduino and select one of the three examples that you will see in the folders

  • SentiloClient-Example-01.ino
  • SentiloClient-Example-02.ino
  • SentiloClient-Example-03.ino

Configure the connection

You must provide some custom configuration before running these sample codes:

char* apiKey = "YOUR_API_KEY";
char* ip = "YOUR_IP_ADDRESS";
int port = YOUR_PORT;

Please, provide your credentials or api key, the Sentilo instance host ip and its port. After that, you can upload the sketch to the Arduino device. 

 

Sketch

The SentiloClient Library for Arduino offers a basic C++ library implementation that allows to the developer a quick integration sketch with the Sentilo Platform through its API Rest Client.

For these examples we’ll create a new sensor in the Sentilo Platform, only if it doesn’t exists, and then we’re going to publish some observations obtained from the local sensors.

 

#include <Ethernet2.h>
#include <SPI.h>

#include "SentiloClient.h"

/*******************************************/
/***** SENTILO *****************************/
/*******************************************/
char* apiKey = "YOUR_API_KEY";
char* ip = "YOUR_IP_ADDRESS";
int port = YOUR_PORT;
char* componentId = "sample-component";
char* providerId = "samples-provider";
char* sensorId = "sample-sensor-arduino-01";

// The Sentilo Client object
SentiloClient sentiloClient = SentiloClient(ip, port);

/*******************************************/
/***** NETWORK *****************************/
/*******************************************/
const int networkConnectionTimeout = 30;

/*******************************************/
/***** GLOBAL VARS *************************/
/*******************************************/
const int generalCalibrationTimeout = 1000; // Wait after system setup is complete
String response = ""; // Rest call response (normaly as JSON message)
int statusCode = -1; // Rest call return code (the HTTP code)

void setup() {
        // Begin serial for debug purposes
        Serial.begin(9600);

        // Setup the Sentilo Client and the network connection
        setupSetiloClient();

        // Wait time for a general calibration
        delay(generalCalibrationTimeout);
}

void loop() {
        // Create the Observation object
        SentiloClient::Observation observation;
        observation.value = "This is a sample observation";

        Serial.println("[loop] Publishing a sample observation...");

        // Publish the observation to Sentilo Platform
        statusCode = sentiloClient.publishObservation(providerId, sensorId, observation, apiKey, response);

        // Read response status and show an error if it is necessary
        if (statusCode !## 200) {
                Serial.print("[loop] [ERROR] Status code from server after publish the observations: ");
                Serial.println(statusCode);
                Serial.print("[loop] [ERROR] Response body from server after publish the observations: ");
                Serial.println(response);
        }

        Serial.println("[loop] Sample observation published!");
        Serial.println("[loop] Program ended");

        // The example has ended, so we are going to execute an infinite loop
        while (true) {}
}


/** Setup the Sentilo Client object, this process also configures the network connection **/
void setupSetiloClient() {
        Serial.print("[setup] Connecting to network via DHCP ");
        sentiloClient.dhcp();
        for (int i = 0; i < networkConnectionTimeout; i++) {
                Serial.print(".");
                delay(100);
        }
        Serial.println(" done!");
        Serial.println("[setup] Connection is now established!");
}


You can follow the Sentilo tutorial for Arduino on SentiloClient blog page.

​Search in our Blog

Acquisition and management of data using Sentilo
Boot & Work Corp. S.L., Support Team May 13, 2019

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>