Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node-RED Flow for a plotclock implementation using a Line-us machine
[
{
"id": "1207feb6.6cb2e1",
"type": "tab",
"label": "Line-us",
"disabled": true,
"info": ""
},
{
"id": "688cc590.31b39c",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "OK Trigger",
"func": "if(msg.payload.indexOf('ok') === 0 && \n msg.payload !== 'ok X:1000 Y:1000 Z:1000') {\n return { trigger: 1 }; \n}\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 930,
"y": 300,
"wires": [
[
"6f91ae91.2df4d"
]
]
},
{
"id": "b6d4508.1513db",
"type": "websocket in",
"z": "1207feb6.6cb2e1",
"name": "Line-us (in)",
"server": "",
"client": "b0a9d5f5.d992f8",
"x": 760,
"y": 240,
"wires": [
[
"688cc590.31b39c",
"2e2cf623.aca12a",
"99effd71.5bfa2",
"2650f90c.13cfa6",
"513b4aec.b2e4a4"
]
]
},
{
"id": "7499a3e3.be696c",
"type": "websocket out",
"z": "1207feb6.6cb2e1",
"name": "Line-us (out)",
"server": "",
"client": "b0a9d5f5.d992f8",
"x": 1410,
"y": 420,
"wires": []
},
{
"id": "6f91ae91.2df4d",
"type": "simple-queue",
"z": "1207feb6.6cb2e1",
"name": "GCODE Queue",
"x": 1220,
"y": 180,
"wires": [
[
"f09eff9a.1201a"
]
]
},
{
"id": "d31b1dd8.ea224",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "Enqueue GCODE",
"func": "msg.payload.forEach(function(element) {\n node.send({ payload: element});\n});\nnode.send({ payload: 'G28' });\nnode.send({ trigger: 1 });",
"outputs": 1,
"noerr": 0,
"x": 950,
"y": 180,
"wires": [
[
"6f91ae91.2df4d"
]
]
},
{
"id": "f09eff9a.1201a",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "Cache payload",
"func": "if (msg.hasOwnProperty('replay')) {\n return context.lastMsg;\n}\ncontext.lastMsg = msg;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1220,
"y": 420,
"wires": [
[
"7499a3e3.be696c"
]
]
},
{
"id": "2e2cf623.aca12a",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "Error Trigger",
"func": "if(msg.payload.indexOf('error') === 0) {\n return { replay: 1 }; \n}\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 930,
"y": 420,
"wires": [
[
"f09eff9a.1201a"
]
]
},
{
"id": "6d5c6cc.32e2294",
"type": "inject",
"z": "1207feb6.6cb2e1",
"name": "Init",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 190,
"y": 180,
"wires": [
[
"8b2632df.05952"
]
]
},
{
"id": "8b2632df.05952",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "Init Variables",
"func": "context.flow.numbers = [\n [ // 0\n [1300,0,0],\n [900,0,0],\n [900,300,0],\n [1100,300,0],\n [1300,0,0],\n [1500,0,0],\n [1500,300,0],\n [1100,300,0],\n [1100,300,1000]\n ],\n [ // 1\n [900,200,0],\n [900,300,0],\n [1500,300,0],\n [1500,300,1000]\n ],\n [ // 2\n [900,0,0],\n [900,300,0],\n [1100,300,0],\n [1300,0,0],\n [1500,0,0],\n [1500,300,0],\n [1500,300,1000]\n ],\n [ // 3\n [900,0,0],\n [900,300,0],\n [1200,100,0],\n [1200,300,0],\n [1500,300,0],\n [1500,0,0],\n [1500,0,1000]\n ],\n [ // 4\n [1300,300,0],\n [1300,0,0],\n [900,300,0],\n [1500,300,0],\n [1500,300,1000]\n ],\n [ // 5\n [900,300,0],\n [900,0,0],\n [1100,0,0],\n [1100,300,0],\n [1500,300,0],\n [1500,0,0],\n [1500,0,1000]\n ],\n [ // 6\n [900,300,0],\n [900,0,0],\n [1500,0,0],\n [1500,300,0],\n [1100,300,0],\n [1100,0,0],\n [1100,0,1000]\n ],\n [ // 7\n [900,0,0],\n [900,300,0],\n [1100,300,0],\n [1300,100,0],\n [1500,100,0],\n [1500,100,1000]\n ],\n [ // 8\n [1100,0,0],\n [900,0,0],\n [900,300,0],\n [1100,300,0],\n [1100,0,0],\n [1500,0,0],\n [1500,300,0],\n [1100,300,0],\n [1100,300,1000]\n ],\n [ // 9\n [1300,300,0],\n [1300,0,0],\n [900,0,0],\n [900,300,0],\n [1500,300,0],\n [1500,0,0],\n [1500,0,1000]\n ]\n];\ncontext.flow.erase = [\n [1000,1000,1300],\n [900,1300,1300],\n [900,1300,0],\n [900,-800,0],\n [1100,-800,0],\n [1100,800,0],\n [1300,800,0],\n [1300,-800,0],\n [1500,-800,0],\n [1500,800,0],\n [900,800,0],\n [900,1300,0],\n [900,1300,1300],\n [1000,1000,1300]\n]\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 350,
"y": 180,
"wires": [
[]
]
},
{
"id": "a0d7e715.4c6308",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "Build GCode",
"func": "var pad = function (num, len) {\n return (new Array(len+1).join(\"0\") + num).slice(-len);\n}\n\nvar hDigits = pad(msg.payload.hours, 2).split('').map(Number);\nvar mDigits = pad(msg.payload.minutes, 2).split('').map(Number);\n\nvar yOffset = -800;\nvar yInc = 400;\nvar gcode = [];\n\n// Erase previous\nif (msg.hasOwnProperty('trigger') && msg.trigger !== -1) {\n context.flow.erase.forEach(function(cmd){\n gcode.push(cmd);\n });\n}\n\n// Hours\nhDigits.forEach(function (d) {\n context.flow.numbers[d].forEach(function(cmd){\n gcode.push([\n cmd[0], // X\n cmd[1] + yOffset, // Y\n cmd[2] // Z\n ])\n })\n yOffset += yInc;\n});\n\n// Dots\ngcode.push([1100,0,0])\ngcode.push([1100,0,1000])\ngcode.push([1300,0,0])\ngcode.push([1300,0,1000])\nyOffset += 100;\n\n// Minutes\nmDigits.forEach(function (d) {\n context.flow.numbers[d].forEach(function(cmd){\n gcode.push([\n cmd[0], // X\n cmd[1] + yOffset, // Y\n cmd[2] // Z\n ])\n })\n yOffset += yInc;\n});\n\nmsg.payload = gcode;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 590,
"y": 240,
"wires": [
[
"5b2ede9d.e9841"
]
]
},
{
"id": "99effd71.5bfa2",
"type": "debug",
"z": "1207feb6.6cb2e1",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 910,
"y": 480,
"wires": []
},
{
"id": "2650f90c.13cfa6",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "Init Trigger",
"func": "// ok X:1000 Y:1000 Z:1000\nif(msg.payload.indexOf('hello') === 0) {\n return { trigger: -1 }; \n}\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 930,
"y": 240,
"wires": [
[
"67dab93a.12c188"
]
]
},
{
"id": "67dab93a.12c188",
"type": "link out",
"z": "1207feb6.6cb2e1",
"name": "init-trigger",
"links": [
"7b0054ef.c9b05c"
],
"x": 1055,
"y": 240,
"wires": []
},
{
"id": "5b2ede9d.e9841",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "Format GCode",
"func": "var gcode = [];\nmsg.payload.forEach(function(el) {\n gcode.push(`G01 X${el[0]} Y${el[1]} Z${el[2]}`);\n});\nmsg.payload = gcode;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 740,
"y": 180,
"wires": [
[
"d31b1dd8.ea224"
]
]
},
{
"id": "513b4aec.b2e4a4",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "Home Trigger",
"func": "if (msg.payload === 'ok X:1000 Y:1000 Z:1000') {\n return { trigger: 1 }; \n}\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 940,
"y": 360,
"wires": [
[
"f3137d65.c8219"
]
]
},
{
"id": "f3137d65.c8219",
"type": "link out",
"z": "1207feb6.6cb2e1",
"name": "home-trigger",
"links": [
"277a7fe9.ac804",
"7b0054ef.c9b05c"
],
"x": 1055,
"y": 360,
"wires": []
},
{
"id": "7b0054ef.c9b05c",
"type": "link in",
"z": "1207feb6.6cb2e1",
"name": "trigger-in",
"links": [
"67dab93a.12c188",
"f3137d65.c8219",
"ec8102c3.6537c"
],
"x": 95,
"y": 240,
"wires": [
[
"496d22ed.664a4c"
]
]
},
{
"id": "70561196.0f73f",
"type": "function",
"z": "1207feb6.6cb2e1",
"name": "Time Cache",
"func": "context.lastTime = context.lastTime || \"\";\n\nvar time = `${msg.payload.hours}:${msg.payload.minutes}`;\nif (context.lastTime != time) {\n context.lastTime = time;\n return [msg, null];\n} else {\n return [null, msg];\n}",
"outputs": 2,
"noerr": 0,
"x": 410,
"y": 240,
"wires": [
[
"a0d7e715.4c6308"
],
[
"32d31101.9737de"
]
]
},
{
"id": "32d31101.9737de",
"type": "delay",
"z": "1207feb6.6cb2e1",
"name": "",
"pauseType": "delay",
"timeout": "1",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 580,
"y": 300,
"wires": [
[
"ec8102c3.6537c"
]
]
},
{
"id": "ec8102c3.6537c",
"type": "link out",
"z": "1207feb6.6cb2e1",
"name": "delay-out",
"links": [
"7b0054ef.c9b05c"
],
"x": 715,
"y": 300,
"wires": []
},
{
"id": "496d22ed.664a4c",
"type": "moment",
"z": "1207feb6.6cb2e1",
"name": "Local Date Time",
"topic": "",
"input": "",
"inputType": "date",
"inTz": "Etc/UTC",
"adjAmount": "0",
"adjType": "hours",
"adjDir": "add",
"format": "object",
"locale": "en_GB",
"output": "payload",
"outputType": "msg",
"outTz": "Europe/London",
"x": 220,
"y": 240,
"wires": [
[
"70561196.0f73f"
]
]
},
{
"id": "b0a9d5f5.d992f8",
"type": "websocket-client",
"z": "",
"path": "ws://line-us.local",
"tls": "",
"wholemsg": "false"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment