IOT Based Operator Control Platform for Vehicle Tele-Operation

This flow is half of the Overall IoT based Control Infrastructure to enable the Remote Tele-Operation of a Vehicle.

The json flow creates a Node-Red User Interface which serves as the Control plaftorm for the Operator to pilot the vehicle. The flow uses a USB HID node to extract the control data (button press) for the vehicle from the Operator using an XBox 360 controller gamepad connected through USB to the host computer running the node-red flow. The data is processed within the flow into a suitable format and sent using an MQTT Output node over an MQTT server hosted by AWS (Amazon Web Services) IOT thing, to the receiver side node-red flow running on a raspberry pi embedded on the vehicle.

The flow utlizes some User contributed node-red nodes such as: USBHID; Node-Red Dashboard nodes for the User Interface (UI). Other nodes utlized are standard node-red nodes available on installation.

[{"id":"7704e947.29ff58","type":"tab","label":"Control Deck"},{"id":"5f87c212.b51e2c","type":"tab","label":"Flow 3"},{"id":"53c008b1.3ebda8","type":"subflow","name":"Loop","info":"","in":[{"x":64,"y":114,"wires":[{"id":"5f120f30.a9f02"}]}],"out":[{"x":557,"y":176,"wires":[{"id":"81193a91.000558","port":0}]}]},{"id":"93be79be.18aad8","type":"subflow","name":"Process HID Data","info":"","in":[{"x":674.5,"y":352.22998046875,"wires":[{"id":"9045dd9e.51fb8"}]}],"out":[{"x":1376,"y":27,"wires":[{"id":"89e2a675.8cbea8","port":0}]},{"x":1374,"y":78,"wires":[{"id":"292c38f8.04f1a8","port":0}]},{"x":1375,"y":126,"wires":[{"id":"3870bd4a.17f942","port":0}]},{"x":1421,"y":158,"wires":[{"id":"b687d7cf.560d88","port":0}]},{"x":1340,"y":443,"wires":[{"id":"e0484e1.1074bb","port":0}]},{"x":1360,"y":636,"wires":[{"id":"a1bf002d.945c","port":0}]},{"x":1441,"y":247,"wires":[{"id":"9b6061cb.bd72e","port":0}]},{"x":1452,"y":305,"wires":[{"id":"2464e1c1.451dee","port":0}]},{"x":1338,"y":363,"wires":[{"id":"f153d49d.d08c48","port":0}]},{"x":1495.9999694824219,"y":157,"wires":[{"id":"b687d7cf.560d88","port":1}]}]},{"id":"6d21f98b.9f47f8","type":"mqtt-broker","z":"","broker":"a16ck7fy1v223m.iot.eu-west-1.amazonaws.com/","port":"8883","tls":"8afee8d.4ef0d18","clientid":"Mobile","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":""},{"id":"8afee8d.4ef0d18","type":"tls-config","z":"","name":"AWS","cert":"C:\\Users\\user\\Downloads\\Node-Red-Stuff\\TSRV.cert.pem","key":"C:\\Users\\user\\Downloads\\Node-Red-Stuff\\TSRV.private.key","ca":"C:\\Users\\user\\Downloads\\Node-Red-Stuff\\root.CA.pem","verifyservercert":true},{"id":"9dd32e10.1894e","type":"ui_tab","z":"","name":"Home","icon":"dashboard"},{"id":"3a3e883c.9803e8","type":"ui_group","z":"","name":"TSRV Video Stream","tab":"9dd32e10.1894e","order":6,"disp":true,"width":"13"},{"id":"af372327.e4868","type":"tls-config","z":"","name":"AWS","cert":"C:\\Users\\alakoa\\pi_socket\\TSRV.cert.pem","key":"C:\\Users\\alakoa\\pi_socket\\TSRV.private.key","ca":"C:\\Users\\alakoa\\pi_socket\\root.CA.pem","verifyservercert":true},{"id":"560573f4.918e1c","type":"ui_group","z":"","name":"Gear Selection","tab":"9dd32e10.1894e","order":3,"disp":true,"width":"7"},{"id":"c08a45ef.fc89e8","type":"ui_group","z":"","name":"Clutch Status","tab":"9dd32e10.1894e","order":7,"disp":true,"width":"5"},{"id":"ee34b6f4.794f78","type":"ui_group","z":"","name":"Throttle","tab":"9dd32e10.1894e","order":8,"disp":true,"width":"5"},{"id":"97bacb12.17bb68","type":"ui_group","z":"","name":"Steering Status","tab":"9dd32e10.1894e","order":5,"disp":true,"width":"5"},{"id":"93d0a6cb.4cd328","type":"ui_group","z":"","name":"Vehicle Status","tab":"9dd32e10.1894e","order":1,"disp":true,"width":"8"},{"id":"336a256d.99ed9a","type":"ui_group","z":"","name":"Grip Control","tab":"9dd32e10.1894e","order":4,"disp":true,"width":"5"},{"id":"506d5761.724988","type":"ui_base","theme":{"name":"theme-custom","lightTheme":{"default":"#0094CE","baseColor":"#CA3838","baseFont":"Helvetica Neue","edited":false,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"Helvetica Neue","edited":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#CA3838","baseFont":"Helvetica Neue","reset":false},"themeState":{"base-color":{"default":"#CA3838","value":"#CA3838","edited":true},"page-titlebar-backgroundColor":{"value":"#CA3838","edited":false},"page-backgroundColor":{"value":"#000000","edited":true},"page-sidebar-backgroundColor":{"value":"#000000","edited":false},"group-textColor":{"value":"#00B500","edited":true},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#ca3838","edited":false},"widget-borderColor":{"value":"#333333","edited":false}}},"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":"abd36d21.3f5c1","type":"HIDConfig","z":"","vid":"16700","pid":"8454","name":"Key"},{"id":"ee5c29a7.217638","type":"HIDConfig","z":"","vid":"1118","pid":"654","name":"Pad"},{"id":"8cc71d29.83c66","type":"ui_group","z":"","name":"Lift Status","tab":"9dd32e10.1894e","order":2,"disp":true,"width":"8"},{"id":"4829e76a.3e5508","type":"mqtt out","z":"7704e947.29ff58","name":"Start","topic":"/Start","qos":"0","retain":"","broker":"6d21f98b.9f47f8","x":990,"y":891,"wires":[]},{"id":"81193a91.000558","type":"function","z":"53c008b1.3ebda8","name":"Loop","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n// console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n// context = {};\nconsole.log('Entering loop');\nconsole.log(msg.loop);\n\nif (msg.loop == 'off' ) {\n\treturn [msg,null];\n} else {\n\tconsole.log('Looping');\n\treturn [msg,msg];\n}","outputs":"2","noerr":0,"x":339,"y":244,"wires":[[],["5f120f30.a9f02"]]},{"id":"8aae0b5e.d4bfa8","type":"delay","z":"53c008b1.3ebda8","name":"Delay it","pauseType":"queue","timeout":"2","timeoutUnits":"seconds","rate":"2","nbRateUnits":"","rateUnits":"second","randomFirst":"","randomLast":"","randomUnits":"seconds","drop":true,"x":419,"y":114,"wires":[["81193a91.000558"]]},{"id":"5f120f30.a9f02","type":"function","z":"53c008b1.3ebda8","name":"Control Loop","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n//   console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n//   context = {};\n\nmsg.loop = 'on';\n\nreturn msg;","outputs":1,"noerr":0,"x":288,"y":115,"wires":[["8aae0b5e.d4bfa8"]]},{"id":"50d01b06.e2e014","type":"mqtt out","z":"7704e947.29ff58","name":"Direction","topic":"/Direction","qos":"0","retain":"","broker":"6d21f98b.9f47f8","x":927.0000152587891,"y":641.2500095367432,"wires":[]},{"id":"331f0f7a.ef50c","type":"mqtt out","z":"7704e947.29ff58","name":"Right/Left","topic":"/RL","qos":"0","retain":"","broker":"6d21f98b.9f47f8","x":981,"y":972,"wires":[]},{"id":"9350cb6d.fe74b8","type":"switch","z":"93be79be.18aad8","name":"Switch to Required Function","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"8","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"32","vt":"num"},{"t":"eq","v":"48","vt":"num"},{"t":"eq","v":"128","vt":"num"},{"t":"eq","v":"64","vt":"num"},{"t":"eq","v":"24","vt":"num"},{"t":"eq","v":"17","vt":"num"},{"t":"eq","v":"20","vt":"num"},{"t":"eq","v":"18","vt":"num"},{"t":"eq","v":"16","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","outputs":14,"x":1033.5,"y":265.22998046875,"wires":[["89e2a675.8cbea8"],["89e2a675.8cbea8"],["292c38f8.04f1a8"],["292c38f8.04f1a8"],["3870bd4a.17f942"],["3870bd4a.17f942"],["b687d7cf.560d88"],["b687d7cf.560d88"],["9b6061cb.bd72e"],["9b6061cb.bd72e"],["2464e1c1.451dee"],["2464e1c1.451dee"],["9b6061cb.bd72e","2464e1c1.451dee","f153d49d.d08c48"],["3870bd4a.17f942","b687d7cf.560d88","f153d49d.d08c48"]]},{"id":"9045dd9e.51fb8","type":"delay","z":"93be79be.18aad8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"2","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":774.5,"y":348.22998046875,"wires":[["e0fed0e6.3b3da"]]},{"id":"e0fed0e6.3b3da","type":"function","z":"93be79be.18aad8","name":"Process Button Data","func":"var buf = new Buffer.from(msg.payload);\n\n//Extract Required Button Data\nmsg.dgcsk = buf.slice(-4, -3);\nmsg.steer$speed = buf.slice(-3, -2);\n\nvar a = new Buffer.from(msg.dgcsk, 'hex')[0];\nvar b = new Buffer.from(msg.steer$speed, 'hex')[0];\n\nvar msg1 = {payload:a};\nvar msg2 = {payload:b};\nreturn [msg1,msg2];","outputs":"2","noerr":0,"x":775,"y":398,"wires":[["9350cb6d.fe74b8"],["51fa3251.fa6f2c"]]},{"id":"89e2a675.8cbea8","type":"function","z":"93be79be.18aad8","name":"Direction","func":"var a = 1;//Reverse Gear\nvar y = 8;//Forward Gear\nvar button = msg.payload;//Output Message\n//var zero = 0;\nif (button == a) \n{var msg = {payload:a.toString()};\n}\nelse if (button == y) \n{var msg = {payload:y.toString()};\n}\n//else {var msg = {payload:zero.toString()};}\nreturn msg;","outputs":1,"noerr":0,"x":1281.5,"y":26.160003662109375,"wires":[[]]},{"id":"292c38f8.04f1a8","type":"function","z":"93be79be.18aad8","name":"Gears","func":"var b = 2;//1st Gear: Low Torque for Flat Terrain\nvar x = 4;//2nd Gear: High Torque for Stairs\n//var zero = 0;\nvar button = msg.payload;//Output Message\nif (button == b) \n{var msg = {payload:b.toString()};\n}\nelse if (button == x) \n{var msg = {payload:x.toString()};\n}\n//else {var msg = {payload:zero.toString()};}\nreturn msg;","outputs":1,"noerr":0,"x":1289.5,"y":78.16000366210938,"wires":[[]]},{"id":"3870bd4a.17f942","type":"function","z":"93be79be.18aad8","name":"Clutch","func":"var a = 32;//Clutch Engaged\nvar b = 48;//Clutch Disengaged\nvar zero = 0;\nvar button = msg.payload;//Output Message\n\nif (button == a) \n{var msg = {payload:a.toString()};\n}\nelse if (button == b) \n{var msg = {payload:b.toString()};}\nelse {var msg = {payload:zero.toString()};}\nreturn msg;","outputs":1,"noerr":0,"x":1290.5,"y":126.16000366210938,"wires":[[]]},{"id":"b687d7cf.560d88","type":"function","z":"93be79be.18aad8","name":"Start/Kill","func":"var start = 128;//Starter Motor\nvar kill = 64;//Kill Switch\nvar button = msg.payload;//Output Message\nvar zero = 0;\nif (button == start) \n{var msg1 = {payload:start.toString()};\n var msg2 = {payload:zero.toString()};\n}\nelse if (button == kill)\n{var msg1 = {payload:zero.toString()};\n var msg2 = {payload:kill.toString()};\n}\nelse {var msg1 = {payload:zero.toString()};\n      var msg2 = {payload:zero.toString()};\n}\nreturn [msg1, msg2];","outputs":"2","noerr":0,"x":1294.5,"y":167.16000366210938,"wires":[[],[]]},{"id":"51fa3251.fa6f2c","type":"switch","z":"93be79be.18aad8","name":"Switch to Required Function","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"12","vt":"num"},{"t":"eq","v":"28","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"20","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","outputs":5,"x":1031,"y":569,"wires":[["e0484e1.1074bb"],["e0484e1.1074bb"],["a1bf002d.945c"],["a1bf002d.945c"],["e0484e1.1074bb","a1bf002d.945c"]]},{"id":"e0484e1.1074bb","type":"function","z":"93be79be.18aad8","name":"Right/Left","func":"var right = 12;//Right Steer\nvar left = 28;//Left Steer\nvar stop = 0;\nvar button = msg.payload;//Input Message\nvar hor=context.global.hor||0;\n\nif (button == right) \n{\n    var msg = {payload:right.toString()};\n    context.global.hor = right.toString();\n}\nelse if (button == left) \n{\n    var msg = {payload:left.toString()};\n    context.global.hor = left.toString();\n}\nelse //if (button == stop)\n{\n    var msg = {payload:stop.toString()};\n    context.global.hor = stop.toString();\n}\n\nvar hor=context.global.hor||0;\nreturn msg;","outputs":1,"noerr":0,"x":1234.5,"y":442.239990234375,"wires":[["1386be0b.07f602"]]},{"id":"d5fe7e19.5f0fc","type":"mqtt out","z":"7704e947.29ff58","name":"Clutch","topic":"/Clutch","qos":"0","retain":"","broker":"6d21f98b.9f47f8","x":996.5,"y":823.0900268554688,"wires":[]},{"id":"78014467.b3fdcc","type":"ui_toast","z":"5f87c212.b51e2c","position":"top right","displayTime":"10","highlight":"","outputs":0,"ok":"","cancel":"","topic":"","name":"Victim Detected","x":820,"y":323,"wires":[]},{"id":"eb7efb90.9c4478","type":"function","z":"5f87c212.b51e2c","name":"Count Function","func":"if (!context.value) {\n    context.value = 0;\n    }\ncontext.value +=1;\nmsg.count = context.value;\nvar i ;\nif (msg.topic == \"Motion Detection Notification\")\n{ \n    i = msg.count\n    msg = {payload: \"Number of Victims Detected is: \"+i};\n}\nvar msg3 = { payload: i }\nreturn [msg, msg3];\n\n","outputs":"2","noerr":0,"x":557,"y":286,"wires":[["46f50bea.bcf0f4","78014467.b3fdcc"],["46f50bea.bcf0f4"]]},{"id":"46f50bea.bcf0f4","type":"debug","z":"5f87c212.b51e2c","name":"","active":true,"console":"false","complete":"payload","x":789,"y":247,"wires":[]},{"id":"8131e9ce.6b06f8","type":"mqtt out","z":"7704e947.29ff58","name":"Gear","topic":"/Gear","qos":"","retain":"","broker":"6d21f98b.9f47f8","x":1068.5,"y":729.0899658203125,"wires":[]},{"id":"bae5c2fe.eba1d","type":"HIDdevice","z":"7704e947.29ff58","connection":"ee5c29a7.217638","name":"HID","x":395,"y":1023,"wires":[["96699938.59dad8"],[]]},{"id":"96699938.59dad8","type":"subflow:93be79be.18aad8","z":"7704e947.29ff58","x":557.5,"y":1017.2100219726562,"wires":[["50d01b06.e2e014","df96e4f8.d779b8"],["8131e9ce.6b06f8","c6636fba.be00f"],["d5fe7e19.5f0fc","97aa6a13.924228"],["4829e76a.3e5508","3d80e8ad.7199e8"],["331f0f7a.ef50c","5425c5ef.72facc"],["a4495a58.2d3ef8","ab85775b.7e5248"],["f1c725af.eb7688","17dace1d.71d2a2"],["a9923988.05b978"],["2b18159e.c7649a"],["3739ce61.1b2052","f6b7c5d7.6d45b8"]]},{"id":"ab85775b.7e5248","type":"mqtt out","z":"7704e947.29ff58","name":"Up/Down","topic":"/UD","qos":"1","retain":"","broker":"6d21f98b.9f47f8","x":999.5,"y":1078.760009765625,"wires":[]},{"id":"45c79e4.59dfc6","type":"ui_text","z":"7704e947.29ff58","group":"560573f4.918e1c","order":0,"width":0,"height":0,"name":"Notification","label":"","format":"{{msg.payload}}","layout":"row-center","x":1301,"y":642,"wires":[]},{"id":"df96e4f8.d779b8","type":"function","z":"7704e947.29ff58","name":"Direction Notification","func":"var a = '1';//Reverse Gear\nvar y = '8';//Forward Gear\n\n\nif (msg.payload == y ) \n{\n    var msg = {payload: \"Forward Gear Selected\"};\n} \nelse if (msg.payload == a) \n{\n    var msg = {payload: \"Reverse Gear Selected\"};\n} \nelse {var msg = {payload: \"Select Direction of Travel\"};}\nreturn msg;\n\n","outputs":"1","noerr":0,"x":1130.5,"y":642.3499755859375,"wires":[["45c79e4.59dfc6"]]},{"id":"c6636fba.be00f","type":"function","z":"7704e947.29ff58","name":"Gear Notification","func":"var b = '2';//1st Gear\nvar x = '4';//2nd Gear\n\nif (msg.payload == b) \n{\n    var msg = {payload: \"1st Gear Selected\"};\n} \nelse if (msg.payload == x) \n{\n    var msg = {payload: \"2nd Gear Selected\"};\n} \nelse {var msg = {payload: \"Select Required Gear For Travel\"};}\nreturn msg;\n","outputs":1,"noerr":0,"x":1109,"y":687.2099609375,"wires":[["31713292.6af4ee"]]},{"id":"31713292.6af4ee","type":"ui_text","z":"7704e947.29ff58","group":"560573f4.918e1c","order":0,"width":0,"height":0,"name":"Notification","label":"","format":"{{msg.payload}}","layout":"row-center","x":1267.5,"y":686.6499633789062,"wires":[]},{"id":"d520daec.052698","type":"ui_text","z":"7704e947.29ff58","group":"c08a45ef.fc89e8","order":2,"width":0,"height":0,"name":"Notification","label":"","format":"{{msg.payload}}","layout":"row-center","x":1265,"y":764,"wires":[]},{"id":"97aa6a13.924228","type":"function","z":"7704e947.29ff58","name":"Clutch Status","func":"var a = '32';//Clutch Engaged\nvar b = '48';//Clutch Disengaged\n\n\nif (!context.step) \n   {context.step = 0;}\n\nif (msg.payload == a ) \n    {\n        var j = context.step+=2;\n        var msg2 = {payload: j};\n        if (j<10)\n            {var msg1 = {payload: \"Clutch Engaging\"};}\n        else{var msg1 = {payload: \"Clutch Engaged\"};}\n    } \nelse if (msg.payload == b) \n    {\n        var k = context.step-=2;\n        var msg2 = {payload: k};\n        if (k===0)\n            {var msg1 = {payload: \"Clutch Disengaged\"};}\n        else{var msg1 = {payload: \"Clutch Disengaging\"};}\n    }\n\n\nreturn [msg1,msg2];\n\n","outputs":"2","noerr":0,"x":1096.5,"y":782.3499755859375,"wires":[["d520daec.052698"],["1da5da06.4cda36"]]},{"id":"3d80e8ad.7199e8","type":"function","z":"7704e947.29ff58","name":"S","func":"var start = '128';//Starter Motor\nvar kill = '64';//Kill Switch\nvar zero = '0';\nif (msg.payload == start ) \n{\n    var msg = {payload: \"Start Button Pressed\"};\n} \nelse if (msg.payload == zero) \n{\n    var msg = {payload: \"Start Button Released\"};\n}\nreturn msg;\n\n","outputs":"1","noerr":0,"x":1107,"y":849,"wires":[["9d4fa315.f484b"]]},{"id":"9d4fa315.f484b","type":"ui_text","z":"7704e947.29ff58","group":"93d0a6cb.4cd328","order":0,"width":0,"height":0,"name":"Notification","label":"","format":"{{msg.payload}}","layout":"row-center","x":1227.5,"y":847.6499938964844,"wires":[]},{"id":"5425c5ef.72facc","type":"function","z":"7704e947.29ff58","name":"Steer","func":"var a = '12';//Right Steer\nvar b = '28';//Left Steer\nvar myarm = context.global.myarm;\n\n\nif (!context.step) \n   {context.step = 0;}\n\nif (msg.payload == a && myarm == \"off\") \n    {\n        var j = context.step+=2;\n        var msg1 = {payload: \"Turning Right\"};\n        var msg2 = {payload: j};\n    } \nelse if (msg.payload == b && myarm == \"off\") \n    {\n        var k = context.step-=2;\n        var msg1 = {payload: \"Turning Left\"};\n        var msg2 = {payload: k};\n    }\nelse if (j===0 && k===0)\n{\n    var msg1 = {payload: \"Moving Forward\"};\n    var msg2 = {payload: k};\n}\n\nreturn [msg1,msg2];\n\n","outputs":"2","noerr":0,"x":1101,"y":928,"wires":[[],["2e31fc1e.051f24"]]},{"id":"a1bf002d.945c","type":"function","z":"93be79be.18aad8","name":"Up/Down","func":"var up = 4;//Open Throttle\nvar down = 20;//Closing Throttle\nvar stop = 0;//Throttle Constant\nvar button = msg.payload;//Input Message\nvar ver=context.global.ver||0;\n\nif (button == up) \n{\n    var msg = {payload:up.toString()};\n    context.global.ver = up.toString();\n}\nelse if (button == down) \n{\n    var msg = {topic: 'a', payload:down.toString()};\n    context.global.ver = down.toString();\n}\nelse //if (button == stop)\n{\n    var msg = {topic: 'a', payload:stop.toString()};\n    context.global.ver = stop.toString();\n}\n\nvar ver=context.global.ver||0;\nreturn msg;","outputs":1,"noerr":0,"x":1251,"y":636,"wires":[["14ab6b06.c20aa5"]]},{"id":"a4495a58.2d3ef8","type":"function","z":"7704e947.29ff58","name":"Throttle","func":"var a = '4';//Throttle Up\nvar b = '20';//Throttle Down\nvar zero = '0';\nvar myarm = context.global.myarm;\n\nif (!context.step) \n   {context.step = 0;}\n\nif (msg.payload == a && myarm == \"off\") \n    {\n        var k = context.step+=1;\n        var msg1 = {payload: myarm};\n        var msg2 = {payload: k};\n    } \nelse if (msg.payload == b && myarm == \"off\") \n    {\n        var k = context.step-=1;\n        var msg1 = {payload: myarm};\n        var msg2 = {payload: k};\n    }\nelse if (msg.payload == zero)\n{\n    var k = context.step;\n    var msg1 = {payload: \"Throttle Constant\"};\n    var msg2 = {payload: k};\n}\n\nreturn [msg1,msg2];\n\n","outputs":"2","noerr":0,"x":981,"y":1033,"wires":[[],["82ddb199.19976"]]},{"id":"d61b5c71.13729","type":"ui_template","z":"7704e947.29ff58","group":"3a3e883c.9803e8","name":"Video Stream","order":1,"width":"13","height":"10","format":"<embed \nsrc=\"https://797363797e.dataplicity.io/?action=stream\"\nwidth=\"650\" height=\"480\">","storeOutMessages":true,"fwdInMessages":true,"x":553,"y":1110,"wires":[[]]},{"id":"9b6061cb.bd72e","type":"function","z":"93be79be.18aad8","name":"Arms Up/Down","func":"var a = 24;//Up\nvar b = 17;//Down\nvar c = 16;//Stop\nvar button = msg.payload;//Output Message\n\nif (button == a) \n{var msg = {payload:a.toString()};\n}\nelse if (button == b) \n{var msg = {payload:b.toString()};}\nelse {var msg = {payload:c.toString()};}\nreturn msg;","outputs":1,"noerr":0,"x":1327,"y":248,"wires":[[]]},{"id":"2464e1c1.451dee","type":"function","z":"93be79be.18aad8","name":"Arms Pinch/Release","func":"var a = 20;//Pinch\nvar b = 18;//Release\nvar c = 16;//Stop\nvar button = msg.payload;//Output Message\nvar pr = context.global.pr||0;\n\nif (button == a) \n{\n    var msg = {payload:a.toString()};\n    var prs = flow.set(\"prs\", \"20\");\n    context.global.pr = flow.get('prs');\n}\nelse if (button == b) \n{\n    var msg = {payload:b.toString()};\n    var prs = flow.set(\"prs\", \"18\");\n    context.global.pr = flow.get('prs');\n}\nelse \n{\n    var msg = {payload:c.toString()};\n    var prs = flow.set(\"prs\", \"16\");\n    context.global.pr = flow.get('prs');\n}\nvar prs = flow.get('prs');\nvar pr = context.global.pr||0;\nreturn msg;","outputs":1,"noerr":0,"x":1313,"y":305,"wires":[["287f8a75.4b5176"]]},{"id":"f1c725af.eb7688","type":"mqtt out","z":"7704e947.29ff58","name":"Lift/Lower","topic":"/Lift","qos":"0","retain":"","broker":"6d21f98b.9f47f8","x":908.5,"y":1166.449951171875,"wires":[]},{"id":"a9923988.05b978","type":"mqtt out","z":"7704e947.29ff58","name":"Pinch/Release","topic":"/PR","qos":"0","retain":"","broker":"6d21f98b.9f47f8","x":981.0714244842529,"y":1216.1642498970032,"wires":[]},{"id":"2b18159e.c7649a","type":"mqtt out","z":"7704e947.29ff58","name":"Shift","topic":"/Shift","qos":"0","retain":"","broker":"6d21f98b.9f47f8","x":971.0714244842529,"y":1264.1642498970032,"wires":[]},{"id":"ecd96bcc.bab498","type":"e-mail in","z":"5f87c212.b51e2c","name":"TSRV Surveillance","protocol":"IMAP","server":"imap.gmail.com","useSSL":true,"port":"993","box":"INBOX","disposition":"None","repeat":"30000","x":332.5,"y":288.44000244140625,"wires":[["eb7efb90.9c4478"]]},{"id":"f153d49d.d08c48","type":"function","z":"93be79be.18aad8","name":"Shift","func":"var a = 16;//Shift\nvar b = 0;//Stop\nvar button = msg.payload;//Output Message\nvar myarm = context.global.myarm||0;\n\nif (button == a) \n{\n    var msg = {payload:a.toString()};\n    var arm = flow.set(\"arm\", \"on\");\n    context.global.myarm = flow.get('arm');\n}\nelse if (button == b) \n{\n    var msg = {payload:b.toString()};\n    var arm = flow.set(\"arm\", \"off\");\n    context.global.myarm = flow.get('arm');\n}\n\nvar arm = flow.get('arm');\nvar myarm = context.global.myarm||0;\nvar msg2 = {payload:myarm};\nreturn [msg, msg2];","outputs":"2","noerr":0,"x":1252,"y":365,"wires":[[],[]]},{"id":"17dace1d.71d2a2","type":"function","z":"7704e947.29ff58","name":"Lift/Lower","func":"var up = '24';//\nvar down = '17';\nvar zero = '16';\nvar button = msg.payload;//Output Message\n    \n/*if (button == up) \n{\n    var msg = {payload: \"Lifting Arms\"};\n} \nelse if (button == down) \n{\n    var msg = {payload: \"Lowering Arms\"};\n}\nelse if (button == zero)\n{var msg = {payload: \"No Vertical Movement\"};}\nreturn msg;*/\n\nif (!context.step) \n   {context.step = 0;}\n\nif (button == up) \n    {\n        var j = context.step+=1;\n        var msg = {payload: j};\n    } \nelse if (button == down) \n    {\n        var j = context.step-=1;\n        var msg = {payload: j};\n    }\nelse\n    {\n        var j = context.step;\n        var msg = {payload: j};\n    }\nreturn msg;","outputs":"1","noerr":0,"x":1026,"y":1133,"wires":[["8a7b8bb.4c40678","afb7469c.d901c8"]]},{"id":"3739ce61.1b2052","type":"mqtt out","z":"7704e947.29ff58","name":"Kill","topic":"/Kill","qos":"0","retain":"","broker":"6d21f98b.9f47f8","x":774.5714225769043,"y":1208.964373588562,"wires":[]},{"id":"1da5da06.4cda36","type":"ui_gauge","z":"7704e947.29ff58","name":"","group":"c08a45ef.fc89e8","order":1,"width":"5","height":"3","gtype":"gage","title":"","label":"","format":"{{value}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1294,"y":808,"wires":[]},{"id":"f6b7c5d7.6d45b8","type":"function","z":"7704e947.29ff58","name":"K","func":"var start = '128';//Starter Motor\nvar kill = '64';//Kill Switch\nvar zero = '0';\nif (msg.payload == kill ) \n{\n    var msg = {payload: \"Kill Switch Pressed\"};\n} \nelse if (msg.payload == zero) \n{\n    var msg = {payload: \"Kill Switch Released\"};\n}\nreturn msg;\n\n","outputs":"1","noerr":0,"x":687.3214263916016,"y":1268.4644050598145,"wires":[["480100d4.c080f"]]},{"id":"480100d4.c080f","type":"ui_text","z":"7704e947.29ff58","group":"93d0a6cb.4cd328","order":0,"width":0,"height":0,"name":"Notification","label":"","format":"{{msg.payload}}","layout":"row-center","x":807.8214263916016,"y":1268.1143989562988,"wires":[]},{"id":"82ddb199.19976","type":"ui_gauge","z":"7704e947.29ff58","name":"","group":"ee34b6f4.794f78","order":1,"width":"5","height":"4","gtype":"wave","title":"Level","label":"","format":"{{value}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1128,"y":1045,"wires":[]},{"id":"2e31fc1e.051f24","type":"ui_gauge","z":"7704e947.29ff58","name":"","group":"97bacb12.17bb68","order":1,"width":"5","height":"4","gtype":"gage","title":"","label":"","format":"{{value}}","min":"-10","max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1218,"y":935,"wires":[]},{"id":"8a7b8bb.4c40678","type":"ui_slider","z":"7704e947.29ff58","name":"","label":"","group":"8cc71d29.83c66","order":2,"width":0,"height":0,"passthru":true,"topic":"","min":"0","max":10,"step":"1","x":1158,"y":1096,"wires":[[]]},{"id":"afb7469c.d901c8","type":"ui_text","z":"7704e947.29ff58","group":"8cc71d29.83c66","order":0,"width":0,"height":0,"name":"","label":"Position 0-10","format":"{{msg.payload}}","layout":"row-spread","x":1169,"y":1162,"wires":[]},{"id":"fcf856a4.4db808","type":"ui_slider","z":"93be79be.18aad8","name":"","label":"Left Arm","group":"336a256d.99ed9a","order":1,"width":0,"height":0,"passthru":true,"topic":"","min":"-10","max":"10","step":"1","x":1767,"y":446,"wires":[[]]},{"id":"12deae93.490d11","type":"ui_slider","z":"93be79be.18aad8","name":"","label":"Right Arm","group":"336a256d.99ed9a","order":3,"width":0,"height":0,"passthru":true,"topic":"","min":"-10","max":"10","step":"1","x":1770,"y":629,"wires":[[]]},{"id":"7184e592.fb28ec","type":"ui_text","z":"93be79be.18aad8","group":"336a256d.99ed9a","order":2,"width":0,"height":0,"name":"","label":"Position -10 - 0 - 10","format":"{{msg.payload}}","layout":"row-spread","x":1775,"y":410,"wires":[]},{"id":"3084345.e150bcc","type":"ui_text","z":"93be79be.18aad8","group":"336a256d.99ed9a","order":4,"width":0,"height":0,"name":"","label":"Position -10 - 0 - 10","format":"{{msg.payload}}","layout":"row-spread","x":1757,"y":667,"wires":[]},{"id":"14ab6b06.c20aa5","type":"function","z":"93be79be.18aad8","name":"Right Arm","func":"var zero = \"0\";\nvar up = \"4\";\nvar down = \"20\";\nvar shift = \"16\";//Shift\nvar release = \"18\";\nvar pinch = \"20\";\nvar pr = context.global.pr;\nvar myarm = context.global.myarm;\ncontext.r = flow.get('k')||0;\n   \nif (msg.payload == up && myarm == \"on\")\n{\n    var k = context.r-=1;\n    var msg = {payload: k};\n}\nelse if (msg.payload == down && myarm == \"on\")\n{\n    var k = context.r+=1;\n    var msg = {payload: k};\n}\nelse\n{   return null;\n}\nvar k = flow.set(\"k\", k);\nreturn msg;","outputs":1,"noerr":0,"x":1540,"y":576,"wires":[["12deae93.490d11","3084345.e150bcc"]]},{"id":"1386be0b.07f602","type":"function","z":"93be79be.18aad8","name":"Left Arm","func":"var zero = \"0\";\nvar right = \"12\";\nvar left = \"28\";\nvar shift = \"16\";//Shift\nvar release = \"18\";\nvar pinch = \"20\";\nvar myarm = context.global.myarm;\nvar pr = context.global.pr;\ncontext.l = flow.get('j')||0;\n\n\nif (msg.payload == right && myarm == \"on\")\n{\n    var j = context.l+=1;\n    var msg = {payload: j};\n}\nelse if (msg.payload == left && myarm == \"on\")\n{\n    var j = context.l-=1;\n    var msg = {payload: j};\n}\nelse\n{   return null;\n}\nvar j = flow.set(\"j\", j);\nreturn msg;","outputs":1,"noerr":0,"x":1541,"y":492,"wires":[["fcf856a4.4db808","7184e592.fb28ec"]]},{"id":"287f8a75.4b5176","type":"function","z":"93be79be.18aad8","name":"P/R Simultaneous","func":"var shift = \"16\";//Shift\nvar release = \"18\";\nvar pinch = \"20\";\ncontext.l = flow.get('j')||0;\ncontext.r = flow.get('k')||0;\n\n\nif (msg.payload == pinch) \n{\n    var j = context.l-=1;\n    var k = context.r-=1;\n    var msg1 = {payload: j};\n    var msg2 = {payload: k};\n} \nelse if (msg.payload == release) \n{\n    var j = context.l+=1;\n    var k = context.r+=1;\n    var msg1 = {payload: j};\n    var msg2 = {payload: k};\n}\nelse\n{\n    return [null,null];\n}\n\nvar j = flow.set(\"j\", j);\nvar k = flow.set(\"k\", k);\nreturn [msg1,msg2];\n","outputs":"2","noerr":0,"x":1555,"y":532,"wires":[["fcf856a4.4db808","7184e592.fb28ec","33e924b8.40250c"],["12deae93.490d11","3084345.e150bcc"]]},{"id":"33e924b8.40250c","type":"debug","z":"93be79be.18aad8","name":"j","active":true,"console":"false","complete":"payload","x":1896,"y":482,"wires":[]},{"id":"bd1203a2.570ee","type":"mqtt in","z":"7704e947.29ff58","name":"Tipping","topic":"/Tipping","qos":"1","broker":"6d21f98b.9f47f8","x":556,"y":907,"wires":[[]]},{"id":"43ca7b9f.9f30c4","type":"ui_toast","z":"7704e947.29ff58","position":"top right","displayTime":"20","highlight":"","outputs":0,"ok":"","cancel":"","topic":"","name":"Stability Status","x":638,"y":856,"wires":[]},{"id":"5f726b4b.af5cc4","type":"mqtt in","z":"7704e947.29ff58","name":"Signal","topic":"/Signal","qos":"1","broker":"6d21f98b.9f47f8","x":490,"y":814,"wires":[["2a84a790.32dfb8","db83313a.4f599"]]},{"id":"1ec0a574.3a465b","type":"ui_toast","z":"7704e947.29ff58","position":"bottom left","displayTime":"100","highlight":"","outputs":0,"ok":"","cancel":"","topic":"","name":"Connection Status","x":623.2500076293945,"y":781.2500114440918,"wires":[]},{"id":"2a84a790.32dfb8","type":"function","z":"7704e947.29ff58","name":"Signal","func":"if (msg.payload === \"0\")\n{\n    var msg = {topic: 'Connection Status:',payload: \"Connection Established\"};\n}\nelse if (msg.payload == \"1\")\n{\n    var msg = {topic: 'Connection Status:',payload: \"Disconnected\"};\n}\nelse\n{\n    return null;\n}\nreturn msg;","outputs":1,"noerr":0,"x":482.75,"y":780.25,"wires":[["1ec0a574.3a465b"]]},{"id":"db83313a.4f599","type":"debug","z":"7704e947.29ff58","name":"","active":true,"console":"false","complete":"false","x":680,"y":711.25,"wires":[]}]
hafizalk

Flow Info

created 4 months, 2 weeks ago

Node Types

Core
  • debug (x3)
  • delay (x2)
  • e-mail in (x1)
  • function (x25)
  • mqtt in (x2)
  • mqtt out (x10)
  • mqtt-broker (x1)
  • switch (x2)
Other
  • HIDConfig (x2)
  • HIDdevice (x1)
  • subflow (x2)
  • subflow:93be79be.18aad8 (x1)
  • tab (x2)
  • tls-config (x2)
  • ui_base (x1)
  • ui_gauge (x3)
  • ui_group (x8)
  • ui_slider (x3)
  • ui_tab (x1)
  • ui_template (x1)
  • ui_text (x8)
  • ui_toast (x3)

Tags

  • AWS
  • IoT
  • Tele-Operation
  • XBox
  • MQTT
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option