Fetching data from factoryinsight

The purpose of this tutorial is to extract data by using factoryinsight and calculate the machine indicator OEE (Overall Equipment Efficiency). This can allow the creation of different tools, such as a production dashboard.

Instructions

  1. Copy the following code and import it in a new flow.
  2. Replace the secret by using OpenLens and the guide in the flow in the node function.
  3. Adjust the parameters at convenient.

Flow

[
    {
        "id": "6e90fd64e1e6a384",
        "type": "tab",
        "label": "Onur prototype",
        "disabled": false,
        "info": ""
    },
    {
        "id": "f720f16004d56efd",
        "type": "http request",
        "z": "6e90fd64e1e6a384",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 660,
        "y": 420,
        "wires": [
            [
                "18237fd55d51d160"
            ]
        ]
    },
    {
        "id": "b28fc506f7fe8fdd",
        "type": "function",
        "z": "6e90fd64e1e6a384",
        "name": "",
        "func": "// note: there are some functions in the \"start\" section of this node\n\nlet location = \"testserver\"\nlet asset = \"jeremy\"\nlet valueName = \"orderTable\"\n\nlet from = new Date().removeHours(1)\nlet to = new Date()\n\nmsg.url = \"http://united-manufacturing-hub-factoryinsight-service/api/v1/factoryinsight/\" + location + \"/\" + asset + \"/\" + valueName + \"?from=\" + from.toISOString() + \"&to=\" + to.toISOString();\n\nmsg.headers = {}\n\n// The value for this can be found in Lens under secrets --> factoryinsight-secret --> apiKey\nmsg.headers[\"Authorization\"] = \"Basic ZmFjdG9yeWluc2lnaHQ6NjdjNDBlZGEtOGI5MS00NzM0LTllYWItZTQ1NTJjZTUyZWZl\"\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "\nDate.prototype.addHours = function(h) {\n  this.setTime(this.getTime() + (h*60*60*1000));\n  return this;\n}\n\nDate.prototype.removeHours = function(h) {\n  this.setTime(this.getTime() - (h*60*60*1000));\n  return this;\n}",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 420,
        "wires": [
            [
                "f720f16004d56efd"
            ]
        ]
    },
    {
        "id": "42089e12117ba295",
        "type": "inject",
        "z": "6e90fd64e1e6a384",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 290,
        "y": 420,
        "wires": [
            [
                "b28fc506f7fe8fdd"
            ]
        ]
    },
    {
        "id": "d77c61a0aa0c7cfb",
        "type": "debug",
        "z": "6e90fd64e1e6a384",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1110,
        "y": 420,
        "wires": []
    },
    {
        "id": "18237fd55d51d160",
        "type": "json",
        "z": "6e90fd64e1e6a384",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 420,
        "wires": [
            [
                "d77c61a0aa0c7cfb"
            ]
        ]
    }
]
Last modified October 5, 2022: Historian article (#107) (5f30dc0)