<aside> 💡 STARTING POINT: There are 2 main sources for the state:
the activity
pressed buttons from button bar
</aside>
Get the activity through MQTT-IN node.
Use a json to convert from string to object.
Use a switch to match the two classisc states on the activity:
activity = 0 → UnspecifiedStopState
activity = 1 → ProducingAtFullSpeedState
these are the two functions for the two states:
UnspecifiedStopState
msg.payload = {
"timestamp_ms": msg.payload["timestamp_ms"],
"state": 40000
}
msg.topic = "ia/factoryinsight/dccaachen/printing/state"
return msg;
ProducingAtFullSpeedState
msg.payload = {
"timestamp_ms": msg.payload["timestamp_ms"],
"state": 10000
}
msg.topic = "ia/factoryinsight/dccaachen/printing/state"
return msg;
After that the only thing left to do is to send out the messages via MQTT-OUT.
Get all the buttons values from MQTT-IN.
Use a json to convert from string to object.
After that we need a function to only send messages if the button got pressed. (msg.payload.value==1)
if (msg.payload.value == 1){
msg.payload = msg.payload;
return msg
}
Because of the buttons sending up to a handful of values with a 1 we need a limit that drops all the unnecessary values in between.
Finally we need to specifiy the stop state (there is a list of available states in our documentation.) And then the last step is as always to send the state message via MQTT-OUT node.
if (msg.payload.value == 1){
msg.payload={
"timestamp_ms": msg.payload.timestamp_ms,
"state": 210000
}
msg.topic = "ia/factoryinsight/dccaachen/thermosetting/state"
return msg;
}