@Bluefox:
Люди уже решили эту проблему.
https://github.com/GermanBluefox/node-red-vis/issues/6 `
Еще раз хочу выразить огромное спасибо! Идея из ссылки выше воплотилась у меня в универсальный КЭШиратор данных (по ссылке надо описывать каждый топик, я сделал так, что кэшируются все топики, начинающиеся на "myhome/tele/", куда все мои устройства отправляют данные). Если интересно, то код и картинка ниже.
Чтобы не ломать форум - код Node-Red прогнал через beautify'er.
[
{
"id": "346b51f3.cb94ae",
"type": "mqtt-broker",
"broker": "localhost",
"port": "1883",
"clientid": ""
},
{
"id": "ed457908.12ba88",
"type": "vis in",
"language": "en",
"x": 412,
"y": 203,
"z": "9aff093a.6500f8",
"wires": [
[
"4a594456.b5a6bc"
]
]
},
{
"id": "4a594456.b5a6bc",
"type": "function",
"name": "Check for page refresh",
"func": "if (msg.topic === \"vis.control.data\") {\n msg.payload = [];\n for (var state in context.global.states)\n msg.payload.push({ topic: state, data: context.global.states[state] });\n\n return msg;\n}\nelse {\n return null;\n}",
"outputs": 1,
"noerr": 0,
"x": 588,
"y": 202,
"z": "9aff093a.6500f8",
"wires": [
[
"5fffe5c0.a0001c"
]
]
},
{
"id": "5fffe5c0.a0001c",
"type": "splitter",
"name": "Iterate on states",
"property": "payload",
"x": 806,
"y": 202,
"z": "9aff093a.6500f8",
"wires": [
[
"be39c3b6.41c64"
]
]
},
{
"id": "6169e126.9e962",
"type": "function",
"name": "Save State",
"func": "context.global.states = context.global.states || [];\ncontext.global.states[msg.topic] = msg.payload;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 220,
"y": 204,
"z": "9aff093a.6500f8",
"wires": [
[
"ed457908.12ba88"
]
]
},
{
"id": "be39c3b6.41c64",
"type": "function",
"name": "Post cached states",
"func": "msg.topic = msg.payload.topic;\nmsg.payload = msg.payload.data;\ndelete msg.payload_unsplit;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 600,
"y": 312,
"z": "9aff093a.6500f8",
"wires": [
[
"ed457908.12ba88"
]
]
},
{
"id": "5f03e43c.a0fc1c",
"type": "mqtt in",
"name": "Telemetry Data",
"topic": "myhome/tele/#",
"broker": "346b51f3.cb94ae",
"x": 135,
"y": 65,
"z": "9aff093a.6500f8",
"wires": [
[
"6169e126.9e962"
]
]
},
{
"id": "de8d6942.217298",
"type": "inject",
"name": "Go",
"topic": "",
"payload": "",
"payloadType": "none",
"repeat": "",
"crontab": "",
"once": false,
"x": 218,
"y": 416,
"z": "9aff093a.6500f8",
"wires": [
[
"4221520e.bddeac"
]
]
},
{
"id": "4221520e.bddeac",
"type": "function",
"name": "Dump states cache to console",
"func": "for (var state in context.global.states)\n console.log(\"state '\" + state + \"' = '\" + context.global.states[state] + \"'\");\n\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 470,
"y": 417,
"z": "9aff093a.6500f8",
"wires": [
[]
]
}
]
852_screen_shot_2015-11-02_at_00.22.06.png