rf24, network.write stop code

Hello,

I have an attiny and a nrf24l01.
I had attach interrupt on a pin for wall switch, when the interrupt is execute I run a " network.write ".
Problem, when the parent node is off, the code stop and need to reboot the attiny.

Exemple :

0 parent node
1 child node

interrupt on child 1 => try to send infomation to parent 0.
Parent 0 is off => child 1 failed and need to reboot.

Could you help me, for if parent 0 is off the child 1 continue his code.

Thank you

alb12:
Could you help me, for if parent 0 is off the child 1 continue his code.

Not without seeing your program code.

...R

const uint16_t this_node = 031;
const uint16_t other_node = 0;

#include <RF24.h>
#include <RF24Network.h>
#include <PinChangeInterrupt.h>

#define relay 9

void setup()
{
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  network.begin(this_node);
  
  attachPCINT(digitalPinToPCINT(1), changeState, CHANGE);
  pinMode(relay, OUTPUT);

  delay(1000);
  SendDataRF24(relay, 0, 0, other_node, 1);
}

void loop()
{
  network.update();  
}

void SendDataRF24(int pin, int value, int etat, int other_node,  int type = -99)
{
 payload_t payload = { pin, value, etat, type };

 RF24NetworkHeader header( other_node,  't');
 network.write(header, &payload, sizeof(payload));
}

void changeState()
{
  int val = !digitalRead(relay);
  digitalWrite(relay, val);
  SendDataRF24(relay, val * 100, val, other_node, 1);
}

First change on pin attached to interrupt execute this (

digitalWrite(relay, val);

) and after stop.

If I disable

 SendDataRF24(relay, val * 100, val, other_node, 1);

of changeState() it’s ok.

The problem exist only if the parent is not running

I have never used the Network library myself - just the RF24 library.

My guess is that the problem is due to sending the message from inside an ISR. I suggest you change your program to this

void loop()
{
  network.update();
  if (newData == true) {
      digitalWrite(relay, val);
      SendDataRF24(relay, val * 100, val, other_node, 1);
      newData = false;
   }
}


void changeState()
{
  val = !digitalRead(relay);
  newData = true;
}

You will also need these definitions at the top of the program

volatile byte val;
boolean newData = false;

...R

Yes this fix the bug but how make for this work in ISR

void loop()
{
  network.update();
  if (newData == true) {
      digitalWrite(relay, val);
      SendDataRF24(relay, val * 100, val, other_node, 1);
      newData = false;
   }
}

alb12:
Yes this fix the bug but how make for this work in ISR

Don't.

That is not what an ISR is for.

...R