Skip to content

Instantly share code, notes, and snippets.

@shirish47
Created March 28, 2016 10:21
Show Gist options
  • Save shirish47/54df16d143b99287673a to your computer and use it in GitHub Desktop.
Save shirish47/54df16d143b99287673a to your computer and use it in GitHub Desktop.
RF24 library trouble with available
nrf24.startListening();
Serial.println("waiting..");
unsigned long started_waiting_at =millis();
bool timeout=false;
while ( ! nrf24.available() ){ // While nothing is received
if ((millis() - started_waiting_at) > 5000 ){ // If waited longer, indicate timeout and exit while loop
timeout = true;
break;
}else
timeout=false;
}
if ( timeout ){ // Describe the results
Serial.println(F("Failed, response timed out."));
}else{
Advertise a;
uint8_t len= sizeof(a);
nrf24.read( &a, len );
Serial.print("Dev ID: ");
Serial.println(a.dev_Id);
Serial.print("Token ID: ");
Serial.println(a.token_Id);
Serial.print("Adv type: ");
Serial.println(a.adv_type);
//just to ensure that location is cleared
a.dev_Id=0;
a.token_Id=0;
a.adv_type= 0;
}
Serial.println("___________has the buffered erased?____________");
Serial.print("Dev ID: ");
Serial.println(a.dev_Id);
Serial.print("Token ID: ");
Serial.println(a.token_Id);
Serial.print("Adv type: ");
Serial.println(a.adv_type);
Serial.println("___________are all of above zeroed?____________");
Serial.print("nrf available test: "); Serial.println(nrf24.available()); //returns true once it returns true :(
Serial.print("timeout :");
Serial.println(timeout);
nrf24.stopListening();// thought this would clear rx buffer :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment