Skip to content

Commit

Permalink
Adv Flow fix P1 workaround
Browse files Browse the repository at this point in the history
Fix workaround for P1 series when unable to get plate_name/id but still printing with only one plate. Better solution soon.
  • Loading branch information
WolfwithSword committed Aug 20, 2023
1 parent d5262b5 commit 215bd7f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions files/nodered/advanced_ftp_db_flow_group.json
Original file line number Diff line number Diff line change
Expand Up @@ -3742,7 +3742,7 @@
"z": "fbda6ab16491b918",
"g": "615e0a4a63e8487d",
"name": "Extract Type And Sum Weights",
"func": "var filaments = {};\n\nvar weight = 0.0;\nvar has_only_one_plate = false;\nvar current_plate_meta = undefined;\nif (msg.payload !== undefined && msg.payload.config != undefined\n && msg.payload.config.plate != undefined) {\n let plates = msg.payload.config.plate;\n if(plates.length == 1 && (flow.get(\"current_platename\") == undefined || flow.get(\"current_platename\") == \"\")) {\n has_only_one_plate = true;\n }\n for (var plate of plates) {\n for (var p of plate.metadata) {\n if(p.property.key == \"index\" && \n (parseInt(p.property.value) == msg.plate_id \n || has_only_one_plate)) {\n current_plate_meta = plate.metadata;\n msg.plate_id = parseInt(p.property.value);\n if(has_only_one_plate && (flow.get(\"current_platename\") == undefined || flow.get(\"current_platename\") == \"\")) {\n flow.set(\"current_platename\", \"plate_\"+msg.plate_id + \".gcode\");\n node.send([null, {}]);\n }\n break;\n }\n //if (p.property.key == \"weight\") {\n // weight += parseFloat(p.property.value);\n //}\n }\n for (var f of plate.filament) {\n if(f.property.type != undefined && \n !f.property.type.includes(\"Support\")\n && f.property.type != \"PLA-S\"\n && f.property.type != \"PA-S\"\n ) {\n if (filaments[f.property.type] == undefined) {\n filaments[f.property.type] = parseFloat(f.property.used_g);\n }\n else {\n filaments[f.property.type] = filaments[f.property.type] + parseFloat(f.property.used_g);\n }\n }\n }\n }\n}\n\nif(current_plate_meta != undefined) {\n for (var p of current_plate_meta) {\n if (p.property.key == \"weight\") {\n weight += parseFloat(p.property.value);\n }\n }\n}\n\nmsg.payload = {};\nmsg.payload.weight = weight;\nmsg.payload.material = \"\";\nvar fil = Object.keys(filaments);\nvar max = 0;\nfor (var ff of fil) {\n if (filaments[ff] >= max) {\n max = filaments[ff];\n msg.payload.material = ff;\n }\n}\nif (max == 0) {\n msg.payload.material = \"\";\n}\nnode.status({ fill: \"blue\", shape: \"ring\", text: msg.payload.weight + \"g of material, mostly or all \" + msg.payload.material });\nnode.send([msg, null]);",
"func": "var filaments = {};\n\nvar weight = 0.0;\nvar has_only_one_plate = false;\nvar current_plate_meta = undefined;\nif (msg.payload !== undefined && msg.payload.config != undefined\n && msg.payload.config.plate != undefined) {\n let plates = msg.payload.config.plate;\n if(plates.length == 1 && (flow.get(\"current_platename\") == undefined || flow.get(\"current_platename\") == \"\")) {\n has_only_one_plate = true;\n }\n for (var plate of plates) {\n for (var p of plate.metadata) {\n if(p.property.key == \"index\" && \n (parseInt(p.property.value) == msg.plate_id \n || has_only_one_plate)) {\n current_plate_meta = plate.metadata;\n msg.plate_id = parseInt(p.property.value);\n if(has_only_one_plate && (flow.get(\"current_platename\") == undefined || flow.get(\"current_platename\") == \"\")) {\n flow.set(\"current_platename\", \"plate_\"+msg.plate_id + \".gcode\");\n let path = flow.get(\"path_prefix\") + flow.get(\"printer_name\");\n \n msg.localFilename = path + \"/current_print.3mf\"\n node.send([null, msg]);\n }\n break;\n }\n //if (p.property.key == \"weight\") {\n // weight += parseFloat(p.property.value);\n //}\n }\n for (var f of plate.filament) {\n if(f.property.type != undefined && \n !f.property.type.includes(\"Support\")\n && f.property.type != \"PLA-S\"\n && f.property.type != \"PA-S\"\n ) {\n if (filaments[f.property.type] == undefined) {\n filaments[f.property.type] = parseFloat(f.property.used_g);\n }\n else {\n filaments[f.property.type] = filaments[f.property.type] + parseFloat(f.property.used_g);\n }\n }\n }\n }\n}\n\nif(current_plate_meta != undefined) {\n for (var p of current_plate_meta) {\n if (p.property.key == \"weight\") {\n weight += parseFloat(p.property.value);\n }\n }\n}\n\nmsg.payload = {};\nmsg.payload.weight = weight;\nmsg.payload.material = \"\";\nvar fil = Object.keys(filaments);\nvar max = 0;\nfor (var ff of fil) {\n if (filaments[ff] >= max) {\n max = filaments[ff];\n msg.payload.material = ff;\n }\n}\nif (max == 0) {\n msg.payload.material = \"\";\n}\nnode.status({ fill: \"blue\", shape: \"ring\", text: msg.payload.weight + \"g of material, mostly or all \" + msg.payload.material });\nnode.send([msg, null]);",
"outputs": 2,
"noerr": 0,
"initialize": "",
Expand All @@ -3755,7 +3755,7 @@
"d0de2bfdbe4c20b5"
],
[
"5473649d0d4b8226"
"82eb71a02f89ed73"
]
]
},
Expand Down Expand Up @@ -4183,7 +4183,7 @@
"z": "fbda6ab16491b918",
"g": "615e0a4a63e8487d",
"name": "Is Project URL Cloud?",
"func": "flow.set(\"current_filename\", \"\");\nflow.set(\"current_platename\", \"\");\nflow.set(\"was_http_successful\", false);\nif(msg.payload != undefined && msg.payload.print != undefined\n && msg.payload.print.command != undefined) {\n if(msg.payload.print.command == \"project_file\"\n && msg.payload.print.url != undefined\n && String(msg.payload.print.url).startsWith(\"http\") ){\n msg.url = msg.payload.print.url;\n delete msg.payload;\n node.send(msg);\n flow.set(\"current_filename\", msg.url);\n\n if(msg.payload.print.param != undefined) {\n let plate = msg.payload.print.param.replace(\"Metadata/\", \"\");\n plate = plate.replace(\".gcode\", \"\");\n flow.set(\"current_platename\", plate);\n }\n }\n}",
"func": "flow.set(\"current_filename\", \"\");\nflow.set(\"current_platename\", \"\");\nflow.set(\"was_http_successful\", false);\nif(msg.payload != undefined && msg.payload.print != undefined\n && msg.payload.print.command != undefined) {\n if(msg.payload.print.command == \"project_file\"\n && msg.payload.print.url != undefined\n && String(msg.payload.print.url).startsWith(\"http\") ){\n msg.url = msg.payload.print.url;\n\n flow.set(\"current_filename\", msg.url);\n\n if(msg.payload.print.param != undefined) {\n let plate = msg.payload.print.param.replace(\"Metadata/\", \"\");\n plate = plate.replace(\".gcode\", \"\");\n flow.set(\"current_platename\", plate);\n }\n\n delete msg.payload;\n node.send(msg);\n }\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
Expand Down

0 comments on commit 215bd7f

Please sign in to comment.