Jump to content

SENSBLUE ATLAS/Node-RED

From ATRONIA Wiki

Node-RED Simplified Flows

Flow Node-RED

These easy-to-implement flows aim to speed up the integration of ATLAS in any scenario by adding an abstraction layer between the user and the stack. This is achieved through the use of subflows, which contain the necessary code for the functionalities and allow changes if needed, providing a node that "hides" the more complex integration.

1. Import Flows to Example Folder

To import the flows and add them to the Node-RED examples folder, execute the following:

1.1 First, copy the ATLAS folder to a folder with permissions, e.g., /pi

1.2 Copy the folder to the Node-RED examples folder using the command:

sudo cp -r /$PATH/ATLAS /usr/lib/node_modules/node-red/node_modules/@node-red/nodes/examples/
 

Simplified Flows.zip

Analog Inputs

This flow demonstrates the acquisition and control of analogue ports AI1..AI4 via MQTT and Node-RED Dashboard 2.0. The system is divided into two main subflows: Analog Inputs (for reading channels AI1 to AI4) and Analog Outputs (for configuring/reading channels AO1 and AO2). The main logic is encapsulated in subflows, allowing reuse in other tabs or projects.

2. Main Components

Component Function
Analog Inputs Subflow responsible for requesting AI1..AI4 readings, receiving results, and forwarding values to gauges/UI and live topic.
Analog Outputs Subflow responsible for sending AO1/AO2 currents, synchronising sliders/gauges, and reading the current state of outputs.
Analog Demo Main tab that instantiates both subflows and displays the Dashboard widgets.
MQTT broker atlas Local broker at 127.0.0.1:1883
Dashboard 2.0 Analog Demo ports page

3. Subflow Analog Inputs

3.1 Function

The Analog Inputs subflow allows you to select which AI channels should be read and in which unit/type each channel should operate: voltage or current. The subflow has four outputs, one per channel: AI1, AI2, AI3, and AI4.

3.2 ENV Variables

Variable Type Default Value Description
readAI1 bool true Enables/disables reading of channel AI1.
AI1_type string voltage Type of AI1 reading: voltage or current.
readAI2 bool true Enables/disables reading of channel AI2.
AI2_type string voltage Type of AI2 reading: voltage or current.
readAI3 bool true Enables/disables reading of channel AI3.
AI3_type string voltage Type of AI3 reading: voltage or current.
readAI4 bool true Enables/disables reading of channel AI4.
AI4_type string voltage Type of AI4 reading: voltage or current.

3.3 AI channel acquisition

Example request payload:

{
  "id": 1780000000000,
  "origin": "Dev",
  "task": {
    "taskParams": {
      "AI1": { "action": "READ" },
      "AI2": { "action": "READ" },
      "AI3": { "action": "READ" },
      "AI4": { "action": "READ" }
    }
  }
}

If no channel is active, the function emits the warning "No AI channels selected" and does not send a message.

3.4 Configuring the AI mode

The group Set acquisition mode allows sending the configuration of the analogue channels to analogInputs/config/in. The function Set AIX mode creates taskParams only for the active channels and sets each channel as:

{
  "mode": "single",
  "type": "voltage"
}

It also saves the configuration in flow context via flow.set("AI_config", taskParams). If the configured type is neither voltage nor current, the function uses voltage as a fallback and emits a warning.

4. Subflow Analog Outputs

4.1 Function

The subflow Analog Outputs controls and monitors two analogue current outputs: AO1 and AO2. It has one input, used by the Dashboard sliders, and two outputs, one for AO1 and another for AO2.

4.2 ENV Variables

Variable Type Default value Description
AO1_enabled bool true Enables/disables output AO1.
AO1_current num 5.5 Initial/default current of AO1 in mA.
AO2_enabled bool true Enables/disables output AO2.
AO2_current num 5.5 Initial/default current of AO2 in mA.

The function set current output receives messages from the sliders with values between 0 and 20 mA. Invalid values are rejected with a warning in the debug panel.

Payload sent to analogOutputs/config/in:

{
  "id": 1780000000000,
  "origin": "APP",
  "task": {
    "taskParams": {
      "mode": "on",
      "AO1": { "current": 5.5 },
      "AO2": { "current": 5.5 }
    }
  }
}

If an output is disabled in the ENV, the current sent to that channel is 0. If both are disabled, the mode field switches to off.

4.5 Reading the AOs

The reading group periodically sends a request to analogOutputs/runtime/in:

{
  "id": 1780000000000,
  "origin": "APP",
  "task": {
    "taskParams": {
      "AO1": { "action": "READ" },
      "AO2": { "action": "READ" }
    }
  }
}

The response is received on analogOutputs/runtime/out. The parser extracts AO1.current and AO2.current and prepares a payload in the appropriate format for writing to a database or further processing:

[
  {
    "ao1": 5.5,
    "ao2": 5.5
  }
]

5. Operating flow

5.1 Reading analogue inputs

  1. The inject on the subflow Analog Inputs triggers the function acquire AIx channels.
  2. The function checks which channels are active in the ENV variables.
  3. A request is published on analogInputs/runtime/in.
  4. The hardware/service responds on analogInputs/runtime/out.
  5. The parser separates the values by channel and updates the AI gauges.

5.2 Configuring analogue outputs

  1. The user moves the AO1 or AO2 slider.
  2. The subflow Analog Outputs receives the value with msg.topic equal to the channel.
  3. The function validates whether the current is between 0 and 20 mA.
  4. The value is stored in flow context.
  5. The configuration is published on analogOutputs/config/in.
  6. The slider, gauge and text of the changed channel are synchronised.

5.3 Reading analogue outputs

  1. A periodic inject sends a READ request for AO1 and AO2 on analogOutputs/runtime/in.
  2. The system responds on analogOutputs/runtime/out.
  3. The parser converts the values into a structured payload with fields ao1, ao2 and tag source_tag.

6. Validations and protections implemented

Area Validation Behaviour on error
AI selection At least one active AI channel Returns null and warning "No AI channels selected".
AI type Only voltage or current Falls back to voltage.
AO current Finite number between 0 and 20 mA Returns null and warning "Invalid current".
AO enable Checks AO1_enabled / AO2_enabled Disabled channel sends current 0.