Makers Blog Communication iot Node-RED PLCnext Connector PLCnext Technology

Node-RED communication with an AXC using the PLCnext Connector

Stefan Brinkmann 13 May 2022 min. read
2,071 views 3 comments

There is a new package available for Node-RED that enables the user to communicate with the PLCnext controller via the REST api. The name of the package is node-red-plc-next-connector. It can be installed via the “Managa palette” menu in Node-RED.

The package includes nodes to browse the available variables and datatypes, to read and write variables and to handle sessions and groups.

The first example shows how to browse all available variables. At the beginning, a new plc-connector must be created, i.e. a connection to the PLC must be configured. This plc-connector can then be used for all other nodes as well.

The result is returned as a dictionary.

Reading variables from the PLC is also very simple. In the read variables node, the plcnext connector must be selected. After that, you can select the variables from a dropdown list. The result is returned as an array of struct, containing the variaable path and the value.

The writing of variables works the same way. The plc-write-variables node expects the msg.payload in json format.

Here is an example payload:

msg.payload= {variables : [
{
  "path": "Arp.Plc.Eclr/I_WarehouseControl1.HMI_rTemperature",
  "value": 12.34,
  "valueType": "Constant"
},
{
  "path": "Arp.Plc.Eclr/I_WarehouseControl1.HMI_iHumidity",
  "value": 85,
  "valueType": "Constant"
} 
]};

Note:

The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.

Discussion

Please login/register to comment

Login/Register

Leave a Reply

mubashir 19.08.2023

is this node still works, i am getting the following error, Error: Request failed with status code 404

Login / Register to reply
Stefan Brinkmann 21.08.2023

I am using FW 2023.0 on an AXC F 2152 and the nodes are still working. In order to make it work you need to create either an eHMI page or activate the RESTinterface in the settings of the Web server in PLCnext Engineer.

pengyiliao 17.10.2023

Hi Stefan, thanks for the great tutorials. I am new to the PLCnext controller. I am using the AXC F 2152, and want to send the data from the controller to the the InfluxDB database. I followed your tutorial and had the same question as Mubashir. I saw your reply and tried to activate the REST interface in the settings of the Web server in PLCnext Engineer. However, I did not find the REST interface in the settings of the Web server in PLCnext Engineer. Do you know any other way to activate the REST interface. Or could you give me some suggestions to create an eHMI page? I can launch the HMI simulator. DOes this mean that I already created an eHMI page? Thanks in advance.

Login / Register to reply
Stefan Brinkmann 17.10.2023

Hello PENGYILIAO, the nodes do still work. In order to access the variable from the PLC ypu need to create at least one (empty) eHMI page or enable the REST interface in the settings of the webbrowser inside PLCnext Engineer. The variables must be either global or if they are local, the HMI checkmark must be set.

pengyiliao 27.10.2023

Hi STEFAN, thanks for your help. Now my 'plc-read-variables' node and 'plc-browse-items' node work fine. I can read variables from PLC on the Node-RED. However, I have an issue with the 'plc-write-variables' node. With the 'plc-write-variables' node, I can write a constant value into a variable in the PLC. However, I can not write a variable's value (the value is generated on the node-RED) into another variable in the PLC. I think the issue is I do not know what I'm supposed to put in the blanks of the 'plc-write-variables' node (Especially the blank with the name 'Value'). There is limited information about the PLCnext Connector nodes. Could you help me with this issue?

Login / Register to reply
Stefan Brinkmann 30.10.2023

You can uswe the following code to write the value of any variable : var value = msg.payload; msg.payload= {variables : [ { "path": "Arp.Plc.Eclr/I_OPCData.G_diNodeRedValue", "value": value, "valueType": "Constant" }]}; return msg;

Newsletter
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users