# Find out incoming wires to a node …

**URL:** <https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765>\
**Category:** Developing Nodes\
**Created:** [21 January 2024 00:05 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765 "2024-01-21T00:05:31Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![helander](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@helander](https://discourse.nodered.org/u/helander)\
**Post date:** [21 January 2024 13:18 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/21 "2024-01-21T13:18:43Z")

</div>

Once I publish my solution you are welcome to explore it

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 January 2024 14:06 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/22 "2024-01-21T14:06:46Z")

</div>

> [@helander](#):
>
> I tried to automatically send a message (node.send({payload: true})) in the node startup code, but in some flows that message never showed up an in other flows that message always showed up. Is there some way to reliably ”send” a message from a node that will get sent prior to any messages being sent from the nodes input handler?

That method does reliably send a message. The problem is that any receiving nodes may not yet have been initialised so will not be ready to receive messages. It is the receiving that is unreliable, as it depends on the order of node initialisation.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 January 2024 15:30 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/23 "2024-01-21T15:30:45Z")

</div>

> [@Colin](#):
>
> That method does reliably send a message. The problem is that any receiving nodes may not yet have been initialised so will not be ready to receive messages. It is the receiving that is unreliable, as it depends on the order of node initialisation.

Just to be clear, in a custom node, the `this.send` function is only available _after_ `RED.nodes.createNode(this, config)` has been called in the function that is called from `RED.nodes.registerType`. That is because the `createNode` function attaches all of a node's standard methods to `this`.

But, as Colin states, that function is called quite early on in Node-RED's startup and depending on the order of nodes and flows having been added, other nodes might not yet be ready for action.

Try wrapping the send in a `setTimeout` function with a couple of hundred ms delay if you are getting that kind of a problem.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 January 2024 15:33 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/24 "2024-01-21T15:33:26Z")

</div>

> [@TotallyInformation](#):
>
> Try wrapping the send in a `setTimeout` function with a couple of hundred ms delay

Was going to suggest sending on a timeout, but got called to do grocery shopping 😏...  
and this kind of delay will aid in the Provider/Gate setup I suggested

```auto
module.exports = function(RED) {
    function Init(config) {
        RED.nodes.createNode(this, config);
        const node = this;

        ....

        setTimeout(() => {
            node.send({
                payload: 'ready'
            })

        }, 250)
    }
}

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 January 2024 15:40 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/25 "2024-01-21T15:40:47Z")

</div>

> [@marcus-j-davies](#):
>
> got called to do grocery shoppin

😀 Know that call all too well. Thankfully, it is very stormy here today so no going out for us!

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [21 January 2024 16:12 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/26 "2024-01-21T16:12:07Z")

</div>

> [@marcus-j-davies](#):
>
> got called to do grocery shopping

You know it's Sunday, right? 🙈

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 January 2024 16:33 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/27 "2024-01-21T16:33:18Z")

</div>

All the more reason I was sooo happy to go out 😒

---

<div class="post-metadata">

**Author:** ![helander](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@helander](https://discourse.nodered.org/u/helander)\
**Post date:** [22 January 2024 11:23 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/28 "2024-01-22T11:23:26Z")

</div>

Thanks for the clarification

---

<div class="post-metadata">

**Author:** ![helander](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@helander](https://discourse.nodered.org/u/helander)\
**Post date:** [22 January 2024 11:24 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/29 "2024-01-22T11:24:40Z")

</div>

Thanks,very valuable information.

---

<div class="post-metadata">

**Author:** ![helander](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@helander](https://discourse.nodered.org/u/helander)\
**Post date:** [22 January 2024 11:27 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/30 "2024-01-22T11:27:12Z")

</div>

This is what I did prior to experimenting using the RED.nodes.eachNode to find the wires.  
Now I have turned back to sending messages to find out incoming wires, and the timer based initial send is back.

---

<div class="post-metadata">

**Author:** ![helander](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@helander](https://discourse.nodered.org/u/helander)\
**Post date:** [22 January 2024 11:56 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/31 "2024-01-22T11:56:56Z")

</div>

Some info about my current state:

- I am now using the topic property to indicate logical inputs.
- While working on the solution where I looked up wires with the eachNode method I also used a messaging hook that added a ’logicsource’ property on each outgoing message. I did that in order not to overwrite existing topic values. Since the hook is gone, I can now use the topic property to indicate logical inputs.
- What is new (I do not recall having seen this in any boolean/ logic plugin) is that I use a configuration message and an initial configuration period to find out the wiring. This removes the need for any other configuration within the network of gate nodes, than the flow wiring (no need to specify number of gate inputs). For me this is very imporant !!!
- I have also added an entrance node that is basically a gate node but it is a single logical input, i.e. it ignores the incoming message topics and feeds each logical message into the gate cluster. You could also create your own entrance nodes using (e.g. a subflow) an inject node that sends an initial configuration with a specific topic and a function node that tags each outgoing message with the same topic.

For the use cases that led me to this design, there is actually always a cluster of a fair amount of gates that have somewhat complex interconnection structure. In this context, having the graphical wiring as could be viewed by the Node Red editor becomes significant for the construction and maintenance of the logical network.  
Using one or a few gates in ”isolation” does not impose the same requirements.

---

<div class="post-metadata">

**Author:** ![helander](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@helander](https://discourse.nodered.org/u/helander)\
**Post date:** [23 January 2024 07:45 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/32 "2024-01-23T07:45:39Z")

</div>

Becoming close to publishing my solution, I realized that what I basically was asking for in my initial question is possible to achieve via the Message Hooks Api. Further some study of external requirements are needed in order to be able to fine-tune the solution. So now I will go back to the drawing board …

Thank you all for your valuable input.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 March 2024 07:46 UTC](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765/33 "2024-03-23T07:46:35Z")

</div>

Closed on 23 March 2024 07:46 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/find-out-incoming-wires-to-a-node/84765.md?page=1)
