Skip to content

Instantly share code, notes, and snippets.

@jpwsutton
Created March 25, 2018 19:35
Show Gist options
  • Save jpwsutton/0518987ce9fd8d037eca3c6e24f5e82d to your computer and use it in GitHub Desktop.
Save jpwsutton/0518987ce9fd8d037eca3c6e24f5e82d to your computer and use it in GitHub Desktop.
Node-red-at-mqttsn-udb-bridge
[{"id":"305d953b.4abf6a","type":"tab","label":"Robot","disabled":true,"info":""},{"id":"910d848f.a215b8","type":"tab","label":"AT Commands","disabled":false,"info":""},{"id":"8a4dab5a.1db6c8","type":"tab","label":"Network","disabled":false,"info":""},{"id":"2cd98bfb.5a9a54","type":"mqtt-broker","z":"","broker":"jit4q3.messaging.internetofthings.ibmcloud.com","port":"1883","clientid":"d:jit4q3:GlowOrbControl:bce8-ff91","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":""},{"id":"d4571afa.2a9fa8","type":"mqtt-broker","z":"","name":"Personal IoT","broker":"wdwf42.messaging.internetofthings.ibmcloud.com","port":"1883","clientid":"a:wdwf42:red","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"2f2480a5.7e57b","type":"ui_tab","z":"","name":"AT Command Simulator","icon":"dashboard"},{"id":"d29fb0c6.58b1b","type":"ui_group","z":"","name":"AT Console","tab":"2f2480a5.7e57b","disp":true,"width":"12","collapse":false},{"id":"2125be53.a62e02","type":"ui_base","theme":{"name":"theme-light","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"themeState":{"base-color":{"default":"#0094CE","value":"#0094CE","edited":false},"page-titlebar-backgroundColor":{"value":"#0094CE","edited":false},"page-backgroundColor":{"value":"#fafafa","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#1bbfff","edited":false},"group-borderColor":{"value":"#ffffff","edited":false},"group-backgroundColor":{"value":"#ffffff","edited":false},"widget-textColor":{"value":"#111111","edited":false},"widget-backgroundColor":{"value":"#0094ce","edited":false},"widget-borderColor":{"value":"#ffffff","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}}},"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}}},{"id":"35448e71.0b9102","type":"inject","z":"305d953b.4abf6a","name":"go","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":90,"y":100,"wires":[["527c3b81.d450d4"]]},{"id":"527c3b81.d450d4","type":"exec","z":"305d953b.4abf6a","command":"bash /Users/jsutton/ibm/iotPlatform/demo/bitio/src/startTilt.sh","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"tilt.py","x":210,"y":100,"wires":[["e5b66494.32d4d8","2a7f18c4.1a0798"],["e5b66494.32d4d8"],["e5b66494.32d4d8"]]},{"id":"e5b66494.32d4d8","type":"debug","z":"305d953b.4abf6a","name":"","active":false,"console":"false","complete":"false","x":370,"y":40,"wires":[]},{"id":"c951002a.87ae","type":"mqtt out","z":"305d953b.4abf6a","name":"IoT Platform - Robot","topic":"iot-2/type/nodered/id/robot/cmd/move/fmt/txt","qos":"0","retain":"","broker":"d4571afa.2a9fa8","x":620,"y":120,"wires":[]},{"id":"2a7f18c4.1a0798","type":"function","z":"305d953b.4abf6a","name":"Format and limit.","func":"var payload = msg.payload.replace(/[\\n\\r]+/g, '');\n\nvar running = flow.get('running')|| false;\n\nif(payload === \"start\"){\n running = true;\n flow.set('running', true);\n} else if (payload === \"stop\"){\n running = false;\n flow.set('running', false);\n msg.payload = \"stop\"\n return msg;\n} else {\n if(running=== true){\n msg.payload = payload;\n return msg;\n }\n}\n","outputs":1,"noerr":0,"x":390,"y":120,"wires":[["203c46dd.032f8a","c951002a.87ae","48f27477.c30cdc"]]},{"id":"203c46dd.032f8a","type":"debug","z":"305d953b.4abf6a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":180,"wires":[]},{"id":"48f27477.c30cdc","type":"switch","z":"305d953b.4abf6a","name":"direction","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"forward","vt":"str"},{"t":"cont","v":"backward","vt":"str"},{"t":"cont","v":"left","vt":"str"},{"t":"cont","v":"right","vt":"str"}],"checkall":"false","outputs":4,"x":200,"y":300,"wires":[["54f63ec1.55cdb"],["eaa38673.92f858"],["505c5f7.f5dd9a"],["c065a5d0.4f74f8"]]},{"id":"505c5f7.f5dd9a","type":"change","z":"305d953b.4abf6a","name":"red","rules":[{"t":"set","p":"payload","pt":"msg","to":"#ff0000","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":340,"wires":[[]]},{"id":"c065a5d0.4f74f8","type":"change","z":"305d953b.4abf6a","name":"green","rules":[{"t":"set","p":"payload","pt":"msg","to":"#00ff00","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":380,"wires":[[]]},{"id":"54f63ec1.55cdb","type":"change","z":"305d953b.4abf6a","name":"white","rules":[{"t":"set","p":"payload","pt":"msg","to":"#ffffff","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":260,"wires":[[]]},{"id":"eaa38673.92f858","type":"change","z":"305d953b.4abf6a","name":"blue","rules":[{"t":"set","p":"payload","pt":"msg","to":"#0000ff","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":300,"wires":[[]]},{"id":"a80151c.e35a9b","type":"inject","z":"305d953b.4abf6a","name":"Make Light Green","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":360,"wires":[["c065a5d0.4f74f8"]]},{"id":"43564980.a81ef8","type":"ui_template","z":"910d848f.a215b8","group":"d29fb0c6.58b1b","name":"Log","order":0,"width":"12","height":"12","format":"<div><pre ng-bind-html=\"msg.payload\"></pre></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":950,"y":80,"wires":[[]]},{"id":"14d7591b.946767","type":"ui_text_input","z":"910d848f.a215b8","name":"Command Input","label":"","group":"d29fb0c6.58b1b","order":0,"width":0,"height":0,"passthru":false,"mode":"text","delay":"0","topic":"","x":100,"y":60,"wires":[["b586283a.707098","9652dc4f.f5944"]]},{"id":"e1ec0677.1e95b8","type":"function","z":"910d848f.a215b8","name":"Add to log","func":"var inputLog = context.get('inputLog') || [];\n\ninputLog.push(msg.payload)\nmsg.payload = inputLog;\ncontext.set('inputLog', inputLog);\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":80,"wires":[["87db5a9d.00fa98","b328b5ab.5a69a8"]]},{"id":"87db5a9d.00fa98","type":"function","z":"910d848f.a215b8","name":"Convert to String","func":"var messages = msg.payload;\nmsg.payload = messages.join('\\n');\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":80,"wires":[["43564980.a81ef8"]]},{"id":"c53eaab1.2e61d8","type":"link in","z":"910d848f.a215b8","name":"TX","links":["4d29eddd.550034","b168ee18.9c6dd"],"x":35,"y":220,"wires":[["9652dc4f.f5944"]]},{"id":"b328b5ab.5a69a8","type":"debug","z":"910d848f.a215b8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":120,"wires":[]},{"id":"8787170d.703cd8","type":"link in","z":"910d848f.a215b8","name":"TX","links":["4d29eddd.550034","b168ee18.9c6dd"],"x":235,"y":60,"wires":[["b586283a.707098"]]},{"id":"78e1f35b.7a1fac","type":"link out","z":"910d848f.a215b8","name":"RX","links":["ea5893b8.9c6d8"],"x":875,"y":240,"wires":[]},{"id":"ea5893b8.9c6d8","type":"link in","z":"910d848f.a215b8","name":"RX","links":["78e1f35b.7a1fac","488b04b5.ce92dc"],"x":235,"y":100,"wires":[["1131b4f.7a7194b"]]},{"id":"9652dc4f.f5944","type":"delay","z":"910d848f.a215b8","name":"","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":150,"y":220,"wires":[["8e54240e.0eae38"]]},{"id":"b586283a.707098","type":"function","z":"910d848f.a215b8","name":"Input","func":"msg.payload = \"> \" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":60,"wires":[["e1ec0677.1e95b8"]]},{"id":"cd8c2873.b5a358","type":"function","z":"910d848f.a215b8","name":"Output","func":"msg.payload = \"< \" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":100,"wires":[["e1ec0677.1e95b8"]]},{"id":"8e54240e.0eae38","type":"function","z":"910d848f.a215b8","name":"Parse AT Input String","func":"var input = msg.payload;\nvar commands = [];\n// Check that we have a string with AT at the start\nif(input.length > 0 && input.startsWith('AT')){\n // First we just check to see if the command is just 'AT'\n if(input === 'AT'){\n commands.push({\n command: 'AT'\n });\n msg.payload = commands;\n return msg;\n } else {\n input = input.substring(2)\n }\n // Split commands if they are concatinated\n var inputCommands = input.split(';');\n for( var x = 0; x < inputCommands.length; x++){\n var rawCmd = inputCommands[x];\n var splitCmd = rawCmd.split('=');\n var args = splitCmd[1].split(',');\n var cmd = {\n command: splitCmd[0],\n args : args\n };\n \n commands.push(cmd);\n }\n \n \n}\nmsg.payload = commands;\nreturn msg;","outputs":1,"noerr":0,"x":360,"y":220,"wires":[["e90586b2.7ed458"]]},{"id":"611154ea.439a5c","type":"debug","z":"910d848f.a215b8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":910,"y":160,"wires":[]},{"id":"345fe697.44c38a","type":"function","z":"8a4dab5a.1db6c8","name":"","func":"var mqttsn = global.get('mqttsn');\nvar conObject = {\n cmd: 'connect',\n will: true,\n cleanSession: true,\n duration: 1800,\n clientId: 'test'\n};\n\nmsg.payload = mqttsn.generate(conObject);\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":440,"wires":[["3ae53729.e9c318"]]},{"id":"3ae53729.e9c318","type":"debug","z":"8a4dab5a.1db6c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":440,"wires":[]},{"id":"27df465b.d4323a","type":"inject","z":"8a4dab5a.1db6c8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":440,"wires":[["345fe697.44c38a"]]},{"id":"da930d59.7ab2c","type":"function","z":"910d848f.a215b8","name":"Process Incoming command","func":"var rawCmd = msg.payload;\nvar cmd = {};\nvar atResp = \"\";\nswitch(rawCmd.command){\n case \"+NSOCR\":\n cmd.cmdType = \"CREATE_SOCKET\";\n cmd.args = {\n type: JSON.parse(rawCmd.args[0]),\n protocol: parseInt(rawCmd.args[1]),\n listen_port: parseInt(rawCmd.args[2]),\n receive_control: parseInt(rawCmd.args[3]),\n socket: parseInt(rawCmd.args[4])\n };\n atResp = [cmd.args.socket, \"OK\"];\n break;\n case \"+NSOST\":\n cmd.cmdType = \"SEND_TO\";\n cmd.args = {\n socket: parseInt(rawCmd.args[0]),\n remote_ip: JSON.parse(rawCmd.args[1]),\n remote_port: parseInt(rawCmd.args[2]),\n length: parseInt(rawCmd.args[3]),\n data: new Buffer(JSON.parse(rawCmd.args[4]), \"hex\")\n };\n atResp = [cmd.args.socket + \",\" + cmd.args.length, \"OK\"];\n break;\n case \"+NSORF\":\n cmd.cmdType = \"RECEIVE_DATA\";\n cmd.args = {\n socket: parseInt(rawCmd.args[0]),\n length: parseInt(rawCmd.args[1])\n };\n break;\n case \"+NSOCL\":\n cmd.cmdType = \"CLOSE_SOCKET\";\n cmd.args = {\n socket: parseInt(rawCmd.args[0])\n };\n atResp = [\"OK\"];\n break;\n default:\n break;\n}\nmsg.payload = cmd;\nvar resp = {};\nresp.payload = atResp;\nreturn [msg, resp];","outputs":2,"noerr":0,"x":720,"y":220,"wires":[["611154ea.439a5c","839a9537.1fe818"],["78e1f35b.7a1fac"]]},{"id":"e90586b2.7ed458","type":"split","z":"910d848f.a215b8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":530,"y":220,"wires":[["da930d59.7ab2c"]]},{"id":"559d320c.3ab00c","type":"udp out","z":"8a4dab5a.1db6c8","name":"","addr":"93.93.128.155","iface":"","port":"10000","ipv":"udp4","outport":"12345","base64":false,"multicast":"false","x":630,"y":60,"wires":[]},{"id":"96506b34.7053d8","type":"udp in","z":"8a4dab5a.1db6c8","name":"","iface":"","port":"12345","ipv":"udp4","multicast":"false","group":"","datatype":"buffer","x":220,"y":180,"wires":[["da653b05.4716b8"]]},{"id":"c28efdf9.ba81a","type":"inject","z":"910d848f.a215b8","name":"AT:Open Socket","topic":"","payload":"AT:Open Socket","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":480,"wires":[["5f6878b0.d1ba78"]]},{"id":"b168ee18.9c6dd","type":"link out","z":"910d848f.a215b8","name":"","links":["8787170d.703cd8","c53eaab1.2e61d8"],"x":695,"y":600,"wires":[]},{"id":"40bb081f.a008c8","type":"function","z":"910d848f.a215b8","name":"Connect","func":"var mqttsn = global.get('mqttsn');\nvar conObject = {\n cmd: 'connect',\n will: false,\n cleanSession: true,\n duration: 1800,\n clientId: 'test'\n};\n\nmsg.payload = mqttsn.generate(conObject);\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":520,"wires":[["9e133437.f8c208"]]},{"id":"2e85b07b.c2ceb","type":"inject","z":"910d848f.a215b8","name":"MQTTSN:Connect","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":520,"wires":[["40bb081f.a008c8"]]},{"id":"9e133437.f8c208","type":"function","z":"910d848f.a215b8","name":"AT:SendToCommand","func":"var bufferToSend = msg.payload;\nvar socketId = 1;\nvar ipAddress = '93.93.128.155';\nvar remPort = 10000;\nvar length = bufferToSend.length;\nvar hex = bufferToSend.toString('hex');\n\nvar command = \"AT+NSOST=\"+socketId+\",\\\"\" + ipAddress + \"\\\",\" + remPort + \",\" + length + \",\\\"\"+hex+\"\\\"\";\nmsg.payload = command;\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":580,"wires":[["b168ee18.9c6dd"]]},{"id":"a0dc94be.2ff748","type":"comment","z":"910d848f.a215b8","name":"Simulate","info":"","x":100,"y":440,"wires":[]},{"id":"f5295bc9.ab47f8","type":"function","z":"910d848f.a215b8","name":"Register","func":"var mqttsn = global.get('mqttsn');\nvar conObject = {\n cmd: 'register',\n topicId: 294,\n msgId: 24,\n topicName: 'james_sutton_sn'\n};\n\nmsg.payload = mqttsn.generate(conObject);\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":560,"wires":[["9e133437.f8c208"]]},{"id":"56d1a807.4743e8","type":"inject","z":"910d848f.a215b8","name":"MQTTSN:Register","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":560,"wires":[["f5295bc9.ab47f8"]]},{"id":"df470f37.23576","type":"function","z":"910d848f.a215b8","name":"Publish","func":"var mqttsn = global.get('mqttsn');\nvar conObject = {\n cmd: 'publish',\n dup: true,\n qos: 1,\n retain: true,\n topicIdType: 'normal',\n topicId: 1,\n msgId: 24,\n payload: new Buffer('{\"test\":\"Node-Red AT-MQTT-SN Relay!\"}')\n};\n\nmsg.payload = mqttsn.generate(conObject);\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":600,"wires":[["9e133437.f8c208"]]},{"id":"bc8ea913.007e08","type":"inject","z":"910d848f.a215b8","name":"MQTTSN:Publish","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":600,"wires":[["df470f37.23576"]]},{"id":"9fcb6041.f5ac6","type":"function","z":"910d848f.a215b8","name":"Subscribe","func":"var mqttsn = global.get('mqttsn');\nvar conObject = {\n cmd: 'subscribe',\n dup: true,\n qos: 1,\n msgId: 523,\n topicIdType: 'normal',\n topicName: 'hello/world'\n};\n\nmsg.payload = mqttsn.generate(conObject);\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":640,"wires":[["9e133437.f8c208"]]},{"id":"2b0e2d66.e02c92","type":"inject","z":"910d848f.a215b8","name":"MQTTSN:Subscribe","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":640,"wires":[["9fcb6041.f5ac6"]]},{"id":"5f6878b0.d1ba78","type":"function","z":"910d848f.a215b8","name":"AT:Open Socket","func":"msg.payload = \"AT+NSOCR=\\\"DGRAM\\\",17,42000,1,1\";\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":500,"wires":[["b168ee18.9c6dd"]]},{"id":"ef718c47.54285","type":"function","z":"910d848f.a215b8","name":"Disconnect","func":"var mqttsn = global.get('mqttsn');\nvar conObject = {\n cmd: 'disconnect',\n duration: 3600\n};\n\nmsg.payload = mqttsn.generate(conObject);\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":680,"wires":[["9e133437.f8c208"]]},{"id":"e5a775.ba84c888","type":"inject","z":"910d848f.a215b8","name":"MQTTSN:Disconnect","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":680,"wires":[["ef718c47.54285"]]},{"id":"179bfa8e.149f95","type":"inject","z":"910d848f.a215b8","name":"AT:Receive Data","topic":"","payload":"22","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":760,"wires":[["60e4ee4e.4f7ca"]]},{"id":"60e4ee4e.4f7ca","type":"function","z":"910d848f.a215b8","name":"AT:Recieve Data","func":"var lengthToRecieve = msg.payload;\n\nvar recieveCmd = \"AT+NSORF=1,\" + parseInt(lengthToRecieve);\n\nmsg.payload = recieveCmd;\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":680,"wires":[["b168ee18.9c6dd"]]},{"id":"817fa1af.373e7","type":"inject","z":"910d848f.a215b8","name":"AT:Close Socket","topic":"","payload":"","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":800,"wires":[["4b7fef20.f9dfa"]]},{"id":"4b7fef20.f9dfa","type":"function","z":"910d848f.a215b8","name":"AT:Close Socket","func":"\nmsg.payload = \"AT+NSOCL=1\";\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":720,"wires":[["b168ee18.9c6dd"]]},{"id":"622c776e.b9d088","type":"link in","z":"8a4dab5a.1db6c8","name":"Send Data","links":["839a9537.1fe818"],"x":135,"y":80,"wires":[["2e3b9a3d.2e3846"]]},{"id":"839a9537.1fe818","type":"link out","z":"910d848f.a215b8","name":"","links":["622c776e.b9d088"],"x":875,"y":200,"wires":[]},{"id":"e3394fd4.bfcc6","type":"function","z":"8a4dab5a.1db6c8","name":"Extract Buffer","func":"var cmd = msg.payload;\n\nif(cmd.cmdType === \"SEND_TO\"){\n msg.ip = cmd.args.remote_ip;\n msg.port = cmd.args.remote_port;\n msg.payload = cmd.args.data;\n return msg;\n}","outputs":1,"noerr":0,"x":420,"y":60,"wires":[["559d320c.3ab00c"]]},{"id":"da653b05.4716b8","type":"function","z":"8a4dab5a.1db6c8","name":"Store Incoming Data and send alert.","func":"var incomingBuffer = global.get('incomingBuffer') || [];\nincomingBuffer.push(msg.payload);\nglobal.set('incomingBuffer', incomingBuffer);\nvar alertCmd = {\n cmdType: \"+NSONMI\",\n args: {\n socket: 1,\n length: msg.payload.length\n }\n}\nmsg.payload = alertCmd;\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":180,"wires":[["630c31ac.90d1c"]]},{"id":"1131b4f.7a7194b","type":"split","z":"910d848f.a215b8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":330,"y":100,"wires":[["cd8c2873.b5a358"]]},{"id":"630c31ac.90d1c","type":"link out","z":"8a4dab5a.1db6c8","name":"Incoming Commands","links":["357ef106.a935ae"],"x":655,"y":180,"wires":[]},{"id":"357ef106.a935ae","type":"link in","z":"910d848f.a215b8","name":"Incoming Commands","links":["630c31ac.90d1c"],"x":115,"y":280,"wires":[["84c073fb.691"]]},{"id":"84c073fb.691","type":"function","z":"910d848f.a215b8","name":"Process Incoming Data Alert","func":"var input = msg.payload;\n\nvar string = input.cmdType + \":\" + input.args.socket + \",\" + input.args.length;\nmsg.payload = string;\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":280,"wires":[["488b04b5.ce92dc"]]},{"id":"488b04b5.ce92dc","type":"link out","z":"910d848f.a215b8","name":"RX","links":["ea5893b8.9c6d8"],"x":615,"y":280,"wires":[]},{"id":"2e3b9a3d.2e3846","type":"switch","z":"8a4dab5a.1db6c8","name":"","property":"payload.cmdType","propertyType":"msg","rules":[{"t":"eq","v":"SEND_TO","vt":"str"},{"t":"eq","v":"RECEIVE_DATA","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":230,"y":80,"wires":[["e3394fd4.bfcc6"],["6e591cdd.d99c04"]]},{"id":"6e591cdd.d99c04","type":"function","z":"8a4dab5a.1db6c8","name":"Retrieve Data","func":"// Ignore for now, just return the whole messsage\nvar lengthToGet = msg.payload.args.length;\n\nvar incomingBuffer = global.get('incomingBuffer') || [];\nvar newData = incomingBuffer.pop();\nglobal.set('incomingBuffer', incomingBuffer);\n\nmsg.payload = newData;\n\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":100,"wires":[["ea37bd64.d69cc"]]},{"id":"ea37bd64.d69cc","type":"link out","z":"8a4dab5a.1db6c8","name":"RX-DATA","links":["547a8573.a0e9dc"],"x":535,"y":100,"wires":[]},{"id":"547a8573.a0e9dc","type":"link in","z":"910d848f.a215b8","name":"RX-DATA","links":["ea37bd64.d69cc"],"x":115,"y":320,"wires":[["47861cbe.3ecd94"]]},{"id":"47861cbe.3ecd94","type":"function","z":"910d848f.a215b8","name":"Process Incoming Data","func":"var incomingData = msg.payload;\n\nvar atResp = {\n respType: \"+NSORF\",\n args : {\n socket: 1,\n remote_ip: 'IP ADDR',\n port: 1212,\n length:incomingData.length,\n data:incomingData,\n remaining_length:0\n }\n}\nmsg.payload = atResp;\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":320,"wires":[["3e30016a.a6a7be","9375be04.5cf03"]]},{"id":"3e30016a.a6a7be","type":"function","z":"910d848f.a215b8","name":"Format AT","func":"var raw = msg.payload;\n\nvar string = raw.args.socket + \",\" + \n raw.args.remote_ip + \",\" + \n raw.args.port + \",\" + \n raw.args.length + \",\" + \n raw.args.data.toString('hex')+ \",\" + \n raw.args.remaining_length;\nmsg.payload = [string];\n\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":300,"wires":[["488b04b5.ce92dc"]]},{"id":"9375be04.5cf03","type":"function","z":"910d848f.a215b8","name":"Parse MQTT-SN Response","func":"var mqttsn = global.get('mqttsn');\nvar parser = mqttsn.parser();\n\nvar data = msg.payload.args.data;\n \nparser.on('packet', function (packet) {\n\n node.send({payload:packet});\n});\n\nparser.parse(data);\nreturn;\n","outputs":1,"noerr":0,"x":540,"y":340,"wires":[["5a7aa76c.21e8d8"]]},{"id":"2565e2a1.b226de","type":"debug","z":"910d848f.a215b8","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":870,"y":340,"wires":[]},{"id":"5a7aa76c.21e8d8","type":"json","z":"910d848f.a215b8","name":"","property":"payload","action":"","pretty":true,"x":730,"y":340,"wires":[["2565e2a1.b226de"]]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment