Go Down

Topic: rf24, network.write stop code (Read 144 times) previous topic - next topic

alb12

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

Robin2

Could you help me, for if parent 0 is off the child 1 continue his code.
Not without seeing your program code.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

alb12

#2
May 22, 2018, 04:55 pm Last Edit: May 22, 2018, 04:57 pm by alb12
Code: [Select]
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 (
Code: [Select]
digitalWrite(relay, val);
 ) and after stop.

If I disable  
Code: [Select]
 SendDataRF24(relay, val * 100, val, other_node, 1);
 of changeState() it's ok.

The problem exist only if the parent is not running

Robin2

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
Code: [Select]
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
Code: [Select]
volatile byte val;
boolean newData = false;


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

alb12

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


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

Robin2

Yes this fix the bug but how make for this work in ISR
Don't.

That is not what an ISR is for.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up