[
    {
        "id": "aecf8663af837ef6",
        "type": "subflow",
        "name": "Sine Wave Generator",
        "info": "A node to generate Sine wave like signal.\nNode has two outputs:\n1) pure sine wave, values -1 to 1, in msg.payload\n2) sine wave with random noise, values -1.5 to 1.5, in msg.payload\n\nOutputs can be passed directly into Chart node and graphed\n\nOptional input can be used to change Sine wave frequency. Message shall be sent with Topic: \"Factor\" and multiplicator number in Payload. Number 1 is no change\n\nBuilt-in UI provides Sine wave frequency control",
        "category": "EMR Simulators",
        "in": [
            {
                "x": 280,
                "y": 80,
                "wires": [
                    {
                        "id": "ac567e13ccce94d4"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 730,
                "y": 160,
                "wires": [
                    {
                        "id": "ac567e13ccce94d4",
                        "port": 0
                    }
                ]
            },
            {
                "x": 730,
                "y": 260,
                "wires": [
                    {
                        "id": "ac567e13ccce94d4",
                        "port": 1
                    }
                ]
            }
        ],
        "env": [],
        "meta": {
            "author": "gene.juk@emerson.com"
        },
        "color": "#3FADB5",
        "outputLabels": [
            "Clean Sine",
            "Noisy Sine"
        ],
        "icon": "node-red/swap.svg"
    },
    {
        "id": "ac567e13ccce94d4",
        "type": "function",
        "z": "aecf8663af837ef6",
        "name": "",
        "func": "if(msg.topic == \"Factor\"){\n    // new Sine wave frequency multiplication factor is being set\n    // store it\n    context.data.factor = msg.payload;\n}else{\n    // periodic tick, calculate new Sine value using time stamp in\n    // msg.payload\n    let sin_val = Math.sin(msg.payload/1000/10*context.data.factor);\n    msg.payload = {};\n    msg.payload = sin_val;\n    msg.topic = \"Clean_Sin\";\n    let msg2 = {};\n    msg2.payload = sin_val+(Math.random()-0.5)*0.4;\n    msg2.topic = \"Noisy_Sin\";\n    node.send([msg,msg2]);\n}\nreturn;",
        "outputs": 2,
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\ncontext.data = {};\ncontext.data.factor = 1;",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 200,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "cc4744047b7261dd",
        "type": "inject",
        "z": "aecf8663af837ef6",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "Tick",
        "payload": "",
        "payloadType": "date",
        "x": 280,
        "y": 200,
        "wires": [
            [
                "ac567e13ccce94d4"
            ]
        ]
    },
    {
        "id": "1954dde90509ef69",
        "type": "inject",
        "z": "aecf8663af837ef6",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "Factor",
        "payload": "1",
        "payloadType": "num",
        "x": 258.75,
        "y": 139.75,
        "wires": [
            [
                "ac567e13ccce94d4"
            ]
        ]
    },
    {
        "id": "32d431a3b7985057",
        "type": "ui_slider",
        "z": "aecf8663af837ef6",
        "name": "",
        "label": "Sine Wave Frequency",
        "tooltip": "",
        "group": "f6f6992c1c53636f",
        "order": 3,
        "width": 0,
        "height": 0,
        "passthru": true,
        "outs": "all",
        "topic": "Factor",
        "topicType": "str",
        "min": "1",
        "max": 10,
        "step": 1,
        "className": "",
        "x": 260,
        "y": 280,
        "wires": [
            [
                "ac567e13ccce94d4"
            ]
        ]
    },
    {
        "id": "f6f6992c1c53636f",
        "type": "ui_group",
        "name": "Sine Wave",
        "tab": "6e9ed412be918ace",
        "order": 1,
        "disp": true,
        "width": "12",
        "collapse": false,
        "className": ""
    },
    {
        "id": "6e9ed412be918ace",
        "type": "ui_tab",
        "name": "Sine Wave",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    },
    {
        "id": "f6f2187d.f17ca8",
        "type": "tab",
        "label": "Store & Forward with Queue Node",
        "disabled": false,
        "info": ""
    },
    {
        "id": "7fd85f64af653c6d",
        "type": "q-gate",
        "z": "f6f2187d.f17ca8",
        "name": "q-gate demo",
        "controlTopic": "control",
        "defaultState": "open",
        "openCmd": "open",
        "closeCmd": "close",
        "toggleCmd": "toggle",
        "queueCmd": "queue",
        "defaultCmd": "default",
        "triggerCmd": "trigger",
        "flushCmd": "flush",
        "resetCmd": "reset",
        "peekCmd": "peek",
        "dropCmd": "drop",
        "statusCmd": "status",
        "maxQueueLength": "0",
        "keepNewest": false,
        "qToggle": false,
        "persist": false,
        "x": 390,
        "y": 880,
        "wires": [
            [
                "1705f0191ca18bc7"
            ]
        ]
    },
    {
        "id": "1705f0191ca18bc7",
        "type": "mqtt out",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "topic": "queue_test",
        "qos": "1",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "150f0b83b25cb2de",
        "x": 630,
        "y": 880,
        "wires": []
    },
    {
        "id": "9575a43615252355",
        "type": "subflow:aecf8663af837ef6",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "x": 220,
        "y": 760,
        "wires": [
            [
                "6910bf4f647310cd"
            ],
            []
        ]
    },
    {
        "id": "08fa858a94564957",
        "type": "mqtt in",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "topic": "queue_test",
        "qos": "1",
        "datatype": "json",
        "broker": "150f0b83b25cb2de",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 860,
        "y": 880,
        "wires": [
            [
                "883b8c7c0c798646",
                "17a6ec97bc28c696"
            ]
        ]
    },
    {
        "id": "883b8c7c0c798646",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1040,
        "y": 840,
        "wires": []
    },
    {
        "id": "6910bf4f647310cd",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "add time stamp",
        "func": "let timestamp = new Date();\nlet value = msg.payload;\n\nmsg.payload = [];\nmsg.payload[0]={};\nmsg.payload[0].measurement = \"queue4\";\nmsg.payload[0].timestamp = (timestamp.getTime()*1000*1000);\nmsg.payload[0].fields = {};\nmsg.payload[0].fields.sin_val = value;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 760,
        "wires": [
            [
                "7fd85f64af653c6d"
            ]
        ]
    },
    {
        "id": "17a6ec97bc28c696",
        "type": "influxdb batch",
        "z": "f6f2187d.f17ca8",
        "influxdb": "f32f037fb43bf103",
        "precision": "",
        "retentionPolicy": "",
        "name": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 1090,
        "y": 880,
        "wires": []
    },
    {
        "id": "49f3e1b8ba0fae38",
        "type": "status",
        "z": "f6f2187d.f17ca8",
        "name": "MQTT Out Status",
        "scope": [
            "1705f0191ca18bc7"
        ],
        "x": 240,
        "y": 1200,
        "wires": [
            [
                "673e80e69cd63503"
            ]
        ]
    },
    {
        "id": "44a82031f03f47ba",
        "type": "ping",
        "z": "f6f2187d.f17ca8",
        "protocol": "Automatic",
        "mode": "triggered",
        "name": "Ping Broker",
        "host": "192.168.2.94",
        "timer": "20",
        "inputs": 1,
        "x": 410,
        "y": 1020,
        "wires": [
            [
                "e1b0e931f47993d6"
            ]
        ]
    },
    {
        "id": "f60728f72329f4d8",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "Periodic Trigger",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 210,
        "y": 1020,
        "wires": [
            [
                "44a82031f03f47ba"
            ]
        ]
    },
    {
        "id": "e1b0e931f47993d6",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "Check Ping and Flow State variable",
        "func": "// store link status\nlet linkOk = msg.payload;\n// clear the message content\nmsg={};\nmsg.topic = \"control\";\n\nif (linkOk && flow.get(\"connectionOk\") ){\n    // connection is fine, open the pipe\n    if(context.data.delay > 0){\n        context.data.delay -= 1;\n        msg.payload = \"QUEUE\";\n    }else{\n        msg.payload = \"OPEN\";\n    }\n}else{\n    //either ping is not getting through or MQTT Client has no connection\n    msg.payload = \"QUEUE\";\n    context.data.delay = 3;\n}\n\nmsg.var = flow.get(\"connectionOk\");\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\ncontext.data = {};\ncontext.data.delay = 0;",
        "finalize": "",
        "libs": [],
        "x": 680,
        "y": 1020,
        "wires": [
            [
                "7fd85f64af653c6d"
            ]
        ]
    },
    {
        "id": "673e80e69cd63503",
        "type": "switch",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "property": "status.text",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "status.disconnected",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "status.connecting",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "status.connected",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 410,
        "y": 1200,
        "wires": [
            [
                "73dc4aebbf46c937"
            ],
            [
                "fea7e0146c7606fc"
            ],
            [
                "bec8f4913c6f34f7"
            ]
        ]
    },
    {
        "id": "73dc4aebbf46c937",
        "type": "change",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "connectionOk",
                "pt": "flow",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 640,
        "y": 1160,
        "wires": [
            []
        ]
    },
    {
        "id": "fea7e0146c7606fc",
        "type": "change",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "connectionOk",
                "pt": "flow",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 640,
        "y": 1200,
        "wires": [
            []
        ]
    },
    {
        "id": "bec8f4913c6f34f7",
        "type": "change",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "connectionOk",
                "pt": "flow",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 640,
        "y": 1240,
        "wires": [
            []
        ]
    },
    {
        "id": "2b670bad547c084b",
        "type": "comment",
        "z": "f6f2187d.f17ca8",
        "name": "Store MQTT Broker connection state in the Flow Variable",
        "info": "",
        "x": 470,
        "y": 1120,
        "wires": []
    },
    {
        "id": "0a1b13994062078d",
        "type": "tab",
        "label": "Store & Forward MQTT",
        "disabled": true,
        "info": "",
        "env": []
    },
    {
        "id": "4e95a46ae9ab710d",
        "type": "mqtt out",
        "z": "0a1b13994062078d",
        "name": "",
        "topic": "queue_test",
        "qos": "1",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "150f0b83b25cb2de",
        "x": 590,
        "y": 240,
        "wires": []
    },
    {
        "id": "dfaf0dcf58a8c53c",
        "type": "subflow:aecf8663af837ef6",
        "z": "0a1b13994062078d",
        "name": "",
        "x": 180,
        "y": 120,
        "wires": [
            [
                "d121c440e7b33915"
            ],
            []
        ]
    },
    {
        "id": "fa714ea93e6f8420",
        "type": "mqtt in",
        "z": "0a1b13994062078d",
        "name": "",
        "topic": "queue_test",
        "qos": "1",
        "datatype": "json",
        "broker": "150f0b83b25cb2de",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 820,
        "y": 240,
        "wires": [
            [
                "551c6954f8a47064",
                "0bac6554dcfede54"
            ]
        ]
    },
    {
        "id": "551c6954f8a47064",
        "type": "debug",
        "z": "0a1b13994062078d",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1000,
        "y": 200,
        "wires": []
    },
    {
        "id": "d121c440e7b33915",
        "type": "function",
        "z": "0a1b13994062078d",
        "name": "add time stamp",
        "func": "let timestamp = new Date();\nlet value = msg.payload;\n\nmsg.payload = [];\nmsg.payload[0]={};\nmsg.payload[0].measurement = \"queue4\";\nmsg.payload[0].timestamp = (timestamp.getTime()*1000*1000);\nmsg.payload[0].fields = {};\nmsg.payload[0].fields.sin_val = value;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 120,
        "wires": [
            [
                "4e95a46ae9ab710d"
            ]
        ]
    },
    {
        "id": "0bac6554dcfede54",
        "type": "influxdb batch",
        "z": "0a1b13994062078d",
        "influxdb": "f32f037fb43bf103",
        "precision": "",
        "retentionPolicy": "",
        "name": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 1050,
        "y": 240,
        "wires": []
    },
    {
        "id": "150f0b83b25cb2de",
        "type": "mqtt-broker",
        "name": "192.168.2.94",
        "broker": "192.168.2.94",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": "3"
    },
    {
        "id": "f32f037fb43bf103",
        "type": "influxdb",
        "hostname": "influxdb",
        "port": "8086",
        "protocol": "http",
        "database": "data",
        "name": "emerson_influxdb",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.x",
        "url": "http://localhost:8086",
        "rejectUnauthorized": true
    }
]