Skip to content

Instantly share code, notes, and snippets.

@getlarge
Last active November 13, 2019 19:53
Show Gist options
  • Save getlarge/33aef619bd70a3c854472ec8b99a3e65 to your computer and use it in GitHub Desktop.
Save getlarge/33aef619bd70a3c854472ec8b99a3e65 to your computer and use it in GitHub Desktop.
node-red-device/aloes-core
[
{
"id": "401f859.7054efc",
"type": "subflow",
"name": "device-tx",
"info": "",
"category": "output",
"in": [
{
"x": 180,
"y": 260,
"wires": [
{
"id": "22fcaa9d.4df4a6"
}
]
}
],
"out": [],
"env": [
{
"name": "ALOES_MQTT_HOST",
"type": "env",
"value": "ALOES_MQTT_HOST"
},
{
"name": "ALOES_MQTT_PORT",
"type": "env",
"value": "ALOES_MQTT_PORT"
},
{
"name": "DEVICE_DEVEUI",
"type": "env",
"value": "DEVICE_DEVEUI"
},
{
"name": "NODE_RED_STORE_TYPE",
"type": "env",
"value": "DEVICE_ID"
},
{
"name": "DEVICE_APPKEY",
"type": "env",
"value": "DEVICE_APPKEY"
},
{
"name": "DEVICE_IN_TOPIC",
"type": "env",
"value": "DEVICE_IN_TOPIC"
},
{
"name": "DEVICE_NAME",
"type": "env",
"value": "DEVICE_NAME"
},
{
"name": "NODE_RED_STORE_TYPE",
"type": "env",
"value": "NODE_RED_STORE_TYPE"
},
{
"name": "debug",
"type": "bool",
"value": "true"
}
],
"icon": "node-red/feed.png",
"status": {
"x": 460,
"y": 140,
"wires": [
{
"id": "51302039.dfd84",
"port": 0
}
]
}
},
{
"id": "2bfd353f.8e1012",
"type": "mqtt out",
"z": "401f859.7054efc",
"name": "Aloes-in",
"topic": "",
"qos": "0",
"retain": "false",
"broker": "df772461.547f58",
"x": 780,
"y": 280,
"wires": []
},
{
"id": "ad0d431f.acd",
"type": "debug",
"z": "401f859.7054efc",
"name": "Device-tx",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 320,
"y": 360,
"wires": []
},
{
"id": "22fcaa9d.4df4a6",
"type": "function",
"z": "401f859.7054efc",
"name": "topicParser",
"func": "try {\n if (msg.topic && msg.topic !== null) {\n const t = msg.topic.split(\"/\");\n const storeType = env.get(\"NODE_RED_STORE_TYPE\") || \"memoryOnly\";\n const deviceName = env.get(\"DEVICE_NAME\");\n if (!deviceName) throw new Error(\"no name found\");\n let device;\n global.get(deviceName, storeType, (err, res)=> {\n if (err) throw err;\n device = res;\n });\n if (!device) throw new Error(\"no device found\");\n const method = t[0];\n const objectId = t[1];\n const nodeId = t[2];\n const sensorId = t[3];\n const resourceId = t[4];\n msg.topic = `${device.devEui}${device.outPrefix}/${method}/${objectId}/${nodeId}/${sensorId}/${resourceId}`;\n msg.parts = msg.topic.split(\"/\");\n if (env.get(\"debug\")){\n return [msg,msg];\n }\n return [msg,null]; \n }\n throw new Error(\"No msg.topic\");\n} catch(error){\n // console.log('error', error);\n return error;\n}\n",
"outputs": 2,
"noerr": 0,
"x": 350,
"y": 260,
"wires": [
[
"26668afd.b28fa6"
],
[
"ad0d431f.acd"
]
]
},
{
"id": "26668afd.b28fa6",
"type": "subflow:d340d3f0.5a1b08",
"z": "401f859.7054efc",
"name": "",
"env": [
{
"name": "device_name",
"type": "env",
"value": "DEVICE_NAME"
},
{
"name": "store_type",
"type": "env",
"value": "NODE_RED_STORE_TYPE"
},
{
"name": "debug",
"type": "env",
"value": "debug"
}
],
"x": 580,
"y": 260,
"wires": [
[],
[
"2bfd353f.8e1012"
]
]
},
{
"id": "51302039.dfd84",
"type": "status",
"z": "401f859.7054efc",
"name": "",
"scope": [
"2bfd353f.8e1012"
],
"x": 220,
"y": 140,
"wires": [
[]
]
},
{
"id": "d340d3f0.5a1b08",
"type": "subflow",
"name": "set-sensor",
"info": "",
"category": "storage",
"in": [
{
"x": 260,
"y": 220,
"wires": [
{
"id": "501bec6b.43d75c"
}
]
}
],
"out": [
{
"x": 600,
"y": 180,
"wires": [
{
"id": "501bec6b.43d75c",
"port": 0
}
]
},
{
"x": 600,
"y": 260,
"wires": [
{
"id": "501bec6b.43d75c",
"port": 1
}
]
}
],
"env": [
{
"name": "device_name",
"type": "str",
"value": ""
},
{
"name": "store_type",
"type": "str",
"value": "memory"
}
],
"icon": "node-red/db.png"
},
{
"id": "501bec6b.43d75c",
"type": "function",
"z": "d340d3f0.5a1b08",
"name": "set-sensor",
"func": "try {\n if (msg.parts && msg.parts !== null) {\n const storeType = env.get(\"store_type\") || \"memory\";\n // console.log('updateInstance', deviceName);\n const method = msg.parts[1];\n const objectId = msg.parts[2];\n const nodeId = msg.parts[3];\n const sensorId = msg.parts[4];\n const resourceId = msg.parts[5];\n if (!method || !objectId || nodeId === undefined || sensorId === undefined || !resourceId) {\n return [null,new Error(\"missing params\")];\n }\n let sensor;\n global.get(`sensor-${nodeId}-${sensorId}`, storeType, (err, res) => {\n if (err) throw err;\n sensor = res;\n });\n if (!sensor || sensor === null) {\n sensor = {};\n }\n if (!sensor.resources) {\n sensor.resources = {};\n }\n sensor.resources[resourceId] = msg.payload;\n sensor.type = Number(objectId);\n sensor.resource = Number(resourceId);\n sensor.value = msg.payload;\n if (method === \"1\") {\n console.log('updateInstance', sensorId, sensor.type, sensor.resource);\n global.set(`sensor-${nodeId}-${sensorId}`, sensor, storeType, (err) => {\n if(err) throw err;\n }); \n }\n msg.payload = sensor;\n const msg2 = {payload: sensor.value, topic: msg.topic, parts: msg.parts, method, objectId, nodeId, sensorId, resourceId};\n return [msg, msg2];\n }\n throw new Error(\"No msg.parts\")\n} catch(error){\n // console.log('updateInstance : error', error);\n return error;\n}\n",
"outputs": 2,
"noerr": 0,
"x": 390,
"y": 220,
"wires": [
[],
[]
]
},
{
"id": "5e808641.b2fa7",
"type": "subflow",
"name": "device-rx",
"info": "",
"category": "input",
"in": [],
"out": [
{
"x": 800,
"y": 200,
"wires": [
{
"id": "a3eb371a.a21ef",
"port": 0
}
]
},
{
"x": 800,
"y": 260,
"wires": [
{
"id": "a3eb371a.a21ef",
"port": 1
}
]
}
],
"env": [
{
"name": "ALOES_MQTT_HOST",
"type": "env",
"value": "ALOES_MQTT_HOST"
},
{
"name": "ALOES_MQTT_PORT",
"type": "env",
"value": "ALOES_MQTT_PORT"
},
{
"name": "DEVICE_DEVEUI",
"type": "env",
"value": "DEVICE_DEVEUI"
},
{
"name": "DEVICE_ID",
"type": "env",
"value": "DEVICE_ID"
},
{
"name": "DEVICE_APPKEY",
"type": "env",
"value": "DEVICE_APPKEY"
},
{
"name": "DEVICE_IN_TOPIC",
"type": "env",
"value": "DEVICE_IN_TOPIC"
},
{
"name": "DEVICE_NAME",
"type": "env",
"value": "DEVICE_NAME"
},
{
"name": "NODE_RED_STORE_TYPE",
"type": "env",
"value": "NODE_RED_STORE_TYPE"
},
{
"name": "debug",
"type": "bool",
"value": "true"
}
],
"icon": "node-red/feed.png",
"status": {
"x": 460,
"y": 140,
"wires": [
{
"id": "d6a73c3.2330f4",
"port": 0
}
]
}
},
{
"id": "2a416e9.b747a92",
"type": "function",
"z": "5e808641.b2fa7",
"name": "parsePacket",
"func": "msg.parts = msg.topic.split(\"/\");\nmsg.method = msg.parts[1];\nmsg.objectId = msg.parts[2];\nmsg.nodeId = msg.parts[3];\nmsg.sensorId = msg.parts[4];\nmsg.resourceId = msg.parts[5];\n\nif (env.get(\"debug\")) {\n return [msg,msg];\n}\nreturn [msg,null];",
"outputs": 2,
"noerr": 0,
"x": 370,
"y": 280,
"wires": [
[
"a3eb371a.a21ef"
],
[
"ab392fa8.28933"
]
]
},
{
"id": "ab392fa8.28933",
"type": "debug",
"z": "5e808641.b2fa7",
"name": "Device-rx",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 460,
"y": 360,
"wires": []
},
{
"id": "b8b16e3.b1c531",
"type": "mqtt in",
"z": "5e808641.b2fa7",
"name": "Aloes-out",
"topic": "${DEVICE_IN_TOPIC}",
"qos": "0",
"datatype": "auto",
"broker": "df772461.547f58",
"x": 200,
"y": 280,
"wires": [
[
"2a416e9.b747a92"
]
]
},
{
"id": "a3eb371a.a21ef",
"type": "subflow:d340d3f0.5a1b08",
"z": "5e808641.b2fa7",
"name": "",
"env": [
{
"name": "device_name",
"type": "env",
"value": "DEVICE_NAME"
},
{
"name": "store_type",
"type": "env",
"value": "NODE_RED_STORE_TYPE"
},
{
"name": "debug",
"type": "env",
"value": "debug"
}
],
"x": 660,
"y": 220,
"wires": [
[],
[]
]
},
{
"id": "d6a73c3.2330f4",
"type": "status",
"z": "5e808641.b2fa7",
"name": "",
"scope": [
"b8b16e3.b1c531"
],
"x": 220,
"y": 140,
"wires": [
[]
]
},
{
"id": "df772461.547f58",
"type": "mqtt-broker",
"z": "",
"name": "Aloes-Client",
"broker": "${ALOES_MQTT_HOST}",
"port": "${ALOES_MQTT_PORT}",
"clientid": "${DEVICE_DEVEUI}",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "bf045b60.fcf578",
"type": "subflow",
"name": "ui-router",
"info": "",
"category": "aloes",
"in": [
{
"x": 140,
"y": 240,
"wires": [
{
"id": "c8c45205.7da3c8"
}
]
}
],
"out": [],
"env": []
},
{
"id": "f5dc1abf.6b22a",
"type": "comment",
"z": "bf045b60.fcf578",
"name": "INPUT",
"info": "- receive tabs ( pages ) changes events.\n\n- validate group diplay based on each tab accessed and global state",
"x": 170,
"y": 80,
"wires": []
},
{
"id": "c8c45205.7da3c8",
"type": "switch",
"z": "bf045b60.fcf578",
"name": "tab name",
"property": "name",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "device",
"vt": "str"
},
{
"t": "eq",
"v": "settings",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 380,
"y": 240,
"wires": [
[
"5b6cacc3.9276c4",
"5d83ec58.982424"
],
[
"be8b2115.6e662"
]
]
},
{
"id": "71c221d6.722398",
"type": "ui_ui_control",
"z": "bf045b60.fcf578",
"name": "init-ui",
"x": 1010,
"y": 340,
"wires": [
[]
]
},
{
"id": "be8b2115.6e662",
"type": "change",
"z": "bf045b60.fcf578",
"name": "showAuth",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"group\":{\"show\":[\"settings_auth\"],\"hide\":[\"settings_aloes\",\"settings_commands\",\"settings_device\",\"settings_node-red\"]}}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 620,
"y": 280,
"wires": [
[
"71c221d6.722398"
]
]
},
{
"id": "dee816d4.f2af18",
"type": "change",
"z": "bf045b60.fcf578",
"name": "showContent",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"group\":{\"hide\":[\"settings_auth\"],\"show\":[\"settings_aloes\",\"settings_commands\",\"settings_device\",\"settings_node-red\"]}}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 630,
"y": 400,
"wires": [
[
"71c221d6.722398"
]
]
},
{
"id": "97fc783f.7ec2f",
"type": "function",
"z": "bf045b60.fcf578",
"name": "",
"func": "try {\n let sequenceIsValid = false;\n let tooManyAttempts = false;\n let number1;\n flow.get(\"number1\", \"memory\", (err, res) => {\n if (err) throw err;\n number1 = res;\n })\n let number2;\n flow.get(\"number2\", \"memory\", (err, res) => {\n if (err) throw err;\n number2 = res;\n })\n let number3;\n flow.get(\"number3\", \"memory\", (err, res) => {\n if (err) throw err;\n number3 = res;\n })\n \n if (number1 === 1 && number2 === 1 && number3 === 2) {\n sequenceIsValid = true;\n }\n // increment countdown\n if (sequenceIsValid === true) {\n return msg;\n } \n return null;\n} catch(error) {\n return error;\n}",
"outputs": 1,
"noerr": 0,
"x": 390,
"y": 400,
"wires": [
[
"dee816d4.f2af18"
]
]
},
{
"id": "215e2e4c.a41eb2",
"type": "ui_button",
"z": "bf045b60.fcf578",
"name": "",
"group": "9f9da226.ad2e3",
"order": 4,
"width": "3",
"height": "1",
"passthru": false,
"label": "validate",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "true",
"payloadType": "bool",
"topic": "",
"x": 180,
"y": 400,
"wires": [
[
"97fc783f.7ec2f"
]
]
},
{
"id": "a9e5906c.4f00f8",
"type": "ui_numeric",
"z": "bf045b60.fcf578",
"name": "number1",
"label": "",
"tooltip": "",
"group": "9f9da226.ad2e3",
"order": 1,
"width": "2",
"height": "1",
"passthru": false,
"topic": "",
"format": "{{value}}",
"min": 0,
"max": "9",
"step": 1,
"x": 180,
"y": 460,
"wires": [
[
"26b0c8e8.664b2"
]
]
},
{
"id": "d35340f0.6ce8d8",
"type": "ui_numeric",
"z": "bf045b60.fcf578",
"name": "number2",
"label": "",
"tooltip": "",
"group": "9f9da226.ad2e3",
"order": 2,
"width": "2",
"height": "1",
"passthru": false,
"topic": "",
"format": "{{value}}",
"min": 0,
"max": "9",
"step": 1,
"x": 180,
"y": 500,
"wires": [
[
"32714a01.0b135e"
]
]
},
{
"id": "70082eea.2f9a7",
"type": "ui_numeric",
"z": "bf045b60.fcf578",
"name": "number3",
"label": "",
"tooltip": "",
"group": "9f9da226.ad2e3",
"order": 3,
"width": "2",
"height": "1",
"passthru": false,
"topic": "",
"format": "{{value}}",
"min": 0,
"max": "9",
"step": 1,
"x": 180,
"y": 540,
"wires": [
[
"8d166f84.dc18e8"
]
]
},
{
"id": "26b0c8e8.664b2",
"type": "change",
"z": "bf045b60.fcf578",
"name": "",
"rules": [
{
"t": "set",
"p": "number1",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 370,
"y": 460,
"wires": [
[]
]
},
{
"id": "32714a01.0b135e",
"type": "change",
"z": "bf045b60.fcf578",
"name": "",
"rules": [
{
"t": "set",
"p": "number2",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 370,
"y": 500,
"wires": [
[]
]
},
{
"id": "8d166f84.dc18e8",
"type": "change",
"z": "bf045b60.fcf578",
"name": "",
"rules": [
{
"t": "set",
"p": "number3",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 370,
"y": 540,
"wires": [
[]
]
},
{
"id": "5b6cacc3.9276c4",
"type": "change",
"z": "bf045b60.fcf578",
"name": "setDeviceTrigger",
"rules": [
{
"t": "set",
"p": "trigger",
"pt": "msg",
"to": "{\"command\":\"refresh\",\"collection\":\"device\"}",
"tot": "json"
},
{
"t": "delete",
"p": "payload",
"pt": "msg"
},
{
"t": "delete",
"p": "tab",
"pt": "msg"
},
{
"t": "delete",
"p": "socketid",
"pt": "msg"
},
{
"t": "delete",
"p": "socketip",
"pt": "msg"
},
{
"t": "delete",
"p": "name",
"pt": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 630,
"y": 180,
"wires": [
[
"4dffc378.e50d94"
]
]
},
{
"id": "f525cc0.6342a38",
"type": "debug",
"z": "bf045b60.fcf578",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 1010,
"y": 180,
"wires": []
},
{
"id": "4dffc378.e50d94",
"type": "delay",
"z": "bf045b60.fcf578",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "2",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"x": 840,
"y": 180,
"wires": [
[
"f525cc0.6342a38"
]
]
},
{
"id": "5d83ec58.982424",
"type": "change",
"z": "bf045b60.fcf578",
"name": "setSensorTrigger",
"rules": [
{
"t": "set",
"p": "trigger",
"pt": "msg",
"to": "{\"command\":\"refresh\",\"collection\":\"sensor\"}",
"tot": "json"
},
{
"t": "delete",
"p": "payload",
"pt": "msg"
},
{
"t": "delete",
"p": "tab",
"pt": "msg"
},
{
"t": "delete",
"p": "socketid",
"pt": "msg"
},
{
"t": "delete",
"p": "socketip",
"pt": "msg"
},
{
"t": "delete",
"p": "name",
"pt": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 630,
"y": 220,
"wires": [
[
"52d7bbe8.291b3c"
]
]
},
{
"id": "52d7bbe8.291b3c",
"type": "delay",
"z": "bf045b60.fcf578",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "2",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"x": 840,
"y": 220,
"wires": [
[]
]
},
{
"id": "9f9da226.ad2e3",
"type": "ui_group",
"z": "",
"name": "auth",
"tab": "7fb22cc9.85b9fc",
"order": 5,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "25ce96fe.d3ecc2",
"type": "subflow",
"name": "http-api",
"info": "",
"category": "aloes",
"in": [
{
"x": 120,
"y": 320,
"wires": [
{
"id": "7e14c4e3.d5ea34"
}
]
}
],
"out": [
{
"x": 1060,
"y": 320,
"wires": [
{
"id": "52d8a1ee.8a4de8",
"port": 0
}
]
}
],
"env": [
{
"name": "debug",
"type": "bool",
"value": "true"
},
{
"name": "node_red_admin_passhash",
"type": "env",
"value": "NODE_RED_ADMIN_PASSHASH"
},
{
"name": "node_red_host",
"type": "env",
"value": "NODE_RED_HOST"
},
{
"name": "node_red_port",
"type": "env",
"value": "NODE_RED_PORT"
},
{
"name": "node_red_url",
"type": "env",
"value": "NODE_RED_URL"
},
{
"name": "node_red_api_root",
"type": "env",
"value": "NODE_RED_API_ROOT"
}
]
},
{
"id": "a245f7a2.2c8708",
"type": "http response",
"z": "25ce96fe.d3ecc2",
"name": "",
"statusCode": "",
"headers": {},
"x": 830,
"y": 140,
"wires": []
},
{
"id": "5aedde0b.279cb8",
"type": "function",
"z": "25ce96fe.d3ecc2",
"name": "Set Content-Type header",
"func": "msg.headers = {\n \"Content-Type\":\"image/jpeg\"\n};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 670,
"y": 140,
"wires": [
[
"a245f7a2.2c8708"
]
]
},
{
"id": "484c642a.6d5bdc",
"type": "file in",
"z": "25ce96fe.d3ecc2",
"name": "",
"filename": "/tmp/example.jpg",
"format": "",
"sendError": true,
"x": 470,
"y": 140,
"wires": [
[
"5aedde0b.279cb8"
]
]
},
{
"id": "eb56c765.ece22",
"type": "http in",
"z": "25ce96fe.d3ecc2",
"name": "",
"url": "/testImage",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 280,
"y": 140,
"wires": [
[
"484c642a.6d5bdc"
]
]
},
{
"id": "b888d43e.0e5288",
"type": "comment",
"z": "25ce96fe.d3ecc2",
"name": "HTTP API",
"info": "",
"x": 200,
"y": 80,
"wires": []
},
{
"id": "1ae29c20.f85fcc",
"type": "http request",
"z": "25ce96fe.d3ecc2",
"name": "",
"method": "use",
"ret": "obj",
"paytoqs": false,
"url": "",
"tls": "",
"proxy": "",
"authType": "basic",
"x": 570,
"y": 320,
"wires": [
[
"52d8a1ee.8a4de8",
"45bf2e30.995738"
]
]
},
{
"id": "7e14c4e3.d5ea34",
"type": "function",
"z": "25ce96fe.d3ecc2",
"name": "setInternalRequest",
"func": "try {\n const host = env.get(\"node_red_host\");\n const port = env.get(\"node_red_port\");\n const apiRoot = env.get(\"node_red_api_root\");\n const url = env.get(\"node_red_url\");\n const token = env.get(\"node_red_admin_passhash\");\n // console.log(\"token\", token)\n // msg.url = `http://${host}:${port}/${apiRoot}/start`;\n if (!token) throw new Error(\"No token retrieved\");\n let reqUrl;\n // console.log(\"payload\", msg.payload)\n if (msg.payload.requestUrl) {\n reqUrl = msg.payload.requestUrl;\n } else {\n reqUrl = \"start\";\n }\n let method;\n if (msg.payload.method) {\n method = msg.payload.method;\n } else {\n method = \"GET\";\n }\n msg.url = `${url}/${reqUrl}`;\n msg.method = method;\n msg.headers = {};\n msg.headers['Authorization'] = token;\n msg.headers['Accept'] = \"application/json\";\n msg.headers['Content-Type'] = \"application/json\";\n msg.headers['x-access-token'] = token;\n if (msg.payload.query) {\n // msg.body = msg.payload.query;\n const query = JSON.stringify(msg.payload.query);\n msg.payload = query;\n console.log(\"payload\", msg.payload)\n } else {\n msg.payload = {token, userId: 'test'};\n }\n // msg.query = {filter};\n return msg;\n} catch(error) {\n return error;\n}",
"outputs": 1,
"noerr": 0,
"x": 350,
"y": 320,
"wires": [
[
"1ae29c20.f85fcc",
"45bf2e30.995738"
]
]
},
{
"id": "52d8a1ee.8a4de8",
"type": "function",
"z": "25ce96fe.d3ecc2",
"name": "",
"func": "\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 780,
"y": 320,
"wires": [
[]
]
},
{
"id": "45bf2e30.995738",
"type": "debug",
"z": "25ce96fe.d3ecc2",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 740,
"y": 260,
"wires": []
},
{
"id": "53d275a4.8b0044",
"type": "subflow",
"name": "set-device",
"info": "",
"category": "storage",
"in": [
{
"x": 160,
"y": 100,
"wires": [
{
"id": "bded361.54e7f48"
}
]
}
],
"out": [
{
"x": 480,
"y": 100,
"wires": [
{
"id": "bded361.54e7f48",
"port": 0
}
]
}
],
"env": [
{
"name": "DEVICE_NAME",
"type": "env",
"value": "DEVICE_NAME"
},
{
"name": "DEVICE_ID",
"type": "env",
"value": "DEVICE_ID"
},
{
"name": "DEVICE_DEVEUI",
"type": "env",
"value": "DEVICE_DEVEUI"
},
{
"name": "DEVICE_APPKEY",
"type": "env",
"value": "DEVICE_APPKEY"
},
{
"name": "DEVICE_TYPE",
"type": "env",
"value": "DEVICE_TYPE"
},
{
"name": "DEVICE_IN_PREFIX",
"type": "env",
"value": "DEVICE_IN_PREFIX"
},
{
"name": "DEVICE_OUT_PREFIX",
"type": "env",
"value": "DEVICE_OUT_PREFIX"
},
{
"name": "NODE_RED_STORE_TYPE",
"type": "env",
"value": "NODE_RED_STORE_TYPE"
}
],
"icon": "node-red/db.png"
},
{
"id": "bded361.54e7f48",
"type": "function",
"z": "53d275a4.8b0044",
"name": "setState",
"func": "try {\n const storeType = env.get(\"NODE_RED_STORE_TYPE\") || \"memory\";\n const deviceName = env.get(\"DEVICE_NAME\") || \"node-red-device\";\n let device;\n global.get(deviceName, storeType, (err, res) => {\n if (err) throw err;\n device = res;\n });\n if (!device || device === null) {\n device = {\n devEui : env.get(\"DEVICE_DEVEUI\"),\n id : env.get(\"DEVICE_ID\"),\n appKey: env.get(\"DEVICE_APPKEY\"),\n type : env.get(\"DEVICE_TYPE\") || \"node\",\n name : deviceName,\n inPrefix: env.get(\"DEVICE_IN_PREFIX\") ||\"-in\",\n outPrefix: env.get(\"DEVICE_OUT_PREFIX\") || \"-out\"\n }; \n } else {\n device.devEui = env.get(\"DEVICE_DEVEUI\");\n device.id = env.get(\"DEVICE_ID\");\n device.appKey = env.get(\"DEVICE_APPKEY\");\n device.type = env.get(\"DEVICE_TYPE\") || \"node\";\n device.name = deviceName;\n device.inPrefix = env.get(\"DEVICE_IN_PREFIX\") || \"-in\";\n device.outPrefix = env.get(\"DEVICE_OUT_PREFIX\") || \"-out\";\n }\n if (device && device.devEui && device.name) {\n global.set(device.name, device, storeType, (err) => {\n if(err) throw err;\n }); \n }\n msg.payload = device;\n return msg; \n} catch(error) {\n console.log(\"setState: error\", error);\n return error;\n}",
"outputs": 1,
"noerr": 0,
"x": 340,
"y": 100,
"wires": [
[]
]
},
{
"id": "b962d874.6a3ae8",
"type": "subflow",
"name": "device-settings",
"info": "",
"category": "aloes",
"in": [
{
"x": 80,
"y": 320,
"wires": [
{
"id": "be14f4e0.e0832"
},
{
"id": "47760796.5bb35"
},
{
"id": "cbd00a4d.541588"
},
{
"id": "c7a92a37.87605"
},
{
"id": "31ae8c14.b7750c"
},
{
"id": "57cd30e0.7592c8"
},
{
"id": "2aa100b7.8631a8"
},
{
"id": "c7adef8b.c283d"
}
]
}
],
"out": [
{
"x": 1080,
"y": 580,
"wires": [
{
"id": "95eac3e8.d7317",
"port": 0
}
]
}
],
"env": [
{
"name": "DEVICE_NAME",
"type": "env",
"value": "DEVICE_NAME"
},
{
"name": "DEVICE_DEVEUI",
"type": "env",
"value": "DEVICE_DEVEUI"
},
{
"name": "DEVICE_ID",
"type": "env",
"value": "DEVICE_ID"
},
{
"name": "DEVICE_APPKEY",
"type": "env",
"value": "DEVICE_APPKEY"
},
{
"name": "DEVICE_TYPE",
"type": "env",
"value": "DEVICE_TYPE"
},
{
"name": "DEVICE_IN_PREFIX",
"type": "env",
"value": "DEVICE_IN_PREFIX"
},
{
"name": "DEVICE_IN_PREFIX",
"type": "env",
"value": "DEVICE_OUT_PREFIX"
},
{
"name": "DEVICE_IN_TOPIC",
"type": "env",
"value": "DEVICE_IN_TOPIC"
},
{
"name": "debug",
"type": "bool",
"value": "true"
}
],
"icon": "font-awesome/fa-cog"
},
{
"id": "be14f4e0.e0832",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceInPrefix",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "DEVICE_IN_PREFIX",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 440,
"wires": [
[
"61dda324.b63344"
]
]
},
{
"id": "61dda324.b63344",
"type": "ui_text_input",
"z": "b962d874.6a3ae8",
"name": "",
"label": "InPrefix ",
"tooltip": "mqtt subscription route : devEui<InPrefix>, default : -in",
"group": "114546cd.f687d9",
"order": 6,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 580,
"y": 440,
"wires": [
[
"361f3617.075ae2"
]
]
},
{
"id": "361f3617.075ae2",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceInPrefix",
"rules": [
{
"t": "set",
"p": "deviceInPrefix",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 440,
"wires": [
[]
]
},
{
"id": "47760796.5bb35",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceOutPrefix",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "DEVICE_OUT_PREFIX",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 480,
"wires": [
[
"d5771c96.353e78"
]
]
},
{
"id": "d5771c96.353e78",
"type": "ui_text_input",
"z": "b962d874.6a3ae8",
"name": "",
"label": "OutPrefix ",
"tooltip": "mqtt publish route : devEui<OutPrefix>/ default : -out",
"group": "114546cd.f687d9",
"order": 7,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 580,
"y": 480,
"wires": [
[
"f4e4ecd1.f76ad8"
]
]
},
{
"id": "f4e4ecd1.f76ad8",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceOutPrefix",
"rules": [
{
"t": "set",
"p": "deviceOutPrefix",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 480,
"wires": [
[]
]
},
{
"id": "cbd00a4d.541588",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceInTopic",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "DEVICE_IN_TOPIC",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 400,
"wires": [
[
"3e367e4a.1fc84a"
]
]
},
{
"id": "3e367e4a.1fc84a",
"type": "ui_text_input",
"z": "b962d874.6a3ae8",
"name": "",
"label": "InTopic",
"tooltip": "mqtt subscription route, default <devEui>-in/#",
"group": "114546cd.f687d9",
"order": 8,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 580,
"y": 400,
"wires": [
[
"baf062b8.f66b3"
]
]
},
{
"id": "baf062b8.f66b3",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceInTopic",
"rules": [
{
"t": "set",
"p": "deviceInTopic",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 400,
"wires": [
[]
]
},
{
"id": "c7a92a37.87605",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceType",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "DEVICE_TYPE",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 360,
"wires": [
[
"ab7353ec.3ef718"
]
]
},
{
"id": "ab7353ec.3ef718",
"type": "ui_text_input",
"z": "b962d874.6a3ae8",
"name": "",
"label": "Type",
"tooltip": "",
"group": "114546cd.f687d9",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 570,
"y": 360,
"wires": [
[
"eff6f1aa.f5c44"
]
]
},
{
"id": "eff6f1aa.f5c44",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceType",
"rules": [
{
"t": "set",
"p": "deviceType",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 810,
"y": 360,
"wires": [
[]
]
},
{
"id": "31ae8c14.b7750c",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceAppKey",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "DEVICE_APPKEY",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 320,
"wires": [
[
"8bdb14e0.986878"
]
]
},
{
"id": "8bdb14e0.986878",
"type": "ui_text_input",
"z": "b962d874.6a3ae8",
"name": "",
"label": "appKey",
"tooltip": "",
"group": "114546cd.f687d9",
"order": 5,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 580,
"y": 320,
"wires": [
[
"5313abc5.52a6cc"
]
]
},
{
"id": "5313abc5.52a6cc",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceAppKey",
"rules": [
{
"t": "set",
"p": "deviceAppKey",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 320,
"wires": [
[]
]
},
{
"id": "57cd30e0.7592c8",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceId",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "DEVICE_ID",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 280,
"wires": [
[
"e15d6355.dd5fa8"
]
]
},
{
"id": "e15d6355.dd5fa8",
"type": "ui_text_input",
"z": "b962d874.6a3ae8",
"name": "",
"label": "Id",
"tooltip": "",
"group": "114546cd.f687d9",
"order": 4,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 570,
"y": 280,
"wires": [
[
"d88d1bc0.c11818"
]
]
},
{
"id": "d88d1bc0.c11818",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceId",
"rules": [
{
"t": "set",
"p": "deviceId",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 800,
"y": 280,
"wires": [
[]
]
},
{
"id": "2aa100b7.8631a8",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceDevEui",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "DEVICE_DEVEUI",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 240,
"wires": [
[
"36f66f62.5b3468"
]
]
},
{
"id": "36f66f62.5b3468",
"type": "ui_text_input",
"z": "b962d874.6a3ae8",
"name": "",
"label": "devEui",
"tooltip": "",
"group": "114546cd.f687d9",
"order": 3,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 570,
"y": 240,
"wires": [
[
"70c100a1.c8ebc8"
]
]
},
{
"id": "70c100a1.c8ebc8",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceDevEui",
"rules": [
{
"t": "set",
"p": "deviceDevEui",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 240,
"wires": [
[]
]
},
{
"id": "69a3c204.6bc5c4",
"type": "debug",
"z": "b962d874.6a3ae8",
"name": "deviceSettingsUpdate",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 900,
"y": 640,
"wires": []
},
{
"id": "c7adef8b.c283d",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceName",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "DEVICE_NAME",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 200,
"wires": [
[
"5e6c6cab.7a7a34"
]
]
},
{
"id": "5e6c6cab.7a7a34",
"type": "ui_text_input",
"z": "b962d874.6a3ae8",
"name": "",
"label": "name",
"tooltip": "",
"group": "114546cd.f687d9",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 570,
"y": 200,
"wires": [
[
"53eb32ae.0c3cb4"
]
]
},
{
"id": "53eb32ae.0c3cb4",
"type": "change",
"z": "b962d874.6a3ae8",
"name": "deviceName",
"rules": [
{
"t": "set",
"p": "deviceName",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 810,
"y": 200,
"wires": [
[]
]
},
{
"id": "4865299c.4042f",
"type": "ui_button",
"z": "b962d874.6a3ae8",
"name": "",
"group": "114546cd.f687d9",
"order": 9,
"width": "3",
"height": "1",
"passthru": false,
"label": "save",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "true",
"payloadType": "bool",
"topic": "",
"x": 570,
"y": 580,
"wires": [
[
"2d011167.736776"
]
]
},
{
"id": "2d011167.736776",
"type": "delay",
"z": "b962d874.6a3ae8",
"name": "1msg/3s",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "3",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"x": 720,
"y": 580,
"wires": [
[
"95eac3e8.d7317"
]
]
},
{
"id": "95eac3e8.d7317",
"type": "function",
"z": "b962d874.6a3ae8",
"name": "setEnv",
"func": "try {\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n const processEnv = global.get(\"processEnv\", storeType);\n if (!processEnv) throw new Error(\"process.env unavailable\");\n const deviceDevEui = flow.get(\"deviceDevEui\");\n if (deviceDevEui) {\n processEnv.DEVICE_DEVEUI = deviceDevEui;\n } \n const deviceId = flow.get(\"deviceId\");\n if (deviceId) {\n processEnv.DEVICE_ID = deviceId;\n }\n const deviceAppKey = flow.get(\"deviceAppKey\");\n if (deviceAppKey) {\n processEnv.DEVICE_APPKEY = deviceAppKey;\n }\n const deviceType = flow.get(\"deviceType\");\n if (deviceType) {\n processEnv.DEVICE_TYPE = deviceType;\n }\n const deviceName = flow.get(\"deviceName\");\n if (deviceName) {\n processEnv.DEVICE_NAME = deviceName;\n }\n // ALOES - MQTT CONFIG\n const deviceInPrefix = flow.get(\"deviceInPrefix\");\n if (deviceInPrefix) {\n processEnv.DEVICE_IN_PREFIX = deviceInPrefix;\n }\n const deviceOutPrefix = flow.get(\"deviceOutPrefix\");\n if (deviceOutPrefix) {\n processEnv.DEVICE_OUT_PREFIX = deviceOutPrefix;\n }\n const deviceInTopic = flow.get(\"deviceInTopic\");\n if (deviceInTopic) {\n processEnv.DEVICE_IN_TOPIC = deviceInTopic;\n }\n if (env.get(\"debug\")) {\n return [msg,msg];\n }\n return [msg,null];\n}catch(error){\n return error;\n}\n",
"outputs": 2,
"noerr": 0,
"x": 870,
"y": 580,
"wires": [
[],
[
"69a3c204.6bc5c4"
]
]
},
{
"id": "114546cd.f687d9",
"type": "ui_group",
"z": "",
"name": "device",
"tab": "7fb22cc9.85b9fc",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "c0c587dc.6f76a8",
"type": "subflow",
"name": "save-settings",
"info": "",
"category": "aloes",
"in": [
{
"x": 80,
"y": 140,
"wires": [
{
"id": "7e0ce9f6.131ff8"
}
]
}
],
"out": [
{
"x": 840,
"y": 140,
"wires": [
{
"id": "5f636f95.8ca2b",
"port": 0
}
]
}
],
"env": [],
"icon": "node-red/file-out.png"
},
{
"id": "1e6a6d63.7b91e3",
"type": "function",
"z": "c0c587dc.6f76a8",
"name": "saveEnvToFile",
"func": "try {\n const processEnv = global.get(\"processEnv\");\n if (!processEnv) throw new Error(\"process.env not available\");\n if (!processEnv.NODE_ENV) {\n msg.filename = \"./.env\";\n } else {\n msg.filename = `./deploy/.env_${processEnv.NODE_ENV}`;\n }\n msg.payload = `NODE_ENV=${processEnv.NODE_ENV}\nNODE_RED_URL=${processEnv.NODE_RED_URL}\nNODE_RED_HOST=${processEnv.NODE_RED_HOST}\nNODE_RED_PORT=${processEnv.NODE_RED_PORT}\nNODE_RED_ADMIN_ROOT=${processEnv.NODE_RED_ADMIN_ROOT}\nNODE_RED_API_ROOT=${processEnv.NODE_RED_API_ROOT}\nNODE_RED_UI_PATH=${processEnv.NODE_RED_UI_PATH}\nNODE_RED_USER_DIR=${processEnv.NODE_RED_USER_DIR}\nNODE_RED_USERNAME=${processEnv.NODE_RED_USERNAME}\nNODE_RED_USERPASS=${processEnv.NODE_RED_USERPASS}\nNODE_RED_PASSHASH=${processEnv.NODE_RED_PASSHASH}\nNODE_RED_ADMIN_PASSHASH=${processEnv.NODE_RED_ADMIN_PASSHASH}\nNODE_RED_SESSION_SECRET=${processEnv.NODE_RED_SESSION_SECRET}\nNODE_RED_CREDENTIAL_SECRET=${processEnv.NODE_RED_CREDENTIAL_SECRET}\nNODE_RED_STORE_TYPE=${processEnv.NODE_RED_STORE_TYPE}\nALOES_MQTT_HOST=${processEnv.ALOES_MQTT_HOST}\nALOES_MQTT_PORT=${processEnv.ALOES_MQTT_PORT}\nALOES_USER_EMAIL=${processEnv.ALOES_USER_EMAIL}\nALOES_USER_PASSWORD=${processEnv.ALOES_USER_PASSWORD}\nDEVICE_DEVEUI=${processEnv.DEVICE_DEVEUI}\nDEVICE_ID=${processEnv.DEVICE_ID}\nDEVICE_APPKEY=${processEnv.DEVICE_APPKEY}\nDEVICE_TYPE=${processEnv.DEVICE_TYPE}\nDEVICE_NAME=${processEnv.DEVICE_NAME}\nDEVICE_IN_PREFIX=${processEnv.DEVICE_IN_PREFIX}\nDEVICE_OUT_PREFIX=${processEnv.DEVICE_OUT_PREFIX}\nDEVICE_IN_TOPIC=${processEnv.DEVICE_IN_TOPIC}\nSERVER_LOGGER_LEVEL=${processEnv.SERVER_LOGGER_LEVEL}\nTUNNEL_URL=${processEnv.TUNNEL_URL}\nGIT_REPO_SSH_URL=${processEnv.GIT_REPO_SSH_URL}`;\n return msg;\n} catch(error){\n return error;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 440,
"y": 140,
"wires": [
[
"5f636f95.8ca2b"
]
]
},
{
"id": "5f636f95.8ca2b",
"type": "file",
"z": "c0c587dc.6f76a8",
"name": "",
"filename": "",
"appendNewline": false,
"createDir": false,
"overwriteFile": "true",
"encoding": "none",
"x": 630,
"y": 140,
"wires": [
[
"2c5c054a.c3fff2"
]
]
},
{
"id": "51abffc3.eef55",
"type": "ui_toast",
"z": "c0c587dc.6f76a8",
"position": "top right",
"displayTime": "3",
"highlight": "",
"outputs": 0,
"ok": "OK",
"cancel": "",
"topic": "",
"name": "",
"x": 707,
"y": 257,
"wires": []
},
{
"id": "2c5c054a.c3fff2",
"type": "function",
"z": "c0c587dc.6f76a8",
"name": "buildNotif",
"func": "msg.payload = \"Environment variables file updated, please restart app to validate them.\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 680,
"y": 200,
"wires": [
[
"51abffc3.eef55"
]
]
},
{
"id": "7e0ce9f6.131ff8",
"type": "delay",
"z": "c0c587dc.6f76a8",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "5",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"x": 217,
"y": 137,
"wires": [
[
"1e6a6d63.7b91e3"
]
]
},
{
"id": "d87e9330.31fc38",
"type": "subflow",
"name": "node-red-settings",
"info": "",
"category": "aloes",
"in": [
{
"x": 60,
"y": 180,
"wires": [
{
"id": "a42aedc0.22462"
},
{
"id": "8a4aed27.ced9f8"
},
{
"id": "77e9b389.65ef9c"
},
{
"id": "646702aa.b6b74c"
},
{
"id": "7fa9b28b.d2eda4"
}
]
}
],
"out": [
{
"x": 1120,
"y": 340,
"wires": [
{
"id": "69d94929.e362e8",
"port": 0
}
]
}
],
"env": [
{
"name": "NODE_RED_URL",
"type": "env",
"value": "NODE_RED_URL"
},
{
"name": "NODE_RED_HOST",
"type": "env",
"value": "NODE_RED_HOST"
},
{
"name": "NODE_RED_PORT",
"type": "env",
"value": "NODE_RED_PORT"
},
{
"name": "NODE_RED_ADMIN_ROOT",
"type": "env",
"value": "NODE_RED_ADMIN_ROOT"
},
{
"name": "NODE_RED_API_ROOT",
"type": "env",
"value": "NODE_RED_API_ROOT"
},
{
"name": "debug",
"type": "bool",
"value": "true"
}
],
"icon": "font-awesome/fa-cog"
},
{
"id": "a42aedc0.22462",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedHost",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "NODE_RED_HOST",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 300,
"y": 140,
"wires": [
[
"5ebcb401.c7ae34"
]
]
},
{
"id": "1f9d8375.e4b535",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedHost",
"rules": [
{
"t": "set",
"p": "nodeRedHost",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 800,
"y": 140,
"wires": [
[]
]
},
{
"id": "5ebcb401.c7ae34",
"type": "ui_text_input",
"z": "d87e9330.31fc38",
"name": "",
"label": "HTTP Host",
"tooltip": "",
"group": "3f8ea5e6.90e04a",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 550,
"y": 140,
"wires": [
[
"1f9d8375.e4b535"
]
]
},
{
"id": "77e9b389.65ef9c",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedPort",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "NODE_RED_PORT",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 300,
"y": 180,
"wires": [
[
"e8f42a78.884b38"
]
]
},
{
"id": "1b91858e.4f0a22",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedPort",
"rules": [
{
"t": "set",
"p": "nodeRedPort",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 800,
"y": 180,
"wires": [
[]
]
},
{
"id": "e8f42a78.884b38",
"type": "ui_text_input",
"z": "d87e9330.31fc38",
"name": "",
"label": "HTTP Port",
"tooltip": "",
"group": "3f8ea5e6.90e04a",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 550,
"y": 180,
"wires": [
[
"1b91858e.4f0a22"
]
]
},
{
"id": "b540848b.2a1bf8",
"type": "function",
"z": "d87e9330.31fc38",
"name": "setEnv",
"func": "try {\n const processEnv = global.get(\"processEnv\");\n if (!processEnv) throw new Error(\"process.env not available\");\n // NODE-RED CONFIG\n if (msg.payload.nodeRedUrl) {\n processEnv.NODE_RED_URL = msg.payload.nodeRedUrl;\n } \n if (msg.payload.nodeRedPort) {\n processEnv.NODE_RED_PORT = msg.payload.nodeRedPort;\n }\n if (msg.payload.nodeRedHost) {\n processEnv.NODE_RED_HOST = msg.payload.nodeRedHost;\n } \n if (msg.payload.nodeRedAdminRoot) {\n processEnv.NODE_RED_ADMIN_ROOT = msg.payload.nodeRedAdminRoot;\n } \n if (msg.payload.nodeRedApiRoot) {\n processEnv.NODE_RED_API_ROOT = msg.payload.nodeRedApiRoot;\n }\n if (env.get(\"debug\")) {\n return [msg,msg];\n }\n return [msg,null];\n}catch(error){\n return error;\n}\n",
"outputs": 2,
"noerr": 0,
"x": 870,
"y": 320,
"wires": [
[],
[]
]
},
{
"id": "8a4aed27.ced9f8",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedUrl",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "NODE_RED_URL",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 290,
"y": 100,
"wires": [
[
"c35d0cf0.367778"
]
]
},
{
"id": "9fd34284.6a981",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedUrl",
"rules": [
{
"t": "set",
"p": "nodeRedUrl",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 790,
"y": 100,
"wires": [
[]
]
},
{
"id": "c35d0cf0.367778",
"type": "ui_text_input",
"z": "d87e9330.31fc38",
"name": "",
"label": "HTTP URL",
"tooltip": "",
"group": "3f8ea5e6.90e04a",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 550,
"y": 100,
"wires": [
[
"9fd34284.6a981"
]
]
},
{
"id": "646702aa.b6b74c",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedAdminRoot",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "NODE_RED_ADMIN_ROOT",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 220,
"wires": [
[
"98a2c855.2c2b4"
]
]
},
{
"id": "26bf3b87.4f26fc",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedAdminRoot",
"rules": [
{
"t": "set",
"p": "nodeRedAdminRoot",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 220,
"wires": [
[]
]
},
{
"id": "98a2c855.2c2b4",
"type": "ui_text_input",
"z": "d87e9330.31fc38",
"name": "",
"label": "HTTP Admin Root",
"tooltip": "URL/<admin root>",
"group": "3f8ea5e6.90e04a",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 570,
"y": 220,
"wires": [
[
"26bf3b87.4f26fc"
]
]
},
{
"id": "b5828b5e.d928",
"type": "ui_text_input",
"z": "d87e9330.31fc38",
"name": "",
"label": "HTTP API Root",
"tooltip": "URL/<api root>",
"group": "3f8ea5e6.90e04a",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 560,
"y": 260,
"wires": [
[
"19ad009b.09421f"
]
]
},
{
"id": "7fa9b28b.d2eda4",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedApiRoot",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "NODE_RED_API_ROOT",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 310,
"y": 260,
"wires": [
[
"b5828b5e.d928"
]
]
},
{
"id": "19ad009b.09421f",
"type": "change",
"z": "d87e9330.31fc38",
"name": "nodeRedApiRoot",
"rules": [
{
"t": "set",
"p": "nodeRedApiRoot",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 810,
"y": 260,
"wires": [
[]
]
},
{
"id": "661ef748.89ab7",
"type": "debug",
"z": "d87e9330.31fc38",
"name": "NodeRedSettingsUpdate",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 950,
"y": 420,
"wires": []
},
{
"id": "7896f940.bf8e2",
"type": "ui_button",
"z": "d87e9330.31fc38",
"name": "",
"group": "3f8ea5e6.90e04a",
"order": 9,
"width": "3",
"height": "1",
"passthru": false,
"label": "save",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "true",
"payloadType": "bool",
"topic": "",
"x": 530,
"y": 360,
"wires": [
[
"8087f288.7cd2f8"
]
]
},
{
"id": "8087f288.7cd2f8",
"type": "delay",
"z": "d87e9330.31fc38",
"name": "1msg/3s",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "3",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"x": 680,
"y": 360,
"wires": [
[
"69d94929.e362e8"
]
]
},
{
"id": "69d94929.e362e8",
"type": "function",
"z": "d87e9330.31fc38",
"name": "setEnv",
"func": "try {\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n const processEnv = global.get(\"processEnv\", storeType);\n if (!processEnv) throw new Error(\"process.env unavailable\");\n const nodeRedUrl = flow.get(\"nodeRedUrl\")\n if (msg.payload.nodeRedUrl) {\n processEnv.NODE_RED_URL = nodeRedUrl;\n } \n const nodeRedPort = flow.get(\"nodeRedPort\")\n if (nodeRedPort) {\n processEnv.NODE_RED_PORT = nodeRedPort;\n }\n const nodeRedHost = flow.get(\"nodeRedHost\")\n if (nodeRedHost) {\n processEnv.NODE_RED_HOST = nodeRedHost;\n } \n const nodeRedAdminRoot = flow.get(\"nodeRedAdminRoot\")\n if (nodeRedAdminRoot) {\n processEnv.NODE_RED_ADMIN_ROOT = nodeRedAdminRoot;\n } \n const nodeRedApiRoot = flow.get(\"nodeRedApiRoot\")\n if (msg.payload.nodeRedApiRoot) {\n processEnv.NODE_RED_API_ROOT = nodeRedApiRoot;\n }\n const tunnelUrl = flow.get(\"tunnelUrl\")\n if (tunnelUrl) {\n processEnv.TUNNEL_URL = tunnelUrl;\n }\n if (env.get(\"debug\")) {\n return [msg,msg];\n }\n return [msg,null];\n}catch(error){\n return error;\n}\n",
"outputs": 2,
"noerr": 0,
"x": 870,
"y": 360,
"wires": [
[],
[
"661ef748.89ab7"
]
]
},
{
"id": "3f8ea5e6.90e04a",
"type": "ui_group",
"z": "",
"name": "node-red",
"tab": "7fb22cc9.85b9fc",
"order": 3,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "ed468146.145398",
"type": "subflow",
"name": "aloes-settings",
"info": "",
"category": "aloes",
"in": [
{
"x": 40,
"y": 360,
"wires": [
{
"id": "71efc8a0.add45"
},
{
"id": "2642a748.6b0d78"
},
{
"id": "31aeff81.55442"
},
{
"id": "6adf001a.67be3"
}
]
}
],
"out": [
{
"x": 1100,
"y": 560,
"wires": [
{
"id": "87e9ce46.56b8f",
"port": 0
}
]
}
],
"env": [
{
"name": "ALOES_MQTT_HOST",
"type": "env",
"value": "ALOES_MQTT_HOST"
},
{
"name": "ALOES_MQTT_PORT",
"type": "env",
"value": "ALOES_MQTT_PORT"
},
{
"name": "ALOES_USER_EMAIL",
"type": "env",
"value": "ALOES_USER_EMAIL"
},
{
"name": "ALOES_USER_PASSWORD",
"type": "env",
"value": "ALOES_USER_PASSWORD"
},
{
"name": "debug",
"type": "bool",
"value": "true"
}
],
"icon": "font-awesome/fa-cog"
},
{
"id": "2642a748.6b0d78",
"type": "change",
"z": "ed468146.145398",
"name": "aloesMqttPort",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "ALOES_MQTT_PORT",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 280,
"y": 360,
"wires": [
[
"e79b9c2e.ca531"
]
]
},
{
"id": "71efc8a0.add45",
"type": "change",
"z": "ed468146.145398",
"name": "aloesMqttHost",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "ALOES_MQTT_HOST",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 280,
"y": 320,
"wires": [
[
"c81dc49c.c62dd"
]
]
},
{
"id": "e79b9c2e.ca531",
"type": "ui_text_input",
"z": "ed468146.145398",
"name": "",
"label": "MQTT Port",
"tooltip": "",
"group": "4b214821.08b9",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 550,
"y": 360,
"wires": [
[
"3e833969.d8142e"
]
]
},
{
"id": "c81dc49c.c62dd",
"type": "ui_text_input",
"z": "ed468146.145398",
"name": "",
"label": "MQTT Host",
"tooltip": "",
"group": "4b214821.08b9",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 550,
"y": 320,
"wires": [
[
"228df67a.46a07a"
]
]
},
{
"id": "3e833969.d8142e",
"type": "change",
"z": "ed468146.145398",
"name": "aloesMqttPort",
"rules": [
{
"t": "set",
"p": "aloesMqttPort",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 360,
"wires": [
[]
]
},
{
"id": "228df67a.46a07a",
"type": "change",
"z": "ed468146.145398",
"name": "aloesMqttHost",
"rules": [
{
"t": "set",
"p": "aloesMqttHost",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 320,
"wires": [
[]
]
},
{
"id": "31aeff81.55442",
"type": "change",
"z": "ed468146.145398",
"name": "aloesUserEmail",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "ALOES_USER_EMAIL",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 280,
"y": 420,
"wires": [
[
"d3b6449f.7ef628"
]
]
},
{
"id": "d3b6449f.7ef628",
"type": "ui_text_input",
"z": "ed468146.145398",
"name": "",
"label": "Aloes Email",
"tooltip": "use the same email address as defined on aloes",
"group": "4b214821.08b9",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 550,
"y": 420,
"wires": [
[
"64611761.a34c3"
]
]
},
{
"id": "64611761.a34c3",
"type": "change",
"z": "ed468146.145398",
"name": "aloesUserEmail",
"rules": [
{
"t": "set",
"p": "aloesUserEmail",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 420,
"wires": [
[]
]
},
{
"id": "813fec44.7fe3c8",
"type": "debug",
"z": "ed468146.145398",
"name": "aloesSettingUpdate",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 840,
"y": 640,
"wires": []
},
{
"id": "6adf001a.67be3",
"type": "change",
"z": "ed468146.145398",
"name": "aloesUserPassword",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "ALOES_USER_PASSWORD",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 300,
"y": 460,
"wires": [
[
"c0d6316.46fe9d"
]
]
},
{
"id": "c0d6316.46fe9d",
"type": "ui_text_input",
"z": "ed468146.145398",
"name": "",
"label": "Aloes password",
"tooltip": "use the same password as defined on aloes",
"group": "4b214821.08b9",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"mode": "text",
"delay": "0",
"topic": "",
"x": 560,
"y": 460,
"wires": [
[
"ae5671f1.db66e"
]
]
},
{
"id": "ae5671f1.db66e",
"type": "change",
"z": "ed468146.145398",
"name": "aloesUserPassword",
"rules": [
{
"t": "set",
"p": "aloesUserPassword",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 840,
"y": 460,
"wires": [
[]
]
},
{
"id": "2d59a642.684822",
"type": "ui_button",
"z": "ed468146.145398",
"name": "",
"group": "4b214821.08b9",
"order": 9,
"width": "3",
"height": "1",
"passthru": false,
"label": "save",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "true",
"payloadType": "bool",
"topic": "",
"x": 530,
"y": 580,
"wires": [
[
"3a17ea9d.549556"
]
]
},
{
"id": "87e9ce46.56b8f",
"type": "function",
"z": "ed468146.145398",
"name": "setEnv",
"func": "try {\n const storeType = env.get(\"store_type\") || \"memoryOnly\";\n const processEnv = global.get(\"processEnv\", storeType);\n if (!processEnv) throw new Error(\"process.env unavailable\");\n const aloesHttpHost = flow.get(\"aloesHttpHost\")\n if (aloesHttpHost) {\n processEnv.ALOES_HTTP_HOST = aloesHttpHost;\n } \n const aloesHttpPort = flow.get(\"aloesHttpPort\")\n if (aloesHttpPort) {\n processEnv.ALOES_HTTP_PORT = aloesHttpPort;\n } \n const aloesMqttHost = flow.get(\"aloesMqttHost\")\n if (aloesMqttHost) {\n processEnv.ALOES_MQTT_HOST = aloesMqttHost;\n } \n const aloesMqttPort = flow.get(\"aloesMqttPort\")\n if (flow.get(\"aloesMqttPort\")) {\n processEnv.ALOES_MQTT_PORT = aloesMqttPort;\n } \n const aloesUserEmail = flow.get(\"aloesUserEmail\")\n if (flow.get(\"aloesUserEmail\")) {\n processEnv.ALOES_USER_EMAIL = aloesUserEmail;\n } \n const aloesUserPassword = flow.get(\"aloesUserPassword\")\n if (flow.get(\"aloesUserPassword\")) {\n processEnv.ALOES_USER_PASSWORD = aloesUserPassword;\n } \n if (env.get(\"debug\")) {\n return [msg,msg];\n }\n return [msg,null];\n}catch(error){\n return error;\n}\n",
"outputs": 2,
"noerr": 0,
"x": 830,
"y": 580,
"wires": [
[],
[
"813fec44.7fe3c8"
]
]
},
{
"id": "3a17ea9d.549556",
"type": "delay",
"z": "ed468146.145398",
"name": "1msg/3s",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "3",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"x": 680,
"y": 580,
"wires": [
[
"87e9ce46.56b8f"
]
]
},
{
"id": "4b214821.08b9",
"type": "ui_group",
"z": "",
"name": "aloes",
"tab": "7fb22cc9.85b9fc",
"order": 2,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "7fb22cc9.85b9fc",
"type": "ui_tab",
"z": "",
"name": "settings",
"icon": "dashboard",
"order": 2,
"disabled": false,
"hidden": false
},
{
"id": "f789c8fe.2fdde",
"type": "tab",
"label": "Core",
"disabled": false,
"info": "https://github.com/aloes-io/aloes-light-handlers"
},
{
"id": "aee33a1c.7402f",
"type": "comment",
"z": "f789c8fe.2fdde",
"name": "Init",
"info": "",
"x": 130,
"y": 80,
"wires": []
},
{
"id": "48ad23c4.e8fbe4",
"type": "ui_button",
"z": "f789c8fe.2fdde",
"name": "",
"group": "209bd20b.48e4c6",
"order": 8,
"width": 0,
"height": 0,
"passthru": false,
"label": "Restart app",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "{\"requestUrl\":\"restart\",\"method\":\"GET\"}",
"payloadType": "json",
"topic": "",
"x": 830,
"y": 480,
"wires": [
[
"9d395bf9.efdae8"
]
]
},
{
"id": "9d395bf9.efdae8",
"type": "link out",
"z": "f789c8fe.2fdde",
"name": "reboot-app",
"links": [
"a20d7553.175b1",
"996bc924.6c79f"
],
"x": 1155,
"y": 480,
"wires": []
},
{
"id": "b6b2c64e.d76fc8",
"type": "subflow:ed468146.145398",
"z": "f789c8fe.2fdde",
"name": "",
"env": [],
"x": 980,
"y": 240,
"wires": [
[
"3cf37524.1fe332"
]
]
},
{
"id": "1be2a570.6b4163",
"type": "subflow:d87e9330.31fc38",
"z": "f789c8fe.2fdde",
"name": "",
"env": [],
"x": 990,
"y": 320,
"wires": [
[
"5bfd0176.25db7"
]
]
},
{
"id": "4b39fb34.71e05c",
"type": "link in",
"z": "f789c8fe.2fdde",
"name": "->node-red-settings-interface",
"links": [
"6ca82e75.36a378",
"b3462368.a93a7",
"905ff57f.c9308",
"6b12ab2b.5d900c"
],
"x": 775,
"y": 320,
"wires": [
[
"1be2a570.6b4163"
]
]
},
{
"id": "6a14fc0.8515d04",
"type": "link in",
"z": "f789c8fe.2fdde",
"name": "->aloes-client-settings-interface",
"links": [
"6ca82e75.36a378",
"b3462368.a93a7",
"905ff57f.c9308",
"6b12ab2b.5d900c"
],
"x": 775,
"y": 240,
"wires": [
[
"b6b2c64e.d76fc8"
]
]
},
{
"id": "1ecee956.6ad337",
"type": "subflow:c0c587dc.6f76a8",
"z": "f789c8fe.2fdde",
"name": "",
"env": [],
"x": 980,
"y": 400,
"wires": [
[
"67bf3235.efbfbc"
]
]
},
{
"id": "f64a82db.33691",
"type": "link in",
"z": "f789c8fe.2fdde",
"name": "before-save-env-vars",
"links": [
"5bfd0176.25db7",
"3cf37524.1fe332",
"711d922e.127e34"
],
"x": 775,
"y": 400,
"wires": [
[
"1ecee956.6ad337"
]
]
},
{
"id": "3cf37524.1fe332",
"type": "link out",
"z": "f789c8fe.2fdde",
"name": "aloes-client-settings-interface->",
"links": [
"f64a82db.33691"
],
"x": 1155,
"y": 240,
"wires": []
},
{
"id": "5bfd0176.25db7",
"type": "link out",
"z": "f789c8fe.2fdde",
"name": "node-red-settings-interface->",
"links": [
"f64a82db.33691"
],
"x": 1155,
"y": 320,
"wires": []
},
{
"id": "af265d98.e84eb8",
"type": "subflow:b962d874.6a3ae8",
"z": "f789c8fe.2fdde",
"name": "",
"env": [],
"x": 980,
"y": 160,
"wires": [
[
"711d922e.127e34"
]
]
},
{
"id": "eabc923d.1233e",
"type": "link in",
"z": "f789c8fe.2fdde",
"name": "->device-settings-interface",
"links": [
"905ff57f.c9308",
"6b12ab2b.5d900c"
],
"x": 775,
"y": 160,
"wires": [
[
"af265d98.e84eb8"
]
]
},
{
"id": "711d922e.127e34",
"type": "link out",
"z": "f789c8fe.2fdde",
"name": "device-settings-interface->",
"links": [
"f64a82db.33691"
],
"x": 1155,
"y": 160,
"wires": []
},
{
"id": "67bf3235.efbfbc",
"type": "debug",
"z": "f789c8fe.2fdde",
"name": "saveSettings",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 1190,
"y": 400,
"wires": []
},
{
"id": "d00ae088.261dd8",
"type": "inject",
"z": "f789c8fe.2fdde",
"name": "bootApp",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 160,
"y": 140,
"wires": [
[
"6aa24973.43e768"
]
]
},
{
"id": "8af3af59.de5708",
"type": "debug",
"z": "f789c8fe.2fdde",
"name": "INIT",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 350,
"y": 280,
"wires": []
},
{
"id": "60727e18.45405",
"type": "subflow:53d275a4.8b0044",
"z": "f789c8fe.2fdde",
"name": "",
"env": [],
"x": 280,
"y": 200,
"wires": [
[
"8af3af59.de5708",
"6b12ab2b.5d900c"
]
]
},
{
"id": "6aa24973.43e768",
"type": "link out",
"z": "f789c8fe.2fdde",
"name": "boot-app",
"links": [
"1d898b50.ae5a75",
"6ae1e1f7.03929"
],
"x": 455,
"y": 140,
"wires": []
},
{
"id": "1d898b50.ae5a75",
"type": "link in",
"z": "f789c8fe.2fdde",
"name": "before-state-init",
"links": [
"6aa24973.43e768"
],
"x": 95,
"y": 200,
"wires": [
[
"60727e18.45405"
]
]
},
{
"id": "6b12ab2b.5d900c",
"type": "link out",
"z": "f789c8fe.2fdde",
"name": "after-state-init",
"links": [
"2f687c43.036514",
"4b39fb34.71e05c",
"eabc923d.1233e",
"6a14fc0.8515d04"
],
"x": 455,
"y": 200,
"wires": []
},
{
"id": "7039e002.9cf228",
"type": "subflow:25ce96fe.d3ecc2",
"z": "f789c8fe.2fdde",
"name": "",
"env": [],
"x": 280,
"y": 560,
"wires": [
[
"280c42b4.d09c5e"
]
]
},
{
"id": "996bc924.6c79f",
"type": "link in",
"z": "f789c8fe.2fdde",
"name": "->node-red-http-in",
"links": [
"b6a4e8ff.1b1848",
"cb3f010.077a6",
"bd30fa14.040b68",
"9d395bf9.efdae8"
],
"x": 95,
"y": 560,
"wires": [
[
"7039e002.9cf228"
]
]
},
{
"id": "280c42b4.d09c5e",
"type": "link out",
"z": "f789c8fe.2fdde",
"name": "node-red-http-in->",
"links": [],
"x": 455,
"y": 560,
"wires": []
},
{
"id": "bdc907dd.d5654",
"type": "comment",
"z": "f789c8fe.2fdde",
"name": "HTTP IN",
"info": "",
"x": 140,
"y": 500,
"wires": []
},
{
"id": "3ee61c64.9de4dc",
"type": "catch",
"z": "f789c8fe.2fdde",
"name": "",
"scope": [
"b6b2c64e.d76fc8",
"33d1fd18.730ab2",
"276b33c2.4503c4",
"af265d98.e84eb8",
"1ecee956.6ad337"
],
"uncaught": false,
"x": 130,
"y": 420,
"wires": [
[
"fec3928d.2d5c78"
]
]
},
{
"id": "8c76bdcc.33d45",
"type": "comment",
"z": "f789c8fe.2fdde",
"name": "Errors",
"info": "",
"x": 130,
"y": 360,
"wires": []
},
{
"id": "fec3928d.2d5c78",
"type": "debug",
"z": "f789c8fe.2fdde",
"name": "ERROR",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 340,
"y": 420,
"wires": []
},
{
"id": "8e1f26be.a52cb",
"type": "ui_button",
"z": "f789c8fe.2fdde",
"name": "",
"group": "209bd20b.48e4c6",
"order": 8,
"width": 0,
"height": 0,
"passthru": false,
"label": "Shutdown device",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "sudo shutdown -h now",
"payloadType": "str",
"topic": "",
"x": 850,
"y": 520,
"wires": [
[
"e5a4bcc2.228668"
]
]
},
{
"id": "4949a8a7.24e0c",
"type": "ui_button",
"z": "f789c8fe.2fdde",
"name": "",
"group": "209bd20b.48e4c6",
"order": 8,
"width": 0,
"height": 0,
"passthru": false,
"label": "Restart device",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "sudo reboot",
"payloadType": "str",
"topic": "",
"x": 840,
"y": 560,
"wires": [
[
"e5a4bcc2.228668"
]
]
},
{
"id": "e5a4bcc2.228668",
"type": "exec",
"z": "f789c8fe.2fdde",
"command": "",
"addpay": true,
"append": "",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "",
"x": 1130,
"y": 540,
"wires": [
[],
[],
[]
]
},
{
"id": "8aa2ae25.40bcd8",
"type": "ui_ui_control",
"z": "f789c8fe.2fdde",
"name": "",
"x": 380,
"y": 720,
"wires": [
[
"abcf4589.163aa"
]
]
},
{
"id": "4275feb2.f7ff48",
"type": "inject",
"z": "f789c8fe.2fdde",
"name": "",
"topic": "",
"payload": "{\"tab\":\"home\",\"hide\":[\"settings\"]}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 720,
"wires": [
[
"8aa2ae25.40bcd8"
]
]
},
{
"id": "abcf4589.163aa",
"type": "subflow:bf045b60.fcf578",
"z": "f789c8fe.2fdde",
"name": "",
"env": [],
"x": 580,
"y": 720,
"wires": []
},
{
"id": "c72c9b51.7a9d6",
"type": "comment",
"z": "f789c8fe.2fdde",
"name": "UI ROUTER",
"info": "",
"x": 150,
"y": 660,
"wires": []
},
{
"id": "d0e4e2a6.487698",
"type": "comment",
"z": "f789c8fe.2fdde",
"name": "ADMIN INTERFACES",
"info": "",
"x": 860,
"y": 80,
"wires": []
},
{
"id": "c04d12e6.f2aed",
"type": "link out",
"z": "f789c8fe.2fdde",
"name": "device-rx->",
"links": [
"4d28dd6.a1b8ca4",
"19def607.021152",
"718fa75e.952fc"
],
"x": 315,
"y": 880,
"wires": []
},
{
"id": "1dd3d9aa.2d13d6",
"type": "subflow:5e808641.b2fa7",
"z": "f789c8fe.2fdde",
"name": "",
"env": [],
"x": 140,
"y": 880,
"wires": [
[],
[
"c04d12e6.f2aed"
]
],
"info": "Configure MQTT Client with env variables\n\n- HOST : ${ALOES_MQTT_HOST}\n\n- PORT : ${ALOES_MQTT_PORT}\n\n- CLIENT ID : ${DEVICE_DEVEUI}\n\n- USERNAME : ${DEVICE_ID}\n\n- PASSWORD : ${DEVICE_APPKEY}"
},
{
"id": "d13a65e6.872e1",
"type": "link in",
"z": "f789c8fe.2fdde",
"name": "->device-tx",
"links": [
"ffce6a0f.1831e8",
"534eb815.853a3",
"75c43f7f.c900c8",
"9632753.4bdca08",
"7806247f.f0a5e4",
"6233a4e0.3a9054",
"eca508b3.4063c",
"9f900528.16a108",
"fa37bf1e.d30998"
],
"x": 880,
"y": 880,
"wires": [
[
"9f1e5bee.14ddb"
]
]
},
{
"id": "9f1e5bee.14ddb",
"type": "subflow:401f859.7054efc",
"z": "f789c8fe.2fdde",
"name": "",
"env": [
{
"name": "debug",
"type": "bool",
"value": "false"
}
],
"x": 1100,
"y": 880,
"wires": [],
"info": "Configure MQTT Client with env variables\n\n- HOST : ${ALOES_MQTT_HOST}\n\n- PORT : ${ALOES_MQTT_PORT}\n\n- CLIENT ID : ${DEVICE_DEVEUI}\n\n- USERNAME : ${DEVICE_ID}\n\n- PASSWORD : ${DEVICE_APPKEY}"
},
{
"id": "9cd9b06a.ca6328",
"type": "comment",
"z": "f789c8fe.2fdde",
"name": "MQTT OUT",
"info": "## Protocol\n\n+prefixedDevEui = devEui+inPrefix\n+method = 0 (\"HEAD\") | 1 (\"POST\") | 2 (\"GET\") | 3 (\"Internal\") | 4 (\"STREAM\")\n\n+prefixedDevEui/+method/+omaObjectId/+nativeSensorId/omaResourceId",
"x": 930,
"y": 820,
"wires": []
},
{
"id": "cb301e29.3bcb88",
"type": "comment",
"z": "f789c8fe.2fdde",
"name": "MQTT IN",
"info": "## Protocol\n\n+prefixedDevEui = devEui+inPrefix\n+method = 0 (\"HEAD\") | 1 (\"POST\") | 2 (\"GET\") | 3 (\"Internal\") | 4 (\"STREAM\")\n\n+prefixedDevEui/+method/+omaObjectId/+nativeSensorId/omaResourceId",
"x": 140,
"y": 820,
"wires": []
},
{
"id": "e126c868.06ec88",
"type": "link in",
"z": "f789c8fe.2fdde",
"name": "->restart-device",
"links": [
"abdef1ee.1a1338"
],
"x": 655,
"y": 560,
"wires": [
[
"4949a8a7.24e0c"
]
]
},
{
"id": "fec1e4b0.b7f2d",
"type": "ui_template",
"z": "f789c8fe.2fdde",
"group": "f7502579.7050a8",
"name": "device-status",
"order": 1,
"width": "10",
"height": "1",
"format": "<!DOCTYPE html>\n<svg viewBox=\"0 0 250 40\" id=\"{{'devices-status-'+ $id}}\">\n <text x=\"0\" y=\"25\" style=\"{{'font-weight:700'}}\" >{{$deviceName}}</text>\n <circle id=\"{{'devices-status-icon-'+$id}}\" x=\"0\" y=\"0\" cx=\"250\" 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 if (msg && msg.device) {\n scope.$deviceName = msg.device.name;\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})(scope);\n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"templateScope": "local",
"x": 560,
"y": 1040,
"wires": [
[]
]
},
{
"id": "ea0708e0.95472",
"type": "status",
"z": "f789c8fe.2fdde",
"name": "device-rx status",
"scope": [
"633b4043.f2982",
"13ad05b4.c80fe2"
],
"x": 160,
"y": 1040,
"wires": [
[
"b2cab557.4864b"
]
]
},
{
"id": "b2cab557.4864b",
"type": "function",
"z": "f789c8fe.2fdde",
"name": "parseStatus",
"func": "try {\n let status = false;\n msg.device = {};\n msg.device.name = env.get(\"DEVICE_NAME\");\n if (msg.status && msg.status.text && msg.status.text.startsWith(\"node-red:common.status.\")) {\n if (msg.status.text.endsWith(\"connected\")) {\n msg.device.status = true;\n } else if (msg.status.text.endsWith(\"disconnected\")) {\n msg.device.status = false;\n }\n }\n return msg;\n} catch(error) {\n return error;\n}",
"outputs": 1,
"noerr": 0,
"x": 370,
"y": 1040,
"wires": [
[
"fec1e4b0.b7f2d"
]
]
},
{
"id": "55d22110.148c18",
"type": "comment",
"z": "f789c8fe.2fdde",
"name": "DEVICE",
"info": "",
"x": 140,
"y": 980,
"wires": []
},
{
"id": "209bd20b.48e4c6",
"type": "ui_group",
"z": "",
"name": "commands",
"tab": "7fb22cc9.85b9fc",
"order": 4,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "f7502579.7050a8",
"type": "ui_group",
"z": "",
"name": "device-interfaces",
"tab": "df0ffcc6.903c4",
"order": 1,
"disp": false,
"width": "10",
"collapse": false
},
{
"id": "df0ffcc6.903c4",
"type": "ui_tab",
"z": "",
"name": "settings",
"icon": "dashboard",
"order": 2,
"disabled": false,
"hidden": false
}
]
@getlarge
Copy link
Author

Node-red flow to quickly create a device using Aloes light protocol, use after registering the device devEui on your Aloes account.

This snippet requires :

  • Your own instance of device-manager or an account on aloes.io
  • A machine running node-red-device

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