Node-RED Guide: 17: an array of common operations

Here Insert Picture Description
This article describes the continued operation of the common definition of Node-RED in an array of elements, split, merge and display.

a

In a way to start the container Node-RED service startup command as follows:

Start command: docker run -it -p 1880: 1880 -v $ PWD / data: / data -e TZ = Asia / Shanghai --name nodered -d nodered / nodered: 1.0.4

Definition array

Inject use node, wherein providing an array of JSON format defined manner, as shown
Here Insert Picture Description
Node-RED also provides a simple JSON editor, can enter directly
Here Insert Picture Description
select the format JSON format can
Here Insert Picture Description
be selected visual editor the way
Here Insert Picture Description

The results show an array

Debug a connection types of nodes, after deployment, manually click the trigger Inject node, you can direct the array results show
Here Insert Picture Description

Split Array

Create a default node for splitting the split arrays
Here Insert Picture Description
is connected, after the deployment of the results of the following
Here Insert Picture Description

Digital operation: rounding

For an array of spin-off operation that generates a digital rounding dropping the fractional processing node can use round
Here Insert Picture Description
connector, deployment, then the results shown below, can be seen in FIG have been rounded up
Here Insert Picture Description

Array merge

After the individual elements are recombined process, you can use the join node, default settings here to be
Here Insert Picture Description
connected to the deployment, then the results shown below, can be seen in FIG array has a combined output
Here Insert Picture Description

JSON format flow

[{"id":"bff77d9a.20b6c","type":"inject","z":"73554227.4474dc","name":"数字数组输入","topic":"","payload":"[1,2.2,3.345,4.456,5.567]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":120,"wires":[["1e13c184.78c3be"]]},{"id":"b4c533a9.3a2e3","type":"debug","z":"73554227.4474dc","name":"数组结果显示","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":540,"y":220,"wires":[]},{"id":"1e13c184.78c3be","type":"split","z":"73554227.4474dc","name":"拆分数组","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":340,"y":120,"wires":[["8054bdc5.ae709"]]},{"id":"8054bdc5.ae709","type":"range","z":"73554227.4474dc","minin":"0","maxin":"100","minout":"0","maxout":"100","action":"scale","round":true,"property":"payload","name":"数字舍五入","x":530,"y":120,"wires":[["71a9d002.49773"]]},{"id":"71a9d002.49773","type":"join","z":"73554227.4474dc","name":"合并数组","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":340,"y":220,"wires":[["b4c533a9.3a2e3"]]}]
Original article published 1133 · won praise 1357 · Views 4.1 million +

Guess you like

Origin blog.csdn.net/liumiaocn/article/details/104745063