How to create a Node-RED flow with simulated PackML data

Instructions
-
Connect to Node-RED using UMHLens and create a new flow.

-
Drag the following nodes into your flow: mqtt-in→filter→json→switch→function(10x)→mqtt-out.

-
Open the filter-node and set it to block unless value changes.

-
Open the switch-node and configure it as shown below. The switch node will check if the incoming message has one of the values we’ve configured and pass it to the correct function-node.

-
Now connect all nodes.

-
Next configure the 10 function-nodes, which will convert the incoming message (Pack-ML state) into the UMH state. If you want to see all UMH states click here. Paste in the following code for each function-node starting from top→bottom.
-
Configure the mqtt-in node with the servicename of hivemq and the topic
testLocation/DefaultArea/DefaultProductionLine/Status/StateCurrent. -
For the mqtt-out node, select the created broker and use the topic
ia/factoryinsight/Aachen/testAsset/state

-
The next set of nodes will return the speed at which the machine is operating. Drag the following nodes into your flow: mqtt-in→json→function→mqtt-out. Configure the mqtt-in node with the topic
testLocation/DefaultArea/DefaultProductionLine/Status/CurMachSpeedand the mqtt-out node with the topicia/factoryinsight/aachen/maschine/processValue.

-
Next convert the current machine speed into a percentage number. Therefore, open the function node and paste in the following:
- Click deploy on the top right, and you are done with this set of nodes.
- The last set of nodes will count the good and defective produced products. Since this simulator already gives us the total number of defective and good products, we have to convert that, so that every time a product is produced (defective or good) we get a count signal. Import two mqtt-in, two json, three function, and one mqtt-out node into your flow.

- Paste this code into function1 → On Start. The code will be run once on start.
- Paste this code into function1 → On Message. The code will be run when a new message appears.
- Now repeat these two steps for function2. Code for function2 → On Start:
- Code for function2 → On Message:
- For function3 you only need to paste code into On Message:
- Since we already specified our mqtt-out topic in the last function node, we only need to configure our mqtt in nodes, with the upper one having the topic:
testLocation/DefaultArea/DefaultProductionLine/Admin/ProdProcessedCount/0/Countand the lower one:testLocation/DefaultArea/DefaultProductionLine/Admin/ProdDefectiveCount/0/Count.To make our changes effective, open the mqtt-out node and click done. Finally click deploy. - If you want to display your created data, make sure to check out our guides fo Grafana. This flow will look something like this in Grafana:



