UNPKG

@ifp-software/node-red-contrib-oee-ai-connector

Version:

Easily connect your production machines to oee.ai – The Industry 4.0 solution for OEE optimization.

1,153 lines 31.6 kB
[ { "id": "97124bbf9df8bcef", "type": "subflow", "name": "Patch production orders", "info": "", "category": "", "in": [ { "x": 220, "y": 340, "wires": [ { "id": "9111d4251855fa3c" } ] } ], "out": [ { "x": 1860, "y": 340, "wires": [ { "id": "b2aa04c83cd84583", "port": 0 } ] } ], "env": [], "meta": {}, "color": "#DDAA99" }, { "id": "74b1b0e5cda0179e", "type": "http request", "z": "97124bbf9df8bcef", "name": "Get existing production order", "method": "GET", "ret": "obj", "paytoqs": "ignore", "url": "https://api.oee.ai/production-orders?filter[code]={{{code}}}&filter[location]={{{location}}}", "tls": "", "persist": false, "proxy": "", "authType": "", "senderr": false, "x": 640, "y": 340, "wires": [ [ "16a2d93e015c1caf" ] ] }, { "id": "f2c55e797140f0df", "type": "function", "z": "97124bbf9df8bcef", "name": "Formatting json payload", "func": "msg.headers = {\n \"Content-Type\": \"application/vnd.api+json\",\n \"Authorization\": \"Bearer \" + msg.bearerToken\n};\n\nmsg.method = \"PATCH\";\n\nmsg.oldProductionOrderId = msg.payload.data[0].id;\n\nmsg.payload = {\n \"data\": {\n \"id\": msg.oldProductionOrderId,\n \"type\": \"production-orders\",\n \"attributes\": {\n \"code\": msg.code,\n \"description\": msg.description,\n \"start-time\": msg[\"start-time\"],\n \"priority\": msg.priority,\n \"details\": {}\n },\n \"relationships\": {\n \"location\": {\n \"data\": {\n \"type\": \"locations\",\n \"id\": msg.location\n }\n }\n }\n }\n}\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1150, "y": 340, "wires": [ [ "eccb0eab86ad18be" ] ] }, { "id": "eccb0eab86ad18be", "type": "http request", "z": "97124bbf9df8bcef", "name": "Patch production order", "method": "use", "ret": "obj", "paytoqs": "ignore", "url": "https://api.oee.ai/production-orders/{{{oldProductionOrderId}}}", "tls": "", "persist": false, "proxy": "", "authType": "", "senderr": false, "x": 1390, "y": 340, "wires": [ [ "b2aa04c83cd84583" ] ] }, { "id": "16a2d93e015c1caf", "type": "change", "z": "97124bbf9df8bcef", "name": "Delete response header", "rules": [ { "t": "delete", "p": "headers", "pt": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 910, "y": 340, "wires": [ [ "f2c55e797140f0df" ] ] }, { "id": "9111d4251855fa3c", "type": "function", "z": "97124bbf9df8bcef", "name": "Set Authorization header", "func": "msg.headers = {\n \"Authorization\": \"Bearer \" + msg.bearerToken\n}\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 390, "y": 340, "wires": [ [ "74b1b0e5cda0179e" ] ] }, { "id": "b2aa04c83cd84583", "type": "change", "z": "97124bbf9df8bcef", "name": "Delete response header and method", "rules": [ { "t": "delete", "p": "headers", "pt": "msg" }, { "t": "delete", "p": "method", "pt": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1670, "y": 340, "wires": [ [] ] }, { "id": "6a0547862d2c12bd", "type": "subflow", "name": "Post production order", "info": "", "category": "", "in": [ { "x": 400, "y": 300, "wires": [ { "id": "af82730f2e0f2a67" } ] } ], "out": [ { "x": 1240, "y": 300, "wires": [ { "id": "ecf684890154a778", "port": 0 } ] } ], "env": [], "meta": {}, "color": "#DDAA99" }, { "id": "af82730f2e0f2a67", "type": "function", "z": "6a0547862d2c12bd", "name": "Formatting json payload", "func": "msg.headers = {\n \"Content-Type\": \"application/vnd.api+json\",\n \"Authorization\": \"Bearer \" + msg.bearerToken\n}\n\nmsg.payload = {\n \"data\": {\n \"type\": \"production-orders\",\n \"attributes\": {\n \"code\": msg.code,\n \"description\": msg.description,\n \"start-time\": msg[\"start-time\"],\n \"priority\": msg.priority,\n \"details\": {}\n },\n \"relationships\": {\n \"location\": {\n \"data\": {\n \"type\": \"locations\",\n \"id\": msg.location\n }\n }\n }\n }\n}\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 570, "y": 300, "wires": [ [ "fbe04830bf90bddc" ] ] }, { "id": "fbe04830bf90bddc", "type": "http request", "z": "6a0547862d2c12bd", "name": "POST product to oee.ai", "method": "POST", "ret": "obj", "paytoqs": "ignore", "url": "https://api.oee.ai/production-orders", "tls": "", "persist": false, "proxy": "", "authType": "", "senderr": false, "x": 830, "y": 300, "wires": [ [ "ecf684890154a778" ] ] }, { "id": "ecf684890154a778", "type": "change", "z": "6a0547862d2c12bd", "name": "delete response header", "rules": [ { "t": "delete", "p": "headers", "pt": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1070, "y": 300, "wires": [ [] ] }, { "id": "9e0e05c7bc00ed5f", "type": "subflow", "name": "Send production orders to oee.ai", "info": "", "category": "", "in": [ { "x": 200, "y": 400, "wires": [ { "id": "1d273f80c08594f0" } ] } ], "out": [ { "x": 1420, "y": 400, "wires": [ { "id": "4eed90b55070876c", "port": 0 } ] } ], "env": [], "meta": {}, "color": "#DDAA99" }, { "id": "7eacd2304b83fbaf", "type": "switch", "z": "9e0e05c7bc00ed5f", "name": "Check if production order already exists", "property": "statusCode", "propertyType": "msg", "rules": [ { "t": "eq", "v": "422", "vt": "num" }, { "t": "else" } ], "checkall": "false", "repair": false, "outputs": 2, "x": 680, "y": 400, "wires": [ [ "b5779e0fed835b05" ], [ "4eed90b55070876c", "85b6d2aca501a2fd" ] ] }, { "id": "85b6d2aca501a2fd", "type": "debug", "z": "9e0e05c7bc00ed5f", "name": "Response from oee.ai", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1240, "y": 360, "wires": [] }, { "id": "1d273f80c08594f0", "type": "subflow:6a0547862d2c12bd", "z": "9e0e05c7bc00ed5f", "name": "", "x": 380, "y": 400, "wires": [ [ "7eacd2304b83fbaf" ] ] }, { "id": "b5779e0fed835b05", "type": "subflow:97124bbf9df8bcef", "z": "9e0e05c7bc00ed5f", "name": "", "x": 990, "y": 360, "wires": [ [ "4eed90b55070876c", "85b6d2aca501a2fd" ] ] }, { "id": "4eed90b55070876c", "type": "change", "z": "9e0e05c7bc00ed5f", "name": "Save productionOrderId", "rules": [ { "t": "set", "p": "productionOrderId", "pt": "msg", "to": "payload.data.id", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1250, "y": 400, "wires": [ [] ] }, { "id": "db2ebd07e8a020a1", "type": "subflow", "name": "Patch line item", "info": "", "category": "", "in": [ { "x": 260, "y": 300, "wires": [ { "id": "1d51f7ddd0cb9949" } ] } ], "out": [ { "x": 1880, "y": 300, "wires": [ { "id": "dccd956853220c3b", "port": 0 } ] } ], "env": [], "meta": {}, "color": "#DDAA99" }, { "id": "1d51f7ddd0cb9949", "type": "function", "z": "db2ebd07e8a020a1", "name": "Set Authorization header", "func": "msg.headers = {\n \"Authorization\": \"Bearer \" + msg.bearerToken\n}\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 430, "y": 300, "wires": [ [ "6ddbb876856ac1a9" ] ] }, { "id": "6ddbb876856ac1a9", "type": "http request", "z": "db2ebd07e8a020a1", "name": "Get existing line item", "method": "GET", "ret": "obj", "paytoqs": "ignore", "url": "https://api.oee.ai/line-items?filter[location]={{{location}}}&filter[production-order]={{{productionOrderId}}}", "tls": "", "persist": false, "proxy": "", "authType": "", "senderr": false, "x": 660, "y": 300, "wires": [ [ "248e3fade1096079" ] ] }, { "id": "248e3fade1096079", "type": "change", "z": "db2ebd07e8a020a1", "name": "Delete response header", "rules": [ { "t": "delete", "p": "headers", "pt": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 910, "y": 300, "wires": [ [ "d21a9a9053ef17c4" ] ] }, { "id": "117d04fe05f74091", "type": "function", "z": "db2ebd07e8a020a1", "name": "Formatting json payload", "func": "msg.headers = {\n \"Content-Type\": \"application/vnd.api+json\",\n \"Authorization\": \"Bearer \" + msg.bearerToken\n};\n\nmsg.method = \"PATCH\";\n\nmsg.payload = {\n \"data\": {\n \"id\": msg.oldLineItemId,\n \"type\": \"line-items\",\n \"attributes\": {\n \"step\": msg.step,\n \"description\": msg.description,\n \"quantity\": msg.quantity,\n \"delta\": msg.delta,\n \"start-time\": msg[\"start-time\"],\n \"changeover-minutes\": msg[\"changeover-minutes\"],\n \"batch\": msg.batch,\n \"details\": {}\n },\n \"relationships\": {\n \"location\": {\n \"data\": {\n \"type\": \"locations\",\n \"id\": msg.location\n }\n },\n \"production-order\": {\n \"data\": {\n \"type\": \"production-orders\",\n \"id\": msg.productionOrderId\n }\n },\n \"product\": {\n \"data\": {\n \"type\": \"products\",\n \"id\": msg.productId\n }\n }\n }\n }\n}\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1450, "y": 300, "wires": [ [ "dccd956853220c3b" ] ] }, { "id": "dccd956853220c3b", "type": "http request", "z": "db2ebd07e8a020a1", "name": "Patch line item", "method": "use", "ret": "obj", "paytoqs": "ignore", "url": "https://api.oee.ai/line-items/{{{oldLineItemId}}}", "tls": "", "persist": false, "proxy": "", "authType": "", "senderr": false, "x": 1680, "y": 300, "wires": [ [] ] }, { "id": "d21a9a9053ef17c4", "type": "function", "z": "db2ebd07e8a020a1", "name": "Find line item matching step", "func": "let match = msg.payload.data.find(lineItem => {\n return lineItem.attributes.step == msg.step;\n});\n\nmsg.oldLineItemId = match.id\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1180, "y": 300, "wires": [ [ "117d04fe05f74091" ] ] }, { "id": "313077532647962a", "type": "subflow", "name": "Post line item", "info": "", "category": "", "in": [ { "x": 40, "y": 240, "wires": [ { "id": "379bdccf9b0ffef1" } ] } ], "out": [ { "x": 1740, "y": 240, "wires": [ { "id": "d902fc6bbce94f66", "port": 0 } ] } ], "env": [], "meta": {}, "color": "#DDAA99" }, { "id": "9cd77018f8f6bfe6", "type": "function", "z": "313077532647962a", "name": "Formatting json payload", "func": "msg.headers = {\n \"Content-Type\": \"application/vnd.api+json\",\n \"Authorization\": \"Bearer \" + msg.bearerToken\n}\n\nmsg.payload = {\n \"data\": {\n \"type\": \"line-items\",\n \"attributes\": {\n \"step\": msg.step,\n \"description\": msg.description,\n \"quantity\": msg.quantity,\n \"delta\": msg.delta,\n \"start-time\": msg[\"start-time\"],\n \"changeover-minutes\": msg[\"changeover-minutes\"],\n \"batch\": msg.batch,\n \"details\": {}\n },\n \"relationships\": {\n \"location\": {\n \"data\": {\n \"type\": \"locations\",\n \"id\": msg.location\n }\n },\n \"production-order\": {\n \"data\": {\n \"type\": \"production-orders\",\n \"id\": msg.productionOrderId\n }\n },\n \"product\": {\n \"data\": {\n \"type\": \"products\",\n \"id\": msg.productId\n }\n }\n }\n }\n}\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1070, "y": 240, "wires": [ [ "d902fc6bbce94f66" ] ] }, { "id": "d902fc6bbce94f66", "type": "http request", "z": "313077532647962a", "name": "POST line item to oee.ai", "method": "POST", "ret": "obj", "paytoqs": "ignore", "url": "https://api.oee.ai/line-items", "tls": "", "persist": false, "proxy": "", "authType": "", "senderr": false, "x": 1330, "y": 240, "wires": [ [] ] }, { "id": "379bdccf9b0ffef1", "type": "function", "z": "313077532647962a", "name": "Set Authorization header", "func": "msg.headers = {\n \"Authorization\": \"Bearer \" + msg.bearerToken\n}\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 190, "y": 240, "wires": [ [ "2c7869ebf1b08e24" ] ] }, { "id": "2c7869ebf1b08e24", "type": "http request", "z": "313077532647962a", "name": "Get product id", "method": "GET", "ret": "obj", "paytoqs": "ignore", "url": "https://api.oee.ai/products?filter[location]={{{location}}}&filter[code-or-description]={{{productCode}}}", "tls": "", "persist": false, "proxy": "", "authType": "", "senderr": false, "x": 420, "y": 240, "wires": [ [ "49ba2661252174ac" ] ] }, { "id": "49ba2661252174ac", "type": "change", "z": "313077532647962a", "name": "Delete response header", "rules": [ { "t": "delete", "p": "headers", "pt": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 650, "y": 240, "wires": [ [ "b9b6f46b07539cef" ] ] }, { "id": "b9b6f46b07539cef", "type": "change", "z": "313077532647962a", "name": "Save product id", "rules": [ { "t": "set", "p": "productId", "pt": "msg", "to": "payload.data[0].id", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 860, "y": 240, "wires": [ [ "9cd77018f8f6bfe6" ] ] }, { "id": "b89018ae29ae6104", "type": "change", "z": "313077532647962a", "name": "Delete response header", "rules": [ { "t": "delete", "p": "headers", "pt": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1570, "y": 240, "wires": [ [] ] }, { "id": "e65994090217c84b", "type": "subflow", "name": "Send line items to oee.ai", "info": "", "category": "", "in": [ { "x": 160, "y": 440, "wires": [ { "id": "78d6c4d3266f4ea5" } ] } ], "out": [], "env": [], "meta": {}, "color": "#DDAA99" }, { "id": "617fce1571ae3e6c", "type": "debug", "z": "e65994090217c84b", "name": "Response from oee.ai", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1720, "y": 440, "wires": [] }, { "id": "7cb968c3fc6af989", "type": "switch", "z": "e65994090217c84b", "name": "Check if line item already exists", "property": "statusCode", "propertyType": "msg", "rules": [ { "t": "eq", "v": "422", "vt": "num" }, { "t": "else" } ], "checkall": "false", "repair": false, "outputs": 2, "x": 1210, "y": 440, "wires": [ [ "1de73a4a71c0e9f7" ], [ "617fce1571ae3e6c" ] ] }, { "id": "34b1a6ade85e59cd", "type": "subflow:313077532647962a", "z": "e65994090217c84b", "name": "", "x": 980, "y": 440, "wires": [ [ "7cb968c3fc6af989" ] ] }, { "id": "1de73a4a71c0e9f7", "type": "subflow:db2ebd07e8a020a1", "z": "e65994090217c84b", "name": "", "x": 1460, "y": 400, "wires": [ [ "617fce1571ae3e6c" ] ] }, { "id": "215cbe88121f1684", "type": "change", "z": "e65994090217c84b", "name": "Mapping line item attributes", "rules": [ { "t": "set", "p": "step", "pt": "msg", "to": "payload.step", "tot": "msg" }, { "t": "set", "p": "description", "pt": "msg", "to": "payload.description", "tot": "msg" }, { "t": "set", "p": "start-time", "pt": "msg", "to": "payload.start-time", "tot": "msg" }, { "t": "set", "p": "batch", "pt": "msg", "to": "payload.batch", "tot": "msg" }, { "t": "set", "p": "quantity", "pt": "msg", "to": "payload.quantity", "tot": "msg" }, { "t": "set", "p": "delta", "pt": "msg", "to": "payload.delta", "tot": "msg" }, { "t": "set", "p": "changeover-minutes", "pt": "msg", "to": "payload.changeover-minutes", "tot": "msg" }, { "t": "set", "p": "productCode", "pt": "msg", "to": "payload.productCode", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 760, "y": 440, "wires": [ [ "34b1a6ade85e59cd" ] ] }, { "id": "78d6c4d3266f4ea5", "type": "change", "z": "e65994090217c84b", "name": "Set payload to lineItemsData", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "lineItemsData", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 320, "y": 440, "wires": [ [ "a897ae91340fba76" ] ] }, { "id": "a897ae91340fba76", "type": "split", "z": "e65994090217c84b", "name": "Split line items", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 540, "y": 440, "wires": [ [ "215cbe88121f1684" ] ] }, { "id": "c658eb7aa9f8be78", "type": "tab", "label": "Synchronizing production orders", "disabled": false, "info": "", "env": [] }, { "id": "9da7e9ef05ad80c2", "type": "comment", "z": "c658eb7aa9f8be78", "name": "Replace the Data input with your source and data transformation", "info": "", "x": 390, "y": 280, "wires": [] }, { "id": "505f86d3ccaefa96", "type": "inject", "z": "c658eb7aa9f8be78", "name": "Data Input", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "[1,2]", "payloadType": "json", "x": 240, "y": 320, "wires": [ [ "54de00a457024fd1" ] ] }, { "id": "53c92e56fff6c06a", "type": "change", "z": "c658eb7aa9f8be78", "name": "Mapping production order attributes", "rules": [ { "t": "set", "p": "code", "pt": "msg", "to": "27777", "tot": "str" }, { "t": "set", "p": "description", "pt": "msg", "to": "Example description", "tot": "str" }, { "t": "set", "p": "start-time", "pt": "msg", "to": "2023-03-30T12:00:00", "tot": "str" }, { "t": "set", "p": "location", "pt": "msg", "to": "", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1050, "y": 320, "wires": [ [ "3abbec71c2f3bc24" ] ] }, { "id": "94eabc63e40796ce", "type": "comment", "z": "c658eb7aa9f8be78", "name": "^^ set production order attributes", "info": "Format your message to the data model of oee.ai\nThen map your message values to the predefined\nmessage values in the change node", "x": 1040, "y": 360, "wires": [] }, { "id": "e579ccea1b51402c", "type": "subflow:e65994090217c84b", "z": "c658eb7aa9f8be78", "name": "", "x": 1710, "y": 320, "wires": [] }, { "id": "3abbec71c2f3bc24", "type": "subflow:9e0e05c7bc00ed5f", "z": "c658eb7aa9f8be78", "name": "", "x": 1410, "y": 320, "wires": [ [ "e579ccea1b51402c" ] ] }, { "id": "c650a899f4fb7f34", "type": "comment", "z": "c658eb7aa9f8be78", "name": "^^ enter your oee.ai API token", "info": "You can find your API Token on oee.ai", "x": 760, "y": 360, "wires": [] }, { "id": "53a6720c2658480c", "type": "change", "z": "c658eb7aa9f8be78", "name": "Set API Token", "rules": [ { "t": "set", "p": "bearerToken", "pt": "msg", "to": "", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 720, "y": 320, "wires": [ [ "53c92e56fff6c06a" ] ] }, { "id": "54de00a457024fd1", "type": "function", "z": "c658eb7aa9f8be78", "name": "Build line items attributes array", "func": "msg.lineItemsData = [\n { \n \"step\": \"1\", \n \"description\": \"FALT150\", \n \"start-time\": \"2023-03-30T12:00:00\", \n \"batch\": \"1\", \n \"quantity\": 15000,\n \"delta\": 0,\n \"changeover-minutes\": 0,\n \"productCode\": \"70343478\"\n }, \n {\n \"step\": \"2\",\n \"description\": \"GLUE150\",\n \"start-time\": \"2023-03-30T16:00:00\",\n \"batch\": \"1\",\n \"quantity\": 14000,\n \"delta\": 0,\n \"changeover-minutes\": 0,\n \"productCode\": \"70343478\"\n }\n]\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 470, "y": 320, "wires": [ [ "53a6720c2658480c" ] ] }, { "id": "629356fc41348c4a", "type": "comment", "z": "c658eb7aa9f8be78", "name": "^^ array of line items in this format", "info": "", "x": 480, "y": 360, "wires": [] } ]