Jump to content

SENSBLUE ATLAS/Node-RED: Difference between revisions

No edit summary
No edit summary
Line 234: Line 234:
|Disabled channel sends current 0.
|Disabled channel sends current 0.
|}
|}
=== 7. Requirements ===
* Node-RED with subflow support.
* '''@flowfuse/node-red-dashboard''' version '''1.30.2'''.
* MQTT broker.
* External service/hardware that stimulates/responds to the '''analogInputs/*''' and '''analogOutputs/*''' topics.
'''Digital Demo'''
=== 8. Objective ===
This flow demonstrates the control and monitoring of digital ports through
Node-RED, MQTT and Dashboard 2.0.
It is composed of two main subflows:
{| class="wikitable"
!Component
!Function
|-
|Digital Inputs
|Reads the states of DI1..DI4 and sends them to LEDs on the Dashboard.
|-
|Digital Outputs
|Controls DO1..DO4 through switches and shows the real state on LEDs.
|-
|Demo Digital ports
|Dashboard page where the digital widgets are displayed.
|-
|MQTT broker atlas
|Local broker at 127.0.0.1:1883.
|}
=== 9. General architecture ===
'''Digital Inputs:'''
Node-RED → digitalInputs/runtime/in → Hardware
Hardware → digitalInputs/runtime/out → Node-RED → LEDs DI1..DI4
'''Digital Outputs:'''
Switches Dashboard → Node-RED → digitalOutputs/runtime/in → Hardware
Hardware → digitalOutputs/runtime/out → Node-RED → LEDs DO1..DO4
=== 10. MQTT topics ===
{| class="wikitable"
!Topic
!Usage
|-
|digitalInputs/runtime/in
|Request to read the digital inputs.
|-
|digitalInputs/runtime/out
|Response with the states of DI1..DI4.
|-
|digitalOutputs/runtime/in
|'''SET''' commands or '''READ''' requests for the digital outputs.
|-
|digitalOutputs/runtime/out
|Response with the states of DO1..DO4.
|}
=== 11. Digital Inputs ===
The '''Digital Inputs''' subflow periodically sends a '''READ''' request to read DI1..DI4.
The '''Force Read''' inject runs every '''1 second'''.
Payload sent:<syntaxhighlight lang="json">
{
  "id": 1780000000000,
  "origin": "APP",
  "task": {
    "action": "READ"
  }
}
</syntaxhighlight>The expected response contains the states of the inputs in:
'''msg.payload.task.taskResult.DI1..DI4'''
The parser converts the states to booleans:
{| class="wikitable"
!State received
!Value sent to UI
|-
|'''high''' with success: '''true'''
|true
|-
|'''low''' with success: '''true'''
|false
|-
|Channel absent or error
|false
|}
The four outputs of the subflow update the LEDs DI1, DI2, DI3 and DI4.
=== 12. Digital Outputs ===
The '''Digital Outputs''' subflow allows controlling DO..DO4 through switches on the Dashboard.
Each switch sends:
{| class="wikitable"
!Switch
!msg.topic
!ON
!OFF
|-
|DO1
|DO1
|true
|false
|-
|DO2
|DO2
|true
|false
|-
|DO3
|DO3
|true
|false
|-
|DO4
|DO4
|true
|false
|}
The '''set digital outputs''' function converts the values into physical states:
{| class="wikitable"
!Logical value
!State sent
|-
|true
|high
|-
|false
|low
|}The command is sent to:
'''digitalOutputs/runtime/in'''
=== 13. ENV variables of the Digital Outputs ===
{| class="wikitable"
!Variable
!Default value
!Function
|-
|DO1
|true
|Initial state of DO1
|-
|DO2
|true
|Initial state of DO2
|-
|DO3
|true
|Initial state of DO3
|-
|DO4
|true
|Initial state of DO4
|}
On deploy/startup, a '''once''' inject initializes the outputs with these values.
=== 14. Dashboard ===
{| class="wikitable"
!Field
!Value
|-
|Page
|Demo Digital ports
|-
|Path
|/dashboard/page2
|-
|Theme
|Atronia
|-
|Layout
|grid
|}Groups on the page:
{| class="wikitable"
!Group
!Content
|-
|Digital Inputs
|LEDs DI1..DI4
|-
|Digital Outputs
|Switches DO1..DO4 and LEDs DO1..DO4
|}Input LEDs: