Creating the first flow

Creating the first flow

This section introduces the programming interface. Creating the first flow, it consists of an injection node, a debugging node, and a function node. Now, let’s start!

1. Enter the programming interface

Referenz: Quick Start your edge gateway

2. Add an Injection Node

‘Injection node’ allows you to inject messages into a process by clicking a button on the node or according to a set time interval.
Select the ‘Injection node’ from the node library and drag it into the workspace, click the ‘Injection node’, and the ‘help documentation’ in the debug area. You can see ‘Injection node’ functional description.

'Injection node' allows you to inject messages into a process by clicking a button on the node or according to a set time interval.

3. Add a Debug Node

The ‘Debug Node’ displays all received messages in the ‘Log Window’. By default, only msg.payload is printed, you can set what you want to print by double clicking on the ‘Debug Node’.

The 'Debug Node' displays all received messages in the 'Log Window'. By default, only msg.payload is printed, you can set what you want to print by double clicking on the 'Debug Node'.The 'Debug Node' displays all received messages in the 'Log Window'. By default, only msg.payload is printed, you can set what you want to print by double clicking on the 'Debug Node'.

4. Connect the two Nodes

Connect the ‘Injection Node’ and ‘Debug Node’ of the canvas together.

The specific method is: 1. mouse move to the output port of the ‘Injection Node’, hold down the left mouse button; 2. drag and drop to the input port of the ‘Debug Node’; 3. release the mouse.

Connect the 'Injection Node' and 'Debug Node' of the canvas together. The specific method is: 1. mouse move to the output port of the 'Injection Node', hold down the left mouse button; 2. drag and drop to the input port of the 'Debug Node'; 3. release the mouse.

5. Deploy

At this point, the nodes and processes exist only in the workspace. If you need the process to execute, you must click the ‘Deploy Button’ to solidify the program into the gateway.

At this point, the nodes and processes exist only in the workspace. If you need the process to execute, you must click the 'Deploy Button' to solidify the program into the gateway.

6. Test

Select the log window in the debug area and click on the left button of the ‘Injection Node’, the log window will print the timestamps.

Select the log window in the debug area and click on the left button of the 'Injection Node', the log window will print the timestamps.

7. Add a Function Node

You can process the message with JavaScript code inside the ‘Function Node’:

1) Delete the existing linkage (select the linkage and press Delete on the keyboard)

2) Connect the ‘Function Node’ between the ‘Injection Node’ and the ‘Debug Node’

3) Double-click the ‘Function Node’ to open the edit dialog, copy the following code into the dialog, click the Finish Button to close the dialog, and click the Deploy button

// Create a Date object from the payload
var date = new Date(msg.payload);
// Change the payload to be a formatted Date string
msg.payload = date.toString();
// Return the message so it can be sent on
return msg;

Now, when clicking the ‘Injection Node’ button, the messages in the log window have been formatted with readable timestamps by the ‘Function Node’:

You can process the message with JavaScript code inside the 'Function Node': 1) Delete the existing linkage (select the linkage and press Delete on the keyboard) 2) Connect the 'Function Node' between the 'Injection Node' and the 'Debug Node' 3) Double-click the 'Function Node' to open the edit dialog, copy the following code into the dialog, click the Finish Button to close the dialog, and click the Deploy button

Summary

This chapter introduced the basic concepts of creating the first flow. It showed how to trigger a process manually using the ‘Injection Node’. It also showed how to view messages in the log window using the ‘Debug Node’. It also showed how to process messages using the ‘Function Node’.

Source Code

All processes support import and export in json format, which is convenient to share the good process with others. This chapter of the process json file is as follows , copy the menu bar in the upper right corner of the choice of import paste can be exported the same reason.

[{"id":"783c29e7b877e75e","type":"inject","z":"265cd2b9785ecf45","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":200,"wires":[["948ded5b0cd90f27"]]},{"id":"013be0bcfbabf68b","type":"debug","z":"265cd2b9785ecf45","name":"调试 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":200,"wires":[]},{"id":"948ded5b0cd90f27","type":"function","z":"265cd2b9785ecf45","name":"函数计算 1","func":"// Create a Date object from the payload\nvar date = new Date(msg.payload);\n// Change the payload to be a formatted Date string\nmsg.payload = date.toString();\n// Return the message so it can be sent on\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":200,"wires":[["013be0bcfbabf68b"]]}]

Kontakt