[{"id":"79f0b1a1.646618","type":"serial-port","serialport":"/dev/ttyACM0","serialbaud":"19200","newline":"\\n"},{"id":"28eae01c.cb8258","type":"mqtt-broker","broker":"192.168.0.88","port":"1883"},{"id":"50110be4.b2e594","type":"mqtt in","name":"Retrieve commands","topic":"ibm/gcco/ma/armless/input","broker":"28eae01c.cb8258","x":112,"y":97,"z":"267553ec.64a2c4","wires":[["c89f9005.7f242"]]},{"id":"36ff412b.a294f6","type":"mqtt out","name":"Publish position","topic":"ibm/gcco/ma/armless/output","broker":"28eae01c.cb8258","x":616,"y":223,"z":"267553ec.64a2c4","wires":[]},{"id":"c89f9005.7f242","type":"serial out","name":"","serial":"79f0b1a1.646618","x":331,"y":97,"z":"267553ec.64a2c4","wires":[]},{"id":"c40fc737.418a4","type":"serial in","name":"","serial":"79f0b1a1.646618","x":113.00001525878906,"y":230,"z":"267553ec.64a2c4","wires":[["b9d36516.6d81c","c120181e.967d78"]]},{"id":"15fdbdf3.b7e082","type":"function","name":"add retain","func":"// We want to retain all position records we publish, so add the retain flag here\nmsg.retain=true;\nreturn msg;","outputs":1,"x":453,"y":223,"z":"267553ec.64a2c4","wires":[["36ff412b.a294f6"]]},{"id":"b9d36516.6d81c","type":"function","name":"Discard 2","func":"// The first two records from the serial node are not valid data\n// but initialisation lines from the motor/servo driver\n// Don't publish them as valid positions else we wipe out the last\n// good retained position\n// Use one of them to trigger the pausing of the motion detection\n// in motion\n\n// Initialise count if it doesn't have a value already\ncontext.count = context.count || 0;\n// Increase count for every msg flowing through\ncontext.count += 1;\n\n// If the count has gone over 2\nif (context.count > 2) {\n   // we have valid records now, so return to first output\n   return [ msg, null ];\n} else if (context.count == 1) {\n   // This is the second record through, send this to the second output\n   // we'll use this one to trigger a pause of the motion detection\n   return [ null, msg ];\n} else {\n   // The very first record gets swallowed\n   return [ null, null ];\n}","outputs":"2","x":304,"y":230,"z":"267553ec.64a2c4","wires":[["15fdbdf3.b7e082"],["49613710.b9f508"]]},{"id":"2ed33fe0.37561","type":"http request","name":"trigger motion snapshot","method":"GET","url":" http://localhost:8080/0/action/snapshot","x":633,"y":311,"z":"267553ec.64a2c4","wires":[[]]},{"id":"c120181e.967d78","type":"delay","name":"delay so we don't miss the action","pauseType":"delay","timeout":"0.1","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","x":375,"y":311,"z":"267553ec.64a2c4","wires":[["2ed33fe0.37561"]]},{"id":"49613710.b9f508","type":"http request","name":"pause motion detection","method":"GET","url":"http://localhost:8080/0/detection/pause","x":493,"y":263,"z":"267553ec.64a2c4","wires":[[]]},{"id":"d65967d.0609398","type":"comment","name":"Subscribe to the arm commands input topic and pass the commands to the arm","info":"","x":302,"y":41,"z":"267553ec.64a2c4","wires":[]},{"id":"cbae92fc.7c2c8","type":"mqtt out","name":"Publish image","topic":"ibm/gcco/ma/armless/image","broker":"28eae01c.cb8258","x":668,"y":451,"z":"267553ec.64a2c4","wires":[]},{"id":"f1b13c2c.48936","type":"function","name":"add retain & drop 0 length","func":"// Need to set retain flag on the image message only if\n// it's an image and not a null\n\nif (msg.payload.length == 0) {\n\treturn null;\n} else {\n    msg.retain=true;\n    return msg;\n}","outputs":1,"x":477.3333740234375,"y":451.6667175292969,"z":"267553ec.64a2c4","wires":[["cbae92fc.7c2c8"]]},{"id":"978fdbf3.d1359","type":"watch","name":"watch for snapshot","files":"/home/pi/images/new/","x":117.66668701171875,"y":464.4444580078125,"z":"267553ec.64a2c4","wires":[["5e40ae0f.1033d8"]]},{"id":"5e40ae0f.1033d8","type":"exec","command":"/home/pi/node-red/catconvert.py","append":"","useSpawn":"","name":"convert image","x":283.66668701171875,"y":464.4444580078125,"z":"267553ec.64a2c4","wires":[["f1b13c2c.48936"],[],[]]},{"id":"8484d16e.c1f4d","type":"comment","name":"Collect the responses from arm, publish position and trigger a snapshot image","info":"","x":293,"y":174,"z":"267553ec.64a2c4","wires":[]},{"id":"68a54207.63760c","type":"comment","name":"Watch for the snapshot to appear, read and encode it then publish it","info":"","x":267,"y":401,"z":"267553ec.64a2c4","wires":[]}]