You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Node-RED
I am using the rpi gpio pins to monitor some normally closed switch contacts (doors). But with the door closed, a 1 is sent from the input pin.
My application requires the input to be inverted so a closed door sends 0 and open sends 1.
I have not been able to find an inverting node to do this. What is the proper code to use in a function node to do the same thing?
Julian Knight
unread,
Jul 31, 2017, 3:29:48 PM7/31/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Node-RED
I'm afraid most of us far too easily fall back on function nodes and I'm sure there are other way. But a really simple way would be to use a function node with the following code - assuming your data is on the payload and can only be a numeric 0 or 1:
msg.payload =! msg.payload; return msg;
Check if it comes out as text though, in which case you may have to force it back to a number. Also make sure it can't be anything other than 0 or 1, if it can, you need to do additional error checks.
rlno...@gmail.com
unread,
Jul 31, 2017, 3:34:09 PM7/31/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Node-RED
Yes that works but it is in text. How do I "force" it back to a number? Noob here.
Julian Knight
unread,
Jul 31, 2017, 3:46:17 PM7/31/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to node...@googlegroups.com
That should be
parseInt
With an e
--
Sent from phone.
Colin Law
unread,
Jul 31, 2017, 4:22:27 PM7/31/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to node...@googlegroups.com
I generally use Number(msg.payload) as that does its best to make
sense of anything you send to it. If it cannot make sense of it then
it returns NaN. Parseint will fail if you give it a number rather
than a string, I think. So I tend to sloppily stick in Number()
whenever I think there is any doubt about the format. Probably that is
reprehensible behaviour on my part.