Simple udp request and response flow
-
-
Save zetxx/e7d29861b7717186921f to your computer and use it in GitHub Desktop.
UDP Request response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"9457cf66.6ba83","type":"udp out","name":"","addr":"127.0.0.1","iface":"","port":"1881","outport":"","base64":false,"multicast":"false","x":710,"y":174,"z":"b91431a8.46ebd","wires":[]},{"id":"9b8de31f.64722","type":"function","name":"MQTT-SN sender","func":"// Takes a payload and topic and makes a QoS -1\n// MQTT-SN message buffer out of it.\n\nfunction makeMqttsBuffer(topic,message) {\n var buf;\n var p=0;\n var len = topic.length + message.length + 7;\n if (len > 254) {\n p=2;\n buf = new Buffer(topic.length + message.length + 7 + p);\n buf[0] = 1;\n buf[1] = parseInt((len+p)/256);\n buf[2] = parseInt((len+p)%256);\n }\n else {\n buf = new Buffer(topic.length + message.length + 7 + p);\n buf[0] = len;\n }\n buf[1+p] = 12;\n buf[2+p] = 96;\n buf[3+p] = parseInt(topic.length/256);\n buf[4+p] = parseInt(topic.length%256);\n buf[5+p] = 32;\n buf[6+p] = 32;\n for (var i = 0; i < topic.length ; i++) {\n buf[7+i+p] = topic.charCodeAt(i);\n }\n for (var i = 0; i < message.length ; i++) {\n buf[7+topic.length+i+p] = message.charCodeAt(i);\n }\n return buf;\n}\n\nmsg.payload = makeMqttsBuffer(msg.topic, msg.payload);\nmsg.type = 'sender';\nreturn msg;","outputs":1,"x":346.00000381469727,"y":274.00003147125244,"z":"b91431a8.46ebd","wires":[["ea88865c.157778","122ef430.edd10c"]]},{"id":"34c90cb5.cb36f4","type":"inject","name":"","topic":"Hello","payload":"Dave","payloadType":"string","repeat":"","crontab":"","once":false,"x":170.00002670288086,"y":287.9999952316284,"z":"b91431a8.46ebd","wires":[["9b8de31f.64722"]]},{"id":"ea88865c.157778","type":"debug","name":"","active":true,"console":"false","complete":"true","x":732,"y":337,"z":"b91431a8.46ebd","wires":[]},{"id":"a43fe2e7.5bc02","type":"udp in","name":"listener","iface":"","port":"1881","datatype":"buffer","multicast":"false","group":"","x":130,"y":370,"z":"b91431a8.46ebd","wires":[["f6434c89.09bcb"]]},{"id":"f6434c89.09bcb","type":"function","name":"MQTT-SN receiver","func":"msg.type = 'receiver';\nreturn msg;","outputs":1,"x":425,"y":367,"z":"b91431a8.46ebd","wires":[["ea88865c.157778"]]},{"id":"122ef430.edd10c","type":"delay","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":529,"y":230,"z":"b91431a8.46ebd","wires":[["9457cf66.6ba83"]]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment