In a normal situation my payload is like this:
1:13.5230:14.0900:0.0000:0.0000:24:24:216:216
Time to time I get back messages like this:
Cells : msg : Object
object
payload: object
NaNVCNaN: undefined
NaNTCNaN: undefined
_msgid: "01b9257b73bb0ea0"
topic: "Cells"
I did try to filter out such type of messages using:
if(isNaN(msg.payload)) {
return null; //halt flow
}
return msg;
and
if(msg.payload=="") {
return null; //halt flow
}
return msg;
but are still going trough.
How do I disregard such undefined messages?
FeliceM:
I did try to filter out such type of messages using:
if(isNaN(msg.payload)) {
return null; //halt flow
}
return msg;
and
if(msg.payload=="") {
return null; //halt flow
}
return msg;
but are still going trough
They wont work as payload
is an object ...
FeliceM:
payload: object
... so will never be caught by these tests.
Assuming your payload is NORMALLY a string as per your example above, you could change your "filter out" tests to ...
if(typeof msg.payload !== "string" || msg.payload == null) {
return null; // halt flow because payload is NOT a string or is empty
}
Thanks for you help.
My normal msg.payload is like this:
Despite the filter function I tried and even the one you suggested, at time this is still going trough:
Try
if (msg.payload == "" || msg.payload == null) {
return null; // halt flow because payload is an empty string
}
ok, so your normal payload is a string. So the suggestion I made should get you closer to a solution as it will discard empty strings and non strings...
Looking at this screenshot, it seems payload has (potentially) a newline character in it. so you could trim it...
if(typeof msg.payload !== "string" || msg.payload.trim() == "") {
return null; // halt flow because payload is NOT a string or is empty
}
Thank you but unfortunately this doesn't work in my case
Thank you. Problem solved.
You can also use a switch node and filter all message which are not null. No need to use a function node.
system
Closed
21 April 2022 11:38
9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.