Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node not working in parallel flow #2

Open
HarterHorst opened this issue Apr 6, 2022 · 3 comments
Open

Node not working in parallel flow #2

HarterHorst opened this issue Apr 6, 2022 · 3 comments

Comments

@HarterHorst
Copy link

HarterHorst commented Apr 6, 2022

First thanks for the node. This is exactly what I need in my project. I love the comprehensive documentation as well.

But I have a strange problem with the node when I try to read I2C registers in parallel.

Case:
I have a PCF8574 attached to a raspberry PI. This chip has I/O Pins that can be used for switches etc. If anything changes on the I/O Pins an interrupt will be generated on a GPIO PIN (PIN 11 in my case). After the PI receives this interrupt, the register of the 8574 can be read via the I2C bus to determine which I/O port changed the status.

Flow:
When I start the following flow by pressing a button, only the Read register part will be executed. The "Button events" node receives the msg object, but does not process the data as exepected. I checked that the node gets the msg object with the VSC remote debugger by setting a breakpoint in the input routine. But was not able to trace why the node is not working because the debugger goes way deep into several .js files and I was not able to follow.

In the following flow only the upper streams works. the 254 indicated that the I/O PIN 0 has been changed and brought back to normal after I released the button. The 0 and 1 come from the debug node at the bottom.

Screenshot 2022-04-06 at 19 18 48

When i 'cut' the wire from the trigger to the read register, the "Button events" node works perfectly. Single and double clicks are recognized reliably.

Screenshot 2022-04-06 at 19 19 53

I'd like to run the detection of the button press in parallel due to the requirement to read the I2C register as fast as possible and I'd like to avoid multiple nodes between the GPIO Node and Button events node.

Versions:

Welcome to Node-RED
===================

6 Apr 18:02:38 - [info] Node-RED version: v2.2.2
6 Apr 18:02:38 - [info] Node.js  version: v14.19.1
6 Apr 18:02:38 - [info] Linux 5.15.30-v7l+ arm LE

Expected behaviour:
Node works as designed
Behaviour:
Node not working

[{"id":"7118ec3979daf874","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"d98e10d19293939d","type":"i2c in","z":"7118ec3979daf874","name":"Read register 0x3f","busno":"1","address":"63","command":"","count":"1","x":650,"y":80,"wires":[["fd69ee1d0f28b5e2"]]},{"id":"fd69ee1d0f28b5e2","type":"debug","z":"7118ec3979daf874","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":80,"wires":[]},{"id":"ab594a152238e00e","type":"button-events","z":"7118ec3979daf874","name":"","outputs":2,"inputField":"payload","inputFieldType":"msg","outputField":"clickmode","outputFieldType":"msg","downValue":"0","downValueType":"num","upValue":"1","upValueType":"num","idleValue":"1","clickedInterval":200,"pressedInterval":200,"debounceInterval":30,"events":[{"type":"clicked"},{"type":"double_clicked"}],"x":420,"y":160,"wires":[["56c5eb89f356fad0"],["70e6ba374db38c31"]]},{"id":"70e6ba374db38c31","type":"debug","z":"7118ec3979daf874","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":180,"wires":[]},{"id":"96eaec33084d06eb","type":"pi-gpiod in","z":"7118ec3979daf874","name":"","host":"localhost","port":8888,"pin":"17","intype":"PUD_UP","debounce":"240","read":false,"x":140,"y":120,"wires":[["39fe7ca11fc54102","36bd7c0ed4a1e5d4","ab594a152238e00e"]]},{"id":"36bd7c0ed4a1e5d4","type":"trigger","z":"7118ec3979daf874","name":"","op1":"1","op2":"","op1type":"str","op2type":"nul","duration":"120","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"topic","topic":"AllBinary","outputs":1,"x":420,"y":80,"wires":[[]]},{"id":"56c5eb89f356fad0","type":"debug","z":"7118ec3979daf874","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":140,"wires":[]},{"id":"39fe7ca11fc54102","type":"debug","z":"7118ec3979daf874","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":410,"y":240,"wires":[]}]
@bartbutenaers
Copy link
Owner

bartbutenaers commented Apr 6, 2022

