# Node-RED

To enable rapid connectivity, experimentation / prototyping, or re-use of existing integrations [Node-RED](https://nodered.org/) may be deployed alongside Engine.

## Access to Node-RED web interface

By default, the Node-RED web interface is exposed *locally only* on the machine that is running Engine, at <http://127.0.0.1:1880>. If accessing the Node-RED web interface from a remote client, use methods such as SSH port forwarding to securely mirror the Engine server's 127.0.0.1:1880 to your machine's 127.0.0.1:1880.

## Installing nodes

Additional Node-RED nodes can be installed by running the below command on the machine running Engine:

`docker exec -it node-red npm install <package-name>`

For example, to install the [connector for Azure IOT Hub](https://flows.nodered.org/node/node-red-contrib-azure-iot-hub), run:

`docker exec -it node-red npm install node-red-contrib-azure-iot-hub`

## Connecting Engine to Node-RED

### Node-RED Websocket output

Engine connects to Node-RED via Node-RED's websockets modules (one for input and one for output). Drag an output websocket module into the Flow, double-click it and set the Type to `Listen on` and the Path to `/ws/`.

![Node-RED Websocket output module](/files/-LsGSUYwLV56y_DmB5QH)

### Engine websocket input

* On the Drivers page of Backoffice, import the [Node-RED Websocket](https://github.com/acaprojects/ruby-engine-drivers/blob/beta/modules/node_red/websocket.rb) driver by searching for it and clicking "Import".
* Now in any System, add a module of that driver and set:
  * IP: `node-red`
  * Port: `1880`

After creating the module, start it and then monitor the [debug messages](https://github.com/acaengine/docs/tree/da66522f4d00324648877ea8a6ba9f92333bb7a3/backoffice/debugging.md).

Messages coming out of the Node-RED websocket output should appear as console log output when debugging the Engine "Node-RED Websocket" module. The status variable "message\_received" will also update to show the last string recieved. Simple strings may be used as inputs for Triggers.

The "Node-RED Websocket" driver can be used as a template for creating new drivers that take actions upon receiving messages from Node-RED, or send websocket messages to a Node-RED Websocket Input module. One example of this is the [Pressac desk sensor driver](https://github.com/acaprojects/ruby-engine-drivers/blob/beta/modules/pressac/sensors/ws_protocol.rb), which uses Node-RED to subscribe to real time updates from Azure IOT Hub.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://engine.place.technology/integrations/iot/node-red.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
