From af7d56696d500c9026dcd1ff47c644c0c7ddea2e Mon Sep 17 00:00:00 2001 From: Aiko Mastboom Date: Thu, 14 May 2015 00:28:19 +0200 Subject: [PATCH] pretty json --- .gitignore | 3 + flows_node-red.json | 257 +------------------------------------------- settings.js | 162 ++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 256 deletions(-) create mode 100644 settings.js diff --git a/.gitignore b/.gitignore index e69de29..0d73247 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,3 @@ +/node_modules/ +.config.json +*.backup diff --git a/flows_node-red.json b/flows_node-red.json index eb47ba1..455613d 100644 --- a/flows_node-red.json +++ b/flows_node-red.json @@ -1,256 +1 @@ -[ - { - "type": "tab", - "id": "e3ca4149.1c35c", - "label": "Sheet 1" - }, - { - "id": "7b9bfb4b.846404", - "type": "mqtt-broker", - "broker": "node1.aiko.sh", - "port": "1883", - "clientid": "prototyper.local" - }, - { - "id": "34f9355a.cb06ca", - "type": "exec", - "command": "cat", - "addpay": true, - "append": "/sys/class/thermal/thermal_zone0/temp", - "useSpawn": "", - "name": "temp", - "x": 327, - "y": 119, - "z": "e3ca4149.1c35c", - "wires": [ - ["6a09262a.95f6d8"], - [], - [] - ] - }, - { - "id": "5e02bbe3.a1fd44", - "type": "inject", - "name": "", - "topic": "", - "payload": "", - "payloadType": "none", - "repeat": "60", - "crontab": "", - "once": false, - "x": 146, - "y": 111, - "z": "e3ca4149.1c35c", - "wires": [ - [ - "34f9355a.cb06ca", - "64325516.9bcdac", - "596d73cf.a6928c", - "13f94a14.ec06b6", - "bd13d8fb.42ec28" - ] - ] - }, - { - "id": "428ea0cf.bd716", - "type": "debug", - "name": "", - "active": true, - "console": "false", - "complete": "payload", - "x": 848, - "y": 57, - "z": "e3ca4149.1c35c", - "wires": [] - }, - { - "id": "6a09262a.95f6d8", - "type": "function", - "name": "convert to C", - "func": "var cpuTemp0=msg.payload.trim();\nvar cpuTemp1=cpuTemp0/1000;\nvar cpuTemp2=cpuTemp0/100;\nvar cpuTempM=cpuTemp2 % cpuTemp1;\n\nmsg.payload={ \n degrees: cpuTemp1,\n raw: cpuTemp0\n};\n\nreturn msg;", - "outputs": 1, - "valid": true, - "x": 538, - "y": 122, - "z": "e3ca4149.1c35c", - "wires": [["1a28d1d1.e5d72e"]] - }, - { - "id": "596d73cf.a6928c", - "type": "exec", - "command": "pm2", - "addpay": true, - "append": "jlist", - "useSpawn": "", - "name": "", - "x": 321, - "y": 238, - "z": "e3ca4149.1c35c", - "wires": [ - ["7fd702.ff8029"], - [], - [] - ] - }, - { - "id": "7fd702.ff8029", - "type": "json", - "name": "", - "x": 535, - "y": 238, - "z": "e3ca4149.1c35c", - "wires": [["f47e2c77.0b81d"]] - }, - { - "id": "64325516.9bcdac", - "type": "exec", - "command": "cat", - "addpay": true, - "append": "/proc/uptime", - "useSpawn": "", - "name": "uptime", - "x": 320, - "y": 357, - "z": "e3ca4149.1c35c", - "wires": [ - ["46790ddf.b986f4"], - [], - [] - ] - }, - { - "id": "46790ddf.b986f4", - "type": "function", - "name": "convert uptime to json", - "func": "var values=msg.payload.trim().split(' ');\nvar uptime=parseFloat(values[0]);\nvar idletime=parseFloat(values[1]);\n\nmsg.payload={\n raw: msg.payload.trim(),\n seconds: uptime,\n idle_total: idletime,\n idle_per_core: idletime / 4\n};\nreturn msg;", - "outputs": 1, - "valid": true, - "x": 552, - "y": 352, - "z": "e3ca4149.1c35c", - "wires": [["45bafe05.ba45"]] - }, - { - "id": "45bafe05.ba45", - "type": "mqtt out", - "name": "", - "topic": "prototyper/status/uptime", - "qos": "", - "retain": "true", - "broker": "7b9bfb4b.846404", - "x": 889, - "y": 353, - "z": "e3ca4149.1c35c", - "wires": [] - }, - { - "id": "f47e2c77.0b81d", - "type": "mqtt out", - "name": "", - "topic": "prototyper/status/pm2", - "qos": "", - "retain": "true", - "broker": "7b9bfb4b.846404", - "x": 890, - "y": 234, - "z": "e3ca4149.1c35c", - "wires": [] - }, - { - "id": "1a28d1d1.e5d72e", - "type": "mqtt out", - "name": "", - "topic": "prototyper/sensors/temp/cpu", - "qos": "", - "retain": "true", - "broker": "7b9bfb4b.846404", - "x": 890, - "y": 123, - "z": "e3ca4149.1c35c", - "wires": [] - }, - { - "id": "13f94a14.ec06b6", - "type": "exec", - "command": "cat", - "addpay": true, - "append": "/proc/loadavg", - "useSpawn": "", - "name": "loadavg", - "x": 320, - "y": 460, - "z": "e3ca4149.1c35c", - "wires": [ - ["8a7d6fb9.75829"], - [], - [] - ] - }, - { - "id": "8a7d6fb9.75829", - "type": "function", - "name": "convert load to json", - "func": "var values=msg.payload.trim().split(' ');\nvar load_1min_part=parseFloat(values[0]);\nvar load_5min_part=parseFloat(values[1]);\nvar load_10min_part=parseFloat(values[2]);\n\nmsg.payload={\n raw: msg.payload.trim(),\n load: {\n one: load_1min_part,\n five: load_5min_part,\n ten: load_10min_part\n }\n};\nreturn msg;", - "outputs": 1, - "valid": true, - "x": 550, - "y": 464, - "z": "e3ca4149.1c35c", - "wires": [["3aa055f6.c55faa"]] - }, - { - "id": "3aa055f6.c55faa", - "type": "mqtt out", - "name": "", - "topic": "prototyper/status/loadavg", - "qos": "", - "retain": "true", - "broker": "7b9bfb4b.846404", - "x": 887, - "y": 462, - "z": "e3ca4149.1c35c", - "wires": [] - }, - { - "id": "bd13d8fb.42ec28", - "type": "exec", - "command": "cat", - "addpay": true, - "append": "/proc/meminfo", - "useSpawn": "", - "name": "meminfo", - "x": 314, - "y": 566, - "z": "e3ca4149.1c35c", - "wires": [ - ["f714138c.08ebf"], - [], - [] - ] - }, - { - "id": "f714138c.08ebf", - "type": "function", - "name": "convert meminfo to json", - "func": "/*\n$ cat /proc/meminfo\nMemTotal: 947444 kB\nMemFree: 715036 kB\nMemAvailable: 806656 kB\nBuffers: 23904 kB\nCached: 74096 kB\nSwapCached: 0 kB\nActive: 171528 kB\nInactive: 31968 kB\nActive(anon): 105524 kB\nInactive(anon): 796 kB\nActive(file): 66004 kB\nInactive(file): 31172 kB\nUnevictable: 8 kB\nMlocked: 8 kB\nSwapTotal: 0 kB\nSwapFree: 0 kB\nDirty: 4 kB\nWriteback: 0 kB\nAnonPages: 105520 kB\nMapped: 29252 kB\nShmem: 828 kB\nSlab: 15904 kB\nSReclaimable: 8344 kB\nSUnreclaim: 7560 kB\nKernelStack: 1048 kB\nPageTables: 1496 kB\nNFS_Unstable: 0 kB\nBounce: 0 kB\nWritebackTmp: 0 kB\nCommitLimit: 473720 kB\nCommitted_AS: 428368 kB\nVmallocTotal: 1105920 kB\nVmallocUsed: 1156 kB\nVmallocChunk: 885752 kB\n*/\n\n\nvar lines=msg.payload.split('\\n');\nvar mem_total=parseInt(lines[0].split(':')[1].trim().split(' ')[0]);\nvar mem_free=parseInt(lines[1].split(':')[1].trim().split(' ')[0]);\nvar mem_available=parseInt(lines[2].split(':')[1].trim().split(' ')[0]);\nvar buffers=parseInt(lines[3].split(':')[1].trim().split(' ')[0]);\nvar cache=parseInt(lines[4].split(':')[1].trim().split(' ')[0]);\nvar swap_cache=parseInt(lines[5].split(':')[1].trim().split(' ')[0]);\nvar swap_total=parseInt(lines[14].split(':')[1].trim().split(' ')[0]);\nvar swap_free=parseInt(lines[15].split(':')[1].trim().split(' ')[0]);\n\nmsg.payload={\n raw: msg.payload.trim(),\n mem: {\n total: mem_total,\n free: mem_free,\n available: mem_available,\n buffers: buffers\n },\n cache: {\n cache: cache,\n swap_cache: swap_cache\n },\n swap: {\n total: swap_total,\n free: swap_free\n }\n};\nreturn msg;", - "outputs": 1, - "valid": true, - "x": 544, - "y": 570, - "z": "e3ca4149.1c35c", - "wires": [["28b96119.d7469e"]] - }, - { - "id": "28b96119.d7469e", - "type": "mqtt out", - "name": "", - "topic": "prototyper/status/meminfo", - "qos": "", - "retain": "true", - "broker": "7b9bfb4b.846404", - "x": 881, - "y": 568, - "z": "e3ca4149.1c35c", - "wires": [] - } -] +[{"type":"tab","id":"e3ca4149.1c35c","label":"Sheet 1"},{"id":"7b9bfb4b.846404","type":"mqtt-broker","broker":"node1.aiko.sh","port":"1883","clientid":"prototyper.local"},{"id":"34f9355a.cb06ca","type":"exec","command":"cat","addpay":true,"append":"/sys/class/thermal/thermal_zone0/temp","useSpawn":"","name":"temp","x":327,"y":119,"z":"e3ca4149.1c35c","wires":[["6a09262a.95f6d8"],[],[]]},{"id":"5e02bbe3.a1fd44","type":"inject","name":"","topic":"","payload":"","payloadType":"none","repeat":"60","crontab":"","once":false,"x":146,"y":111,"z":"e3ca4149.1c35c","wires":[["34f9355a.cb06ca","64325516.9bcdac","596d73cf.a6928c","13f94a14.ec06b6","bd13d8fb.42ec28"]]},{"id":"428ea0cf.bd716","type":"debug","name":"","active":true,"console":"false","complete":"payload","x":848,"y":57,"z":"e3ca4149.1c35c","wires":[]},{"id":"6a09262a.95f6d8","type":"function","name":"convert to C","func":"var cpuTemp0=msg.payload.trim();\nvar cpuTemp1=cpuTemp0/1000;\nvar cpuTemp2=cpuTemp0/100;\nvar cpuTempM=cpuTemp2 % cpuTemp1;\n\nmsg.payload={ \n degrees: cpuTemp1,\n raw: cpuTemp0\n};\n\nreturn msg;","outputs":1,"valid":true,"x":538,"y":122,"z":"e3ca4149.1c35c","wires":[["1a28d1d1.e5d72e"]]},{"id":"596d73cf.a6928c","type":"exec","command":"pm2","addpay":true,"append":"jlist","useSpawn":"","name":"","x":321,"y":238,"z":"e3ca4149.1c35c","wires":[["7fd702.ff8029"],[],[]]},{"id":"7fd702.ff8029","type":"json","name":"","x":535,"y":238,"z":"e3ca4149.1c35c","wires":[["f47e2c77.0b81d"]]},{"id":"64325516.9bcdac","type":"exec","command":"cat","addpay":true,"append":"/proc/uptime","useSpawn":"","name":"uptime","x":320,"y":357,"z":"e3ca4149.1c35c","wires":[["46790ddf.b986f4"],[],[]]},{"id":"46790ddf.b986f4","type":"function","name":"convert uptime to json","func":"var values=msg.payload.trim().split(' ');\nvar uptime=parseFloat(values[0]);\nvar idletime=parseFloat(values[1]);\n\nmsg.payload={\n raw: msg.payload.trim(),\n seconds: uptime,\n idle_total: idletime,\n idle_per_core: idletime / 4\n};\nreturn msg;","outputs":1,"valid":true,"x":552,"y":352,"z":"e3ca4149.1c35c","wires":[["45bafe05.ba45"]]},{"id":"45bafe05.ba45","type":"mqtt out","name":"","topic":"prototyper/status/uptime","qos":"","retain":"true","broker":"7b9bfb4b.846404","x":889,"y":353,"z":"e3ca4149.1c35c","wires":[]},{"id":"f47e2c77.0b81d","type":"mqtt out","name":"","topic":"prototyper/status/pm2","qos":"","retain":"true","broker":"7b9bfb4b.846404","x":890,"y":234,"z":"e3ca4149.1c35c","wires":[]},{"id":"1a28d1d1.e5d72e","type":"mqtt out","name":"","topic":"prototyper/sensors/temp/cpu","qos":"","retain":"true","broker":"7b9bfb4b.846404","x":890,"y":123,"z":"e3ca4149.1c35c","wires":[]},{"id":"13f94a14.ec06b6","type":"exec","command":"cat","addpay":true,"append":"/proc/loadavg","useSpawn":"","name":"loadavg","x":320,"y":460,"z":"e3ca4149.1c35c","wires":[["8a7d6fb9.75829"],[],[]]},{"id":"8a7d6fb9.75829","type":"function","name":"convert load to json","func":"var values=msg.payload.trim().split(' ');\nvar load_1min_part=parseFloat(values[0]);\nvar load_5min_part=parseFloat(values[1]);\nvar load_10min_part=parseFloat(values[2]);\n\nmsg.payload={\n raw: msg.payload.trim(),\n load: {\n one: load_1min_part,\n five: load_5min_part,\n ten: load_10min_part\n }\n};\nreturn msg;","outputs":1,"valid":true,"x":550,"y":464,"z":"e3ca4149.1c35c","wires":[["3aa055f6.c55faa"]]},{"id":"3aa055f6.c55faa","type":"mqtt out","name":"","topic":"prototyper/status/loadavg","qos":"","retain":"true","broker":"7b9bfb4b.846404","x":887,"y":462,"z":"e3ca4149.1c35c","wires":[]},{"id":"bd13d8fb.42ec28","type":"exec","command":"cat","addpay":true,"append":"/proc/meminfo","useSpawn":"","name":"meminfo","x":314,"y":566,"z":"e3ca4149.1c35c","wires":[["f714138c.08ebf"],[],[]]},{"id":"f714138c.08ebf","type":"function","name":"convert meminfo to json","func":"/*\n$ cat /proc/meminfo\nMemTotal: 947444 kB\nMemFree: 715036 kB\nMemAvailable: 806656 kB\nBuffers: 23904 kB\nCached: 74096 kB\nSwapCached: 0 kB\nActive: 171528 kB\nInactive: 31968 kB\nActive(anon): 105524 kB\nInactive(anon): 796 kB\nActive(file): 66004 kB\nInactive(file): 31172 kB\nUnevictable: 8 kB\nMlocked: 8 kB\nSwapTotal: 0 kB\nSwapFree: 0 kB\nDirty: 4 kB\nWriteback: 0 kB\nAnonPages: 105520 kB\nMapped: 29252 kB\nShmem: 828 kB\nSlab: 15904 kB\nSReclaimable: 8344 kB\nSUnreclaim: 7560 kB\nKernelStack: 1048 kB\nPageTables: 1496 kB\nNFS_Unstable: 0 kB\nBounce: 0 kB\nWritebackTmp: 0 kB\nCommitLimit: 473720 kB\nCommitted_AS: 428368 kB\nVmallocTotal: 1105920 kB\nVmallocUsed: 1156 kB\nVmallocChunk: 885752 kB\n*/\n\n\nvar lines=msg.payload.split('\\n');\nvar mem_total=parseInt(lines[0].split(':')[1].trim().split(' ')[0]);\nvar mem_free=parseInt(lines[1].split(':')[1].trim().split(' ')[0]);\nvar mem_available=parseInt(lines[2].split(':')[1].trim().split(' ')[0]);\nvar buffers=parseInt(lines[3].split(':')[1].trim().split(' ')[0]);\nvar cache=parseInt(lines[4].split(':')[1].trim().split(' ')[0]);\nvar swap_cache=parseInt(lines[5].split(':')[1].trim().split(' ')[0]);\nvar swap_total=parseInt(lines[14].split(':')[1].trim().split(' ')[0]);\nvar swap_free=parseInt(lines[15].split(':')[1].trim().split(' ')[0]);\n\nmsg.payload={\n raw: msg.payload.trim(),\n mem: {\n total: mem_total,\n free: mem_free,\n available: mem_available,\n buffers: buffers\n },\n cache: {\n cache: cache,\n swap_cache: swap_cache\n },\n swap: {\n total: swap_total,\n free: swap_free\n }\n};\nreturn msg;","outputs":1,"valid":true,"x":544,"y":570,"z":"e3ca4149.1c35c","wires":[["28b96119.d7469e"]]},{"id":"28b96119.d7469e","type":"mqtt out","name":"","topic":"prototyper/status/meminfo","qos":"","retain":"true","broker":"7b9bfb4b.846404","x":881,"y":568,"z":"e3ca4149.1c35c","wires":[]}] diff --git a/settings.js b/settings.js new file mode 100644 index 0000000..641567b --- /dev/null +++ b/settings.js @@ -0,0 +1,162 @@ +/** + * Copyright 2013, 2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +// The `https` setting requires the `fs` module. Uncomment the following +// to make it available: +//var fs = require("fs"); + + +module.exports = { + // the tcp port that the Node-RED web server is listening on + uiPort: 1880, + + // By default, the Node-RED UI accepts connections on all IPv4 interfaces. + // The following property can be used to listen on a specific interface. For + // example, the following would only allow connections from the local machine. + //uiHost: "127.0.0.1", + + // Retry time in milliseconds for MQTT connections + mqttReconnectTime: 15000, + + // Retry time in milliseconds for Serial port connections + serialReconnectTime: 15000, + + // Retry time in milliseconds for TCP socket connections + //socketReconnectTime: 10000, + + // Timeout in milliseconds for TCP server socket connections + // defaults to no timeout + //socketTimeout: 120000, + + // The maximum length, in characters, of any message sent to the debug sidebar tab + debugMaxLength: 1000, + + // The file containing the flows. If not set, it defaults to flows_.json + //flowFile: 'flows.json', + + // To enabled pretty-printing of the flow within the flow file, set the following + // property to true: + flowFilePretty: true, + + // By default, all user data is stored in the Node-RED install directory. To + // use a different location, the following property can be used + //userDir: '/home/nol/.node-red/', + + // Node-RED scans the `nodes` directory in the install directory to find nodes. + // The following property can be used to specify an additional directory to scan. + //nodesDir: '/home/nol/.node-red/nodes', + + // By default, the Node-RED UI is available at http://localhost:1880/ + // The following property can be used to specifiy a different root path. + // If set to false, this is disabled. + //httpAdminRoot: '/admin', + + // You can protect the user interface with a userid and password by using the following property. + // The password must be an md5 hash eg.. 5f4dcc3b5aa765d61d8327deb882cf99 ('password') + //httpAdminAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"}, + + // Some nodes, such as HTTP In, can be used to listen for incoming http requests. + // By default, these are served relative to '/'. The following property + // can be used to specifiy a different root path. If set to false, this is + // disabled. + //httpNodeRoot: '/nodes', + + // To password protect the node-defined HTTP endpoints, the following property + // can be used. + // The password must be an md5 hash eg.. 5f4dcc3b5aa765d61d8327deb882cf99 ('password') + //httpNodeAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"}, + + // When httpAdminRoot is used to move the UI to a different root path, the + // following property can be used to identify a directory of static content + // that should be served at http://localhost:1880/. + //httpStatic: '/home/nol/node-red-dashboard/', + + // To password protect the static content, the following property can be used. + // The password must be an md5 hash eg.. 5f4dcc3b5aa765d61d8327deb882cf99 ('password') + //httpStaticAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"}, + + // The following property can be used in place of 'httpAdminRoot' and 'httpNodeRoot', + // to apply the same root to both parts. + //httpRoot: '/red', + + // The following property can be used in place of 'httpAdminAuth' and 'httpNodeAuth', + // to apply the same authentication to both parts. + //httpAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"}, + + // The following property can be used to disable the editor. The admin API + // is not affected by this option. To disable both the editor and the admin + // API, use either the httpRoot or httpAdminRoot properties + //disableEditor: false, + + // The following property can be used to enable HTTPS + // See http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener + // for details on its contents. + // See the comment at the top of this file on how to load the `fs` module used by + // this setting. + // + //https: { + // key: fs.readFileSync('privatekey.pem'), + // cert: fs.readFileSync('certificate.pem') + //}, + + // The following property can be used to configure cross-origin resource sharing + // in the HTTP nodes. + // See https://github.com/troygoode/node-cors#configuration-options for + // details on its contents. The following is a basic permissive set of options: + //httpNodeCors: { + // origin: "*", + // methods: "GET,PUT,POST,DELETE" + //}, + + // Anything in this hash is globally available to all functions. + // It is accessed as context.global. + // eg: + // functionGlobalContext: { os:require('os') } + // can be accessed in a function block as: + // context.global.os + + functionGlobalContext: { + // os:require('os'), + // bonescript:require('bonescript'), + // jfive:require("johnny-five"), + // j5board:require("johnny-five").Board({repl:false}) + }, + + + // The following property can be used to order the categories in the editor + // palette. If a node's category is not in the list, the category will get + // added to the end of the palette. + // If not set, the following default order is used: + //paletteCategories: ['subflows', 'input', 'output', 'function', 'social', 'storage', 'analysis', 'advanced'], + + // Configure the logging output + logging: { + // Only console logging is currently supported + console: { + // Level of logging to be recorded. Options are: + // fatal - only those errors which make the application unusable should be recorded + // error - record errors which are deemed fatal for a particular request + fatal errors + // warn - record problems which are non fatal + errors + fatal errors + // info - record information about the general running of the application + warn + error + fatal errors + // debug - record information which is more verbose than info + info + warn + error + fatal errors + // trace - record very detailed logging + debug + info + warn + error + fatal errors + level: "info", + + // Whether or not to include metric events in the log output + metrics: false + } + } +};