Brunata API example

brunata api

This project is used to add water meter data from Brunata API to Orion-LD context broker. Subscriptions are implemented to save data in Postgres database.

Services Used

  • FIWARE IoT-Agent JSON – FIWARE agent

  • FIWARE Orion-LD context broker - Context broker

  • EMQX broker - MQTT broker

  • Postgres database - database

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

Most of the logic in this project is adapted from the fiware-playground example. For the full walkthrough of that reference flow—covering IoT-Agent and Orion-LD setup—see the official guide.

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://iotagent-json:1027',
    'entity_type': 'WaterConsumptionObserved',
    'attributes': [
        {
            'object_id': 'owner',
            'name': 'owner',
            'type': 'string',
            'expression': `'owner:'+owner`
        },
        {
            'object_id': 'ref_device',
            'name': 'ref_device',
            'type': 'string',
            'expression': `'device:'+owner`
        }
    ]
}

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.

FLOW: test output

The flow uses the Brunata-connector node, which connects to the Brunata API to retrieve real sensor data—either current or historical. Locations and IDs are randomly generated. The node provides a simple configuration window where you can choose between current or historical data, enter a name, select date ranges for the data, and choose between normalized or key-value format.

gui brunata connector