# Gpio end node catch

**URL:** <https://discourse.nodered.org/t/gpio-end-node-catch/95774>\
**Category:** General\
**Created:** [3 March 2025 16:35 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774 "2025-03-03T16:35:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [3 March 2025 16:35 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/1 "2025-03-03T16:35:07Z")

</div>

hello, I need to monitor the operation of some gpio (on rpi), I would like to use the catch node and possibly the status node. I never used these nodes and it is a little complicated to understand how they work.  
I would like to know if it is possible to get what I need and if the catch node captures any anomalies on gpio.  
thanks

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [3 March 2025 16:39 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/2 "2025-03-03T16:39:22Z")

</div>

They are very simple nodes, all you need to do is drag the node on to the work space and select the node you wish to monitor in the config panel. You could also try the complete node. You will need to add a debug node to check what they return, if at all anything, depending on how the node you wish to monitor has been written.

---

<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:** [3 March 2025 16:49 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/3 "2025-03-03T16:49:46Z")

</div>

> [@pin32](#):
>
> I would like to use the catch node and possibly the status node

What exactly are you trying to pick up from the nodes? are they input node or an output node?

> [@pin32](#):
>
> if the catch node captures any anomalies on gpio.

What sort of anomalies?

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [3 March 2025 17:21 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/4 "2025-03-03T17:21:38Z")

</div>

sometimes gives me a bug on python, but very rarely, since these gpio serve for pretty crucial actions I would like a confirmation or a warning of the good functioning.  
the catch node I connect to the correct gpio are 24 inputs (16 on i2c) and 21 out (16 on i2c).  
the difficulty I encounter because not being able to generate an error I do not understand what kind of output from the catch node. if possible an example would be grateful

---

<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:** [3 March 2025 17:38 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/5 "2025-03-03T17:38:25Z")

</div>

Feed the Catch node into a Debug node set to Output Complete Message and see what you get.

I don't know under what circumstances, if ever, the GPIO nodes will generate a catchable error though.

You could also use a Status node which will give you the text that appears under the node. See what are its normal outputs are and if anything else is seen that that may indicate an error.

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [4 March 2025 07:30 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/6 "2025-03-04T07:30:06Z")

</div>

ok thanks for the information. I saw that it is quite simple, the catch node reports the error of the node to which you attach it, the problem is to figure out exactly what error to capture from the gpio node, doing some research seems that the most frequent error is: nrpgio python command not running.  
so I will look for this error for flow management.  
To find out if it works again how could I do?

---

<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:** [4 March 2025 07:45 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/7 "2025-03-04T07:45:54Z")

</div>

> [@pin32](#):
>
> To find out if it works again how could I do

What does the Status node show when it is in error, and when it recovers?

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [4 March 2025 07:50 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/8 "2025-03-04T07:50:05Z")

</div>

> [@Colin](#):
>
> What does the Status node show when it is in error, and when it recovers?

Good question, when you need the error never comes...

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [4 March 2025 10:43 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/9 "2025-03-04T10:43:27Z")

</div>

I attach the code that I am using to manage the error, but do not know how to handle the recovery of the error, for now I have entered that if data transit the problem is solved, but it is not the maximum result I would get, Do you have any tips for implementing a better way to handle error recovery?

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [4 March 2025 10:43 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/10 "2025-03-04T10:43:54Z")

</div>

```auto
// Imposta dinamicamente la chiave (modificabile facilmente qui)
var chiave = "GPIOIN_1"; // La chiave dinamica

// Recupera il payload in ingresso e forziamo il tipo in numero (utilizziamo Number())
var input = msg.payload;

// Se l'input è una stringa, forziamo la conversione in stringa
if (typeof input !== 'string') {
    input = String(input);
}

// Oggetto JSON da inviare in out2
var jsonOut2 = {
    "name": chiave,
    "stat_t": `DATI FOTOVOLTAICO/INGRESSI/${chiave}`,
    "avty_t": `DATI FOTOVOLTAICO/INGRESSI/${chiave}/LWT`,
    "pl_avail": "Online",
    "pl_not_avail": "Offline",
    "uniq_id": chiave,
    "icon": "mdi:electric-switch",
    "dev": {
        "ids": ["Quadro Domotica"],
        "name": "Quadro Domotica",
        "mf": "TopPino",
        "mdl": "Aggregatore mqtt",
        "sw": "0.1",
        "sa": "Fotovoltaico"
    }
};

// Recupera l'ultimo input salvato dal contesto
var lastInput = context.get('lastInput');
var lastOut1 = context.get('lastOut1') || null;
var lastOut2 = context.get('lastOut2') || null;
var lastOut3 = context.get('lastOut3') || null;

// Aggiungi un controllo per evitare che `null` venga trattato come un valore valido per il confronto
if (lastInput === undefined || lastInput === null) {
    // Salva l'input attuale e non inviare messaggi finché non ci sono cambiamenti futuri
    context.set('lastInput', input);
    return null; // Non inviare nulla nel primo ciclo
}

// Se l'input è uguale all'ultimo input, non fare nulla (ignora i messaggi duplicati)
if (input === lastInput && input !== 'agg') {
    // Se l'input è uguale all'ultimo e non è "agg", non fare nulla, ma ripristina lo stato su out3 a "Online"
    if (lastOut3 !== "Online") {
        lastOut3 = "Online"; // Ripristina lo stato su "Online" se l'errore è stato rimosso
        node.send([null, null, { payload: "Online" }]); // Invia solo a out3
    }
    return null; // Non inviare nulla se l'input è lo stesso dell'ultimo e non è "agg"
}

// Se l'input è "agg", invia i messaggi precedenti senza modificare `lastInput`
if (input === 'agg') {
    if (lastOut1 !== null && lastOut2 !== null && lastOut3 !== null) {
        msg.payload = lastOut1;
        msg.topic = "out1";
        node.send([msg, { payload: lastOut2 }, { payload: lastOut3 }]);
    } else {
        // Se non c'è stato un messaggio precedente, invia un errore su out3
        node.send([null, null, { payload: null }]);
    }
    return null; // Non cambiare lo stato dopo l'aggiornamento
}

// Se il messaggio di errore è "nrpgio python command not running", invia solo "Offline" su out3
if (msg.payload === "nrpgio python command not running") {
    lastOut3 = "Offline"; // Imposta lo stato come "Offline"
    msg.payload = "Offline";
    msg.topic = "out3";
    node.send([null, null, msg]); // Invia solo su out3

    // Memorizza lo stato per il prossimo ciclo
    context.set('lastOut3', lastOut3);
    return null; // Non inviare altro per questo ciclo
}

// Se l'input è '1', invia "ON", l'oggetto JSON e "Online" su out3
if (input === '1') {
    lastOut1 = "ON";
    lastOut2 = jsonOut2;
    lastOut3 = "Online"; // Imposta sempre "Online" quando il valore è valido
    msg.payload = "ON";
    msg.topic = "out1";
    node.send([msg, { payload: jsonOut2 }, { payload: "Online" }]);

    // Memorizza i messaggi per un eventuale reinvio
    context.set('lastOut1', lastOut1);
    context.set('lastOut2', lastOut2);
    context.set('lastOut3', lastOut3);
} 
// Se l'input è '0', invia "OFF", l'oggetto JSON e "Online" su out3
else if (input === '0') {
    lastOut1 = "OFF";
    lastOut2 = jsonOut2;
    lastOut3 = "Online"; // Imposta sempre "Online" quando il valore è valido
    msg.payload = "OFF";
    msg.topic = "out1";
    node.send([msg, { payload: jsonOut2 }, { payload: "Online" }]);

    // Memorizza i messaggi per un eventuale reinvio
    context.set('lastOut1', lastOut1);
    context.set('lastOut2', lastOut2);
    context.set('lastOut3', lastOut3);
} 
else {
    // In tutti gli altri casi invia un messaggio di errore su out3
    node.send([null, null, { payload: null }]);
}

// Memorizza lo stato dell'input per il prossimo ciclo
context.set('lastInput', input);
context.set('lastOut1', lastOut1);
context.set('lastOut2', lastOut2);
context.set('lastOut3', lastOut3);

return null; // Non inviare nulla di default se non è stato mandato un messaggio

```

---

<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:** [4 March 2025 13:32 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/11 "2025-03-04T13:32:59Z")

</div>

I have not got time to look at your flow.

What does the Status node show when it is in error, and when it recovers?

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [4 March 2025 14:31 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/12 "2025-03-04T14:31:35Z")

</div>

> [@pin32](#):
>
> `nrpgio python command not running`

don’t know how to stimulate these events, the major problem is this, for the error I did a search and found that a frequent mistake is: nrpgio python command not running, to restore normal state I have no idea of how to proceed, I am looking for example ideas

---

<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:** [4 March 2025 15:41 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/13 "2025-03-04T15:41:58Z")

</div>

`nrgpio` is a python script that runs in the background and reads/writes to the gpio pins for node-red. If it is not running then you will have to find why it is not running and fix it. There is nothing you could do in the flows, other than possibly restarting node-red or rebooting the pi.

---

<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:** [2 June 2025 15:42 UTC](https://discourse.nodered.org/t/gpio-end-node-catch/95774/14 "2025-06-02T15:42:11Z")

</div>

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