Simulators example

simulators example

This project shows how to use our tracker-simulation node. The node is built to drop straight into the sample flows available in the sandbox. Simulator outputs data following FIWARE’s Smart Data models, making it ideal to use with other FIWARE examples.

To run the demo manually, click the Inject buttons in the Node-RED editor. For automatic runs, open an Inject node and set up a schedule.

Services Used

  • EMQX – MQTT broker

  • IoT-Agent – FIWARE’s agent: MQTT → Orion-LD

  • Orion-LD – Orion context broker

List of installed packages

  • @senlab/node-red-generate-random-senlab - Tracker simulation node

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

  • 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

GROUP: Data simulation

group data simulation

This group contains four flows—the first three simply generate data with the tracker-simulation node, triggered by their Inject buttons.

Tracker-simulation node settings:

  1. Tracker type – choose a tracker model; each model sets the output schema.

  2. Area – enter top-left and bottom-right coordinates to bound the simulated location.

  3. Count – number of tracker instances to emulate.

  4. Start / End date – the period in which timestamps will be generated; each batch is spaced by the specified time window (e.g., 24 h).

  5. Range – min/max limits for the measured value.

After deploying, fire the Inject node to create the next data batch; timestamps keep advancing until the End date is reached.

gui sim node

FLOW: water measurement simulation

First three flows are almost identical the only differenc being configuration of the Tracker simulator node. First flow is configured to simulate water consumption measurement devices complying to FIWARE’s smart data model. Output of the simulator node is array of data, where each element coresponds to one measurement, number of measurements is defined by the count value in configuration. Function node is implemented to split array and send each measurement seperately to MQTT broker, topic is selected such so that data send can be recieved by the FIWARE’s IoT-Agent.

node.send() method can be used to send message from the function node without existing the code prematurely.

function sendSeperately(sensArr) {
    sensArr.forEach(device => {
        device.metadata.id = `${device.metadata.trackerType}-${device.metadata.id}`;
        node.send({
            payload: device,
            topic: `/sensor/${device.metadata.id}`
        });
    });
}

FLOW: restructure topic

This flow can be used to modify topic to work with another API key used by IoT-Agent JSON. MQTT Agent defines following topic structure: /<apikey>/<device_id>/attrs

GROUP: IoTAgent manager

group iotagent manager

This group replicates the identically named group from the FIWARE Playground example (link TBD). For advanced IoT-Agent setup—attribute mapping, explicit attributes, etc.—see the shelly-to-datagrid docs (link TBD).

GROUP: Orion-LD manager

group orion ld manager

Most of the logic in this group 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: Orion-LD sub to db

flow sub to db

The HTTP-in node receives the Orion-LD notifications set up in the previous group. A downstream function node then builds a basic PostgreSQL command that:

  1. Creates (if needed) a table with a single JSONB column called data.

  2. Inserts each incoming event into that column.

Storing the entire event as JSONB keeps the schema flexible for the mixed payloads generated by the tracker-simulation nodes.