Hi @HarterHorst,

Thanks for the nice analysis of the problem! That makes thing much easier to follow...

That is a strange problem. So it seems that the first chain of nodes (trigger, read register, ...) has impact on the second chain of nodes (button events, ...). Cannot immediately explain this. Because - unless things have changed recently - NR works like this when 3 wires are connected to an output:

image

  1. The original message is send to the first wire
  2. The message is cloned and that clone is send to the second wire
  3. The message is cloned again and that clone is send to the third wire

Since the button-event event node will receive a copy of the original message, how on earth can there be a relation...

Could you do some extra experiments please:

  • In the second flow, add a debug node to your trigger node. And then test, to see whether there is a problem at the output of the trigger node.
  • If you remove the trigger node, and you replace it by the read-register node. Does my button-event node still work?
  • Others ...

And can you share: an export of this part of your flow. I am wondering what the trigger node does in your case?

Hopefully a bell will start ringing when I have extra feedback...
Bart

@HarterHorst
Copy link
Author

Hi, glad to hear that you struggle with this in the same way. First I thought that I missed fundamentals regarding objects in flows.

Your interpretation of the flow is correct.

Here are the results from the additional test:

  1. Add debug node after trigger node. You can see, that the trigger node modifies the msg.payload and makes it a string. Beside this no signs of trouble.

Screenshot 2022-04-07 at 16 05 27

  1. No changes in the behaviour when I remove the trigger node.

Screenshot 2022-04-07 at 16 11 27

  1. As I wrote, I connected to the nodered service with the vsc debugger and set a breakpoint at your node. Here are the results. On the left hand you can see the object, which looks good to me.

Screenshot 2022-04-07 at 16 25 29

  1. You can find the flow in my original post.

@bartbutenaers
Copy link
Owner

Since I don't use the gpiod nodes, it is not possible to reproduce your problem.
So I have replaced your gpiod node by a trigger node, to simulate the behaviour:

[{"id":"99b05d5ec7a850ba","type":"i2c in","z":"b72068aa707669b0","name":"Read register 0x3f","busno":"1","address":"63","command":"","count":"1","x":710,"y":260,"wires":[["cf70786923288cba"]]},{"id":"cf70786923288cba","type":"debug","z":"b72068aa707669b0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":260,"wires":[]},{"id":"16f81ac983ae6d0a","type":"button-events","z":"b72068aa707669b0","name":"","outputs":2,"inputField":"payload","inputFieldType":"msg","outputField":"clickmode","outputFieldType":"msg","downValue":"0","downValueType":"num","upValue":"1","upValueType":"num","idleValue":"1","clickedInterval":200,"pressedInterval":200,"debounceInterval":30,"events":[{"type":"clicked"},{"type":"double_clicked"}],"x":480,"y":340,"wires":[["02013e600b986b47"],["2eace1ebe45a1e4e"]]},{"id":"2eace1ebe45a1e4e","type":"debug","z":"b72068aa707669b0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":360,"wires":[]},{"id":"d3d2db86c70a3c09","type":"trigger","z":"b72068aa707669b0","name":"","op1":"1","op2":"","op1type":"str","op2type":"nul","duration":"120","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"topic","topic":"AllBinary","outputs":1,"x":480,"y":260,"wires":[["99b05d5ec7a850ba"]]},{"id":"02013e600b986b47","type":"debug","z":"b72068aa707669b0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":320,"wires":[]},{"id":"a6f84e9dac9c30db","type":"trigger","z":"b72068aa707669b0","name":"","op1":"0","op2":"1","op1type":"num","op2type":"num","duration":"120","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"topic","topic":"AllBinary","outputs":1,"x":260,"y":260,"wires":[["16f81ac983ae6d0a","d3d2db86c70a3c09"]]},{"id":"576ea356da93195c","type":"inject","z":"b72068aa707669b0","name":"0","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":90,"y":260,"wires":[["a6f84e9dac9c30db"]]}]

But that still works for me, even when the 'read register' node is available.
Could you please update the timings in my flow so that I can use it to reproduce the problem.
Otherwise unfortunately I have no clue why it fails in your case...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants