7 minute read
Before continuing with this guide, please make sure you have installed the United Manufacturing Hub and have acquired data to process. If you are using simulated data, none of the examples currently apply for the simulated data. You can either read through the examples and use them as guidelines or you can import the template Node-RED flow from the Guide about simulation of MQTT messages.
In this guide we will process raw sensor data, as well as setting up supporting information, like new shifts. This is something you can theoretically do however you want, e.g. by writing your own code to connect to the message broker and processing the data. However, we recommend using Node-RED as it is easy to use and very flexible. It uses so-called nodes, which you connect and create workflows with it.
For more basic Information on basic Node-RED, please feel free to try out the First Flow Tutorial from Node-RED.
In this guide we are showing how to create 4 basic Node-RED flows:
If you used the recommended installation guide with a light barrier sensor, it is recommended you try out also processing the light barrier data.
We also have a video on the topic, so make sure to take a look at it.
After you went through your setup and have managed to set up, make sure to return to the Get Started Walkthrough.
In the United Manufacturing Hub a shift is defined as the planned production time and is therefore important for OEE calculations. If no shifts have been added, it is automatically assumed that the machine is not planned to run. Therefore, all stops will be automatically considered as states of “no shift” or “Operator Break” until a shift is added.
A shift can be added by sending an [addshift](https://learn.umh.app/docs/datamodel/messages/addshift/)
message. In Node-RED, this needs to be handled by at least three nodes.
add shift
in the picture)You don’t need to adjust the Inject node as it can be used unmodified.
For the function node, you need to insert the following code to add message payload according to the datamodel.
msg.payload = {
"timestamp_ms": 1639522810000,
"timestamp_ms_end": 1639609200000
}
msg.topic = "ia/factoryinsight/dccaachen/docs/addShift"
return msg;
The MQTT node needs to be configured to connect with the MQTT broker (if nothing has been changed from the default United Manufacturing Hub Installation, it will be selected automatically).
Now you can deploy the flow and by clicking on the inject node you will generate the MQTT message. A shift will be added for the customer factoryinsight
, the asset location dccaachen
and the asset name docs
.
The shift will start on 2021-12-14 00:00 and end 2021-12-15 00:00 standard time. If you need to translate the UNIX timestamp in millisecords to a properly readable format, we recommend Currentmillis.com
Now we will process sensor data instead of sending new data as before. With the light barrier it is possible, for example, to record the number of pieces produced. Also with a more complicated logic, machine states can be detected directly with a light barrier. For the sake of simplicity, this is not explored and applied in our example.
The first two nodes in this exaple will be the same for all other remaining examples as well.
First Node: MQTT-in
ia_nodered
without password.The topic structure is /ia/raw/<transmitterID>/gatewaySerialNumber>/<portNumber>/<IOLinkSensorID>
.
As you can see in the image, an example for such a topic is ia/raw/development/000200410332/X02/310-372
. This means that an IO-Link gateway with serial number 000200410332
has connected to the sensor 310-372
to the first port X02
.
Now all messages coming in (around 20 messages per second and sensor) will start a Node-RED message flow.
Second Node: JSON
The payload of incoming messages will be in a JSON format. Therefore we need to add a JSON node to interpret the data correctly.
Third Node: function
The third node function
formats the incoming data by extracting information from the JSON (timestamp and relevant data point) and arranging it in a usable way for Node-RED (parsing). The code for this node looks like this:
msg.timestamp=msg.payload.timestamp_ms
msg.payload=msg.payload.Distance;
return msg;
Fourth Node: trigger
The trigger allows us, in this example in the case of the light barrier, to sort out distances that are irrelevant for our evaluation, i.e. greater than 15 cm. To do this, you need to enter a 15 to the “Threshhold” field.
Fifth Node: function
In our example, we want to count the number of produced parts. As a trolley on a rail is responsible for the transport into a container after the production of the part and moves towards the light barrier, the number of produced parts shall be increased by one as soon as the distance between the trolley and the light barries is smaller than 15. To do this, we need a function with the following code:
msg.payload = {
"timestamp_ms": msg.timestamp,
"count": 1
}
msg.topic = "ia/factoryinsight/dccaachen/docs/count"
return msg;
Sixth node: MQTT-out
To publish messages to a pre-configured topc, the MQTT-Out node is used. The complete Node-RED flow then looks like this:
Third node: function
The third node function
formats the incoming data by extracting information from the JSON (timestamp and relevant data point) and arranging it in a usable way for Node-RED (parsing). The code for this node looks like this:
msg.timestamp=msg.payload.timestamp_ms
msg.payload=msg.payload.value_string;
return msg;
Fourth node: filter
The filter blocks the values of a sensor until the value is changed. A change of the property of the node is not necessary.
Fifth node: switch
The switch node is used to distinguish between the different inputs for the following flow and only lets through the values that come through the previously defined input.
With the button bar, these are the individual buttons. You can see which name is assigned to a single button by the number that appears in the debug window when you press a button. For our example, these are the numbers “0108”, “0104”, “0120” and “0101”.
Sixth node: function
The switch node is followed by a separate function for each button. In our example different states are transmitted. States can be e.g. active, unknown pause, material change, process etc. are defined via numbers. The different states can be found here.
For example, the code for the active function looks like this:
msg.payload = {
"timestamp_ms": msg.timestamp,
"state": 10000
}
msg.topic = "ia/factoryinsight/dccaachen/docs/state"
return msg;
To reach further machine states, only the adaption of the state number is necessary.
Seventh node: MQTT-out
To publish messages to a pre-configured topic, the MQTT-Out node is used.
The complete Node-RED flow then looks like this:
Third node: function
In the third node “function” a timestamp is generated for each capacitive value. The timestamp is stored in the form of a string. This makes it possible, for example, to read out the time at which an item was produced.
The code for this node looks like this:
msg.timestamp=msg.payload.timestamp_ms
msg.payload=msg.payload["Process value"]
return msg;
Fourth node: function
In our example, the following function formats the incoming data from MQTT-in by extracting information from the JSON (timestamp and relevant data point) and arranging it in a usable way for Node-RED (parsing). To do this, we need a function with the following code:
msg.payload = {
"timestamp_ms": msg.timestamp,
"process_value": msg.payload
}
msg.topic = "ia/factoryinsight/dccaachen/docs/processValue"
return msg;
The process value name process_value
can be chosen freely.
Fifth node: MQTT-Out
To publish messages to a pre-configued topic, the MQTT-out node is used.
The complete Node-RED flow then looks like this:
Return to the Getting Started page to make sure