[
    {
        "id": "fcf4ba66.688748",
        "type": "subflow",
        "name": "HTTP Post Data",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 20,
                "y": 160,
                "wires": [
                    {
                        "id": "751d9da2.6c0d74"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 1060,
                "y": 160,
                "wires": [
                    {
                        "id": "4b234547.15115c",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "color": "#DDAA99"
    },
    {
        "id": "751d9da2.6c0d74",
        "type": "function",
        "z": "fcf4ba66.688748",
        "name": "Data Payload & Headers",
        "func": "// Reference: https://docs.exosite.io/account/iot-connectors/connected-products/device-http-api#provision\nmsg.url = `${msg.device.url}/onep:v1/stack/alias`;\n\nmsg.headers = {};\nmsg.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';\nmsg.headers['X-Exosite-CIK'] = msg.device.token;\n\nlet data = JSON.stringify(msg.device.data);\n\nmsg.payload = `data_in=${data}`;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 190,
        "y": 160,
        "wires": [
            [
                "38eefff0.b9df2",
                "ba0a62fd.1a775"
            ]
        ]
    },
    {
        "id": "ba0a62fd.1a775",
        "type": "http request",
        "z": "fcf4ba66.688748",
        "name": "POST Data",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "cc6d5451.fb9658",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 410,
        "y": 160,
        "wires": [
            [
                "40e9ff84.d95dd",
                "c671cea6.bf60d"
            ]
        ]
    },
    {
        "id": "38eefff0.b9df2",
        "type": "debug",
        "z": "fcf4ba66.688748",
        "name": "Data Request",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 160,
        "y": 100,
        "wires": []
    },
    {
        "id": "40e9ff84.d95dd",
        "type": "debug",
        "z": "fcf4ba66.688748",
        "name": "Data Response",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 420,
        "y": 100,
        "wires": []
    },
    {
        "id": "c671cea6.bf60d",
        "type": "switch",
        "z": "fcf4ba66.688748",
        "name": "Data Response Handler",
        "property": "statusCode",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "204",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "204",
                "vt": "str"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 630,
        "y": 160,
        "wires": [
            [
                "4b234547.15115c"
            ],
            [
                "b542425d.100de"
            ]
        ],
        "outputLabels": [
            "Sucess",
            "Failure"
        ]
    },
    {
        "id": "b542425d.100de",
        "type": "debug",
        "z": "fcf4ba66.688748",
        "name": "Data Failure",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 220,
        "wires": []
    },
    {
        "id": "4b234547.15115c",
        "type": "function",
        "z": "fcf4ba66.688748",
        "name": "Clear Request Properties",
        "func": "delete msg.redirectList;\ndelete msg.responseUrl;\ndelete msg.statusCode;\n\n// Clear device data object for next run\nmsg.device.data = {};\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 890,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "5303e7d4.f58bc8",
        "type": "subflow",
        "name": "HTTP Post Config",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 20,
                "y": 160,
                "wires": [
                    {
                        "id": "1490875e.8483b9"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 1080,
                "y": 160,
                "wires": [
                    {
                        "id": "2e7b6d53.fcc182",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "color": "#DDAA99"
    },
    {
        "id": "78263cde.91d2f4",
        "type": "debug",
        "z": "5303e7d4.f58bc8",
        "name": "Config Request",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 160,
        "y": 100,
        "wires": []
    },
    {
        "id": "732b4785.813cc8",
        "type": "http request",
        "z": "5303e7d4.f58bc8",
        "name": "POST Config",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "cc6d5451.fb9658",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 430,
        "y": 160,
        "wires": [
            [
                "b17dddad.dadf7",
                "cb899967.51c098"
            ]
        ]
    },
    {
        "id": "1490875e.8483b9",
        "type": "function",
        "z": "5303e7d4.f58bc8",
        "name": "Config Payload & Headers",
        "func": "// Reference: https://docs.exosite.io/account/iot-connectors/connected-products/device-http-api#provision\nmsg.url = `${msg.device.url}/onep:v1/stack/alias`;\n\nmsg.headers = {};\nmsg.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';\nmsg.headers['X-Exosite-CIK'] = msg.device.token;\n\nlet config = JSON.stringify(msg.device.config);\n\nmsg.payload = `config_io=${config}`;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 200,
        "y": 160,
        "wires": [
            [
                "78263cde.91d2f4",
                "732b4785.813cc8"
            ]
        ]
    },
    {
        "id": "b17dddad.dadf7",
        "type": "debug",
        "z": "5303e7d4.f58bc8",
        "name": "Config Response",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 450,
        "y": 100,
        "wires": []
    },
    {
        "id": "cb899967.51c098",
        "type": "switch",
        "z": "5303e7d4.f58bc8",
        "name": "Config Response Handler",
        "property": "statusCode",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "204",
                "vt": "num"
            },
            {
                "t": "neq",
                "v": "204",
                "vt": "str"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 650,
        "y": 160,
        "wires": [
            [
                "2e7b6d53.fcc182"
            ],
            [
                "e96ccec4.306e7"
            ]
        ],
        "inputLabels": [
            "POST Config Response"
        ],
        "outputLabels": [
            "Success",
            "Failure"
        ]
    },
    {
        "id": "e96ccec4.306e7",
        "type": "debug",
        "z": "5303e7d4.f58bc8",
        "name": "Config Failure",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 220,
        "wires": []
    },
    {
        "id": "2e7b6d53.fcc182",
        "type": "function",
        "z": "5303e7d4.f58bc8",
        "name": "Clear Request Properties",
        "func": "delete msg.redirectList;\ndelete msg.responseUrl;\ndelete msg.statusCode;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 910,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "5e91c58.8bc983c",
        "type": "subflow",
        "name": "HTTP Provision",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 20,
                "y": 160,
                "wires": [
                    {
                        "id": "4711cd79.823434"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 1720,
                "y": 160,
                "wires": [
                    {
                        "id": "69de45a3.3aaf7c",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "color": "#DDAA99"
    },
    {
        "id": "9b811725.ac5968",
        "type": "http request",
        "z": "5e91c58.8bc983c",
        "name": "POST Provision",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "cc6d5451.fb9658",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 440,
        "y": 160,
        "wires": [
            [
                "abcc02ef.0da1d",
                "c075ebfd.ed6738"
            ]
        ]
    },
    {
        "id": "4711cd79.823434",
        "type": "function",
        "z": "5e91c58.8bc983c",
        "name": "Provision Payload & Headers",
        "func": "// Reference: https://docs.exosite.io/account/iot-connectors/connected-products/device-http-api#provision\nmsg.url = `${msg.device.url}/provision/activate`;\n\nmsg.headers = {};\nmsg.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';\n\nmsg.payload = `id=${msg.device.identity}`;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 200,
        "y": 160,
        "wires": [
            [
                "956f18f3.cfd328",
                "9b811725.ac5968"
            ]
        ]
    },
    {
        "id": "abcc02ef.0da1d",
        "type": "debug",
        "z": "5e91c58.8bc983c",
        "name": "Provision Response",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 460,
        "y": 100,
        "wires": []
    },
    {
        "id": "956f18f3.cfd328",
        "type": "debug",
        "z": "5e91c58.8bc983c",
        "name": "Provision Request",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 170,
        "y": 100,
        "wires": []
    },
    {
        "id": "c075ebfd.ed6738",
        "type": "switch",
        "z": "5e91c58.8bc983c",
        "name": "Provision Response Handler",
        "property": "statusCode",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "200",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "200",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 680,
        "y": 160,
        "wires": [
            [
                "3ca6b0c5.0640e"
            ],
            [
                "9ef20798.32ca38"
            ]
        ],
        "outputLabels": [
            "Success",
            "Failure"
        ]
    },
    {
        "id": "9ef20798.32ca38",
        "type": "debug",
        "z": "5e91c58.8bc983c",
        "name": "Provision Failure",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 220,
        "wires": []
    },
    {
        "id": "3ca6b0c5.0640e",
        "type": "function",
        "z": "5e91c58.8bc983c",
        "name": "Clear Request Properties",
        "func": "delete msg.redirectList;\ndelete msg.responseUrl;\ndelete msg.statusCode;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 950,
        "y": 160,
        "wires": [
            [
                "26998da4.901fc2"
            ]
        ]
    },
    {
        "id": "69de45a3.3aaf7c",
        "type": "file",
        "z": "5e91c58.8bc983c",
        "name": "Device File",
        "filename": "device.json",
        "appendNewline": false,
        "createDir": false,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 1590,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "26998da4.901fc2",
        "type": "function",
        "z": "5e91c58.8bc983c",
        "name": "Update Device File",
        "func": "msg.device.token = msg.payload;\n\nmsg.payload = msg.device;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 1190,
        "y": 160,
        "wires": [
            [
                "d622e85.3e20218"
            ]
        ]
    },
    {
        "id": "d622e85.3e20218",
        "type": "json",
        "z": "5e91c58.8bc983c",
        "name": "JSON Formatter",
        "property": "payload",
        "action": "str",
        "pretty": true,
        "x": 1400,
        "y": 160,
        "wires": [
            [
                "69de45a3.3aaf7c"
            ]
        ]
    },
    {
        "id": "cc6d5451.fb9658",
        "type": "tls-config",
        "name": "HTTP IoT Connector (TLS)",
        "cert": "",
        "key": "",
        "ca": "",
        "certname": "",
        "keyname": "",
        "caname": "",
        "servername": "<TODO>",
        "verifyservercert": true,
        "alpnprotocol": ""
    },
    {
        "id": "65302557.9e299c",
        "type": "subflow",
        "name": "HTTP Device Definition",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 40,
                "y": 100,
                "wires": [
                    {
                        "id": "c9b10a78.1700a8"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 880,
                "y": 100,
                "wires": [
                    {
                        "id": "32ee44f1.57f53c",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "color": "#DDAA99"
    },
    {
        "id": "471d605b.4ef84",
        "type": "file in",
        "z": "65302557.9e299c",
        "name": "Device File",
        "filename": "device.json",
        "filenameType": "str",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "x": 330,
        "y": 100,
        "wires": [
            [
                "db6703a.b03a5"
            ]
        ]
    },
    {
        "id": "db6703a.b03a5",
        "type": "json",
        "z": "65302557.9e299c",
        "name": "Device Parser",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 520,
        "y": 100,
        "wires": [
            [
                "32ee44f1.57f53c"
            ]
        ]
    },
    {
        "id": "32ee44f1.57f53c",
        "type": "function",
        "z": "65302557.9e299c",
        "name": "Device Definition",
        "func": "msg.device = {};\n\nif (msg.payload.url.endsWith('/')) {\n    msg.device.url = msg.payload.url.substring(0, msg.payload.url.length - 1);\n} else {\n    msg.device.url = msg.payload.url;\n}\n\nmsg.device.identity = msg.payload.identity;\nmsg.device.token = msg.payload.token || '';\nmsg.device.config = msg.payload.config || {};\nmsg.device.data = msg.payload.data || {};\n\nmsg.payload = msg.device.token;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 730,
        "y": 100,
        "wires": [
            [
                "2610b033.6b26"
            ]
        ]
    },
    {
        "id": "2610b033.6b26",
        "type": "debug",
        "z": "65302557.9e299c",
        "name": "Device Definition",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 160,
        "wires": []
    },
    {
        "id": "25f78485.2eb20c",
        "type": "catch",
        "z": "65302557.9e299c",
        "name": "Catch: File DNE",
        "scope": [
            "471d605b.4ef84"
        ],
        "uncaught": false,
        "x": 100,
        "y": 240,
        "wires": [
            [
                "46e7a516.8edb8c"
            ]
        ]
    },
    {
        "id": "46e7a516.8edb8c",
        "type": "function",
        "z": "65302557.9e299c",
        "name": "Device Init",
        "func": "msg.device = {};\n\n// - - - - - - - - - - - - - - - - -\n// - - - - - -  Required  - - - - -\n// - - - - - - - - - - - - - - - - -\n\n// Set IoT Connector Host\nmsg.device.url = '';\n\n// Set Device ID\nmsg.device.identity = '';\n\n\n// - - - - - - - - - - - - - - - - -\n// - - - - - -  Optional  - - - - -\n// - - - - - - - - - - - - - - - - -\n\n// Set Token if Device ID is already provisioned\nmsg.device.token = '';\n\n// Set a config_io value (ref: https://docs.exosite.io/schema/channel-signal_io_schema#device-gateway-channel-configuration-schema)\nmsg.device.config = {};\n\n// Set an initial data_in payload\nmsg.device.data = {};\n\n\n// Remove trailing '/' from IoT Connector Host if it is present\nif (msg.device.url.endsWith('/')) {\n    msg.device.url = msg.device.url.substring(0, msg.device.url.length - 1);\n}\n\nmsg.payload = msg.device;\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 290,
        "y": 240,
        "wires": [
            [
                "7bc4b054.be71d"
            ]
        ]
    },
    {
        "id": "c9b10a78.1700a8",
        "type": "function",
        "z": "65302557.9e299c",
        "name": "Schema",
        "func": "msg.schema = {\n  \"type\": \"object\",\n  \"properties\": {\n    \"url\": {\n      \"type\": \"string\",\n      \"description\": \"IoT Connector host url\"\n    },\n    \"identity\": {\n      \"type\": \"string\",\n      \"description\": \"Identity under which to provision\"\n    },\n    \"token\": {\n      \"type\": \"string\",\n      \"description\": \"Authentication token\"\n    },\n    \"config\": {\n      \"type\": \"object\",\n      \"description\": \"ExoSense channel configuration object\"\n    },\n    \"data\": {\n      \"type\": \"object\",\n      \"description\": \"ExoSense channel data object\"\n    }\n  },\n  \"required\": [\n    \"url\",\n    \"identity\"\n  ]\n};\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 160,
        "y": 100,
        "wires": [
            [
                "471d605b.4ef84"
            ]
        ]
    },
    {
        "id": "7bc4b054.be71d",
        "type": "json",
        "z": "65302557.9e299c",
        "name": "JSON Formatter",
        "property": "payload",
        "action": "str",
        "pretty": true,
        "x": 480,
        "y": 240,
        "wires": [
            [
                "9936e449.7bcb08"
            ]
        ]
    },
    {
        "id": "9936e449.7bcb08",
        "type": "file",
        "z": "65302557.9e299c",
        "name": "Device File",
        "filename": "device.json",
        "appendNewline": false,
        "createDir": false,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 670,
        "y": 240,
        "wires": [
            [
                "471d605b.4ef84"
            ]
        ]
    },
    {
        "id": "80d703fe2c873c91",
        "type": "tab",
        "label": "Temperature Logger",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "42880fe2077086d8",
        "type": "inject",
        "z": "80d703fe2c873c91",
        "name": "Flow Started",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 200,
        "wires": [
            [
                "5b1859361d536fd3"
            ]
        ]
    },
    {
        "id": "ea52789fa351615f",
        "type": "grpc-call",
        "z": "80d703fe2c873c91",
        "name": "ListDevices",
        "server": "822831c0030813b2",
        "service": "TemperatureSensor",
        "method": "ListDevices",
        "chain": "",
        "key": "",
        "x": 110,
        "y": 320,
        "wires": [
            [
                "b1e0da01fc369010"
            ]
        ]
    },
    {
        "id": "cfa190f9a8bd4928",
        "type": "inject",
        "z": "80d703fe2c873c91",
        "name": "Initialize Configuration",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"url\":\"https://XXXXXXXX.m2.exosite.io\",\"identity\":\"TDCX25190039\"}",
        "payloadType": "json",
        "x": 160,
        "y": 80,
        "wires": [
            [
                "d8fc36ccff834a5e"
            ]
        ]
    },
    {
        "id": "d8fc36ccff834a5e",
        "type": "file",
        "z": "80d703fe2c873c91",
        "name": "",
        "filename": "device.json",
        "filenameType": "str",
        "appendNewline": true,
        "createDir": false,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 390,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "035d9659489bc67b",
        "type": "comment",
        "z": "80d703fe2c873c91",
        "name": "Edit the config here and run once",
        "info": "",
        "x": 170,
        "y": 40,
        "wires": []
    },
    {
        "id": "5b1859361d536fd3",
        "type": "subflow:65302557.9e299c",
        "z": "80d703fe2c873c91",
        "name": "",
        "env": [],
        "x": 150,
        "y": 260,
        "wires": [
            [
                "8be2a9e20eeb7164"
            ]
        ]
    },
    {
        "id": "8be2a9e20eeb7164",
        "type": "switch",
        "z": "80d703fe2c873c91",
        "name": "Provision State Switch",
        "property": "device.token",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "",
                "vt": "str"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 380,
        "y": 260,
        "wires": [
            [
                "a0aad2e0fef9aa6c"
            ],
            [
                "ea52789fa351615f"
            ]
        ],
        "outputLabels": [
            "Not Provisioned",
            "Provisioned"
        ]
    },
    {
        "id": "a0aad2e0fef9aa6c",
        "type": "subflow:5e91c58.8bc983c",
        "z": "80d703fe2c873c91",
        "name": "",
        "env": [],
        "x": 600,
        "y": 260,
        "wires": [
            [
                "5b1859361d536fd3"
            ]
        ]
    },
    {
        "id": "2b0af8c8129b26f4",
        "type": "subflow:5303e7d4.f58bc8",
        "z": "80d703fe2c873c91",
        "x": 590,
        "y": 320,
        "wires": [
            [
                "061462e8b45629d9"
            ]
        ]
    },
    {
        "id": "b1e0da01fc369010",
        "type": "function",
        "z": "80d703fe2c873c91",
        "name": "Config_IO from Temp Devices",
        "func": "if (msg.device === undefined) {\n    msg.device = {};\n}\nmsg.device.config = {\n    \"last_edited\": Date.now(),\n    \"channels\": Object.fromEntries(msg.payload.devices.map( v=> {\n        return [v.name, {\n            \"display_name\": v.name,\n            \"properties\": {\n                \"data_type\": \"TEMPERATURE\",\n                \"data_unit\": \"DEG_CELSIUS\",\n                \"precision\": 2\n            },\n            \"protocol_config\": {\n                \"report_rate\": 30000,\n                \"timeout\": 60000\n            }\n        }]\n    }))\n};\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 330,
        "y": 320,
        "wires": [
            [
                "2b0af8c8129b26f4"
            ]
        ]
    },
    {
        "id": "061462e8b45629d9",
        "type": "grpc-call",
        "z": "80d703fe2c873c91",
        "name": "ListDevices",
        "server": "822831c0030813b2",
        "service": "TemperatureSensor",
        "method": "ListDevices",
        "chain": "",
        "key": "",
        "x": 310,
        "y": 380,
        "wires": [
            [
                "bbee0b7ddce5e707"
            ]
        ]
    },
    {
        "id": "bbee0b7ddce5e707",
        "type": "split",
        "z": "80d703fe2c873c91",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "property": "payload.devices",
        "x": 450,
        "y": 380,
        "wires": [
            [
                "2b53a92c80cf4133"
            ]
        ]
    },
    {
        "id": "f8642730447aec95",
        "type": "grpc-call",
        "z": "80d703fe2c873c91",
        "name": "Read",
        "server": "822831c0030813b2",
        "service": "TemperatureSensor",
        "method": "Read",
        "chain": "",
        "key": "",
        "x": 290,
        "y": 420,
        "wires": [
            [
                "cdc0ad593f774981"
            ]
        ]
    },
    {
        "id": "2b53a92c80cf4133",
        "type": "change",
        "z": "80d703fe2c873c91",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "payload.devices.name",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "msg.payload.devices",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 600,
        "y": 380,
        "wires": [
            [
                "f8642730447aec95"
            ]
        ]
    },
    {
        "id": "a0383fe4e860d5b1",
        "type": "join",
        "z": "80d703fe2c873c91",
        "name": "",
        "mode": "auto",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "useparts": false,
        "accumulate": "false",
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "x": 590,
        "y": 420,
        "wires": [
            [
                "ef8c840489ae14c6"
            ]
        ]
    },
    {
        "id": "cdc0ad593f774981",
        "type": "change",
        "z": "80d703fe2c873c91",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload.name",
                "pt": "msg",
                "to": "topic",
                "tot": "msg"
            },
            {
                "t": "delete",
                "p": "payload.unit",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "parts.property",
                "pt": "msg",
                "to": "payload",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 440,
        "y": 420,
        "wires": [
            [
                "a0383fe4e860d5b1"
            ]
        ]
    },
    {
        "id": "ef8c840489ae14c6",
        "type": "function",
        "z": "80d703fe2c873c91",
        "name": "Fill Device.data",
        "func": "if (msg.device === undefined) {\n    msg.device = {};\n}\nmsg.device.data = Object.fromEntries(msg.payload.map(v => [v.name,v.value]));\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 420,
        "wires": [
            [
                "9f911e1db1b14470"
            ]
        ]
    },
    {
        "id": "9f911e1db1b14470",
        "type": "subflow:fcf4ba66.688748",
        "z": "80d703fe2c873c91",
        "name": "",
        "env": [],
        "x": 320,
        "y": 460,
        "wires": [
            [
                "8c8228bc15a08228"
            ]
        ]
    },
    {
        "id": "8c8228bc15a08228",
        "type": "delay",
        "z": "80d703fe2c873c91",
        "name": "Interval",
        "pauseType": "delay",
        "timeout": "30",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 100,
        "y": 500,
        "wires": [
            [
                "061462e8b45629d9"
            ]
        ]
    },
    {
        "id": "841c947e60286492",
        "type": "comment",
        "z": "80d703fe2c873c91",
        "name": "After doing the above, you can change the inject below to \"inject once after\" to autostart",
        "info": "",
        "x": 350,
        "y": 160,
        "wires": []
    },
    {
        "id": "822831c0030813b2",
        "type": "grpc-server",
        "server": "unix:///var/run/hal/hal.sock",
        "name": "TDC-Temp",
        "protoFile": "/**\n * Temperature sensor service.\n *\n * Service that provides device temperature sensor reading\n */\nsyntax = \"proto3\";\n\npackage hal.temperaturesensor;\n\nimport \"google/protobuf/empty.proto\";\n\noption go_package = \"./protos;protos\";\n\n\nmessage TemperatureSensorDevice {\n  string name = 1;\n}\n\n/**\n * Represents the ListDevice response data.\n */\nmessage TemperatureSensorListDeviceResponse {\n  repeated TemperatureSensorDevice devices = 1;\n}\n\nmessage TemperatureSensorReadRequest {\n  string name = 1;\n}\n\nmessage TemperatureSensorReadResponse {\n  float value = 1;\n  string unit = 2;\n}\n\n/**\n * Service exposing TemperatureSensor functions.\n */\nservice TemperatureSensor {\n  /// Used to retrieve all available temperature sensors\n  rpc ListDevices(google.protobuf.Empty) returns (TemperatureSensorListDeviceResponse) {}\n\n  /// Used to read value of a particular temperature sensor.\n  rpc Read(TemperatureSensorReadRequest) returns (TemperatureSensorReadResponse) {}\n}",
        "ca": "",
        "chain": "",
        "key": "",
        "mutualTls": false,
        "ssl": false,
        "selfsigned": false,
        "localServer": false
    },
    {
        "id": "e4a0e9127d4c0696",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-contrib-grpc": "1.2.7"
        }
    }
]
