Release 4.1: Publicación de APIS REST vía NGSI V2

En la Release 4.1 de Sofia2 IoT Platform se ha incorporado una novedad en el API Manager.


Se trata de la posibilidad de publicar APIS que expongan los datos a través del protocolo NGSI.

Es tan sencillo como seleccionar este nuevo tipo de API “Publicar Ontología como API REST NGSI” en API MANAGER > APIs > Crear API:


Por último, seleccionamos la operación GET disponible para este tipo de APIs y creamos el API.

A la hora de probar el API, nos fijamos en que el endpoint cumple con los requisitos del protocolo NGSI V2:


Para más información se puede consultar este post dónde se desarrolla un ejemplo completo de consultas mediante el protocolo NGSI, de donde se extrae el siguiente ejemplo de query:




Release 4.1: Publicación de APIS REST vía NGSI V2

Soporte consultas desde el CRUD para TimeSeries

En posts anteriores hemos hablado de las ontologías TimeSeries que dan soporte al concepto de series temporales.


Recientemente se ha añadido una nueva funcionalidad para estas ontologías, que consiste en la posibilidad de realizar consultas desde el CRUD de la consola de administración.

Lo primero a tener en cuenta es recordar que en este tipo de ontologías, la instancia a insertar tiene que concordar con el tipo de dato definido a la hora de crear dicha ontología. En este caso la ontología con la que estamos trabajando tiene un tipo de dato simple, por tanto la instancia que se debe de enviar tendrá que ser del tipo:

{“timestamp”:{“$date”: “2014-01-30T17:14:00Z”},”value”:”string”}

Por lo que si accedemos a  Ontologías > Gestión Crud de Instancias y seleccionamos una ontología de tipo TimeSeries, el formulario que nos muestra para insertar datos, cumplirá con el esquema anterior:


Otro detalle a recordar es la forma en el que se insertan los datos en las ontologías TimeSerie, dónde sólo hay una instancia por cada ventana temporal dónde se agruparan los datos enviados dependiendo de la configuración de dicha ventana. Por esta razón hasta que no cambiemos de ventana temporal, solo nos aparecerá una instancia :


A la hora de borrar desde esta pantalla hay que tener en cuenta que se borrará toda la instancia correspondiente a la ventana temporal.

Soporte consultas desde el CRUD para TimeSeries

Ejemplo APIS NGSI v2 en Sofia2

ngsi8Una de las capacidades del API Manager de Sofia2 es permitir exponer ontologías como entidades para ser consultadas mediante el protocolo NGSI v2.

En este post vamos a mostrar como crear una pequeña aplicación que realiza consultas a Sofia2 mediante el protocolo NGSI v2.

Una entidad NGSI tiene siempre dos atributos obligatorios:

  • id: identificador único de la entidad.
  • type: define el tipo de entidad.

De manera que para exponer con el API Manager de Sofia2 una ontologia como API NGSI v2 es necesario que disponga al menos de dichos atributos.

Seguir leyendo “Ejemplo APIS NGSI v2 en Sofia2”

Ejemplo APIS NGSI v2 en Sofia2

IoT Technologies and its support in Sofia2


IoT technologies make it easy to connect all kinds of things to the network and develop applications to control and manage these “things”. All the complexities of enabling connectivity, services, and deployment for these devices is the task of the IoT platform.

An IoT platform ensures integration with different hardware devices supporting a wide range of communication protocols. Through the integration interfaces provided by the platform, you can also manage the IoT data collected to specific systems for data visualization, data storage, as well as transmitting data to connected devices (configuration, notifications) or between them (controls, events ).

IoT platforms are also known as IoT Middleware, which underlines its functional role as mediator between hardware and application layers.

Let’s see an IoT flow and the components involved:


Sofia2 supports each and every one of the modules in the previous diagram as follows:


         Generic IoT Platform                                  Sofia2 IoT Platform

p2                 thingssofia2

