Skip to content

Instantly share code, notes, and snippets.

@getlarge
Created November 13, 2019 19:54
Show Gist options
  • Save getlarge/cd9e17f59f24018ba006cb25a1a4aa33 to your computer and use it in GitHub Desktop.
Save getlarge/cd9e17f59f24018ba006cb25a1a4aa33 to your computer and use it in GitHub Desktop.
node-red-bridge/device-flow-snips-agent
[
{
"id": "77a5eb29.d56ae4",
"type": "subflow",
"name": "set-aloes-request",
"info": "",
"category": "aloes",
"in": [
{
"x": 140,
"y": 180,
"wires": [
{
"id": "312fba7d.92e516"
}
]
}
],
"out": [
{
"x": 1200,
"y": 180,
"wires": [
{
"id": "477232e0.a27d64",
"port": 1
},
{
"id": "57935401.66304c",
"port": 0
}
]
},
{
"x": 1200,
"y": 260,
"wires": [
{
"id": "fd89a51d.5c68c8",
"port": 1
}
]
}
],
"env": [
{
"name": "aloes_token",
"type": "env",
"value": "ALOES_TOKEN"
},
{
"name": "aloes_http_secure",
"type": "env",
"value": "ALOES_HTTP_SECURE"
},
{
"name": "aloes_http_host",
"type": "env",
"value": "ALOES_HTTP_HOST"
},
{
"name": "aloes_http_port",
"type": "env",
"value": "ALOES_HTTP_PORT"
},
{
"name": "aloes_http_api_root",
"type": "env",
"value": "ALOES_HTTP_API_ROOT"
},
{
"name": "content_type",
"type": "str",
"value": "application/json"
},
{
"name": "collection",
"type": "str",
"value": "Devices"
},
{
"name": "method",
"type": "str",
"value": "GET"
},
{
"name": "path",
"type": "str",
"value": ""
}
],
"icon": "node-red/white-globe.png",
"status": {
"x": 1200,
"y": 60,
"wires": [
{
"id": "a86f1d14.753788",
"port": 0
}
]
}
},
{
"id": "312fba7d.92e516",
"type": "function",
"z": "77a5eb29.d56ae4",
"name": "set-aloes-request",
"func": "try {\n const token = env.get('aloes_token');\n const path = env.get('path');\n msg.contentType = env.get(\"content_type\") || \"application/json\";\n msg.method = env.get(\"method\") || 'GET';\n msg.headers = {};\n msg.headers['Authorization'] = token;\n msg.headers['Accept'] = `${msg.contentType}, text/plain`;\n msg.headers['Content-Type'] = msg.contentType;\n msg.headers['x-access-token'] = token;\n // msg.headers['Origin'] = 'http://localhost:8000';\n // msg.headers['Connection'] = 'keep-alive';\n let protocol = 'http';\n if (env.get('aloes_http_secure') === 'true') {\n protocol = 'https';\n }\n const collection = env.get('collection') || 'Devices';\n const aloesApiRoot = env.get('aloes_http_api_root') || '/api';\n msg.baseUrl = `${protocol}://${env.get('aloes_http_host')}:${env.get('aloes_http_port')}${aloesApiRoot}`;\n msg.url = `${msg.baseUrl}/${collection}`;\n if (path) {\n msg.url = `${msg.url}/${path}`;\n }\n if (msg.filter) {\n // msg.url = `${msg.url}?filter=${JSON.stringify(msg.filter).toString()}`;\n msg.url = `${msg.url}?filter=${msg.filter}`;\n }\n return msg; \n} catch(error) {\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 310,
"y": 180,
"wires": [
[
"39642d63.477342"
]
]
},
{
"id": "39642d63.477342",
"type": "http request",
"z": "77a5eb29.d56ae4",
"name": "",
"method": "use",
"ret": "txt",
"paytoqs": false,
"url": "",
"tls": "",
"proxy": "",
"authType": "basic",
"x": 530,
"y": 180,
"wires": [
[
"fd89a51d.5c68c8"
]
]
},
{
"id": "477232e0.a27d64",
"type": "switch",
"z": "77a5eb29.d56ae4",
"name": "",
"property": "contentType",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "application/json",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 950,
"y": 160,
"wires": [
[
"57935401.66304c"
],
[]
]
},
{
"id": "57935401.66304c",
"type": "json",
"z": "77a5eb29.d56ae4",
"name": "",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 1070,
"y": 140,
"wires": [
[]
]
},
{
"id": "fd89a51d.5c68c8",
"type": "function",
"z": "77a5eb29.d56ae4",
"name": "parse-HTTP-response",
"func": "try {\n if (msg.statusCode && msg.statusCode === 200) {\n node.status({fill:\"green\",shape:\"ring\",text:\"success\"});\n return [msg,null];\n }\n node.status({fill:\"red\",shape:\"ring\",text:\"error\"});\n return [null,msg];\n} catch(error) {\n return error;\n}\n",
"outputs": 2,
"noerr": 0,
"x": 740,
"y": 180,
"wires": [
[
"477232e0.a27d64"
],
[]
]
},
{
"id": "a86f1d14.753788",
"type": "status",
"z": "77a5eb29.d56ae4",
"name": "",
"scope": [
"39642d63.477342",
"fd89a51d.5c68c8"
],
"x": 720,
"y": 60,
"wires": [
[]
]
},
{
"id": "41c6c6f2.febed8",
"type": "subflow",
"name": "device-selected",
"info": "",
"category": "",
"in": [
{
"x": 200,
"y": 160,
"wires": [
{
"id": "fe378273.e7e4"
}
]
}
],
"out": [
{
"x": 460,
"y": 160,
"wires": [
{
"id": "fe378273.e7e4",
"port": 0
}
]
}
],
"env": [
{
"name": "debug",
"type": "bool",
"value": "false"
},
{
"name": "device_name",
"type": "env",
"value": "device_name"
}
]
},
{
"id": "fe378273.e7e4",
"type": "function",
"z": "41c6c6f2.febed8",
"name": "isSelected",
"func": "try {\n const debug = env.get(\"debug\");\n const deviceName = env.get(\"device_name\");\n if (!deviceName) throw new Error(\"no device name env\");\n const compareNames = source => {\n if (source && source !== null) {\n return source === deviceName.toLowerCase();\n }\n return false;\n };\n const index = msg.payload.findIndex(compareNames);\n msg.payload = false;\n if (index > -1) {\n msg.payload = true;\n }\n if (debug) {\n console.log(\"isSelected\", index, msg.payload);\n }\n return msg;\n} catch(error) {\n return error;\n}",
"outputs": 1,
"noerr": 0,
"x": 330,
"y": 160,
"wires": [
[]
]
},
{
"id": "d253d97e.e3e448",
"type": "subflow",
"name": "get-device",
"info": "",
"category": "function",
"in": [
{
"x": 160,
"y": 120,
"wires": [
{
"id": "b6b86bf5.bd0af"
}
]
}
],
"out": [
{
"x": 460,
"y": 120,
"wires": [
{
"id": "b6b86bf5.bd0af",
"port": 0
}
]
}
],
"env": [
{
"name": "device_name",
"type": "env",
"value": "device_name"
},
{
"name": "user_id",
"type": "env",
"value": "user_id"
},
{
"name": "store_type",
"type": "env",
"value": "store_type"
},
{
"name": "debug",
"type": "bool",
"value": "false"
}
]
},
{
"id": "b6b86bf5.bd0af",
"type": "function",
"z": "d253d97e.e3e448",
"name": "getDevice",
"func": "try {\n const debug = env.get(\"debug\");\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n const deviceName = env.get(\"device_name\");\n if (!deviceName) throw new Error(\"Missing env vars\"); \n const storeKey = `device-${deviceName}`;\n if(!storeKey) throw new Error(\"Missing params\");\n if (debug) {\n console.log(\"get device store_key\", storeKey);\n }\n global.get(storeKey, storeType, (err,res) => {\n if(err) throw err;\n msg.device = res;\n }); \n if (!msg.device || msg.device === null) throw new Error(\"no device found\"); \n const userId = env.get(\"user_id\");\n msg.parts = [userId, \"Device\", \"HEAD\", msg.device.id];\n msg.topic = msg.parts.join(\"/\");\n if (debug) {\n console.log(\"get device topic\", msg.topic);\n }\n return msg;\n} catch(error) {\n // console.log(\"get device error\", error);\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 320,
"y": 120,
"wires": [
[]
]
},
{
"id": "8a55823f.f6ad1",
"type": "subflow",
"name": "get-sensor",
"info": "",
"category": "function",
"in": [
{
"x": 160,
"y": 200,
"wires": [
{
"id": "8fa149cd.a14938"
}
]
}
],
"out": [
{
"x": 440,
"y": 200,
"wires": [
{
"id": "8fa149cd.a14938",
"port": 0
}
]
}
],
"env": [
{
"name": "store_type",
"type": "env",
"value": "store_type"
},
{
"name": "device_name",
"type": "env",
"value": "device_name"
},
{
"name": "object_id",
"type": "str",
"value": "3300"
},
{
"name": "sensor_id",
"type": "str",
"value": "1"
},
{
"name": "user_id",
"type": "env",
"value": "user_id"
},
{
"name": "debug",
"type": "bool",
"value": "false"
}
]
},
{
"id": "8fa149cd.a14938",
"type": "function",
"z": "8a55823f.f6ad1",
"name": "getSensor",
"func": "try {\n const debug = env.get(\"debug\");\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n const deviceName = env.get(\"device_name\");\n const objectId = env.get(\"object_id\");\n const nativeSensorId = env.get(\"sensor_id\");\n if (!deviceName || !objectId || !nativeSensorId) throw new Error(\"Missing env vars\"); \n const storeKey = `sensor-${deviceName}-${objectId}-${nativeSensorId}`;\n // console.log(\"save sensor storeKey : \", storeKey);\n if(!storeKey) throw new Error(\"Missing params\");\n if (debug) {\n console.log(\"get sensor store_key\", storeKey);\n }\n global.get(storeKey, storeType, (err,res) => {\n if(err) throw err;\n msg.sensor = res;\n }); \n if (!msg.sensor || msg.sensor === null) throw new Error(\"no sensor found\"); \n const userId = env.get(\"user_id\");\n msg.parts = [userId, \"Sensor\", \"HEAD\", msg.sensor.id];\n msg.topic = msg.parts.join(\"/\");\n if (debug) {\n console.log(\"get sensor topic\", msg.topic);\n }\n const resources = Object.keys(msg.sensor.resources);\n if (debug) {\n console.log(\"get sensor resources\", resources);\n }\n resources.forEach(resource => {\n msg.sensor.resource = Number(resource);\n msg.sensor.method = \"HEAD\";\n // msg.payload = msg.sensor.resources[resource];\n node.send(msg);\n });\n return null;\n} catch(error) {\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 290,
"y": 200,
"wires": [
[]
]
},
{
"id": "744e75eb.cf669c",
"type": "subflow",
"name": "set-instance",
"info": "**set-instance**\n\nSet device or sensor from incoming MQTT packet .\n\n`device_name` Name under which sensor or device is saved \n\n`debug` control debug display ( true / false ) \n\n`store_type` How to store instances ( \"memory\" / \"file\" ) \n",
"category": "storage",
"in": [
{
"x": 120,
"y": 220,
"wires": [
{
"id": "c0705021.3ee38"
}
]
}
],
"out": [
{
"x": 780,
"y": 80,
"wires": [
{
"id": "db98c356.1414",
"port": 0
}
]
},
{
"x": 780,
"y": 160,
"wires": [
{
"id": "cc6a3d07.dc47e",
"port": 0
}
]
},
{
"x": 780,
"y": 220,
"wires": [
{
"id": "c0705021.3ee38",
"port": 2
}
]
},
{
"x": 780,
"y": 300,
"wires": [
{
"id": "c0705021.3ee38",
"port": 3
}
]
},
{
"x": 780,
"y": 360,
"wires": [
{
"id": "93a425d1.a5175",
"port": 0
}
]
},
{
"x": 420,
"y": 460,
"wires": [
{
"id": "c0705021.3ee38",
"port": 5
}
]
}
],
"env": [
{
"name": "debug",
"type": "env",
"value": "debug"
},
{
"name": "device_name",
"type": "env",
"value": "device_name"
},
{
"name": "store_type",
"type": "env",
"value": "store_type"
}
],
"outputLabels": [
"device",
"sensor",
"measurement",
"status",
"trigger",
"debug"
],
"icon": "node-red/split.png"
},
{
"id": "c0705021.3ee38",
"type": "function",
"z": "744e75eb.cf669c",
"name": "dispatch-message",
"func": "try {\n if (!msg.topic) throw new Error(\"no msg.topic\");\n if (!msg.parts) {\n msg.parts = msg.topic.split(\"/\");\n }\n const debug = env.get(\"debug\");\n if (msg.device && msg.device !== null) {\n if (debug) {\n const message = {topic: msg.topic, payload : msg.device}\n return [msg, null, null, null, null, message];\n }\n return [msg, null, null, null,null, null];\n } else if (msg.sensor && msg.sensor !== null) {\n if (debug) {\n const message = {topic: msg.topic, payload : msg.sensor}\n return [null, msg, null, null, null, message];\n }\n return [null, msg, null, null, null, null];\n } else if (msg.measurement && msg.measurement !== null) {\n if (debug) {\n const message = {topic: msg.topic, payload : msg.measurement}\n return [null, null, msg, null, null, message];\n }\n return [null, null, msg, null, null, null];\n } else if (msg.status && msg.status !== null) {\n if (debug) {\n const message = {topic: msg.topic, payload : msg.status}\n return [null, null, null, msg, null, message];\n }\n return [null, null,null, msg, null, null];\n } else if (msg.trigger && msg.trigger !== null) {\n if (debug) {\n const message = {topic: msg.topic, payload : msg.trigger}\n return [null, null, null, null, msg, message];\n }\n return [null, null, null, null, msg, null];\n }\n return [null,null, null, null, null, null];\n} catch(error){\n return error;\n}",
"outputs": 6,
"noerr": 0,
"x": 270,
"y": 220,
"wires": [
[
"db98c356.1414"
],
[
"cc6a3d07.dc47e"
],
[],
[],
[
"93a425d1.a5175"
],
[]
],
"outputLabels": [
"device",
"sensor",
"measurement",
"status",
"trigger",
"debug"
]
},
{
"id": "cc6a3d07.dc47e",
"type": "function",
"z": "744e75eb.cf669c",
"name": "save-sensor",
"func": "try {\n const debug = env.get(\"debug\");\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n const deviceName = env.get(\"device_name\");\n if (!deviceName) throw new Error(\"Missing env vars\"); \n const objectId = msg.sensor.type;\n const nativeSensorId = msg.sensor.nativeSensorId;\n const storeKey = `sensor-${deviceName}-${objectId}-${nativeSensorId}`;\n if (debug) {\n console.log(\"save sensor storeKey : \", storeKey)\n }\n if(!storeKey) throw new Error(\"Missing params\");\n global.set(storeKey, msg.sensor, storeType, err => {\n if(err) throw err;\n }); \n return msg;\n} catch(error){\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 160,
"wires": [
[]
]
},
{
"id": "db98c356.1414",
"type": "function",
"z": "744e75eb.cf669c",
"name": "save-device",
"func": "try {\n const debug = env.get(\"debug\");\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n const deviceName = env.get(\"device_name\");\n if (!deviceName) throw new Error(\"Missing env vars\"); \n let devicesList;\n global.get(\"devicesList\", storeType, (err, res) => {\n if (err) throw err;\n devicesList = res;\n });\n if (!devicesList || devicesList === null) {\n devicesList = [];\n }\n const index = devicesList.indexOf(deviceName);\n if (debug) {\n console.log(\"save device, index\", deviceName, index)\n }\n if (index === -1) {\n devicesList.push(deviceName);\n global.set(\"devicesList\", devicesList, \"memoryOnly\", err => {\n if (err) throw err;\n });\n }\n if (debug) {\n console.log(\"update devices list\", devicesList)\n }\n const storeKey = `device-${deviceName}`;\n // console.log(\"saveDevice storeKey : \", storeKey);\n if(!storeKey) throw new Error(\"Missing params\");\n global.set(storeKey, msg.device, storeType, err => {\n if(err) throw err;\n }); \n return msg;\n} catch(error){\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 80,
"wires": [
[]
]
},
{
"id": "93a425d1.a5175",
"type": "function",
"z": "744e75eb.cf669c",
"name": "dispatch-trigger",
"func": "if (!msg.deviceName) return null;\nconst deviceName = env.get(\"device_name\");\nif (msg.deviceName === deviceName) {\n // console.log(\"trigger device\", deviceName);\n return msg;\n}\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 580,
"y": 360,
"wires": [
[]
]
},
{
"id": "1e283bd5.9de3d4",
"type": "subflow",
"name": "snips-agent-logic",
"info": "",
"category": "snips",
"in": [
{
"x": 120,
"y": 160,
"wires": [
{
"id": "aca2f63.b64e908"
}
]
}
],
"out": [
{
"x": 1060,
"y": 160,
"wires": [
{
"id": "3610fc8e.598594",
"port": 0
}
]
},
{
"x": 880,
"y": 520,
"wires": [
{
"id": "851d8e62.32145",
"port": 0
}
]
},
{
"x": 880,
"y": 580,
"wires": [
{
"id": "851d8e62.32145",
"port": 1
}
]
},
{
"x": 880,
"y": 640,
"wires": [
{
"id": "37b7e0e5.64a858",
"port": 0
}
]
},
{
"x": 880,
"y": 700,
"wires": [
{
"id": "37b7e0e5.64a858",
"port": 1
}
]
},
{
"x": 880,
"y": 780,
"wires": [
{
"id": "2e3de84a.2b1fb",
"port": 0
}
]
}
],
"env": [
{
"name": "debug",
"type": "bool",
"value": "false"
},
{
"name": "device_id",
"type": "env",
"value": "device_id"
},
{
"name": "device_name",
"type": "env",
"value": "device_name"
},
{
"name": "user_id",
"type": "env",
"value": "user_id"
},
{
"name": "store_type",
"type": "env",
"value": "store_type"
}
],
"outputLabels": [
"device-properties",
"*/3306/*/5850",
"*/3306/*/5851",
"*/3339/*/5522",
"*/3339/*/5523",
"*/3341/*/5527"
],
"icon": "node-red/batch.png"
},
{
"id": "c8c91af3.aa8098",
"type": "comment",
"z": "1e283bd5.9de3d4",
"name": "FLOW INPUT",
"info": "",
"x": 170,
"y": 40,
"wires": []
},
{
"id": "4df1306e.d42328",
"type": "switch",
"z": "1e283bd5.9de3d4",
"name": "objectId",
"property": "sensor.type",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "3306",
"vt": "num"
},
{
"t": "eq",
"v": "3339",
"vt": "num"
},
{
"t": "eq",
"v": "3341",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 3,
"x": 400,
"y": 560,
"wires": [
[
"851d8e62.32145"
],
[
"37b7e0e5.64a858"
],
[
"2e3de84a.2b1fb"
]
]
},
{
"id": "2e3de84a.2b1fb",
"type": "switch",
"z": "1e283bd5.9de3d4",
"name": "3341-resourceId",
"property": "sensor.resource",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "5527",
"vt": "num"
},
{
"t": "eq",
"v": "5851",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 630,
"y": 780,
"wires": [
[],
[]
]
},
{
"id": "851d8e62.32145",
"type": "switch",
"z": "1e283bd5.9de3d4",
"name": "3306-resourceId",
"property": "sensor.resource",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "5850",
"vt": "num"
},
{
"t": "eq",
"v": "5851",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 630,
"y": 540,
"wires": [
[],
[]
]
},
{
"id": "3d3aea88.ed3a36",
"type": "debug",
"z": "1e283bd5.9de3d4",
"name": "${device_name}",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 260,
"y": 240,
"wires": []
},
{
"id": "aca2f63.b64e908",
"type": "subflow:744e75eb.cf669c",
"z": "1e283bd5.9de3d4",
"name": "",
"env": [],
"x": 270,
"y": 160,
"wires": [
[
"a5cbd61.d2cb1a8"
],
[
"896dd7c3.fdd108"
],
[],
[],
[
"c68b3f18.047938"
],
[
"3d3aea88.ed3a36"
]
]
},
{
"id": "896dd7c3.fdd108",
"type": "link out",
"z": "1e283bd5.9de3d4",
"name": "filter-sensors->",
"links": [
"645222b2.ca0aa4"
],
"x": 495,
"y": 120,
"wires": []
},
{
"id": "cb6b2292.25c9f",
"type": "link out",
"z": "1e283bd5.9de3d4",
"name": "filter-sensors->",
"links": [
"645222b2.ca0aa4"
],
"x": 495,
"y": 1520,
"wires": []
},
{
"id": "2531cf7f.962a8",
"type": "inject",
"z": "1e283bd5.9de3d4",
"name": "refreshViews",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "60",
"crontab": "",
"once": true,
"onceDelay": "30",
"x": 180,
"y": 1360,
"wires": [
[]
]
},
{
"id": "9f736f91.9bac08",
"type": "comment",
"z": "1e283bd5.9de3d4",
"name": "Refresh interfaces",
"info": "",
"x": 190,
"y": 1280,
"wires": []
},
{
"id": "3986218b.8ffb7e",
"type": "subflow:8a55823f.f6ad1",
"z": "1e283bd5.9de3d4",
"name": "get-sensor-3306-1",
"env": [
{
"name": "object_id",
"type": "str",
"value": "3306"
}
],
"x": 290,
"y": 1520,
"wires": [
[
"cb6b2292.25c9f"
]
]
},
{
"id": "61dbe671.bc35",
"type": "subflow:8a55823f.f6ad1",
"z": "1e283bd5.9de3d4",
"name": "get-sensor-3306-2",
"env": [
{
"name": "object_id",
"type": "str",
"value": "3306"
},
{
"name": "sensor_id",
"type": "str",
"value": "2"
}
],
"x": 290,
"y": 1580,
"wires": [
[
"cb6b2292.25c9f"
]
]
},
{
"id": "645222b2.ca0aa4",
"type": "link in",
"z": "1e283bd5.9de3d4",
"name": "->filter-sensors",
"links": [
"896dd7c3.fdd108",
"cb6b2292.25c9f"
],
"x": 115,
"y": 560,
"wires": [
[
"fb1cc403.634f4"
]
]
},
{
"id": "fbe4c467.533b08",
"type": "comment",
"z": "1e283bd5.9de3d4",
"name": "FLOW OUTPUT",
"info": "",
"x": 980,
"y": 60,
"wires": []
},
{
"id": "3610fc8e.598594",
"type": "link in",
"z": "1e283bd5.9de3d4",
"name": "subflow-output->",
"links": [
"a5cbd61.d2cb1a8",
"1369aa55.a1e876"
],
"x": 920,
"y": 160,
"wires": [
[]
]
},
{
"id": "6c212846.f55758",
"type": "comment",
"z": "1e283bd5.9de3d4",
"name": "Filter sensor properties",
"info": "",
"x": 200,
"y": 400,
"wires": []
},
{
"id": "a5cbd61.d2cb1a8",
"type": "link out",
"z": "1e283bd5.9de3d4",
"name": "filter-device->",
"links": [
"3610fc8e.598594"
],
"x": 495,
"y": 80,
"wires": []
},
{
"id": "7f9c6e7e.e9c42",
"type": "comment",
"z": "1e283bd5.9de3d4",
"name": "Filter trigger properties",
"info": "",
"x": 200,
"y": 1040,
"wires": []
},
{
"id": "c68b3f18.047938",
"type": "link out",
"z": "1e283bd5.9de3d4",
"name": "filter-triggers->",
"links": [
"86217279.d978c"
],
"x": 495,
"y": 220,
"wires": []
},
{
"id": "86217279.d978c",
"type": "link in",
"z": "1e283bd5.9de3d4",
"name": "->filter-triggers",
"links": [
"c68b3f18.047938"
],
"x": 115,
"y": 1120,
"wires": [
[
"1d627ab4.3a3aa5"
]
]
},
{
"id": "3b62b6a6.b17192",
"type": "subflow:d253d97e.e3e448",
"z": "1e283bd5.9de3d4",
"name": "",
"env": [],
"x": 270,
"y": 1460,
"wires": [
[
"1369aa55.a1e876"
]
]
},
{
"id": "1369aa55.a1e876",
"type": "link out",
"z": "1e283bd5.9de3d4",
"name": "filter-device->",
"links": [
"3610fc8e.598594"
],
"x": 495,
"y": 1460,
"wires": []
},
{
"id": "6823f15c.458a88",
"type": "link in",
"z": "1e283bd5.9de3d4",
"name": "->trigger-refresh-sensors",
"links": [
"1d0d408c.740797"
],
"x": 115,
"y": 1520,
"wires": [
[
"3986218b.8ffb7e",
"61dbe671.bc35"
]
]
},
{
"id": "1d627ab4.3a3aa5",
"type": "switch",
"z": "1e283bd5.9de3d4",
"name": "Command",
"property": "trigger",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "refresh",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 1,
"x": 310,
"y": 1120,
"wires": [
[
"91e573fb.63d91"
]
]
},
{
"id": "91e573fb.63d91",
"type": "switch",
"z": "1e283bd5.9de3d4",
"name": "Collection",
"property": "collection",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "sensor",
"vt": "str"
},
{
"t": "eq",
"v": "device",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 540,
"y": 1120,
"wires": [
[
"1d0d408c.740797"
],
[
"8742ac8e.019fd"
]
]
},
{
"id": "1d0d408c.740797",
"type": "link out",
"z": "1e283bd5.9de3d4",
"name": "trigger-refresh-sensor->",
"links": [
"6823f15c.458a88"
],
"x": 795,
"y": 1080,
"wires": []
},
{
"id": "8742ac8e.019fd",
"type": "link out",
"z": "1e283bd5.9de3d4",
"name": "trigger-refresh-device->",
"links": [
"36750aea.ac8576"
],
"x": 795,
"y": 1160,
"wires": []
},
{
"id": "36750aea.ac8576",
"type": "link in",
"z": "1e283bd5.9de3d4",
"name": "->trigger-refresh-device",
"links": [
"8742ac8e.019fd"
],
"x": 115,
"y": 1460,
"wires": [
[
"3b62b6a6.b17192"
]
]
},
{
"id": "fb1cc403.634f4",
"type": "change",
"z": "1e283bd5.9de3d4",
"name": "",
"rules": [
{
"t": "set",
"p": "method",
"pt": "msg",
"to": "parts[2]",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 240,
"y": 560,
"wires": [
[
"4df1306e.d42328"
]
]
},
{
"id": "37b7e0e5.64a858",
"type": "switch",
"z": "1e283bd5.9de3d4",
"name": "3339-resourceId",
"property": "sensor.resource",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "5522",
"vt": "num"
},
{
"t": "eq",
"v": "5523",
"vt": "num"
},
{
"t": "eq",
"v": "5524",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 3,
"x": 630,
"y": 660,
"wires": [
[],
[],
[]
]
},
{
"id": "8ff67ce6.9014f",
"type": "subflow",
"name": "set-custom-btn",
"info": "",
"category": "",
"in": [
{
"x": 220,
"y": 160,
"wires": [
{
"id": "7234cf4c.dc519"
}
]
}
],
"out": [
{
"x": 460,
"y": 160,
"wires": [
{
"id": "7234cf4c.dc519",
"port": 0
}
]
}
],
"env": [
{
"name": "label_true",
"type": "str",
"value": ""
},
{
"name": "tooltip_true",
"type": "str",
"value": ""
},
{
"name": "topic_true",
"type": "str",
"value": ""
},
{
"name": "payload_true",
"type": "str",
"value": ""
},
{
"name": "color_true",
"type": "str",
"value": ""
},
{
"name": "bg_color_true",
"type": "str",
"value": ""
},
{
"name": "label_false",
"type": "str",
"value": ""
},
{
"name": "tooltip_false",
"type": "str",
"value": ""
},
{
"name": "topic_false",
"type": "str",
"value": ""
},
{
"name": "payload_false",
"type": "str",
"value": ""
},
{
"name": "color_false",
"type": "str",
"value": ""
},
{
"name": "bg_color_false",
"type": "str",
"value": ""
}
]
},
{
"id": "7234cf4c.dc519",
"type": "function",
"z": "8ff67ce6.9014f",
"name": "",
"func": "try {\n if (msg.payload === true || msg.payload === \"true\") {\n msg.label = env.get(\"label_true\") || \"Remove\";\n msg.tooltip = env.get(\"tooltip_true\") || \"Remove from device selection\";\n msg.topic = env.get(\"topic_true\") || \"DELETE/devicesSelection\";\n msg.payload = env.get(\"payload_true\") || true;\n } else if (msg.payload === false || msg.payload === \"false\") {\n msg.payload = env.get(\"payload_false\") || false;\n msg.label = env.get(\"label_false\") || \"Add\";\n msg.tooltip = env.get(\"tooltip_false\") || \"Add to device selection\";\n msg.topic = env.get(\"topic_false\") || \"POST/devicesSelection\"; \n } else {\n msg.enabled = false;\n }\n return msg;\n} catch(error) {\n return error;\n}",
"outputs": 1,
"noerr": 0,
"x": 350,
"y": 160,
"wires": [
[]
]
},
{
"id": "32f8e46a.971f8c",
"type": "subflow",
"name": "select-device-update",
"info": "",
"category": "",
"in": [
{
"x": 340,
"y": 300,
"wires": [
{
"id": "9191679b.289108"
}
]
}
],
"out": [
{
"x": 580,
"y": 300,
"wires": [
{
"id": "9191679b.289108",
"port": 0
}
]
}
],
"env": [
{
"name": "device_name",
"type": "env",
"value": "device_name"
},
{
"name": "store_type",
"type": "env",
"value": "store_type"
},
{
"name": "debug",
"type": "bool",
"value": "false"
}
]
},
{
"id": "9191679b.289108",
"type": "function",
"z": "32f8e46a.971f8c",
"name": "",
"func": "try {\n const debug = env.get(\"debug\");\n const deviceName = env.get(\"device_name\");\n if (!deviceName) throw new Error(\"no device name env\");\n const storeType = env.get(\"store_type\") || \"file\";\n let selection;\n \n global.get(\"devicesSelection\", storeType, (err,res) => {\n if (err) throw err;\n selection = res || [];\n });\n if (msg.payload === false) {\n const index = selection.indexOf(deviceName);\n if (index > -1) {\n selection.splice(index, 1);\n global.set(\"devicesSelection\", selection, storeType, err => {\n if (err) throw err;\n });\n }\n } else if (msg.payload === true) {\n const index = selection.indexOf(deviceName);\n if (index === -1) {\n selection.push(deviceName);\n global.set(\"devicesSelection\", selection, storeType, err => {\n if (err) throw err;\n });\n }\n }\n if (debug) {\n console.log(\"update device selection\", selection);\n }\n // msg.payload = selection;\n return msg;\n} catch(error) {\n return error;\n}",
"outputs": 1,
"noerr": 0,
"x": 470,
"y": 300,
"wires": [
[]
]
},
{
"id": "de56f8d.072c908",
"type": "subflow",
"name": "set-topic",
"info": "",
"category": "function",
"in": [
{
"x": 260,
"y": 160,
"wires": [
{
"id": "134d435d.20bced"
}
]
}
],
"out": [
{
"x": 600,
"y": 160,
"wires": [
{
"id": "134d435d.20bced",
"port": 0
}
]
}
],
"env": [
{
"name": "collection",
"type": "str",
"value": "sensor"
},
{
"name": "method",
"type": "str",
"value": "HEAD"
},
{
"name": "sensor_id",
"type": "str",
"value": "1"
},
{
"name": "object_id",
"type": "str",
"value": "3300"
},
{
"name": "resource_id",
"type": "str",
"value": "5700"
},
{
"name": "user_id",
"type": "env",
"value": "user_id"
},
{
"name": "save_instance",
"type": "bool",
"value": "false"
},
{
"name": "debug",
"type": "bool",
"value": "false"
}
]
},
{
"id": "134d435d.20bced",
"type": "function",
"z": "de56f8d.072c908",
"name": "setTopic",
"func": "try {\n const debug = env.get(\"debug\");\n const userId = env.get(\"user_id\");\n const save = env.get(\"save_instance\");\n if (!userId ) throw new Error(\"Missing params\"); \n if (save) {\n msg.save = save;\n }\n if (debug) {\n console.log(\"get-topic\", msg.topic, msg.save)\n }\n if (!msg.sensor) {\n const method = env.get(\"method\") || \"HEAD\";\n const collection = env.get(\"collection\") || \"sensor\";\n const objectId = env.get(\"object_id\") || \"3300\";\n const instanceId = env.get(\"sensor_id\");\n const resourceId = env.get(\"resource_id\");\n msg.topic = `${method}/${collection}/${objectId}/${instanceId}/${resourceId}`;\n if (debug) {\n console.log(\"set-topic from empty\", msg.topic)\n }\n return msg;\n } else if (msg.sensor && msg.sensor.method && msg.sensor.method === \"HEAD\") {\n if (debug) {\n console.log(\"get-topic\", msg.sensor.method)\n }\n return null;\n } else if (msg.topic.startsWith(userId) && msg.parts) {\n const method = msg.parts[2];\n const collection = msg.parts[1].toLowerCase();\n const objectId = msg.sensor.type;\n const instanceId = msg.sensor.nativeSensorId;\n const resourceId = msg.sensor.resource;\n msg.topic = `${method}/${collection}/${objectId}/${instanceId}/${resourceId}`;\n if (debug) {\n console.log(\"set-topic from existing\", msg.topic)\n }\n return msg;\n }\n return null;\n} catch(error) {\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 420,
"y": 160,
"wires": [
[]
]
},
{
"id": "1e071b74.a346dd",
"type": "subflow",
"name": "set-boolean",
"info": "",
"category": "function",
"in": [
{
"x": 380,
"y": 120,
"wires": [
{
"id": "756683ff.5394ac"
}
]
}
],
"out": [
{
"x": 740,
"y": 120,
"wires": [
{
"id": "756683ff.5394ac",
"port": 0
}
]
}
],
"env": [
{
"name": "resource_id",
"type": "str",
"value": ""
},
{
"name": "debug",
"type": "bool",
"value": "false"
}
],
"icon": "font-awesome/fa-check"
},
{
"id": "756683ff.5394ac",
"type": "function",
"z": "1e071b74.a346dd",
"name": "setBoolean",
"func": "try {\n const debug = env.get(\"debug\");\n if (!msg || msg === null || !msg.sensor) throw new Error(\"No input to parse\");\n const resourceId = env.get(\"resource_id\");\n if (!resourceId) throw new Error(\"no resource id set\")\n const value = msg.sensor.resources[resourceId];\n // const value = msg.sensor.value;\n if (debug) {\n console.log(`get-boolean for ${resourceId} : ${typeof value}`)\n }\n if (typeof value === \"string\") {\n msg.payload = value; \n } else if (typeof value === \"number\") {\n msg.payload = value.toString(); \n } else if (typeof value === \"boolean\") {\n msg.payload = value; \n } else if (typeof value === \"object\" && value.type && value.data){\n // msg.payload = value.data.toString('utf-8');\n msg.payload = Buffer.from(value.data).toString('utf-8');\n } else if (Buffer.isBuffer(value)){\n msg.payload = value.toString('utf-8');\n } else if (value instanceof Array) {\n msg.payload = Buffer.from(value).toString('utf-8');\n } else {\n throw new Error(\"No value found\")\n }\n if (msg.payload === \"true\" || msg.payload === \"1\" || msg.payload === 1) {\n msg.payload = true;\n } else if (msg.payload === \"false\" || msg.payload === \"0\" || msg.payload === 0) {\n msg.payload = false;\n }\n if (debug) {\n console.log(`set-boolean for ${resourceId} : ${msg.payload}`)\n }\n return msg;\n} catch(error) {\n return error;\n}",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 120,
"wires": [
[]
]
},
{
"id": "2188cc9a.23fde4",
"type": "subflow",
"name": "update-instance",
"info": "**update-instance**\n\nFind and update device or sensor from incoming msg.topic.\n\nValidate payload before publishing via MQTT.\n\n`user_id` aloes user id ( default : set from `ALOES_USER_ID` )\n\n`device_name` Name under which sensor or device is saved \n\n`debug` control debug display ( true / false ) \n\n`store_type` How to store instances ( \"memory\" / \"file\" ) \n",
"category": "storage",
"in": [
{
"x": 100,
"y": 220,
"wires": [
{
"id": "200e493e.d70e76"
}
]
}
],
"out": [
{
"x": 820,
"y": 220,
"wires": [
{
"id": "575059b0.8d7a2",
"port": 0
}
]
}
],
"env": [
{
"name": "debug",
"type": "bool",
"value": "false"
},
{
"name": "store_type",
"type": "env",
"value": ""
},
{
"name": "user_id",
"type": "env",
"value": ""
},
{
"name": "device_name",
"type": "str",
"value": ""
},
{
"name": "print_debug",
"type": "bool",
"value": "false"
}
],
"icon": "node-red/split.png"
},
{
"id": "200e493e.d70e76",
"type": "function",
"z": "2188cc9a.23fde4",
"name": "find-instance",
"func": "try {\n // pattern : POST/sensor/3339/3/5523\n if (msg.topic) {\n const t = msg.topic.split(\"/\");\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n const deviceName = env.get(\"device_name\") || t[0];\n const debug = env.get(\"debug\");\n const userId = env.get(\"user_id\");\n if (debug) {\n console.log(\"instance payload: \", deviceName, msg.topic, msg.payload);\n }\n if (msg.payload === undefined) throw new Error(\"Missing payload\"); \n if (!userId || !deviceName) throw new Error(\"Missing env vars\"); \n const method = t[0];\n const collection = t[1].toLowerCase();\n const objectId = t[2];\n const nativeSensorId = t[3];\n const resourceId = t[4];\n const collectionName = `${collection.charAt(0).toUpperCase()}${collection.slice(1)}`;\n\n if (debug) {\n console.log(\"instance topic: \", method, collectionName, objectId);\n }\n\n let storeKey;\n if (collection === \"sensor\" && objectId && nativeSensorId) {\n storeKey = `sensor-${deviceName}-${objectId}-${nativeSensorId}`;\n } else if (collection === \"device\") {\n storeKey = `device-${deviceName}`;\n }\n if (debug) {\n console.log(\"findInstance storeKey : \", storeKey);\n }\n if(!storeKey) throw new Error(\"Missing params\");\n let instance;\n global.get(storeKey, storeType, (err, res) => {\n if(err) throw err;\n instance = res;\n // return instance;\n }); \n if (!instance) throw new Error('No instance found');\n if (debug) {\n console.log(\"foundInstance: \", instance.name);\n }\n if (method === \"POST\") {\n msg.topic = `${userId}/${collectionName}/${method}`;\n } else {\n msg.topic = `${userId}/${collectionName}/${method}/${instance.id}`;\n }\n // msg.topic = `${userId}/IoTAgent/${method}/${instance.id}`;\n\n msg[collection] = instance;\n msg.value = msg.payload;\n msg.resource = resourceId;\n msg.method = method;\n msg.attribute = objectId;\n msg.deviceName = deviceName;\n if (debug) {\n console.log(\"instance params: \", msg.topic, msg.resource);\n }\n return msg;\n }\n throw new Error(\"Missing params\");\n} catch(error){\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 250,
"y": 220,
"wires": [
[
"4c607fd0.a70968"
]
]
},
{
"id": "4c607fd0.a70968",
"type": "function",
"z": "2188cc9a.23fde4",
"name": "update-instance",
"func": "try {\n const debug = env.get(\"debug\");\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n // console.log(\"resource : \", msg.resource);\n // if (msg.payload === undefined) throw new Error(\"undefined sensor value\");\n if (msg.device) {\n msg.payload = msg.device;\n }\n if (msg.sensor && msg.resource) {\n let updater; \n global.get(\"aloesHandlers\", storeType, (err,res) => {\n if (err) throw err;\n updater = res.updateAloesSensors;\n });\n if (!updater) throw new Error(\"Can't import Aloes Handlers\");\n if (debug) {\n console.log(\"updateInstance value type: \", typeof msg.payload);\n }\n const sensor = updater(msg.sensor, Number(msg.resource), msg.payload);\n if (!sensor || sensor === null ) throw new Error(\"Error while updating sensor\");\n if (debug) {\n console.log(\"updateInstance : \", sensor.name, sensor.resource);\n }\n sensor.method = msg.method;\n msg.payload = sensor;\n if (msg instanceof Error) {\n console.log(\"updateInstance Error : \",msg)\n }\n if (debug) {\n return [msg, msg];\n }\n\n return [msg,null];\n // return msg;\n }\n throw new Error(\"no sensor instance\");\n} catch(error){\n return error;\n}\n",
"outputs": 2,
"noerr": 0,
"x": 420,
"y": 220,
"wires": [
[
"575059b0.8d7a2"
],
[
"8c068de2.ed7d48"
]
]
},
{
"id": "8c068de2.ed7d48",
"type": "debug",
"z": "2188cc9a.23fde4",
"name": "updateInstance",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 560,
"y": 280,
"wires": []
},
{
"id": "575059b0.8d7a2",
"type": "function",
"z": "2188cc9a.23fde4",
"name": "print-debug",
"func": "try {\n if (env.get(\"print_debug\")) {\n const d = new Date();\n const filename = './log/game.log';\n let payload;\n if (msg.sensor) {\n payload = `${d.toLocaleString()}-update sensor-${msg.deviceName}-${msg.sensor.nativeSensorId}-${msg.sensor.resource}`;\n delete msg.sensor;\n } else if (msg.device) {\n payload = `${d.toLocaleString()}-update device-${msg.deviceName}`;\n delete msg.device;\n }\n const message = {payload, filename};\n console.log(\"print debug : \", message);\n delete msg.deviceName;\n delete msg.collection\n return [msg, message];\n }\n if (msg.sensor) {\n delete msg.sensor;\n } else if (msg.device) {\n delete msg.device;\n }\n delete msg.deviceName;\n return msg;\n} catch(error) {\n return error;\n}\n",
"outputs": 2,
"noerr": 0,
"x": 610,
"y": 220,
"wires": [
[],
[
"de459056.eb403"
]
]
},
{
"id": "de459056.eb403",
"type": "file",
"z": "2188cc9a.23fde4",
"name": "",
"filename": "",
"appendNewline": true,
"createDir": true,
"overwriteFile": "false",
"encoding": "none",
"x": 820,
"y": 300,
"wires": [
[]
]
},
{
"id": "7333a36d.5a2e54",
"type": "subflow",
"name": "snips-agent-1",
"info": "",
"category": "snips",
"in": [
{
"x": 120,
"y": 280,
"wires": [
{
"id": "e058d4da.f45a48"
}
]
}
],
"out": [
{
"x": 1100,
"y": 160,
"wires": [
{
"id": "d770046e.348668",
"port": 0
}
]
}
],
"env": [
{
"name": "debug",
"type": "bool",
"value": "false"
},
{
"name": "device_id",
"type": "str",
"value": ""
},
{
"name": "device_name",
"type": "str",
"value": ""
},
{
"name": "user_id",
"type": "env",
"value": "ALOES_USER_ID"
},
{
"name": "store_type",
"type": "env",
"value": "NODE_RED_STORE_TYPE"
}
],
"icon": "font-awesome/fa-desktop"
},
{
"id": "4714132a.9a04c4",
"type": "subflow:2188cc9a.23fde4",
"z": "7333a36d.5a2e54",
"name": "",
"env": [
{
"name": "store_type",
"type": "env",
"value": "store_type"
},
{
"name": "user_id",
"type": "env",
"value": "user_id"
},
{
"name": "device_name",
"type": "env",
"value": "device_name"
}
],
"x": 1100,
"y": 960,
"wires": [
[
"ab183e8b.dc42f8"
]
]
},
{
"id": "ab183e8b.dc42f8",
"type": "link out",
"z": "7333a36d.5a2e54",
"name": "updated-instance->",
"links": [
"d770046e.348668"
],
"x": 1235,
"y": 960,
"wires": []
},
{
"id": "d770046e.348668",
"type": "link in",
"z": "7333a36d.5a2e54",
"name": "subflow-out->",
"links": [
"b20487ea.7a6268",
"ab183e8b.dc42f8"
],
"x": 955,
"y": 160,
"wires": [
[]
]
},
{
"id": "7705e317.278cbc",
"type": "link in",
"z": "7333a36d.5a2e54",
"name": "SWITCH/3306/1/5850",
"links": [
"457ba71a.879be8"
],
"x": 115,
"y": 960,
"wires": [
[
"c3dbf65d.d0f7f8"
]
]
},
{
"id": "59746cff.806a7c",
"type": "subflow:1e071b74.a346dd",
"z": "7333a36d.5a2e54",
"name": "",
"env": [
{
"name": "resource_id",
"type": "str",
"value": "5850"
}
],
"x": 390,
"y": 960,
"wires": [
[
"27b55d4e.81133a"
]
]
},
{
"id": "658f3785.e77e",
"type": "subflow:de56f8d.072c908",
"z": "7333a36d.5a2e54",
"name": "",
"env": [
{
"name": "method",
"type": "str",
"value": "PUT"
},
{
"name": "object_id",
"type": "str",
"value": "3306"
},
{
"name": "resource_id",
"type": "str",
"value": "5850"
}
],
"x": 880,
"y": 960,
"wires": [
[
"4714132a.9a04c4"
]
]
},
{
"id": "8a546cba.03e33",
"type": "comment",
"z": "7333a36d.5a2e54",
"name": "FLOW INPUT",
"info": "",
"x": 170,
"y": 60,
"wires": []
},
{
"id": "38492cf3.3b32dc",
"type": "comment",
"z": "7333a36d.5a2e54",
"name": "FLOW OUPUT",
"info": "",
"x": 1020,
"y": 60,
"wires": []
},
{
"id": "ca2808f9.91a8d8",
"type": "link in",
"z": "7333a36d.5a2e54",
"name": "->filter-device",
"links": [
"a3d7d599.4b06d8"
],
"x": 115,
"y": 680,
"wires": [
[
"790e6871.aec21",
"8e3316c7.d8d6d",
"7f502a69.c6b1cc"
]
]
},
{
"id": "790e6871.aec21",
"type": "change",
"z": "7333a36d.5a2e54",
"name": "devicesSelection",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "#:(file)::devicesSelection",
"tot": "global"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 290,
"y": 680,
"wires": [
[
"75ca98f8.6fb928"
]
]
},
{
"id": "4040e47a.7e887c",
"type": "ui_switch",
"z": "7333a36d.5a2e54",
"name": "snips-agent-1-selection",
"label": "{{msg.label}}",
"tooltip": "{{msg.tooltip}}",
"group": "18dbcafd.0bd0d5",
"order": 12,
"width": "3",
"height": "1",
"passthru": false,
"decouple": "true",
"topic": "",
"style": "",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"x": 950,
"y": 680,
"wires": [
[
"93d14dfb.8a01c8"
]
]
},
{
"id": "8e3316c7.d8d6d",
"type": "ui_template",
"z": "7333a36d.5a2e54",
"group": "18dbcafd.0bd0d5",
"name": "snips-agent-1-status",
"order": 11,
"width": "6",
"height": "1",
"format": "<!DOCTYPE html>\n<svg viewBox=\"0 0 270 40\" id=\"{{'devices-status-'+ $id}}\">\n <text x=\"0\" y=\"25\" style=\"{{'font-weight:700'}}\" >{{$deviceName}}</text>\n <image\n id=\"{{'device-icon-'+$id}}\" \n x=\"200\"\n y=\"2\"\n width=\"35px\" \n height=\"35px\"\n preserveAspectRatio=\"xMidYMin slice\"\n xlink:href=\"{{ $getImageUrl() }}\"></image>\n <circle id=\"{{'devices-status-icon-'+$id}}\" x=\"0\" y=\"0\" cx=\"265\" cy=\"20\" r=\"15\" fill=\"{{$statusColor}}\" ></circle>\n</svg>\n<script>\n(function(scope) {\n scope.$watch('msg', (msg) => {\n try{\n scope.$statusText = \"Waiting\";\n scope.$deviceName = \"\";\n scope.$statusColor = \"#ff4500\";\n scope.$getImageUrl = () => {\n const icon = scope.$deviceIcon || \"\";\n return icon;\n }\n if (msg && msg.device) {\n scope.$deviceName = msg.device.name;\n scope.$deviceIcon = msg.device.icons[0];\n if (msg && (msg.device.status === true || msg.device.status === \"true\")) {\n scope.$statusColor = \"#baff00\";\n scope.$statusText = \"Ready\";\n }\n }\n // return msg;\n } catch(error){\n return error;\n }\n \n });\n})(scope);\n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"templateScope": "local",
"x": 300,
"y": 720,
"wires": [
[]
]
},
{
"id": "93d14dfb.8a01c8",
"type": "subflow:32f8e46a.971f8c",
"z": "7333a36d.5a2e54",
"name": "",
"env": [
{
"name": "store_type",
"type": "str",
"value": "file"
}
],
"x": 1200,
"y": 680,
"wires": [
[
"7a0cd6f5.7cd788"
]
]
},
{
"id": "7a0cd6f5.7cd788",
"type": "subflow:8ff67ce6.9014f",
"z": "7333a36d.5a2e54",
"name": "",
"env": [
{
"name": "label_true",
"type": "str",
"value": "Remove"
},
{
"name": "tooltip_true",
"type": "str",
"value": "Remove from device selection"
},
{
"name": "topic_true",
"type": "str",
"value": "DELETE/devicesSelection"
},
{
"name": "payload_true",
"type": "bool",
"value": "true"
},
{
"name": "label_false",
"type": "str",
"value": "Add"
},
{
"name": "tooltip_false",
"type": "str",
"value": "Add to device selection"
},
{
"name": "topic_false",
"type": "str",
"value": "POST/devicesSelection"
},
{
"name": "payload_false",
"type": "bool",
"value": "false"
}
],
"x": 720,
"y": 680,
"wires": [
[
"4040e47a.7e887c"
]
]
},
{
"id": "e65888e0.b049a8",
"type": "comment",
"z": "7333a36d.5a2e54",
"name": "Sensor properties",
"info": "",
"x": 190,
"y": 860,
"wires": []
},
{
"id": "c73be9ec.f0ee4",
"type": "comment",
"z": "7333a36d.5a2e54",
"name": "Device properties",
"info": "",
"x": 190,
"y": 620,
"wires": []
},
{
"id": "701d2d48.eb893c",
"type": "comment",
"z": "7333a36d.5a2e54",
"name": "Scenario",
"info": "",
"x": 160,
"y": 1340,
"wires": []
},
{
"id": "b20487ea.7a6268",
"type": "link out",
"z": "7333a36d.5a2e54",
"name": "updated-instance->",
"links": [
"d770046e.348668"
],
"x": 1355,
"y": 1420,
"wires": []
},
{
"id": "a3d7d599.4b06d8",
"type": "link out",
"z": "7333a36d.5a2e54",
"name": "device-properties->",
"links": [
"ca2808f9.91a8d8"
],
"x": 435,
"y": 160,
"wires": []
},
{
"id": "c3dbf65d.d0f7f8",
"type": "switch",
"z": "7333a36d.5a2e54",
"name": "Method",
"property": "method",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "POST",
"vt": "str"
},
{
"t": "eq",
"v": "PUT",
"vt": "str"
},
{
"t": "eq",
"v": "GET",
"vt": "str"
},
{
"t": "eq",
"v": "HEAD",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 4,
"x": 220,
"y": 960,
"wires": [
[
"59746cff.806a7c"
],
[
"59746cff.806a7c"
],
[],
[
"59746cff.806a7c"
]
]
},
{
"id": "db8dc8a4.e8e3f8",
"type": "link out",
"z": "7333a36d.5a2e54",
"name": "*/3306/2/5850",
"links": [
"a9270ffa.d5f258"
],
"x": 855,
"y": 240,
"wires": []
},
{
"id": "457ba71a.879be8",
"type": "link out",
"z": "7333a36d.5a2e54",
"name": "*/3306/1/5850",
"links": [
"7705e317.278cbc"
],
"x": 855,
"y": 200,
"wires": []
},
{
"id": "97f7bbee.17e24",
"type": "link in",
"z": "7333a36d.5a2e54",
"name": "3341/4/5527->",
"links": [
"3a1ec4f9.99718c"
],
"x": 115,
"y": 1480,
"wires": [
[
"f0b880c3.524d2"
]
]
},
{
"id": "c47bc910.ad3e98",
"type": "subflow:2188cc9a.23fde4",
"z": "7333a36d.5a2e54",
"name": "",
"env": [
{
"name": "store_type",
"type": "env",
"value": "store_type"
},
{
"name": "user_id",
"type": "env",
"value": "user_id"
},
{
"name": "device_name",
"type": "env",
"value": "device_name"
}
],
"x": 1200,
"y": 1420,
"wires": [
[
"b20487ea.7a6268"
]
]
},
{
"id": "27b55d4e.81133a",
"type": "ui_button",
"z": "7333a36d.5a2e54",
"name": "PUT/sensor/3306/1/5850",
"group": "6ab73aae.f2f7dc",
"order": 2,
"width": "6",
"height": "1",
"passthru": false,
"label": "Reset sequence",
"tooltip": "Reset recording sequence",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "true",
"payloadType": "bool",
"topic": "",
"x": 630,
"y": 960,
"wires": [
[
"658f3785.e77e"
]
]
},
{
"id": "a9270ffa.d5f258",
"type": "link in",
"z": "7333a36d.5a2e54",
"name": "SWITCH/3306/2/5850",
"links": [
"db8dc8a4.e8e3f8"
],
"x": 115,
"y": 1060,
"wires": [
[
"8582bcf6.7eba5"
]
]
},
{
"id": "2bb815a3.d04202",
"type": "subflow:1e071b74.a346dd",
"z": "7333a36d.5a2e54",
"name": "",
"env": [
{
"name": "resource_id",
"type": "str",
"value": "5850"
}
],
"x": 390,
"y": 1060,
"wires": [
[
"2d0ceaae.5b49f6"
]
]
},
{
"id": "80e782f8.3fc698",
"type": "subflow:de56f8d.072c908",
"z": "7333a36d.5a2e54",
"name": "",
"env": [
{
"name": "method",
"type": "str",
"value": "PUT"
},
{
"name": "sensor_id",
"type": "str",
"value": "2"
},
{
"name": "object_id",
"type": "str",
"value": "3306"
},
{
"name": "resource_id",
"type": "str",
"value": "5850"
}
],
"x": 880,
"y": 1060,
"wires": [
[
"4714132a.9a04c4"
]
]
},
{
"id": "8582bcf6.7eba5",
"type": "switch",
"z": "7333a36d.5a2e54",
"name": "Method",
"property": "method",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "POST",
"vt": "str"
},
{
"t": "eq",
"v": "PUT",
"vt": "str"
},
{
"t": "eq",
"v": "GET",
"vt": "str"
},
{
"t": "eq",
"v": "HEAD",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 4,
"x": 220,
"y": 1060,
"wires": [
[
"2bb815a3.d04202"
],
[
"2bb815a3.d04202"
],
[],
[
"2bb815a3.d04202"
]
]
},
{
"id": "7f502a69.c6b1cc",
"type": "change",
"z": "7333a36d.5a2e54",
"name": "description",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "device.description",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 270,
"y": 760,
"wires": [
[
"7de59df4.0236c4"
]
]
},
{
"id": "7de59df4.0236c4",
"type": "ui_text",
"z": "7333a36d.5a2e54",
"group": "6ab73aae.f2f7dc",
"order": 1,
"width": "12",
"height": "1",
"name": "description",
"label": "",
"format": "{{msg.payload || \"\" }}",
"layout": "row-left",
"x": 450,
"y": 760,
"wires": []
},
{
"id": "cbff0ff0.4f46e8",
"type": "function",
"z": "7333a36d.5a2e54",
"name": "setTextDisplays",
"func": "const channelsCount = 2;\nconst start = 3;\nif ((msg.method === \"POST\" || msg.method === \"PUT\") && msg.sensor && msg.sensor.nativeSensorId) {\n const nativeSensorId = msg.sensor.nativeSensorId;\n if (Number(nativeSensorId) >= start || Number(nativeSensorId) < start + channelsCount ) {\n // msg.payload = JSON.parse(Buffer.from(msg.sensor.resources[\"5527\"]));\n // console.log(\"resource 5527 :\", Buffer.from(msg.sensor.resources[\"5527\"]).toString())\n msg.payload = JSON.parse(Buffer.from(msg.sensor.resources[\"5527\"]).toString());\n // msg.payload = msg.sensor.value;\n return msg;\n }\n}\n",
"outputs": 1,
"noerr": 0,
"x": 520,
"y": 400,
"wires": [
[
"34c82181.cb9916"
]
]
},
{
"id": "34f61a65.120156",
"type": "function",
"z": "7333a36d.5a2e54",
"name": "selectSwitches",
"func": "const switchesCount = 2;\nconst start = 1;\nif (msg.sensor && msg.sensor.nativeSensorId) {\n const nativeSensorId = msg.sensor.nativeSensorId;\n if (Number(nativeSensorId) >= start || Number(nativeSensorId) < start + switchesCount ) {\n return msg;\n }\n}\n",
"outputs": 1,
"noerr": 0,
"x": 520,
"y": 220,
"wires": [
[
"3f9b37a0.c7b75"
]
]
},
{
"id": "81317e8d.65be68",
"type": "function",
"z": "7333a36d.5a2e54",
"name": "selectSliders",
"func": "const slidersCount = 2;\nconst start = 1;\nif (msg.sensor && msg.sensor.nativeSensorId) {\n const nativeSensorId = msg.sensor.nativeSensorId;\n if (Number(nativeSensorId) >= start || Number(nativeSensorId) < start + slidersCount ) {\n return msg;\n }\n}\n",
"outputs": 1,
"noerr": 0,
"x": 510,
"y": 300,
"wires": [
[
"a7f1b65f.556038"
]
]
},
{
"id": "1ab7d6c3.3bd2e9",
"type": "link out",
"z": "7333a36d.5a2e54",
"name": "*/3341/3/5527",
"links": [],
"x": 855,
"y": 380,
"wires": []
},
{
"id": "637563f7.f1ef3c",
"type": "link out",
"z": "7333a36d.5a2e54",
"name": "*/3306/1/5851",
"links": [],
"x": 855,
"y": 280,
"wires": []
},
{
"id": "a6d54fea.72abf8",
"type": "link out",
"z": "7333a36d.5a2e54",
"name": "*/3306/2/5851",
"links": [],
"x": 855,
"y": 320,
"wires": []
},
{
"id": "3f9b37a0.c7b75",
"type": "switch",
"z": "7333a36d.5a2e54",
"name": "sensorId",
"property": "sensor.nativeSensorId",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "str"
},
{
"t": "eq",
"v": "2",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 720,
"y": 220,
"wires": [
[
"457ba71a.879be8"
],
[
"db8dc8a4.e8e3f8"
]
]
},
{
"id": "a7f1b65f.556038",
"type": "switch",
"z": "7333a36d.5a2e54",
"name": "sensorId",
"property": "sensor.nativeSensorId",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "str"
},
{
"t": "eq",
"v": "2",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 720,
"y": 300,
"wires": [
[
"637563f7.f1ef3c"
],
[
"a6d54fea.72abf8"
]
]
},
{
"id": "3a1ec4f9.99718c",
"type": "link out",
"z": "7333a36d.5a2e54",
"name": "*/3341/4/5527",
"links": [
"97f7bbee.17e24"
],
"x": 855,
"y": 420,
"wires": []
},
{
"id": "e058d4da.f45a48",
"type": "subflow:1e283bd5.9de3d4",
"z": "7333a36d.5a2e54",
"name": "",
"env": [],
"x": 280,
"y": 280,
"wires": [
[
"a3d7d599.4b06d8"
],
[
"34f61a65.120156"
],
[
"81317e8d.65be68"
],
[],
[],
[
"cbff0ff0.4f46e8"
]
]
},
{
"id": "2d0ceaae.5b49f6",
"type": "ui_switch",
"z": "7333a36d.5a2e54",
"name": "PUT/sensor/3306/2/5850",
"label": "listening",
"tooltip": "Toggle bot listening state",
"group": "6ab73aae.f2f7dc",
"order": 3,
"width": 0,
"height": 0,
"passthru": false,
"decouple": "false",
"topic": "",
"style": "",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"x": 630,
"y": 1060,
"wires": [
[
"80e782f8.3fc698"
]
]
},
{
"id": "1a464999.b7bff6",
"type": "function",
"z": "7333a36d.5a2e54",
"name": "get-instance-by-name",
"func": "try {\n const ownerId = env.get('ALOES_USER_ID');\n const payload = msg.payload;\n const deviceName = payload.deviceName.trim().toLowerCase().replace(/\\s+/g, '-');\n // const deviceName = new RegExp(`.*${payload.deviceName.trim()}.*`, 'i').toString();\n const deviceType = payload.deviceType.trim().toLowerCase().replace(/\\s+/g, '-');\n\n const filter = {\n where : { \n and : [\n { ownerId },\n { type : deviceType },\n { or : \n [\n { name : deviceName },\n { name : { like:`.*${payload.deviceName.trim()}.*`, options:'i' } },\n ]\n }\n ] \n },\n limit: 1\n };\n // console.log(\"filter\", filter.where.and[2].or[1]);\n\n if (payload.sensorName) {\n filter.include = {\n relation: 'sensors',\n scope: {\n where: {\n and: [\n // { name : {regexp : sensorName } },\n { name : { like:`.*${payload.sensorName.trim()}.*`, options:'i' } },\n ],\n },\n limit: 3,\n },\n }\n // filter.where.include.scope.include = {\n // relation: 'resources',\n // scope: {\n // where: {\n // \"5750\" : { like: new RegExp(`.*${payload.sensorName}.*`, 'i') }\n // },\n // limit: 1,\n // },\n // };\n if (payload.nativeSensorId) {\n filter.include.scope.where.and.push({nativeSensorId: payload.nativeSensorId});\n }\n }\n // msg.url = `${msg.url}?filter=${JSON.stringify(filter).toString()}`\n // msg.filter = JSON.stringify(filter).toString();\n msg.payload = {filter};\n return msg; \n} catch(error) {\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 420,
"y": 1420,
"wires": [
[
"4d7db291.2b626c",
"554e2526.364e94"
]
]
},
{
"id": "c4ac2d4d.4d87d",
"type": "link in",
"z": "7333a36d.5a2e54",
"name": "3341/3/5527->",
"links": [],
"x": 115,
"y": 1660,
"wires": [
[]
]
},
{
"id": "5ac34aca.75cb64",
"type": "function",
"z": "7333a36d.5a2e54",
"name": "post-to-instance-by-name",
"func": "try {\n const debug = env.get(\"debug\");\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n // console.log(\"resource : \", msg.resource);\n if (msg.payload === undefined) throw new Error(\"undefined sensor.value\");\n let encoder;\n global.get(\"aloesHandlers\", storeType, (err,res) => {\n if (err) throw err;\n encoder = res.aloesClientEncoder;\n });\n if (!updater) throw new Error(\"Can't import Aloes Handlers\");\n\n // find instance into node red cache\n let sensor;\n global.get(`sensor-${payload.sensorName}-${payload.nativeSensorId}-`, storeType, (err,res) => {\n if (err) throw err;\n sensor = res;\n });\n if (debug) {\n console.log(\"post-to-instance-by-name-request sensor: \", sensor);\n }\n \n return msg; \n} catch(error) {\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 430,
"y": 1480,
"wires": [
[]
]
},
{
"id": "2fccbb16.77c86c",
"type": "debug",
"z": "7333a36d.5a2e54",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 790,
"y": 1360,
"wires": []
},
{
"id": "f0b880c3.524d2",
"type": "switch",
"z": "7333a36d.5a2e54",
"name": "Intent",
"property": "payload.intent",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "getlarge:getInstanceByName",
"vt": "str"
},
{
"t": "eq",
"v": "getlarge:postToInstanceByName",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 230,
"y": 1480,
"wires": [
[
"1a464999.b7bff6"
],
[
"5ac34aca.75cb64"
]
]
},
{
"id": "34c82181.cb9916",
"type": "switch",
"z": "7333a36d.5a2e54",
"name": "sensorId",
"property": "sensor.nativeSensorId",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "3",
"vt": "str"
},
{
"t": "eq",
"v": "4",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 720,
"y": 400,
"wires": [
[
"1ab7d6c3.3bd2e9"
],
[
"3a1ec4f9.99718c"
]
]
},
{
"id": "ea818d82.02d4b8",
"type": "change",
"z": "7333a36d.5a2e54",
"name": "PUT/sensor/3341/3/5527",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "PUT/sensor/3341/3/5527",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 890,
"y": 1420,
"wires": [
[
"c47bc910.ad3e98"
]
]
},
{
"id": "75ca98f8.6fb928",
"type": "subflow:41c6c6f2.febed8",
"z": "7333a36d.5a2e54",
"name": "",
"env": [],
"x": 500,
"y": 680,
"wires": [
[
"7a0cd6f5.7cd788"
]
]
},
{
"id": "4d7db291.2b626c",
"type": "debug",
"z": "7333a36d.5a2e54",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 530,
"y": 1360,
"wires": []
},
{
"id": "554e2526.364e94",
"type": "subflow:77a5eb29.d56ae4",
"z": "7333a36d.5a2e54",
"name": "",
"x": 670,
"y": 1420,
"wires": [
[
"2fccbb16.77c86c"
],
[
"2fccbb16.77c86c"
]
]
},
{
"id": "18dbcafd.0bd0d5",
"type": "ui_group",
"z": "",
"name": "List",
"tab": "fe99d4b2.836eb",
"order": 8,
"disp": true,
"width": "9",
"collapse": true
},
{
"id": "6ab73aae.f2f7dc",
"type": "ui_group",
"z": "7333a36d.5a2e54",
"name": "snips-agent-1",
"tab": "fe99d4b2.836eb",
"order": 7,
"disp": true,
"width": "12",
"collapse": true
},
{
"id": "fe99d4b2.836eb",
"type": "ui_tab",
"z": "",
"name": "devices",
"icon": "dashboard",
"order": 3,
"disabled": false,
"hidden": false
},
{
"id": "17af590f.41f4ff",
"type": "subflow",
"name": "aloes-device",
"info": "**aloes-device**\n\nFilter MQTT messages concerning the selected device. \nBuild and dispatch sensor / device models.\n\n\n`device_id` device to listen\n\n`device_name` Aloes instance host ( eg 1883, 3000, . )\n\n`debug` control debug display ( true / false ) \n\n`store_type` How to store instance ( true / false ) \n",
"category": "aloes",
"in": [
{
"x": 180,
"y": 220,
"wires": [
{
"id": "6d9bf80.8361708"
}
]
}
],
"out": [
{
"x": 600,
"y": 160,
"wires": [
{
"id": "6d9bf80.8361708",
"port": 0
}
]
},
{
"x": 600,
"y": 220,
"wires": [
{
"id": "6d9bf80.8361708",
"port": 1
}
]
},
{
"x": 600,
"y": 280,
"wires": [
{
"id": "6d9bf80.8361708",
"port": 2
}
]
}
],
"env": [
{
"name": "device_id",
"type": "str",
"value": ""
},
{
"name": "device_name",
"type": "str",
"value": ""
},
{
"name": "debug",
"type": "bool",
"value": "true"
}
],
"outputLabels": [
"Device",
"Sensor",
"Measurement"
],
"icon": "node-red/feed.png",
"status": {
"x": 620,
"y": 80,
"wires": [
{
"id": "1dffd3c6.5dd6b4",
"port": 0
}
]
}
},
{
"id": "6d9bf80.8361708",
"type": "function",
"z": "17af590f.41f4ff",
"name": "switch-msg-properties",
"func": "try {\n const debug = env.get(\"debug\");\n let deviceName = env.get(\"device_name\");\n if (!deviceName) throw new Error(\"Missing device_name variable\");\n const deviceId = env.get(\"device_id\");\n if (!deviceId) throw new Error(\"Missing device_id variable\");\n deviceName = deviceName.toLowerCase();\n if (msg.device && msg.device !== null && msg.device.id) {\n if (msg.device.id.toString() === deviceId) {\n if (msg.device.status) {\n node.status({fill:\"green\",shape:\"ring\",text:\"connected\"});\n } else {\n node.status({fill:\"red\",shape:\"ring\",text:\"disconnected\"});\n }\n if (msg.device.sensors) {\n delete msg.device.sensors;\n }\n if (debug) {\n console.log(\"set Device\", msg.device);\n const message = {topic: msg.topic, payload : msg.device};\n return [msg, null, null, message];\n }\n return [msg, null, null, null];\n }\n return [null, null, null];\n } else if (msg.sensor && msg.sensor !== null && msg.sensor.deviceId) {\n const deviceId = env.get(\"device_id\");\n if (msg.sensor.deviceId.toString() === deviceId) {\n if (debug) {\n // console.log(\"set Sensor\", msg.sensor);\n const message = {topic: msg.topic, payload : msg.sensor};\n return [null, msg, null, message];\n }\n return [null, msg, null, null];\n }\n return [null, null, null];\n } else if (msg.measurement && msg.measurement !== null && msg.measurement.deviceId) {\n const deviceId = env.get(\"device_id\");\n if (msg.measurement.deviceId === deviceId) {\n if (debug) {\n // console.log(\"set Measurement\", msg.measurement);\n const message = {topic: msg.topic, payload : msg.measurement};\n return [null, null, msg, message];\n }\n return [null, null, msg, null];\n }\n return [null, null, null, null];\n } \n throw new Error(\"No instance to parse\");\n} catch(error){\n return error;\n}\n",
"outputs": 4,
"noerr": 0,
"x": 340,
"y": 220,
"wires": [
[],
[],
[],
[
"e681b8fd.712ee"
]
]
},
{
"id": "e681b8fd.712ee",
"type": "debug",
"z": "17af590f.41f4ff",
"name": "${device_name}",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 380,
"y": 320,
"wires": []
},
{
"id": "1dffd3c6.5dd6b4",
"type": "status",
"z": "17af590f.41f4ff",
"name": "Aloes-Client status",
"scope": [
"6d9bf80.8361708"
],
"x": 250,
"y": 80,
"wires": [
[]
]
},
{
"id": "c12dfc2c.76dcf",
"type": "subflow:17af590f.41f4ff",
"z": "87bcccbf.ba98c",
"name": "snips-agent-1",
"env": [
{
"name": "device_id",
"type": "str",
"value": "5d123a647a11d703bfa8be01"
},
{
"name": "device_name",
"type": "str",
"value": "snips-agent-1"
},
{
"name": "debug",
"type": "bool",
"value": "false"
}
],
"x": 300,
"y": 1060,
"wires": [
[
"e481b0d3.a9a8"
],
[
"e481b0d3.a9a8"
],
[]
]
},
{
"id": "bde0c443.ed9eb8",
"type": "link in",
"z": "87bcccbf.ba98c",
"name": "->snips-agent-1-in",
"links": [
"7d6dcf14.3d90c8",
"7f8ad7c.77305a8",
"af6d43bf.4a9de"
],
"x": 175,
"y": 1060,
"wires": [
[
"c12dfc2c.76dcf"
]
]
},
{
"id": "e481b0d3.a9a8",
"type": "link out",
"z": "87bcccbf.ba98c",
"name": "snips-agent-1-in->",
"links": [
"87feb6ca.4ef2f8"
],
"x": 455,
"y": 1060,
"wires": []
},
{
"id": "f9c36a64.8d29a8",
"type": "status",
"z": "87bcccbf.ba98c",
"name": "snips-agent-1 status",
"scope": [
"c12dfc2c.76dcf"
],
"x": 270,
"y": 1020,
"wires": [
[
"e481b0d3.a9a8"
]
]
},
{
"id": "87feb6ca.4ef2f8",
"type": "link in",
"z": "87bcccbf.ba98c",
"name": "->snips-agent-1-interfaces",
"links": [
"589593f.4531bec",
"e481b0d3.a9a8"
],
"x": 575,
"y": 1060,
"wires": [
[
"47452dc1.3613c4"
]
]
},
{
"id": "6abd88df.ea28e8",
"type": "link out",
"z": "87bcccbf.ba98c",
"name": "snips-agent-1-interfaces->",
"links": [
"a447ee9d.24b2d"
],
"x": 875,
"y": 1060,
"wires": []
},
{
"id": "47452dc1.3613c4",
"type": "subflow:7333a36d.5a2e54",
"z": "87bcccbf.ba98c",
"name": "",
"env": [
{
"name": "device_id",
"type": "str",
"value": "5d123a647a11d703bfa8be01"
},
{
"name": "device_name",
"type": "str",
"value": "snips-agent-1"
}
],
"x": 710,
"y": 1060,
"wires": [
[
"6abd88df.ea28e8"
]
]
}
]
@getlarge
Copy link
Author

Flow to add in node-red-bridge instance to communicate with a device registered on Aloes and Snips.

Prerequisites :

  • Your own instance of device-manager or an account on aloes.io
  • A machine running node-red-bridge with node-red-bridge/aloes-core configured to your Aloes account
  • A device registered on your Aloes account with Snips Platform and node-red-device and this flow installed
  • Snips Agent installed and configured on your device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment