Scorpio testbench

shelly to datagrid

This project is used to recieve messages from shelly devices and republish them to Orion-LD context broker. Subscriptions on broker are then implemented where endpoint recieves notifications and inserts data into Postgres database.

Services Used

  • FIWARE IoT-Agent JSON – FIWARE agent

  • FIWARE Orion-LD context broker - Context broker

  • EMQX broker - MQTT broker

  • PostgreSQL database – Used to store and query data

List of used nodes

  • Inject/Timestamp – Triggers flow execution

  • Function – Adds custom logic using JavaScript

  • HTTP Request – Sends HTTP requests to external services

  • Debug – Displays messages in the debug console

  • HTTP in – Recieve HTTP messages

  • JSON - parse JSON to JS object

  • MQTT in - MQTT subscription node

  • MQTT out - MQTT published node

  • Postgres node - Executes queries passed in msg.query property

For details, see Node-RED Documentation

FLOW: provision iotagent service

This flow extends the basic IoT-Agent service definition with two extra body fields:

  • explicitAttrs =true Forward only the attributes listed in attributes to Orion-LD.

  • attributes Array that declares the common attributes every device will expose, following the AC Measurement Smart Data Model. Each entry can apply a JEXL expression to map incoming MQTT data.

Example:

{
  "apikey":       "apikey",
  "resource":     "",
  "cbroker":      "http://127.0.0.1:1027",
  "entity_type":  "devType",
  "explicitAttrs": true,
  "attributes": [
    {
      "object_id": "temperature",
      "name":      "temperature",
      "type":      "Number",
      "expression":"temperature.tC"
    },
    {
      "object_id": "ref_device",
      "name":      "ref_device",
      "type":      "String",
      "expression":"'device:' + id"
    },
    {
      "object_id": "location",
      "name":      "location",
      "type":      "GeoProperty",
      "value": {
        "type":        "Point",
        "coordinates": [46.17, 14.55]
      }
    }
  ]
}

This configuration tells the IoT-Agent to:

  1. accept MQTT messages under the given apikey,

  2. republish only the temperature, ref_device, and location attributes, and

  3. transform each attribute using the specified JEXL expressions before storing the data in Orion-LD.

FLOW: DELETE all entities

This flow works by combining 2 HTTP requests to Orion broker. GET /ngsi-ld/v1/entities fetches every entity ID. The Function node inserts those IDs into a JSON body and calls POST /ngsi-ld/v1/entityOperations/delete. The pair of requests removes all entities from Orion-LD in one go.

FLOW DELETE all devices from IoT-Agent JSON

Similar to previous flow 2 HTTP requests are used, both to IoT-Agent. GET /iot/devices returns the full device list. A Function node loops over the result and issues DELETE /iot/devices/{deviceId} for each entry. All provisioned devices are thus purged from the IoT Agent.

GROUP: subscription endpoints

This group hosts three flows that handle the notifications which are produced by subscriptions defined using another three flows from this project.

  1. Event subscription – Incoming sensor payloads are turned into a Postgres command:

CREATE TABLE IF NOT EXISTS datagrid.events (
    index SERIAL PRIMARY KEY,
    data  JSONB
);
INSERT INTO datagrid.events (data)
VALUES ('${JSON.stringify(msg.payload.data[0])}');

The data column is JSONB, so any event schema fits.

  1. Device subscription – Writes device metadata to datagrid.devices, matching the FIWARE Device smart-data model.

  2. Owner subscription – Stores owner details in datagrid.owners, following the Owner model.

Click each Inject once to create its subscription; Orion-LD will then POST updates to the corresponding Node-RED endpoint, which immediately saves them to Postgres.