Node-Red and Web socket

2019-08-12 07:20发布

问题:

I'm trying to works on node-red's websockets on windows environment (I've successfully try on Linux).

I've simple apps like pictured below

and it's doesn't work output on console :

17 Feb 09:07:04 - [error] [websocket out:c87881cc.37878] TypeError: Cannot read property 'wholemsg' of null

node-red json :

[{
    "id": "50702139.8696e",
    "type": "websocket-client",
    "z": "f00fcb86.2de8f8",
    "path": "/press",
    "wholemsg": "false"
}, {
    "id": "c87881cc.37878",
    "type": "websocket out",
    "z": "f00fcb86.2de8f8",
    "name": "",
    "server": "",
    "client": "50702139.8696e",
    "x": 361,
    "y": 66,
    "wires": []
}, {
    "id": "c99314fe.366ce8",
    "type": "inject",
    "z": "f00fcb86.2de8f8",
    "name": "",
    "topic": "",
    "payload": "",
    "payloadType": "date",
    "repeat": "",
    "crontab": "",
    "once": false,
    "x": 163,
    "y": 67,
    "wires": [["c87881cc.37878"]]
}, {
    "id": "12f91072.ed06f",
    "type": "websocket in",
    "z": "f00fcb86.2de8f8",
    "name": "",
    "server": "",
    "client": "50702139.8696e",
    "x": 162,
    "y": 147,
    "wires": [["62f0f292.9d0f0c"]]
}, {
    "id": "62f0f292.9d0f0c",
    "type": "debug",
    "z": "f00fcb86.2de8f8",
    "name": "",
    "active": true,
    "console": "true",
    "complete": "true",
    "x": 344,
    "y": 147,
    "wires": []
}]

does someone have any ideas ?

回答1:

It looks like the json as a whole is an array. In the first element of the array there is an object and within that is the wholemsg. Address as node-red json[0].wholemsg where "node-red json" is your variable name holding the message.