Proglove workflow replication (MQTT)
This flow is an example of how to use node-red to replicate workflow.
Example Scenario
Scan a barcode with the content “123923kr9k23”
Send a message to mark display with the header: Location and Text: 123923kr9k23 or Trigger feedback on Scanner
Configuration steps
-Configur the mqtt node with unique clientId and the ip adress of your intended mqtt server
-The topic in the connectivity device config and on the node-red mqtt-out should be the same and start with ‘shared/’.
-Add ‘/#’ at the end of the topic name on node-red mqtt-out node. As proglove add the device serial number at the end of the topic for each scanner adding /# at the end of the topic prefix will allow node-red mqtt-out to listen on all the topics with the same prefix.
[{"id":"7f82a2aa.8b649c","type":"tab","label":"end to end (workflow exp) mqtt","disabled":false,"info":""},{"id":"6db4b161.ddc03","type":"mqtt in","z":"7f82a2aa.8b649c","name":"mqtt out","topic":"shared/test.proglove/#","qos":"2","datatype":"auto","broker":"a293c71a.da5678","x":220,"y":200,"wires":[["cf1f4698.60da08"]]},{"id":"f21c747a.84ae98","type":"function","z":"7f82a2aa.8b649c","name":"display feedback function","func":"// function receives the object msg\n\nvar incomingMsg=JSON.parse(JSON.stringify(msg)) //preserving the original input from the mqtt broker\nvar outgoingMsg=null \nvar payload = JSON.parse(incomingMsg.payload) // converting JSON string to Object\n\n// checking the event type so that for other sorts of msg it does not change\n// checking if scan code is 123923kr9k23 \n// and if similar setting the display accordingly\nif(payload.event_type=='scan' && payload.scan_code == '123923kr9k23' )\n{\n //copying original msg to outgoing object\n outgoingMsg=JSON.parse(JSON.stringify(msg))\n //changing the topic accordingly\n outgoingMsg.topic= 'shared/test.proglove/gateway/PGGW202108518/display!'\n //changing the payload accordingly\n outgoingMsg.payload={\n \"api_version\": \"1.0\",\n \"event_type\": \"display!\",\n \"event_id\": \"02114da8-feae-46e3-8b00-a3f7ea8672df\",\n \"time_created\": 1546300800000,\n \"time_validity_duration\": 1000,\n \"device_serial\": \"MBMRF25109117\",\n \"display_template_id\": \"PG1\",\n \"display_refresh_type\": \"DEFAULT\",\n \"display_fields\": [\n {\n \"display_field_id\": 1,\n \"display_field_header\": \"Location\",\n \"display_field_text\": \"123923kr9k23\"\n }\n ]\n}\n}\n\n// As the output is increased to 2, we have to return an array of length 2\n// 1st obj is for 1st output and 2nd object for 2nd out put\nreturn [outgoingMsg,incomingMsg]\n\n","outputs":2,"noerr":0,"x":470,"y":200,"wires":[[],[]]},{"id":"2257277c.dd03e8","type":"mqtt out","z":"7f82a2aa.8b649c","name":"mqtt publisher","topic":"","qos":"","retain":"","broker":"a293c71a.da5678","x":720,"y":140,"wires":[]},{"id":"a15fdce2.886fb","type":"debug","z":"7f82a2aa.8b649c","name":"debug mqtt subscriber ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":740,"y":260,"wires":[]},{"id":"cf1f4698.60da08","type":"function","z":"7f82a2aa.8b649c","name":"feedback function","func":"// function receives the object msg\n\nvar incomingMsg=JSON.parse(JSON.stringify(msg)) //preserving the original input from the mqtt broker\nvar outgoingMsg=null \nvar payload = JSON.parse(incomingMsg.payload) // converting JSON string to Object\n// checking the event type so that for other sorts of msg it does not change\n// checking if scan code is 123923kr9k23 \n// and if similar setting the payload to have positive feedback\nif(payload.event_type=='scan' && payload.scan_code == '123923kr9k23' )\n{\n //copying original msg to outgoing object\n outgoingMsg=JSON.parse(JSON.stringify(msg))\n //changing the topic accordingly\n outgoingMsg.topic= 'shared/test.proglove/gateway/PGGW202108518/feedback!'\n //changing the payload accordingly\n outgoingMsg.payload={\n \"api_version\": \"1.0\",\n \"event_type\": \"feedback!\",\n \"event_id\": \"02114da8-feae-46e3-8b00-a3f7ea8672df\",\n \"time_created\": 1546300800000,\n \"device_serial\": \"MBMRF25109117\",\n \"feedback_action_id\": \"FEEDBACK_SPECIAL_YELLOW\"\n }\n}\n// As the output is increased to 2, we have to return an array of length 2\n// 1st obj is for 1st output and 2nd object for\nreturn [outgoingMsg,incomingMsg]\n\n","outputs":2,"noerr":0,"x":450,"y":280,"wires":[["2257277c.dd03e8"],["a15fdce2.886fb"]]},{"id":"a293c71a.da5678","type":"mqtt-broker","z":"","name":"","broker":"","port":"1883","clientid":"id2","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]