Sensors activity


Sentilo is an open source sensor and actuator platform designed to fit in the Smart City architecture of any city looking for openness and easy interoperability. This platform provides a simple HTTP REST API to manage sensory data.

The city of Sant Feliu de Llobregat uses Sentilo to publish the data of their sensors. They decide to develope this Braint4it module to detect which sensors have stopped sending data to the platform. This information is provided in two different ways:

The following diagram illustrates the functioning of the system:

Programming the module

This module has been programmed using the timer functions. The use of these functions is very appropriate to execute repetitive tasks because they do not consume an executor thread permanently.

When the module is started, the code contained in the start variable (spawn (eval main)) is evaluated.

This code schedules a sensor checking function to be executed every access_interval_msec milliseconds:

  (function ()
          "Calculates time_reference, checks sensors"
        (set variables/active true)
        "*" =>
            "When an error takes place, it is saved in a variable named 'error'"
          (set error
            (list (format-date (date)) ex)

The scheduled function performs the following tasks:

First cleans the list containing the ID's of the sensors that were failing the in last iteration. After that, a new reference time is calculated as the difference between the current date and the access interval for checking the sensor values. This reference time will be used later in order to decide whether the sensors are working properly or not.

Next step is checking the sensors. New values are obtained and evaluated. For each sensor value Sentilo also provides the timestamp of its publication. If that timestamp is older than the previously calculated reference time, then we assume that the sensor is failing and include it in the list of failing sensors. Those sensors without information are considered as if they were broken down too.

Failing sensors list is showed in the dashboard and an email is sent to the user by calling this function:

(function (sensor_id sensor_provider)
    "This fuction sends an email to the selected direction in order to inform about the incidence"
    "host" => setup/host
    "port" => setup/port
    "from" => setup/from
    "to" => variables/to
    "subject" => (concat setup/subject sensor_id)
    "body" =>
      "Provider: "
      "Sensor ID: "

The message that the user receives contains a brief description of the problem:

The dashboard of the module gives the user the option of choosing the access interval and the email receiver. Every time the interval is changed the checking function is scheduled again:

(function (header data)
  (### "Sets the value in the 'range' widget")
  (set variables/access_interval data)
  (calculate-access-interval-sec data)
  (if variables/active
      (eval main)
  (module-notify "@get-access-interval")

When the module is stopped, the stop variable is evaluated and the scheduled task is cancelled.

The module configuration parameters (Sentilo properties, sensors to verify, etc.) are hold in the setup list.

Download module