# Node hierarchy opinions?

**URL:** <https://discourse.nodered.org/t/node-hierarchy-opinions/95979>\
**Category:** Developing Nodes\
**Created:** [13 March 2025 18:54 UTC](https://discourse.nodered.org/t/node-hierarchy-opinions/95979 "2025-03-13T18:54:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [13 March 2025 18:54 UTC](https://discourse.nodered.org/t/node-hierarchy-opinions/95979/1 "2025-03-13T18:54:18Z")

</div>

**Hi,** 🙂  
I'm try to fix problems at the famous (built-in) [Arduino](https://nodered.org/docs/faq/interacting-with-arduino) module of Node-RED.  
Here is my progress so far:

> <https://github.com/node-red/node-red-nodes/issues/920#issuecomment-2709252741>
>
> \### Which node are you reporting an issue on?
> node-red-node-arduino
> \### What a…re the steps to reproduce?
> 1. Use Arduino Input
> 2. Connect Arduino
> \### What happens?
> Node-red crashed with error: \`TypeError: cannot set properties of undefined (setting 'pinMode') at Firmata.pinMode (/root/.node-red/node\_modules/firmata-io/lib/firmata.js:947:27)\`
> \### What do you expect to happen?
> Successful read from pin
> \### Please tell us about your environment:
> 
> \- \[\] Node-RED version: 2.2.2
> \- \[\] node.js version: v16.14.2
> \- \[\] npm version: 8.1.3
> \- \[\] Platform/OS: armv7/ Alpine Linux
> \- \[\] Browser: Yandex Browser (on other PC with Windows)

But I'm stuck because I've faced how many problems is there with the current code structure, so the only way to fix every problem is to refactor it completely.

## My question is:

What is the recommended way to develop a node module, where:

1. There is a "main" (Firmata board) node, which is hidden
2. The `in + out` nodes are basically visualisation of the main module's capabilities.
3. If the main node state is changing, it is affecting all the "sub-nodes". Like :
  - it is (re-)connecting,
  - has wrong com port setup, or none
  - disconnected
  - can not open com port _(because is was **not** closed and now it is occupied!!!)_
  - working fine
  - ... partial re-deployed? ... will discuss the problem [here ...](https://discourse.nodered.org/t/custom-node-subscribed-to-flow-restart-event/42350)

### Should I :

- Add an array to the main node, where I keep track of all sub-nodes?

- Keep the current code's plan, how it is?  
_(recursive time-loop of the sub-nodes every 5 secs to reflect changes)_

- Any other ideas?

```js
// state types of the Firmata Board:
const BdStates = Object.freeze({ // (freeze = immutable record)
    permanentError: -3, // no COM-port specified
    disconnected : -2,
    tryReconnect : -1,
    start : 0,
    gettingVersion: 1,
    OK : 2
});

```

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [13 March 2025 19:17 UTC](https://discourse.nodered.org/t/node-hierarchy-opinions/95979/2 "2025-03-13T19:17:16Z")

</div>

I've enhanced the old code with many extra log lines, and what I see is:

- either the consol logs are not starting soon enough to reflect what is happening,
- or main node is not always starting as first one.

... or is there any (other) logical explanation, why I get first log line from the child-nodes?

 ![kép](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff13e625d5a7464632ca5ef0a46f94a541ff501a.png)

Uploaded current code here: ([link](https://github.com/user-attachments/files/19235324/node-red-node-arduino-1.2.1.zip))  
**Warning !** This code is half-destroyed, half-fixed = **not working** well currently!

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [29 March 2025 03:44 UTC](https://discourse.nodered.org/t/node-hierarchy-opinions/95979/3 "2025-03-29T03:44:20Z")

</div>

I've found a great node called: ffmpeg and learned that I would need to completely restructure the registering **function** into a **class**.

_Too complicated work for me ..._

current stable 1.3.3 version of Arduino modure is here: ([link](https://github.com/user-attachments/files/19515074/node-red-node-arduino_v1.3.3.zip))

Will open a new topic about it, before creating a commit.

---

<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:** [28 May 2025 03:44 UTC](https://discourse.nodered.org/t/node-hierarchy-opinions/95979/4 "2025-05-28T03:44:28Z")

</div>

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