We understand Things as any device that is capable of sending data, whether sensors, surveillance cameras, robotic arms, Smart watch … Some of the devices supported by Sofia2 are:

  • Devices:
    • Opening and closing doors sensor : CLIMAX, Leedarson, Nyce, Wulian, Centralite.
    • Environmental thermometer: Several manufactures
    • Pulsoximetros: several manufactures using IEEE protocol
  • Smart Home: presence sensor: CLIMAX, Leedarson, Nyce, Wulian, Centralite, DEVELCO.
  • Smart Building: Smart Plug: Meazon, 4-Noks
  • Smart Retail:
    • Thermostat: 4-Noks, Centralite
    • IP Camera: D-LINK, Panasonic
    • Temperature and humidity sensor: Wulian, Centralite, Leedarson
    • Smoke and gas sensor: CLIMAX, DEVELCO, Leedarson, Wulian
    • Flood sensor: Centralite, CLIMAX, DEVELCO, Wulian
    • Light sensor: Leedarson
    • Smoke Listener: Centralite
    • Siren: Metalligence, Wulian
    • LED illumination: LG, Leedarson
    • Switches: CLIMAX, Centralite
    • Thermostatic valve: CLIMAX
    • Weather station: Adafruit sensors
    • Beacon: Indra, Estimote
    • Panic button: CLIMAX, Centralite
    • Smart Meters: Several manufactures
  • Smart Cities: Environmental humidity sensor: several manufactures
  • Smart Traffic: Sensor power consumption: several manufactures
  • Smart Agro: Flowmeter: several manufactures
  • Smart Tourism:
    • Tensiometer: several manufactures
    • Potentiometer: several manufactures
    • Smart metering: several manufactures
    • Traffic ligth: Cross
    • Intelligent lighting: UVAX, LUIX
    • Libelium sensors
      • Air Quality
      • Atmospheric pressure
      • Temperature
      • Humidity
      • Luminosity
      • Waspmote internal temperature, batterty level, accelerometer
  • Smart Health: scales, several manufactures using IEEE protocol
  • Smart Insurance:
    • Tensiometers: several manufactures using IEEE protocol
    • Thermometer: Fora
    • Glucometer: Fora
    • Nociceptor: several manufactures
    • Anesthesia tower: Drager, General Electric
    • Pressure sensor in bed
    • Fall sensor
    • SmartBand: Withings
  • Otros:
    • Quadrirotor/Drone: Indra, 3DRobotics, Microsoft IPCam
    • Rover/Drone: Indra
    • Raspberry Pi: Indra
    • ARduino

In addition to supporting the data collection of all these devices, Sofia2 also allows the ingestion of data from other types of sources, such as RRSS, APIs and general files:



Generic IoT Platform        Sofia2 IoT Platform

p3.PNG    Comunicacion Sofia2

Sofia2 is agnostic of the communications, with implementations in multiple protocols of light communication (REST, OPC, MODBUS,  WebSockets, MQTT, WS, JMS, AMQP…)

In addition, among others, the gateways supported by Sofia2 are:


Services and Cloud

 Generic IoT Platform                                   Sofia2 IoT Platform


In the platform Sofia2 the following elementary concepts are defined:

smart space sofia2


It is the collaborative universe of systems and/or devices (ThinKPs) that exchange information between them. The core of a Smart Space is the SIB (Semantic Information Broker):

SIB: It is the core of the Smart Space, acts as an element of integration of the information exchanged by the devices. There may be several in a Smart Space.

ThinKP: Each of the systems and / or applications that interoperate in the Smart Space through the SIB must be defined as ThinKP in the same. The ThinKP is an element deployed in the Smart Space that can consume and/or produce information.

Ontology: Semantic atomic element with which to model the different information systems that interoperate in the Smart Space domain.

Ontologies are semantic descriptions of a set of classes. In this way, applications that share classes (usually called concepts) of the same ontology, can exchange information through concrete instances of these common classes.

In Sofia2, these ontologies are represented in JSON-Schema format that defines and validates them.

In terms of data storage in Sofia2 we distinguish between:


For each ontology can be configured a time window from which the information is considered ‘historical’.

The information remains in this database until it is automatically migrated to the historical information repository.

The stored information will be available as data source for the different modules of the platform: Integration, Machine Learning, APIManager.

Sofia2 has an API Manager with the following capabilities:


Apps and Analytics

Generic IoT Platform                             Sofia2 IoT Platform

p5   AppsyAnalyticsSofia2

In sofia2/console we will find the user interface and experimentation environment with all the capabilities of the platform. In it we can not only create Ontologies to model our data, ThinKPs or ingest data files or RRSS, but also we can create rules (SCRIPTS) to process all this information in the way we are most interested, to visualize this data in Gadgets and Dashboards Or publish ontologies via API. We also have Analytics modules that will allow us to create pipelines and notebooks, or create Machine Learning flows:


To conclude, here we can see the architecture of the platform Sofia2:


As well as an overview of the Sofia2 components:

flujo general Sofia2

