Buonasera,
sto sviluppando un progetto con gli NRF24 e la libreria RF24network.
Tutto funziona come deve ovvero il master riceve da 4 slaves i valori di 4 variabili.
Il problema è che se uno slave muore per qualsivoglia motivo (batteria?)
mi resta l'ultimo valore letto in memoria.
ho provato a forzare a fine main loop le variabili a 0 per poi farle rileggere dal network.read
ma poi quando le visualizzo col Serial.print mi stampa suia la variabile a 0 che il valore letto in due righe successive
la cosa trana è che il Serial.print è solo nel ciclo ...
allego il listato del master se qualcuno ha voglia di dare un occhio.
Grazie.
/*master per progetto comparatori radio con NRF24Network*/
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
//#define DEBUG
RF24 radio(10, 9); // nRF24L01(+) radio attached using Getting Started board
RF24Network network(radio); // Network uses that radio
const uint16_t this_node = 00; // Address of our node in Octal format ( 04,031, etc)
const uint16_t node_1 = 01; // Address of the other node in Octal format
const uint16_t node_2 = 02; // Address of the other node in Octal format
const uint16_t node_3 = 03; // Address of the other node in Octal format
const uint16_t node_4 = 04; // Address of the other node in Octal format
int lettura_1 = 8888; //imposto la variabile a 8888 in modo da capire se il sensore ha fatto almeno 1 lettura
int lettura_2 = 8888;
int lettura_3 = 8888;
int lettura_4 = 8888;
struct payload_t { // Structure of our payload
int num_sent;
};
void setup(void)
{
Serial.begin(38400);
#ifdef DEBUG
Serial.println("Ricevitore v0.1");
#endif
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
}
void loop(void) {
network.update(); // Check the network regularly
while ( network.available() ) { // Is there anything ready for us?
RF24NetworkHeader header; // If so, grab it and print it out
payload_t payload;
network.read(header, &payload, sizeof(payload));
#ifdef DEBUG
Serial.print(" from ");
Serial.print(header.from_node);
Serial.print("Received ");
Serial.print(payload.num_sent);
#endif
/* if ((header.from_node == 01) == true) {
lettura_1 = payload.num_sent;
}
else if ((header.from_node == 01) == false) {
lettura_1 = 9999;
}
if ((header.from_node == 02) == true) {
lettura_2 = payload.num_sent;
}
else if ((header.from_node == 02) == false) {
lettura_2 = 9999;
}*/
switch (header.from_node) {
case 01:
lettura_1 = payload.num_sent;
break;
case 02:
lettura_2 = payload.num_sent;
break;
case 03:
lettura_3 = payload.num_sent;
break;
case 04:
lettura_4 = payload.num_sent;
break;
}
Serial.print(lettura_1);
Serial.print(",");
Serial.print(lettura_2);
Serial.print(",");
Serial.print(lettura_3);
Serial.print(",");
Serial.println(lettura_4);
}
}