Actions

Difference between revisions of "Node-Red - Getting Started"

From Zenitel Wiki

(Communication between Node-RED and Zenitel Connect Pro)
(Wamp URI's)
 
(133 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{C}}
 
{{C}}
=Introduction=
 
 
Node-RED is the open-source software that is used as an event programming for Zenitel Connect Pro.<br>
 
Node-RED is the open-source software that is used as an event programming for Zenitel Connect Pro.<br>
 
The benefits of Node-RED are
 
The benefits of Node-RED are
Line 9: Line 8:
 
*Intuitive debug possibilities​
 
*Intuitive debug possibilities​
  
For installation of Node-RED you can go to this article: [[Node-Red - Installation]]
+
For installation of Node-RED see the article: [[Node-Red - Installation]]
  
 
__TOC__
 
__TOC__
 
<br>
 
<br>
==Interface==
+
==General description==
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<td style="display: block; vertical-align: bottom;">[[Image:Node_red_workspace.JPG|1200px]]</td>
 
</tr>
 
<tr>
 
<td style='background-color:#efefef;'>Node-RED User Interface</td>
 
</tr>
 
</table>
 
==Operation==
 
 
Node-RED is a graphical programming language based around receiving, processing and sending messages.<br>
 
Node-RED is a graphical programming language based around receiving, processing and sending messages.<br>
Messages can be manipulated using 'nodes' that can be dragged and dropped to the workspace, linked together in chains and then sent to the output.<br>
+
 
With respect to Zenitel Connect Pro, these messages can be events occuring, such as Calls or Door Opening events.<br>
+
Messages can be manipulated using 'nodes' that can be dragged and dropped to the workspace, linked together in chains and then sent to the output. With respect to Zenitel Connect Pro, these messages can be events occurring in the server, such as Calls or Door Opening events.
Manipulation of the message may include IF statements, setting a new parameter such as Directory Number or including a delay.<br>
+
Manipulation of the message may include IF statements, setting a new parameter such as Directory Number or including a delay.
Output from Node-RED can be sent back in to ZCP to initiate a new call, or control a GPO. It could also be towards a third party application.<br>
+
 
 +
Output from Node-RED can be sent back in to ZCP to initiate a new call, or control an output or relay. It could also be towards a third party application.
 +
 
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Node_red_mpc.JPG|1200px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:Node_red_mpc.JPG|700px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
Line 37: Line 29:
 
</table>
 
</table>
  
==Communication between Node-RED and Zenitel Connect Pro==
+
==Zenitel Connect Pro configuration==
 
=== License ===
 
=== License ===
Node-Red connects to Zenitel Connect Pro as a Zenitel Link user. This requires an  
+
Node-RED connects to Zenitel Connect Pro as a Zenitel Link user. This requires an  
 
* Integration license (ZCL-API) - 1002720900
 
* Integration license (ZCL-API) - 1002720900
  
 +
===Zenitel Link user===
 +
The communication between Node-Red and Zenitel Connect Pro is using the "Zenitel Link" protocol.<br>
 +
A [[User Management (Zenitel Connect Pro)|Zenitel Link user]] must be created in Zenitel Connect Pro.
 +
 +
* In ZCP go to [[User Management (Zenitel Connect Pro)|System > Users]]
 +
*Press the [[File:ZC_PlusIcon.PNG|25px]] to add a new user
 +
*Give the user a Name and a Password, and set the Role = "Zenitel Link User"
  
 
===Firewall===
 
===Firewall===
Communication between Node-RED and ZCP is via WAMP.<br>
+
The communication between Node-RED and ZCP requires that TCP port 8086 (Secure WAMP) is enabled in the firewall of the ZCP. This port is by default enabled.  If you want to use unsecure WAMP, you need to enable port 8087.<br>
This requires that port 8086 is enabled in the firewall of ZCP for Secure WAMP which is the default.  If you are using unsecure WAMP, you need to enable port 8087.<br>
 
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Node_red_firewall.JPG|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:NodeRedFirewall.png|600px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
Line 55: Line 53:
 
</table>
 
</table>
  
===Zenitel Link===
+
<br>
By default, there is no account in ZCP that will allow for connection to the Zenitel Link interface.<br>
 
A dedicated Zenitel Link user must be created in the System and Users menu.
 
*Press the + icon to add a new user.
 
*Give the user a name and a password, and set the Role to Zenitel Link User
 
*Press the Tick icon.
 
  
=Installing Zenitel Connect Pro WAMP connector node=
+
==The Node-RED User Interface==
 +
To access the Node-RED web GUI enter '''https://[IP Address]:1880''' in your browser, where "IP Address" is the IP address of the Zenitel Connect Pro. (e.g. "<nowiki>https://10.9.8.207:1880</nowiki>").
  
To connect Node-RED to Zenitel Connect Pro, we must first install the Zenitel specific WAMP connector node<br>
+
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
*Navigate to the Node Red menu and choose 'Manage palette'
+
<tr style="rowspan:2;">
*Choose the 'Install' tab
+
<td style="display: block; vertical-align: bottom;">[[Image:Node_red_workspace.JPG|700px]]</td>
*In the search bar, type 'Zenitel' and press enter
+
</tr>
*Select 'Node-RED-contrib-zenitel-wamp-auth' and press Install
+
<tr>
 +
<td style='background-color:#efefef;'>Node-RED User Interface</td>
 +
</tr>
 +
</table>
 +
 
 +
 
 +
===Installing WAMP nodes ===
 +
In order to connect Node-RED to Zenitel Connect Pro, the first step is to install the Zenitel specific WAMP connector nodes.<br>
 +
*In the Node-RED user interface click on the "Hamburger" menu icon in the top right, and choose '''Manage palette'''
 +
*Choose the '''Install''' tab
 +
*In the search bar, type '''zenitel''' and press enter
 +
*Select 'Node-RED-contrib-zenitel-wamp-auth' and press '''Install'''
  
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Node_red_wamp_install.JPG|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:NodeRedInstallPalette.PNG|600px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
Line 79: Line 84:
 
</table>
 
</table>
  
{{Note|If you get an EAI_AGAIN error please check your DNS settings }}
+
This will install 3 new nodes available in the Palette (the left-hand side list of nodes). These three nodes are Zenitel specific: '''Wamp In''', '''Wamp Out''' and '''Wamp Call'''.
 +
 
 +
{{Note|If you get an EAI_AGAIN error on installing please check your DNS settings }}
 +
*'''Wamp In''' is a "listener" that will subscribe to certain WAMP events in ZCP and pass these messages to other nodes in the Flow. WAMP events that the '''Wamp In''' node can connect to include items like devices and directory, groups, calls and open door.
 +
*'''Wamp Out''' is
 +
*'''Wamp Call''' is a "publisher" that will send messages it receives to certain WAMP connection points within ZCP. WAMP connection points that the '''Wamp Call''' node can connect to include items like calls, open door, gpos and device key emulation.
 +
 
 +
 
 +
=== Wamp URI's===
 +
A WAMP URI (Web Application Messaging Protocol, Uniform Resource Identifier) is a standardized way to identify resources in Zenitel Connect Pro.
 +
 
 +
For example, to subscribe to Call events, you would drag a '''Wamp In''' node to the workspace, and subscribe to the Wamp URI '''com.zenitel.calls'''. All call activity would be reported by this node to the next node in the chain.<br>
 +
To make a call using Node-RED, you would drag a '''Wamp Call''' node to the workspace, and attach it to the Wamp URI '''com.zenitel.calls.post'''.  Sending a correctly formatted message to this node would initiate a call in ZCP.<br>
 +
 
 +
For a full overview of available Wamp URI's, enter '''<ZCP IP Address>/openapi''' in your browser (e.g. 10.9.8.207/openapi)
  
=WAMP Message Formatting=
 
ZCP sends information as an Array containing labels and values as strings.<br>
 
The format of these arrays varies depending on the message itself, and the format documentation is available from <zcp_ipaddress>/openapi<br>
 
The Open Door event for example generates the following items <br>
 
from_dirno - Directory Number of operator opening door
 
from_name - Display name of operator opening door
 
door_dirno - Directory number of Door
 
door_name - Display name of Door
 
gpo
 
    gpo_id - Id of the GPO activated
 
    mac_address - MAC of the device hosting the GPO being activated
 
    time - Duration in seconds for a timed relay activation.
 
 
<br>
 
<br>
Node-RED receives this array as a message payload, which is referred to as msg.payload<br>
+
 
 +
===WAMP Message Formatting===
 +
ZCP sends information as an Array containing labels and values as strings. The format of these arrays varies depending on the message itself, and the format documentation is available from '''<ZCP IP Address>/openapi'''<br>
  
 
As an example, if we look at a Door Open event, it has the following properties<br>
 
As an example, if we look at a Door Open event, it has the following properties<br>
Line 106: Line 115:
 
<br>
 
<br>
 
Using this information, we can receive Door Opening events, and process this information.<br>
 
Using this information, we can receive Door Opening events, and process this information.<br>
=Wamp Nodes=
 
  
There are 2 WAMP nodes that we utilise in our Node-RED Flow; Wamp In and Wamp Call<br>
+
from_dirno - Directory Number of operator opening door
*Wamp In is a listener that will subscribe to certain WAMP events in ZCP and pass these messages to other nodes in the Flow.
+
from_name - Display name of operator opening door
*Wamp Call is a publisher that will send messages it receives to certain WAMP connection points within ZCP.
+
door_dirno - Directory number of Door
 +
door_name - Display name of Door
 +
gpo
 +
    gpo_id - Id of the GPO activated
 +
    mac_address - MAC of the device hosting the GPO being activated
 +
    time - Duration in seconds for a timed relay activation.
 +
<br>
 +
Node-RED receives this array as a message payload, which is referred to as '''msg.payload'''<br>
  
WAMP events that the Wamp In node can connect to include items like devices and directory, groups, calls and open door.<br>
+
<br>
WAMP connection points that the Wamp Call node can connect to include items like calls, open door, gpos and device key emulation.<br>
 
  
For example, to subscribe to Call events, you would drag a Wamp In node to the workspace, and subscribe to com.zenitel.calls. All call activity would be reported by this node to the next node in the chain.<br>
+
===Setting up Node-RED for the first time===
To make a call using Node-RED, you would drag a Wamp Call node to the workspace, and attach it to com.zenitel.calls.post.  Sending a correctly formatted message to this node would initiate a call in ZCP<br>
 
 
 
==First time use==
 
 
When setting up Node-RED for the first time, we need to add a WAMP Connection point and the authentication details.<br>
 
When setting up Node-RED for the first time, we need to add a WAMP Connection point and the authentication details.<br>
*Drag and drop a Wamp In node to the workspace.
+
*Drag and drop a '''Wamp In''' node to the workspace.
 
*Double click on the node
 
*Double click on the node
*Press the + icon beside the field 'Add new wamp-client'
+
*Press the + icon beside the field '''Add new wamp-client'''
*Add your ZCP IP Address to the wamp.placeholder.router field
+
** '''wamp.placeholder.router''' field: Enter the ZCP IP Address and port number "wss://<IP Address>:8086"
*Add 'zenitel' to the wamp.placeholder.realm field
+
** '''wamp.placeholder.realm''' field: Enter "zenitel"
*Add your Zenitel Link username to the wamp.placeholder.authid field
+
** '''wamp.placeholder.authid''' field: The Zenitel Link username
*Add your Zenitel Link password to wamp.placeholder.password field
+
** '''wamp.placeholder.password''' field: The Zenitel Link password
*Give your Wamp Connection a friendly name
+
** '''Name''': Give your Wamp Connection a friendly name (e.g. "Zenitel Connect Pro")
*Click Add and then Done to finalise the properties. These details will be retained in the system
+
*Click '''Add''' and then '''Done''' to finalize the properties. These details will be retained in the system
 +
 
 +
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 +
<tr style="rowspan:2;">
 +
<td style="display: block; vertical-align: bottom;">[[Image:NodeRed FirstTime.PNG|700px]]</td>
 +
</tr>
 +
<tr>
 +
<td style='background-color:#efefef;'>Node-RED WAMP node installation</td>
 +
</tr>
 +
</table>
 +
 
 +
==Examples==
 +
===Ex 1: Trigger a second Relay at Door Opening===
 +
Scenario: A client requires that in addition to the Relay being triggered at the Door intercom for access control, a second relay on another device is required to provide a signal to indicate the door has been opened.  This additional signal is for a mimic panel, and for input into the Building Management System.<br>
  
=Examples=
 
==First example flow==
 
A client requires that in addition to the Relay being triggered at the Door for access control, a second relay on another device is required to provide a signal to indicate the door has been opened.  This additional signal is for a mimic panel, and for input into the Building Management System.<br>
 
 
The directory number of the Door is 202 and the Directory number of the second device is 204.<br>
 
The directory number of the Door is 202 and the Directory number of the second device is 204.<br>
This is the only door that is monitored in this way, so while other doors may be opened, they should be ignored.<br>
+
 
 +
# From the Palette, drag and drop  a '''Wamp In''' node to the Workspace
 +
# From the Palette, drag and drop  a '''Function''' node to the Workspace
 +
# From the Palette, drag and drop  a '''Wamp Call''' node to the Workspace
 +
# Connect the nodes by drawing a line between the connection points in each node
 +
 
  
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Node_red_flow2.JPG|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:NodeRedFlow1.png|601px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td style='background-color:#efefef;'>The flow we will be describing step by step</td>
+
<td style='background-color:#efefef;'>Wamp In, Function and Wamp Call nodes on the Workspace</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
  
To achieve this, we can subscribe to the Open Door WAMP event using a Wamp In node that is subscribed to the Open Door events at com.zenitel.system.open_door.<br>
+
Double-click the '''Wamp In''' node and subscribe to the Open Door event '''com.zenitel.system.open_door'''.<br>
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Node_red_wampin.JPG|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:NodeRed WampIn.png|400px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td style='background-color:#efefef;'>The settings on the WAMP in node</td>
+
<td style='background-color:#efefef;'>Configuring the WAMP in node</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
The next bit is where the low code comes in
 
We can use a small amount of Java code within a Function node to extract the directory number from the incoming message payload and at the same time set up the new payload.<br>
 
  
The incoming events are sent to a Function node that extracts the value from msg.payload.args[0]["open_door"], uses an If statement to test whether the door is Dir 202, and then formats the outgoing message to be sent to the Wamp Call node.<br>
+
* The 1st first field is the name of the connection, which we defined in the previous step [[#Setting_up_Node-RED_for_the_first_time|Setting up Node-RED for the first time]]
 +
* The 2nd field is the event we want to subscribe to. Here "com.zenitel.system.open_door", which is the Door Open event.
 +
* The 3rd field is any descriptive name.
 +
 
 +
 
 +
The next step is to configure the '''Function''' node. Double-click the "Function" node.
 +
Here we use a small amount of Java code within the Function node to extract the directory number from the incoming message payload and at the same time set up the new payload. The Function node extracts the value from '''msg.payload.args[0]["open_door"]''', and uses an If statement to test whether the door is Dir 202, and then formats the outgoing message to be sent to the "Wamp Call" node.<br>
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:node_red_flow2_function.JPG|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:node_red_flow2_function.JPG|400px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td style='background-color:#efefef;'>The code written inside the function node</td>
+
<td style='background-color:#efefef;'>The code written inside the Function node</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
The Function Node code is
+
 
 +
The code is:
 
{{Code3| // Retrieve the incoming number from the message payload
 
{{Code3| // Retrieve the incoming number from the message payload
 
  var door <nowiki>=</nowiki> msg.payload.args[0]["door_dirno"];
 
  var door <nowiki>=</nowiki> msg.payload.args[0]["door_dirno"];
Line 185: Line 216:
 
  } }}
 
  } }}
  
Finally, we can send this message to ZCP using a Wamp Call node connected to the GPO connection at com.zenitel.devices.device.gpos.gpo.post<br>
+
Finally, we can send this message to Zenitel Connect Pro using a '''Wamp Call''' node connected to the GPO connection at '''com.zenitel.devices.device.gpos.gpo.post'''.
 +
 
 +
Double-click the "Wamp Call" node, and select the connection, the connection point '''com.zenitel.devices.device.gpos.gpo.post''', and a descriptive name:
 +
 
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Node_red_wampcall.JPG|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:NodeRed WampCall.png|400px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td style='background-color:#efefef;'>The settings in the outgoing wamp call node</td>
+
<td style='background-color:#efefef;'>Configuring the Wamp Call node</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
  
==Second example flow==
+
 
 +
The flow should now look like this:
 +
 
 +
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 +
<tr style="rowspan:2;">
 +
<td style="display: block; vertical-align: bottom;">[[Image:NodeRedFlow2.png|601px]]</td>
 +
</tr>
 +
<tr>
 +
<td style='background-color:#efefef;'>Node-RED flow configured, but not deployed</td>
 +
</tr>
 +
</table>
 +
 
 +
 
 +
The blue circle in a node indicates that there has been changes to the node which has not yet been Deployed.
 +
 
 +
Click on the '''Deploy''' button in the top right corner of the Node-RED interface to save the configuration. The Wamp In and Wamp Call nodes should now indicate that they have established connection with the Zenitel Connect Pro:
 +
 
 +
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 +
<tr style="rowspan:2;">
 +
<td style="display: block; vertical-align: bottom;">[[Image:NodeRedFlow3.png|601px]]</td>
 +
</tr>
 +
<tr>
 +
<td style='background-color:#efefef;'>Node-RED flow configured and deployed</td>
 +
</tr>
 +
</table>
 +
 
 +
If you now establish a call with Door 202 and press digit "6" to trigger the relay, also the relay of device 204 should trigger.
 +
 
 +
<br>
 +
 
 +
===Ex 2: Trigger a second Relay at Door Opening - Multiple doors===
 
If we have many doors in our system and we need to provide a related relay for each door, we can expand our Function node with a key-value pair table.<br>
 
If we have many doors in our system and we need to provide a related relay for each door, we can expand our Function node with a key-value pair table.<br>
 
An IP-LCM provides up to 9 relays, so our function needs to relate to the Directory Number and the Relay to be used.<br>
 
An IP-LCM provides up to 9 relays, so our function needs to relate to the Directory Number and the Relay to be used.<br>
  
The code is
+
The code is:
 
  {{Code3|// Retrieve the incoming number from the message payload
 
  {{Code3|// Retrieve the incoming number from the message payload
 
  var door <nowiki>=</nowiki> msg.payload.args[0]["door_dirno"];
 
  var door <nowiki>=</nowiki> msg.payload.args[0]["door_dirno"];
Line 235: Line 299:
 
  } }}
 
  } }}
  
=Free available data on the Internet=
+
<br>
 +
 
 +
==Free available data on the Internet==
 
On the internet there are lots of API's available to request various types of data. Some of these are on a payment plan but there is also many that are provided by governments free of charge. Examples of these are weather and natural events related data or timetables for public transport.
 
On the internet there are lots of API's available to request various types of data. Some of these are on a payment plan but there is also many that are provided by governments free of charge. Examples of these are weather and natural events related data or timetables for public transport.
 +
 
Here you can find the example of the National Weather Service in the US: https://www.weather.gov/documentation/services-web-api.
 
Here you can find the example of the National Weather Service in the US: https://www.weather.gov/documentation/services-web-api.
 
In their documentation you find that '''<nowiki>https://api.weather.gov/gridpoints/{wfo}/{x},{y}/forecast</nowiki>''' gives you the weather forecast for a specific location. The values for '''wfo''', '''x''', and '''y''' are a location system used by the NWS, the description is in the documentation.
 
In their documentation you find that '''<nowiki>https://api.weather.gov/gridpoints/{wfo}/{x},{y}/forecast</nowiki>''' gives you the weather forecast for a specific location. The values for '''wfo''', '''x''', and '''y''' are a location system used by the NWS, the description is in the documentation.
Line 244: Line 311:
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Http request.png|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:Http request.png|400px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
Line 253: Line 320:
 
Now when this node gets triggered it will request the current weather forecast from the NWS.
 
Now when this node gets triggered it will request the current weather forecast from the NWS.
  
=Debugging and troubleshooting options=
+
==Debugging and troubleshooting options==
 
To be able to troubleshoot a flow you might want to be able to manipulate and inspect the messages being send between the nodes.
 
To be able to troubleshoot a flow you might want to be able to manipulate and inspect the messages being send between the nodes.
 
There are two very useful nodes to accomplish this.
 
There are two very useful nodes to accomplish this.
==The inject node==
+
===The inject node===
 
The inject node can be used to inject a message anywhere in the flow. This can be particular useful when you are expecting a message coming from a third party system but this is not available yet. With the inject node you can start testing your flow beforehand.
 
The inject node can be used to inject a message anywhere in the flow. This can be particular useful when you are expecting a message coming from a third party system but this is not available yet. With the inject node you can start testing your flow beforehand.
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Inject node.png|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:Inject node.png|400px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
Line 269: Line 336:
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Inject node message options.png|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:Inject node message options.png|400px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
Line 276: Line 343:
 
</table>
 
</table>
  
==The debug node==
+
<br>
 +
 
 +
===The debug node===
 
On the right hand side of your Node-RED window there is a debug pane. You can display messages being send between nodes by using the debug node.
 
On the right hand side of your Node-RED window there is a debug pane. You can display messages being send between nodes by using the debug node.
 
If you have multiple debug nodes in your flow you can turn them on and off to only view the one you are interested in.
 
If you have multiple debug nodes in your flow you can turn them on and off to only view the one you are interested in.
Line 283: Line 352:
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Debug node.png|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:Debug node.png|400px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
Line 292: Line 361:
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<table style="max-width:80%; border-style: double; border-color: #c7c7c7;">
 
<tr style="rowspan:2;">
 
<tr style="rowspan:2;">
<td style="display: block; vertical-align: bottom;">[[Image:Debug node options.png|600px]]</td>
+
<td style="display: block; vertical-align: bottom;">[[Image:Debug node options.png|400px]]</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
Line 299: Line 368:
 
</table>
 
</table>
  
=Further reading=
+
<br>
 +
 
 +
==Further reading==
 
We advise beginners to read further in the Node-RED cookbook: https://cookbook.nodered.org
 
We advise beginners to read further in the Node-RED cookbook: https://cookbook.nodered.org
  
 
[[Category: Zenitel Connect Pro]]
 
[[Category: Zenitel Connect Pro]]
 
[[Category: Zenitel Connect Pro Integrations]]
 
[[Category: Zenitel Connect Pro Integrations]]

Latest revision as of 14:04, 20 November 2024

ZCP IconPlatf.PNG

Node-RED is the open-source software that is used as an event programming for Zenitel Connect Pro.
The benefits of Node-RED are

  • Easy to use – Low code platform​, graphical way of programming​
  • Although low code: still powerful​
  • Many existing integrations and programming examples​
  • Easy to re-use (export and import capability)​
  • Intuitive debug possibilities​

For installation of Node-RED see the article: Node-Red - Installation


General description

Node-RED is a graphical programming language based around receiving, processing and sending messages.

Messages can be manipulated using 'nodes' that can be dragged and dropped to the workspace, linked together in chains and then sent to the output. With respect to Zenitel Connect Pro, these messages can be events occurring in the server, such as Calls or Door Opening events. Manipulation of the message may include IF statements, setting a new parameter such as Directory Number or including a delay.

Output from Node-RED can be sent back in to ZCP to initiate a new call, or control an output or relay. It could also be towards a third party application.

Node red mpc.JPG
Node-RED example

Zenitel Connect Pro configuration

License

Node-RED connects to Zenitel Connect Pro as a Zenitel Link user. This requires an

  • Integration license (ZCL-API) - 1002720900

Zenitel Link user

The communication between Node-Red and Zenitel Connect Pro is using the "Zenitel Link" protocol.
A Zenitel Link user must be created in Zenitel Connect Pro.

  • In ZCP go to System > Users
  • Press the ZC PlusIcon.PNG to add a new user
  • Give the user a Name and a Password, and set the Role = "Zenitel Link User"

Firewall

The communication between Node-RED and ZCP requires that TCP port 8086 (Secure WAMP) is enabled in the firewall of the ZCP. This port is by default enabled. If you want to use unsecure WAMP, you need to enable port 8087.

NodeRedFirewall.png
Firewall ports for WAMP connection to Node-RED


The Node-RED User Interface

To access the Node-RED web GUI enter https://[IP Address]:1880 in your browser, where "IP Address" is the IP address of the Zenitel Connect Pro. (e.g. "https://10.9.8.207:1880").

Node red workspace.JPG
Node-RED User Interface


Installing WAMP nodes

In order to connect Node-RED to Zenitel Connect Pro, the first step is to install the Zenitel specific WAMP connector nodes.

  • In the Node-RED user interface click on the "Hamburger" menu icon in the top right, and choose Manage palette
  • Choose the Install tab
  • In the search bar, type zenitel and press enter
  • Select 'Node-RED-contrib-zenitel-wamp-auth' and press Install
NodeRedInstallPalette.PNG
Node-RED WAMP node installation

This will install 3 new nodes available in the Palette (the left-hand side list of nodes). These three nodes are Zenitel specific: Wamp In, Wamp Out and Wamp Call.

Note icon If you get an EAI_AGAIN error on installing please check your DNS settings


  • Wamp In is a "listener" that will subscribe to certain WAMP events in ZCP and pass these messages to other nodes in the Flow. WAMP events that the Wamp In node can connect to include items like devices and directory, groups, calls and open door.
  • Wamp Out is
  • Wamp Call is a "publisher" that will send messages it receives to certain WAMP connection points within ZCP. WAMP connection points that the Wamp Call node can connect to include items like calls, open door, gpos and device key emulation.


Wamp URI's

A WAMP URI (Web Application Messaging Protocol, Uniform Resource Identifier) is a standardized way to identify resources in Zenitel Connect Pro.

For example, to subscribe to Call events, you would drag a Wamp In node to the workspace, and subscribe to the Wamp URI com.zenitel.calls. All call activity would be reported by this node to the next node in the chain.
To make a call using Node-RED, you would drag a Wamp Call node to the workspace, and attach it to the Wamp URI com.zenitel.calls.post. Sending a correctly formatted message to this node would initiate a call in ZCP.

For a full overview of available Wamp URI's, enter <ZCP IP Address>/openapi in your browser (e.g. 10.9.8.207/openapi)


WAMP Message Formatting

ZCP sends information as an Array containing labels and values as strings. The format of these arrays varies depending on the message itself, and the format documentation is available from <ZCP IP Address>/openapi

As an example, if we look at a Door Open event, it has the following properties

msg.payload.args[0]["door_dirno"]
msg.payload.args[0]["door_name"]
msg.payload.args[0]["from_dirno"]
msg.payload.args[0]["from_name"]
msg.payload.args[0][gpo]["gpo_id"]
msg.payload.args[0][gpo]["mac_address"]
msg.payload.args[0][gpo]["time"]


Using this information, we can receive Door Opening events, and process this information.

from_dirno - Directory Number of operator opening door
from_name - Display name of operator opening door
door_dirno - Directory number of Door
door_name - Display name of Door
gpo
    gpo_id - Id of the GPO activated
    mac_address - MAC of the device hosting the GPO being activated
    time - Duration in seconds for a timed relay activation.


Node-RED receives this array as a message payload, which is referred to as msg.payload


Setting up Node-RED for the first time

When setting up Node-RED for the first time, we need to add a WAMP Connection point and the authentication details.

  • Drag and drop a Wamp In node to the workspace.
  • Double click on the node
  • Press the + icon beside the field Add new wamp-client
    • wamp.placeholder.router field: Enter the ZCP IP Address and port number "wss://<IP Address>:8086"
    • wamp.placeholder.realm field: Enter "zenitel"
    • wamp.placeholder.authid field: The Zenitel Link username
    • wamp.placeholder.password field: The Zenitel Link password
    • Name: Give your Wamp Connection a friendly name (e.g. "Zenitel Connect Pro")
  • Click Add and then Done to finalize the properties. These details will be retained in the system
NodeRed FirstTime.PNG
Node-RED WAMP node installation

Examples

Ex 1: Trigger a second Relay at Door Opening

Scenario: A client requires that in addition to the Relay being triggered at the Door intercom for access control, a second relay on another device is required to provide a signal to indicate the door has been opened. This additional signal is for a mimic panel, and for input into the Building Management System.

The directory number of the Door is 202 and the Directory number of the second device is 204.

  1. From the Palette, drag and drop a Wamp In node to the Workspace
  2. From the Palette, drag and drop a Function node to the Workspace
  3. From the Palette, drag and drop a Wamp Call node to the Workspace
  4. Connect the nodes by drawing a line between the connection points in each node


NodeRedFlow1.png
Wamp In, Function and Wamp Call nodes on the Workspace

Double-click the Wamp In node and subscribe to the Open Door event com.zenitel.system.open_door.

NodeRed WampIn.png
Configuring the WAMP in node
  • The 1st first field is the name of the connection, which we defined in the previous step Setting up Node-RED for the first time
  • The 2nd field is the event we want to subscribe to. Here "com.zenitel.system.open_door", which is the Door Open event.
  • The 3rd field is any descriptive name.


The next step is to configure the Function node. Double-click the "Function" node. Here we use a small amount of Java code within the Function node to extract the directory number from the incoming message payload and at the same time set up the new payload. The Function node extracts the value from msg.payload.args[0]["open_door"], and uses an If statement to test whether the door is Dir 202, and then formats the outgoing message to be sent to the "Wamp Call" node.

Node red flow2 function.JPG
The code written inside the Function node

The code is:

// Retrieve the incoming number from the message payload
var door = msg.payload.args[0]["door_dirno"];
// Test whether the door open is Directory number 202
if (door == 202){
   // Create the new outgoing command
   msg = {
       payload: {
           'dirno': '204',
           'id': 'relay1',
           'operation': 'set_timed',
           'time': 3
       }
   }
   // Send the command to the next node
   return msg;
} 


Finally, we can send this message to Zenitel Connect Pro using a Wamp Call node connected to the GPO connection at com.zenitel.devices.device.gpos.gpo.post.

Double-click the "Wamp Call" node, and select the connection, the connection point com.zenitel.devices.device.gpos.gpo.post, and a descriptive name:

NodeRed WampCall.png
Configuring the Wamp Call node


The flow should now look like this:

NodeRedFlow2.png
Node-RED flow configured, but not deployed


The blue circle in a node indicates that there has been changes to the node which has not yet been Deployed.

Click on the Deploy button in the top right corner of the Node-RED interface to save the configuration. The Wamp In and Wamp Call nodes should now indicate that they have established connection with the Zenitel Connect Pro:

NodeRedFlow3.png
Node-RED flow configured and deployed

If you now establish a call with Door 202 and press digit "6" to trigger the relay, also the relay of device 204 should trigger.


Ex 2: Trigger a second Relay at Door Opening - Multiple doors

If we have many doors in our system and we need to provide a related relay for each door, we can expand our Function node with a key-value pair table.
An IP-LCM provides up to 9 relays, so our function needs to relate to the Directory Number and the Relay to be used.

The code is:

// Retrieve the incoming number from the message payload

var door = msg.payload.args[0]["door_dirno"];
// Define a lookup table for door number substitutions with an additional 'id' field
// Each door number maps to an object with 'dirno' and 'id'
var lookupTable = {
   202: { dirno: 204, id: 'relay1' },  // Example: if door is 202, activate relay 1 on IP-LCM at Directory number 204
   302: { dirno: 204, id: 'relay2' },  // Example: if door is 302, activate relay 2 on IP-LCM at Directory number 204 
   402: { dirno: 204, id: 'relay3' }   // Add more pairs as needed with their respective 'dirno' and 'id'
   // Add new entries here in the format: 'door_number': { dirno: 'substitute_number', id: 'relayX' }
};
// Check if the incoming 'door' number exists in the lookup table
if (lookupTable.hasOwnProperty(door)) {
   // Get the corresponding object (which contains both dirno and id) from the lookup table
   var substitution = lookupTable[door];
   // Create a new message object with the substituted 'dirno' and 'id' values
   msg = {
       payload: {
           'dirno': substitution.dirno.toString(), // Convert the number to string if needed
           'id': substitution.id,                  // Use the 'id' from the lookup table
           'operation': 'set_timed',               // Example operation, adjust as needed
           'time': 3                               // Example time value, adjust as needed
       }
   };
   
   // Return the modified message
   return msg;
} else {
   // If the 'door' number does not exist in the lookup table, return null or handle the case appropriately
   node.warn("Door number " + door + " not found in lookup table.");
   return null;
} 



Free available data on the Internet

On the internet there are lots of API's available to request various types of data. Some of these are on a payment plan but there is also many that are provided by governments free of charge. Examples of these are weather and natural events related data or timetables for public transport.

Here you can find the example of the National Weather Service in the US: https://www.weather.gov/documentation/services-web-api. In their documentation you find that https://api.weather.gov/gridpoints/{wfo}/{x},{y}/forecast gives you the weather forecast for a specific location. The values for wfo, x, and y are a location system used by the NWS, the description is in the documentation. If we fill in the values for a given location in the US we get for example a request URL that looks like this: https://api.weather.gov/gridpoints/EAX/46,52/forecast This URL can be used with the HTTP request node.

Http request.png
The URL in the HTTP request node

Now when this node gets triggered it will request the current weather forecast from the NWS.

Debugging and troubleshooting options

To be able to troubleshoot a flow you might want to be able to manipulate and inspect the messages being send between the nodes. There are two very useful nodes to accomplish this.

The inject node

The inject node can be used to inject a message anywhere in the flow. This can be particular useful when you are expecting a message coming from a third party system but this is not available yet. With the inject node you can start testing your flow beforehand.

Inject node.png
The inject node
Inject node message options.png
The options for injecting different types of messages


The debug node

On the right hand side of your Node-RED window there is a debug pane. You can display messages being send between nodes by using the debug node. If you have multiple debug nodes in your flow you can turn them on and off to only view the one you are interested in. In the configuration of this node you can choose to only display the message payload, which is only the actual data, or the entire message object that is including all the meta data.

Debug node.png
The debug node
Debug node options.png
The options for displaying only the payload or the entire message object


Further reading

We advise beginners to read further in the Node-RED cookbook: https://cookbook.nodered.org