IoT Technologies and its support in Sofia2

Visual development in Sofia2 with Raspberry, Node-RED and Dashboards


We have already spoken in previous publications about Node-RED, a tool for visual editing and execution of flows.

In this post will be presented a set of nodes designed to interact with Sofia2 IoT Platform and will present a small demo using those nodes deployed on a Raspberry with a SenseHat sensor.

We will start presenting this set of nodes:


We have a configuration node that has a global reach, that is, its state will be shared between flows. This node represents a shared connection with a remote system, in this case the configuration node is responsible for creating the connection (REST or MQTT) and make it available to the other nodes.

As for the other nodes are the performers of the operations of insertion, update, deletion, queries and release of the connection.

The nodes are available in Sofia2’s Github, in the npm repository and in the official Node-RED page.

Next we will develop two flows using the Node-RED tool, one of them will be deployed in a Raspberry Pi and another in Sofia2 IoT Platform:


The flow of the Raspberry Pi will trigger the process:


  • A node controls the SenseHat sensor data that we have integrated with our Raspberry Pi, and triggers the flow every second with temperature, pressure and humidity data.
  • A function node performs a data processing to generate a JSON instance that matches the ontology that is registered in Sofia2.
  • One of the nodes previously presented, will be responsible for sending a message to Sofia2 IoT Platform with the data obtained from SenseHat to the ontology and will be stored in the Real Time Database, which will feed us later the Dashboard.

The flow in Sofia2 IoT Platform


We have a flow that consists of two parts:

  • On the one hand we have a node that retrieves from an Internet service the temperature of Madrid. This data is stored in the context at the flow level.
  • On the other hand we have a node listening the events received from the Raspberry to the ontology in which the data obtained from the SenseHat board are being inserted. In this flow a simple calculation will be made to obtain the difference of temperatures, in addition a rule will be created in which if that difference exceeds a certain threshold a tweet will be sent. Note that the temperature variation data will also be stored in another ontology in Sofia2, so that you can then feed the Dashboard.

Once the demo is in progress, we create a Dashboard on the Platform, which represents the data of temperature, pressure and humidity, collected from the SenseHat sensor, and also the data of the calculated temperature variation.


This Demo is available in a guide format at the following link:

Visual development in Sofia2 with Raspberry, Node-RED and Dashboards

Release 4.0: Soporte modelado de ontologías tipo Time Series

En la Release 4.0 de Sofia2 IoT Platform se incorpora un nuevo tipo de ontología que da soporte al concepto de series temporales.


Este nuevo tipo de ontología registra eventos con su marca de tiempo dentro de una ventana temporal, los cuales están agrupados en un documento en la BDTR, haciendo más eficiente la consulta, ya que con una única lectura en BDTR se pueden consultar todos, o un subconjunto de los eventos.

Esta funcionalidad está accesible desde la consola de administración Ontologías > Crear Ontología > Crear Ontología de tipo TimeSerie

Seguir leyendo “Release 4.0: Soporte modelado de ontologías tipo Time Series”

Release 4.0: Soporte modelado de ontologías tipo Time Series

Creating Dashboards with Node-RED


As we mentioned in previous posts, Node-RED is a tool with which you can create flows visually. In this post we will see a new use of Node-RED as a tool to create Dashboards.

To do this we will use the Freeboard node, it is available on GitHub, this node allows us to design our own dashboards.

For this demo, we used a Meshlium sensor concentrator, which inserts real-time data into two ontologies defined by a single ThinKP. To access this data, in our Node-RED flow we will use the following nodes:

  •  A SSAP-process-request node: listening to insert events on the ontologies defined.
  • A function node, whose function will be to parse the data recovered from the ontology. It must be taken into account that the freeboard node only represents the data provided by the message payload in JSON format.
  • A Freeboard node, this will allows us to design our dashboard.

Our flow would look like this:


We will create two different Dashboards, in one of them we will represent the monitoring data of the device as the battery, internal temperature … In the other one we will represent the measurements provided by the sensors: solar radiation, humidity …

The two dashboards are shown below:



Once we have created the Dashboard, we save it to be able to access it from other devices or at another time. There are two ways to open a dashboard that you have saved:

  • By copying the URL generated at the time of saving the dashboard, through this URL we can access it from another device or browser.
  • By selecting the option “LOAD FREEBOARD” in the upper left corner, where we will have to load the generated .json file when we save the dashboard.

In the following video you can see a video of the demo:

Creating Dashboards with Node-RED