Node-Red连接云平台

一、What is Node-RED and what can I do with it?

Node-RED is a web based programming tool. With it you can wire together Nodes. Nodes are software components which collect and transfer data with different protocols from different machines. The wires transfer Events from one Node to another. You can even do some simple computation or data conversion with the Function Node.

There are some Nodes pre-installed like http, tcp, udp, etc., but you can further install one of over 3000 available packages with more Nodes and functionality inside. This can be done via the “Manage palette”-Tab. After the installation the new Nodes will appear in the Node-View on the left of the screen.

二、First HTTP-Request of Cloud

01-Node-RED

The main window (1) is the area where you can drag and drop Nodes in to program your application. The Nodes (2) can be found in the Node-Pallettes (3).

Our first flow will be a Request of https://proficloud.io. Place a injection-, http-request- and debug-Node into the main view. And connect them. By double clicking on the http-request Node the configuration window for this Node will open. Here you can enter the URL. A click on the button Deploy will make the flow running. After activating the injection Node the http-request Node will request the webpage and the debug Node prints the result in the debug window.

三、Manage palette – Installing additional Nodes

02-Node-RED-and-Proficloud.io-Manage-palette-Installing-additional-Nodes

NodeRED provides over 3200 libraries with different Nodes to create connectivity to a lot of different systems and devices.

To install one of them just open the palette manager form the submenu in the the upper right corner. In the pallet manager window click on the install tab and search for the library you like to install. By clicking on the install button the libraries will be installed in NodeRED and provided in the Nodes palette on the left side of the screen. Depending on the power of the host machine, this can take a while.

四、Installation of ProficloudDevice-Node

03-Node-RED-and-Proficloud-io-Installation-of-ProficloudDevice-Node

Now you can install the library required to connect NodeRED with the Proficloud.io. Use the way you learned on the last page to install the node-red-contrib-proficloud library. After the installation you will find the ProficloudDevice-Node in the Phoenix Contact category.

Before connecting the Node with the Proficloud you need to add the UUID in your Proficloud account. If you don’t have a UUID for your virtual device, please contact us (info@phoenixcontact-sb.io). Now enter the UUID in the configuration of the ProficloudDevice-Node and activate AutoConnect. After the deployment of the flow the Node should connect to the Proficloud. The first connection could take a while, because of the exchange of client certificates.

五、Set static metadata for devices in Proficloud.io

04-Node-RED-and-Proficloud-io-Set-static-metadata

Devices can send metadata to Proficloud.io by including it in their payload. You can override the device-specific metadata by enabling the ‘Custom Metadata’-option in the Proficloud Device Node in Node-RED.

Double click the Proficloud Device Node to open the Node options.

Node-Red连接云平台

‘Custom Metadata’ is enabled by default. Enter values for Serial Number, Firmware Version and Hardware Version. After deploying your flow, these will appear in the ‘Information’-Tab of the Proficloud.io Device Management Service.

Node-Red连接云平台

六、Send Time Series Data to Proficloud.io

05-Node-RED-and-Proficloud-io-Send-Time-Series-Data-to-Proficloud-io

To send TimeSeriesData you use the input of the “ProficloudDevice”-Node. You should collect the data from your application with one of the default Nodes of Node-RED. In this lesson we are working with fake data. After the collection the data should be formatted as json object inside `msg.payload.data` as the following example:


msg = {};
msg.payload = {"data" : {"humidity": 12.0, "temp": 2.0}};
return msg;

To test it just put the code above in a function node and trigger it with an injection node. The TimeSeriesData will then show up in the “Device Template” of the TimeSeriesData-Service.

In the described example the timestamp of Proficloud.io is set for the incoming data. To use your local timestamp, put it with the key “timestamp“ and the timestamp in milliseconds as value inside the data object.

七、Send Health Status to Proficloud.io

06-Node-RED-and-Proficloud.io-Send-Health-Status-to-Proficloud-io

The TrafficLight represents the status of the device. It will be shown in the DeviceManagement-Service as color of the device and with a short status message in the information tab. The transfer of the TrafficLight works the same way as the transfer of TimeSeriesData. You should send a json object with the following information to the input of the ProficloudDevice-Node.


msg = {};
msg.payload = {"trafficlight": {"color": 2, "msg": "Some problem"}};
return msg;

The color is encoded as number. The value 0 is green, 1 is orange and 2 is red. In the “msg” field the status massage takes place. After triggering this message you can check the result in the DeviceManagement-Service.

八、Send Logs to Proficloud.io

07-Node-RED-and-Proficloud-io-Send-Logs-to-Proficloud-io

You can transfer logs directly with the ProficloudDevice-Node to Proficloud.io. The json object which should be sent to the input of the ProficloudDevice-Node should log as follows.


msg = {};
msg.payload = {"log": {"level": 2, "tag":"Node-RED","msg": "System tarted"}};
return msg;

To test it you can put this code in a function node of Node-RED and connect it with an injection node. The key “level” is the level of the log message (0 = Debug, 1 = Info, 2 = Warn, 3 = Error, 4 = Fatal). To identify from which component the message is from you can set the “tag”. The “msg” field is the actual log message.


© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...