Hi folks,
First of all my best wishes for 2017 !!!
I have created my first github fork to contribute some new functionality to the core Node-Red nodes, more specific the rpi-gpio input node.
I would be great to get some constructive feedback, before I start a pull request. Thanks !
Current implementation
The current implementation of the input node, offers the following functionality:
The value of the gpio pin (0 or 1) appears as a message on the output port, only if a rising OR falling edge is detected. Optionally this message is also generated at flow startup (when the checkbox is checked by the user).
New implementation
However, I would like the node to have some extra functions:
*/ I would like to configure which edges need to be detected: none, leading, trailing, both
*/ I would like to read the port value whenever I want (by polling)
*/ I would like to combinate polling with edge detection (to avoid overlooking small pulses between two measurements)
Fortunately, the required functionality was already available in the python module that is used underneath. The nodes start (i.e. spawn) the python script with input parameters, and the python script returns results using standard io:
Since I want to decide myself when the port value should be read, I have added an input pin to the node. As soon as a message arrives, the pin value will be read (the message content can be whatever since it is ignored):
The above example flow allows us to read the value periodically, and plot the result in a graph (like a low-budget oscilloscope):
In some conditions it would be nice to combine a periodical polling like above, with an edge detection: this way we can make sure that small glitches don't get lost. E.g. when polling the value every 4 seconds, someone could open a door (with a reed relay) during 2 seconds, and we would not detect it:
To accomplish this, different edge detection capabilities have been added in the new implementation:
The default is set to 'both' for compatibility with the current node implementation. When only polling is required, the edge property can be set to 'none'. When only edge detection is required, it is sufficient not to send any messages on the input port.
Remark: I have removed following checkbox from the properties:
Reason for this decision is that the same result can be achieved, by linking an inject node (to the new input port) that is triggered at startup:
This looks to me a more typical Node-red approach. Moreover, allowing the user to mix both solutions seems to be very confusing to me... The disadvantage of this approach is that it is not backwards compatible: a existing flow that has this checkbox activated, should be changed manually to add an inject node. Is there some way to validate this automatically? Something like 'if the old node version is loaded (from the flow json with the old checkbox = 'true' value) into a new node version, an error is displayed to indicate that an inject node should be added...????
The rpi-gpio input node only creates messages at some event (system startup or signal change), the Msg cloner function node clones the last message at some periodical interval (e.g. every second), and all these (duplicated) messages can be visualised at the end using a graph node.
while true {
" The msgoriginal should be updated by the function node as soon as as a new message arrives
var msgclone = RED.util.cloneMessage(msgoriginal);
node.send(msgclone);
}
--
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/bef2d734-2acb-408d-8eee-10a7d8a1c34f%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.