Fiware-Orion Output Example Flow

Introduction
This flow is a part of 2 seperate collections, Fiware-Orion collection and output flows collection. Output flows are used for exporting data out of Node-RED using numerous different ways including Fiware-Orion Context Broker
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.

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 POST request to create new Entity in FIWARE Orion and how to update values of an Entity. To Find out more about what entites are and what is their purpose, please refer to this documentation: Fiware-orion
Example 1: Creating an Entity in FIWARE Orion
To create an entity, such as a Room with attributes like temperature and pressure, you can construct the body of the HTTP POST request as follows:
URL for the POST request: http://orion:1026/v2/entities
Body of the request:
{
"id": "Room1",
"type": "Room",
"temperature": {
"value": 23,
"type": "Integer"
},
"pressure": {
"value": 720,
"type": "Integer"
}
}
Example 2: Updating an Entity in FIWARE Orion
To update an existing entity, for example changing the temperature attribute of Room1, you can use the following:
URL for the POST request: http://orion:1026/v2/entities/Room1/attrs
{
"temperature": {
"value": 26,
"type": "Integer"
}
}
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.
