Function tried to send a message of type boolean

3,059 views
Skip to first unread message

Leif Neland

unread,
Nov 21, 2017, 8:12:00 AM11/21/17
to Node-RED

Wanted:


When IP changes from non-pingable (ping node returns boolean false) to pingable (ping node returns number) send true (once)





But the function "return msg.payload>=0" gives this error:

21/11/2017 14.04.08node: (msg.payload)>0;function : (error)

"Function tried to send a message of type boolean"


Yeah? That's the general idea: True of pingable, false if not.

Then into rbe to only send changes along, then into switch to send only true along.


What is the problem?

[
    {
        "id": "f14a2b71.c397b8",
        "type": "ping",
        "z": "280fd4cd.e0f79c",
        "name": "",
        "host": "192.168.1.110",
        "timer": "5",
        "x": 150,
        "y": 613,
        "wires": [
            [
                "496dc9a4.d21688"
            ]
        ]
    },
    {
        "id": "496dc9a4.d21688",
        "type": "function",
        "z": "280fd4cd.e0f79c",
        "name": "(msg.payload)>0;",
        "func": "\nreturn (msg.payload)>0;",
        "outputs": 1,
        "noerr": 0,
        "x": 357,
        "y": 612,
        "wires": [
            [
                "187e1fd5.eaa1c"
            ]
        ]
    },
    {
        "id": "187e1fd5.eaa1c",
        "type": "rbe",
        "z": "280fd4cd.e0f79c",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "x": 532,
        "y": 612,
        "wires": [
            [
                "e8257bf4.8f1f28"
            ]
        ]
    },
    {
        "id": "e8257bf4.8f1f28",
        "type": "switch",
        "z": "280fd4cd.e0f79c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            }
        ],
        "checkall": "true",
        "outputs": 1,
        "x": 680,
        "y": 612,
        "wires": [
            [
                "25f00ac6.5d0656"
            ]
        ]
    }
]

Colin Law

unread,
Nov 21, 2017, 8:51:35 AM11/21/17
to node...@googlegroups.com
As the error says you have returned a value from the function instead of a valid message.  Functions must always return objects not values, so you could use something like

msg.payload  =  (msg.payload>=0);
return msg;
or
return {payload: msg.payload}
The former is generally preferred as it is more effecient to pass on an existing message rather than make a new one.

Note that you can do this in a Change node.

Colin

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/a8f87094-0632-4676-b64e-7c6e5bb82bc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages