Fiware-Orion Input Example Flow

orion input flow

Introduction

This flow is a part of 2 seperate collections, Fiware-Orion collection and input flows collection. Input flows are used for importing data inside Node-RED environment for further processing.

To read more about Fiware-Orion, please refer to this documentation: Fiware-orion

Important: for more clarity, comments have been added throughout this example flow. It is recommended to read these comments while reviewing the documentation to gain a better understanding of each component’s role and functionality.

Prerequisites

This flow along with other dependencies and flows is available to user in the following package:

@Senlab/node-red-fiware-orion-senlab

To learn more about Verdaccio and how to install packages, please refer to this documentation: Verdaccio

Fiware-Orion service needs to be up and running on Sandbox for communication to work. To find out how to install services on Sandbox, please refer to this documentation: services

Initializing flow with Inject Node

We initiate our flow with the Inject Node, which is a basic node and already preinstalled inside Node-RED. It can be found under the common tab.

The Inject Node can function as a button or a signal generator. Users need to specify which property and value the node will inject into the flow. For the purposes of this flow, the specific configuration of the property and value is not critical, as the primary goal is to activate other nodes within the flow. In the configuration panel, users have the option to set the Inject Node to either inject the value just once or to do so repeatedly at a specified interval.

step1 inject

Setting up Function Nodes for HTTP Request generation

Function Node is powerful Node-RED node which enables us to add our Custom Javascript code to Node-RED without the need to make custom nodes.

Instead of hardcoding HTTP Request body or URL inside HTTP Request node, function node can be used, where URL and body of the request can be dynamically constructed from incomming data, this example still has hardcoded URL and request body, but it shows how those parameters can be passed from the function node inside HTTP Request node.

URL must be passed inside the msg.url property and body of the message must be JS object.

This example shows how to construct HTTP GET Request to Query data from specified entity based on specified criteria, this example also shows how to request metadata information and how to subscribe to changes in entity. To find out what Entity and Subscribing in Fiware Orion, please refer to this documentation: Fiware-orion

Example 1: Querying Based on a Specific Variable

This example retrieves all WeatherStation entities where the temperature is greater than 20 degrees Celsius.

This request filters entities of type WeatherStation where the temperature attribute is greater than 20.

Example 2: Querying Based on Geolocation

This request retrieves all WeatherStation entities located within a specific geographical area. Let’s assume we are interested in a region around a certain point with a specific radius.

This query filters for WeatherStation entities where the location is within 1000 meters of the coordinates 52.5074, 13.3903.

Example 3: Subscribing to Changes in a Timestamp and All Data

To subscribe to changes in the lastUpdated timestamp of an entity, and to be notified about all changes in data, you can use the subscription feature of Orion. This requires sending a POST request to create a subscription, but here is the conceptual setup:

URL for the HTTP POST Request: http://orion:1026/v2/subscriptions/

Body of the request:

{
    "description": "Subscribe to WeatherStation data updates",
    "subject": {
        "entities": [
            {
                "id": "WeatherStation1",
                "type": "WeatherStation"
            }
        ],
        "condition": {
            "attrs": ["lastUpdated"]
        }
    },
    "notification": {
        "http": {
            "url": "http://your-listener-url.com/notify"
        },
        "attrs": ["temperature", "humidity", "location", "lastUpdated"]
    },
    "expires": "2040-01-01T14:00:00.00Z",
    "throttling": 5
}

This JSON setup defines a subscription to the Orion Context Broker to notify a specified endpoint whenever the lastUpdated attribute changes. It includes all attributes in the notification, ensuring full data delivery.

HTTP Request Node

The HTTP Request Node is a fundamental component within Node-RED, utilized for executing various HTTP requests, a prevalent communication method among IoT devices.

When parameters like URL and message body are supplied by a preceding function, the configuration required involves selecting the type of request and the type of return object. In this scenario, since POST requests are being made and the response is irrelevant to subsequent flow activities, the method is set to POST, and the response handling can be disregarded.

http request node

Debug Node

This node is used to view properties of msg object, user can select to view complete msg object or only one selected property of msg object. This node is cruical for development inside Node-RED and should be used as much as possible.