Esempio n. 1
1
void setupRadio() {
  printf_begin();

  // Setup and configure radio
  radio.begin();
  radio.setAutoAck(1);                    // Ensure autoACK is enabled
  radio.enableAckPayload();               // Allow optional ack payloads
  radio.setRetries(2,15);                 // Smallest time between retries, max no. of retries
  radio.setPayloadSize(8);
  radio.setDataRate(RF24_250KBPS);
  
  if( radio.getDataRate() == RF24_250KBPS ) 
  {
    debugPrint("Radio is available");
    radio_hw_available = true;
    
    radio.startListening();                 // Start listening
    radio.powerUp();
  
    radio.openWritingPipe(pipes[0]);       // Open different pipes when writing. Write on pipe 0, address 0
    radio.openReadingPipe(1,pipes[1]);     // Read on pipe 1, as address 1
  } else {
    debugPrint("Radio is NOT available");
  }
  //radio.printDetails(); // Dump the configuration of the rf unit for debugging
}
Esempio n. 2
0
void mapFreeCH()
{
    radio.setAutoAck(false);
    radio.startListening();
    radio.stopListening();

    for( int i = 30; i< 127; i++)
    {
        radio.setChannel(i);
        radio.startListening();
        delay(25);
        radio.stopListening();

        if ( !radio.testCarrier() )
        {
            freeCH[nFreeCH++] = i;
        }
    }
    radio.setAutoAck(true);
    radio.startListening();
    //test printing
    for (int i =0; i<nFreeCH; i++)
    {
        //Serial.println(freeCH[i]);
    }
    //Serial.println("");
    //Serial.print(freeCH[nextFreeCH]);
    //Serial.println("");
}
Esempio n. 3
0
int main(int argc, char** argv)
{
  printf("RF24 example starting.")

  /** Set up the radio **/
  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]);
  radio.startListening();


  /** Loop forever, writing and then listening for response **/
  while (1)
  {
    /** Send out the current time **/
    radio.stopListening();
    unsigned long time = millis();
    bool ok = radio.write(&time, sizeof(unsigned long));

    if (!ok)
      printf("Failed to send for some reason.\n");

    radio.startListening();


    /** Start waiting around for the response **/
    unsigned long started_waiting_at = millis();
    bool timeout = false;
    while( !radio.available() && !timeout )
    {
      if (millis() - started_waiting_at > 200)
        timeout = true;
    }


    /** Describe the results **/
    if (timeout)
    {
      printf("Failed. Response timed out.\n")
    }
    else
    {
      unsigned long got_time;
      radio.read(&got_time, sizeof(unsigned long))

      printf("Got response %lu, round-trip delay: %lu\n",
            got_time, millis() - got_time);

      sleep(1);
    }
  }
Esempio n. 4
0
// Setup //
void setup(void) {
  //
  // Print preamble
  //

  printf("\n\rRF24/examples/scanner/\n\r");
  //
  // Setup and configure rf radio
  //
  radio.begin();
  radio.setAutoAck(false);
  // Get into standby mode
  radio.startListening();
  radio.stopListening();
  // Print out header, high then low digit
  int i = 0;
  while ( i < num_channels )
  {
    printf("%x",i>>4);
    ++i;
  }
  printf("\n\r");
  i = 0;
  while ( i < num_channels )
  {
    printf("%x",i&0xf);
    ++i;
  }
  printf("\n\r");
}
Esempio n. 5
0
bool COM_24g::sendFrame(RF24 _radioCom)
{
	// First, stop listening so we can talk
	_radioCom.stopListening(); 
 
	//Opening the writting Pipe
	_radioCom.openWritingPipe(_writingPipe);
	delay(20);

	//put in place the Paypload
	_payload.type    = _dataType;
	_payload.version = _dataVersion;
	_payload.data    = _data;
	bool Writestatus = _radioCom.write(&_payload, sizeof(_payload));

  if (Writestatus)
      printf("Communication has been sent successfully. \n");
    else
      printf("Communication has failed.\n\r");

	//back in read mode
	_radioCom.startListening(); 
	
 
}
Esempio n. 6
0
void setup(void) {
    //maxa = EEPROM.read(CONFIG_START);
    //EEPROM.write(CONFIG_START, maxa);
    lcd.begin (20,4);
    delay(10);
    lcd.setBacklightPin(BACKLIGHT,POSITIVE);
    lcd.setBacklight(HIGH);
    lcd.clear();
    delay(10);
    lcd.home ();
    
    Serial.begin(57600);

    printf_begin();
    
    radio.begin();
    radio.setPALevel(RF24_PA_MAX); //RF24_PA_MIN = 0, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR 
    radio.setDataRate(RF24_250KBPS); //RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS
    //radio.setAutoAck(1);
    radio.setRetries(15,15);
    
    radio.enableDynamicPayloads();
    
    radio.openWritingPipe(pipes[1]);
    radio.openReadingPipe(1, pipes[0]);
    radio.startListening();
    radio.printDetails();
}
Esempio n. 7
0
void setup(void)
{
        //
        // Refer to RF24.h or nRF24L01 DS for settings
        radio.begin();
        radio.enableDynamicPayloads();
        radio.setAutoAck(1);
        radio.setRetries(15,15);
        radio.setDataRate(RF24_250KBPS);
        radio.setPALevel(RF24_PA_MAX);
        radio.setChannel(70);
        radio.setCRCLength(RF24_CRC_8);

        // Open 6 pipes for readings ( 5 plus pipe0, also can be used for reading )
        radio.openWritingPipe(pipes[0]);
        radio.openReadingPipe(1,pipes[1]);
        radio.openReadingPipe(2,pipes[2]);
        radio.openReadingPipe(3,pipes[3]);
        radio.openReadingPipe(4,pipes[4]);
        radio.openReadingPipe(5,pipes[5]);

        // Start Listening
        radio.startListening();

        radio.printDetails();

        usleep(1000);
}
Esempio n. 8
0
void setup(void)
{
  TRI_LOG(sizeof(long));
  TRI_LOG(sizeof(int));
	// Refer to RF24.h or nRF24L01 DS for settings

  TRI_LOG_STR("radio.begin()");
  radio.begin();

  TRI_LOG_STR("CONFIGURE_RADIO(radio)");
  CONFIGURE_RADIO(radio);

	// Open 6 pipes for readings ( 5 plus pipe0, also can be used for reading )
  radio.openWritingPipe(WRITING_PIPE);
  radio.openReadingPipe(1, READING_PIPE);

  radio.startListening();

	//
	// Dump the configuration of the rf unit for debugging
	//
  radio.printDetails();

  memset(&EMPTY_MESSAGE, 0, sizeof(ArPiMessage));
}
void setup(void)
{
	// setup interrupt
	gpio_export(int_gpio_num);
	gpio_set_edge(GPIO_STR, "rising", "1");

	radio.begin();
	// enable dynamic payloads
	radio.enableAckPayload();
	radio.enableDynamicPayloads();
	radio.setAutoAck(1);
	// optionally, increase the delay between retries & # of retries
	radio.setRetries(15, 15);
	radio.setDataRate(RF24_2MBPS);
	radio.setPALevel(RF24_PA_MIN);
	radio.setChannel(50);
	radio.setCRCLength(RF24_CRC_16);
	// Open pipes to other nodes for communication
	// Open pipe for reading
	radio.openReadingPipe(0, pipes[0]);
	radio.openReadingPipe(1, pipes[1]);
	// Start listening
	radio.startListening();
	// Dump the configuration of the rf unit for debugging
	radio.printDetails();
}
void setup(void){
	//Prepare the radio module
	printf("\nPreparing NRF24L01 interface\n");
	radio.begin();
	radio.setRetries( 15, 15);
	radio.setChannel(120);
	radio.enableAckPayload();
	//radio.disableCRC();
	radio.setAutoAck(true);
	radio.openWritingPipe(pipes[0]);
	radio.openReadingPipe(2,pipes[1]);
	radio.openReadingPipe(3,pipes[2]);
	radio.openReadingPipe(1,pipes[0]);
	radio.printDetails();
	printf("\nPreparing MySQL interface.\n");
	mysql_connect();
	if ((mysql1 != NULL)) {
		sprintf(SQLstring,"CREATE TABLE IF NOT EXISTS CC_SENSOR_DYN (timestamp DATETIME, id INTEGER, temperature FLOAT, value INTEGER);");
		if (!mysql_query(mysql1, SQLstring)) { printf("SQL CC_SENSOR_DYN Table is Ok: %s\n",SQLstring); }  else { printf("SQL CC_SENSOR_DYN NOk: %s\n",SQLstring); printf("%s\n", mysql_error(mysql1)); }

		sprintf(SQLstring,"CREATE TABLE IF NOT EXISTS CC_SENSOR_HIST (timestamp DATETIME, id INTEGER, hist_type VARCHAR(1), hist_period INTEGER, value FLOAT);");
		if (!mysql_query(mysql1, SQLstring)) { printf("SQL CC_SENSOR_HIST Table is Ok: %s\n",SQLstring); }  else { printf("SQL CC_SENSOR_HIST NOk: %s\n",SQLstring); printf("%s\n", mysql_error(mysql1)); }
				
		}
	radio.startListening();
	printf("\nNow Listening...\n");

}
Esempio n. 11
0
/********************************************************************************
Main
********************************************************************************/
int main(void) {
    // initialize code
	usart_init();

    // enable interrupts
    //sei();

	_delay_ms(2000);

    printf("Start NRF24L01P test...");

    radio.begin();
    radio.setRetries(15,15);
    radio.setPayloadSize(8);
    radio.setPALevel(RF24_PA_MAX);
    radio.setChannel(120);

    radio.openWritingPipe(pipes[1]);
    radio.openReadingPipe(1,pipes[0]);

    radio.startListening();

    radio.printDetails();

	loop();

    // main loop
    while (true) {
    	_delay_ms(1000);
    	printf("Elapsed: %u \n", TCNT1);
    }
}
Esempio n. 12
0
boolean sendRadioCommand(const byte cmd_buffer[]) {
  if( !radio_hw_available ) {
    debugPrint("Radio is NOT available");
    return false;
  }
  
  int counter = 0;
  
  //byte cmd_buffer[] = { 0xFF, 0x00, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00};
  
  radio.stopListening();
  
  debugPrint("Now sending payload: ",counter);
  
  boolean radio_write_ok = false;
  
  while( !radio_write_ok && counter < MAX_RADIO_RETRIES ) {
    radio_write_ok = radio.write(cmd_buffer,8);
    if( !radio_write_ok )
      debugPrint("Retry send: ", counter++);
  }
  
  debugPrint("Payload sent. ",counter);
  
  radio.startListening();
  
  return radio_write_ok;
}
Esempio n. 13
0
void changeChannel(byte newC)
{
    radio.stopListening();

    radio.setChannel(newC);
    radio.startListening();
}
Esempio n. 14
0
void setup(void)
{
	wiringPiSetupGpio();

	//
	// Refer to RF24.h or nRF24L01 DS for settings
	radio.begin(WPI_MODE_GPIO);
	radio.enableDynamicPayloads();
	radio.setAutoAck(1);
	radio.setRetries(15,15);
	radio.setDataRate(RF24_1MBPS);
	radio.setPALevel(RF24_PA_MAX);
	radio.setChannel(76);
	radio.setCRCLength(RF24_CRC_16);

	// Open 6 pipes for readings ( 5 plus pipe0, also can be used for reading )
	radio.openWritingPipe(pipes[0]);
	radio.openReadingPipe(1,pipes[1]);
	radio.openReadingPipe(2,pipes[2]);
	radio.openReadingPipe(3,pipes[3]);
	radio.openReadingPipe(4,pipes[4]);
	radio.openReadingPipe(5,pipes[5]);

	//
	// Dump the configuration of the rf unit for debugging
	//

	// Start Listening
	radio.startListening();

	radio.printDetails();
	printf("\n\rOutput below : \n\r");
	usleep(1000);
}
Esempio n. 15
0
boolean newBoardAvailable()
{
    if((nBoards < MAX_N_BOARDS) && (nSenActs < MAX_N_SENACT)&&nFreeCH)
    {
        radio.stopListening();
        radio.setChannel( APPLICATION_CH );
        radio.startListening();

        if(readPackage(newBoardPacked, 32))
        {
            if(writePackage(newBoardPacked, 32))return true;
            else
            {
                Serial.println("\nError: writng back board");
                return false;
            }
        }
        else
        {
            //Serial.println("\nError: no New Board");
            return false;
        }
    }
    else
    {
        Serial.println("Error: no more buffer/channel space");
        return false;
    }
}
Esempio n. 16
0
boolean writePackage(void * package, unsigned char len)
{
    radio.stopListening();
    boolean temp = radio.write(package,32);
    radio.startListening();
    return temp;
}
Esempio n. 17
0
void trans()
{
    Serial.println("Enter a msg (max 32 Characters)");
    while(!Serial.available());
      delay(32); // for collection
      char tx[32];
      for(int j=0;j<32;j++)
      {
       tx[j]=Serial.read();
       if(tx[j]==(char)-1)    // to avoid writing unkown char in spaces
       {
         tx[j]='\0';
         goto loop1;
       }
      }
      loop1:
     loop2: 
     bool done = radio.write(tx, sizeof(tx));  
     if(done==false)
     { 
       retx++;
       Serial.println("Tx Failed");
       if(retx<10)
       {
       goto loop2;
       }else retx=0;
     }
     radio.startListening();
     print_welcome_message();
}
Esempio n. 18
0
void loop(void)
{
  // Clear measurement values 
  memset(values,0,num_channels);

  // Scan all channels num_reps times
  int rep_counter = num_reps;
  while (rep_counter--)
  {
    int i = num_channels;
    while (i--)
    {
      // Select this channel
      radio.setChannel(i);

      // Listen for a little
      radio.startListening();
      delayMicroseconds(128);
      radio.stopListening();

      // Did we get a carrier?
      if ( radio.testCarrier() )
	++values[i];
    }
  }

  // Print out channel measurements, clamped to a single hex digit 
  int i = 0;
  while ( i < num_channels )
  {
    printf("%x",min(0xf,values[i]&0xf));
    ++i;
  }
  printf("\n\r");
}
Esempio n. 19
0
void add_names_to_devices(){
	uint8_t i=0;
	uint64_t mask=0xFFFFFFFFFF000000LL;
	dev device;
	uint8_t tam;
	printf("Please add names to the devices\r\n");
	while(load_address(&RFbuffer.destino,i)){
		blink_led();
		device.addr=RFbuffer.destino;
		RFbuffer.comando=all_on;
		radio.stopListening();
		radio.openWritingPipe((RFbuffer.destino & mask));
		radio.write(&RFbuffer,sizeof(RFbuffer));
		radio.startListening();
		printf("enter name for device:%d,with addr:%lX%08lX\r\n",i+1,(uint32_t)(device.addr>>32),(uint32_t)device.addr);
		while(!Serial.available());
		do {
			blink_led();
			tam=Serial.readBytes(device.name,sizeof(device));
			if (tam>=sizeof(device.name)){
				printf("name must be smaller than 7 letter\r\n");
			}else{
				device.name[tam]='\0';
				printf("device name set to:");
				int n=0;
				do{
					printf("%c",device.name[n]);
					n++;
				} while (device.name[n]!='\0');
				printf("\r\n");
				file=SD.open("devs.lst",FILE_WRITE);
				if (file){
					file.write((byte *)&device,sizeof(device));
				}
				file.close();
			}
		} while (tam>=sizeof(device.name));
		RFbuffer.comando=all_off;
		radio.stopListening();
		radio.openWritingPipe((RFbuffer.destino & mask));
		radio.write(&RFbuffer,sizeof(RFbuffer));
		radio.startListening();
		i++;
	}
	printf("done\r\n");
	return;
}
void sendPacket(Packet packet)
{
	radio.stopListening();
	radio.openWritingPipe(base_pipe+packet.nodeId); //open pipe unique to the node
	radio.setAutoAck(0, false);
	radio.write( &packet, sizeof(Packet) );
	radio.startListening();
}
Esempio n. 21
0
int main(int argc, char** argv){

//  bool role_ping_out = true, role_pong_back = false;
//  bool role = role_pong_back;

  printf("RF24/examples/GettingStarted/\n");

  // Setup and configure rf radio
  radio.begin();

  radio.setChannel(2);
  radio.setDataRate(RF24_2MBPS);
  radio.setPayloadSize(8);

  // optionally, increase the delay between retries & # of retries
//  radio.setRetries(15,15);
  // Dump the configuration of the rf unit for debugging
  radio.printDetails();


/***********************************/
	radio.startListening();
	
	// forever loop
	while (1)
	{

		// if there is data ready
		if ( radio.available() )
		{
			// Dump the payloads until we've gotten everything
			unsigned long got_time;

			// Fetch the payload, and see if this was the last one.
			while(radio.available()){
				radio.read( &got_time, sizeof(unsigned long) );
			}
//			radio.stopListening();
				
//			radio.write( &got_time, sizeof(unsigned long) );

			// Now, resume listening so we catch the next packets.
//			radio.startListening();

			// Spew it
			printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time);
			
				
		}
		delay(925); //Delay after payload responded to, minimize RPi CPU time
		printf("."); fflush(stdout);
//  radio.printDetails();
		

	} // forever loop

  return 0;
}
Esempio n. 22
0
void setupRadio() {
  radio.begin();
  radio.setRetries(0,15);
  radio.setPayloadSize(sizeof(PosData));
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);

  radio.startListening();
}
Esempio n. 23
0
/**
   fungsi untuk mengirim paket via radio
   @param paket* alamat ke paket
   @return ok bernilai true jika pengiriman berhasil, false jika sebaliknya
*/
bool kirim_paket(paket* paket_dikirim)
{
  uint8_t yang_dikirim[PANJANG_PAKET];
  toarray(paket_dikirim, yang_dikirim);
  printf("ngirim paket gan "); cetakpaket(paket_dikirim);
  radio.stopListening();
  bool ok = radio.write(yang_dikirim, PANJANG_PAKET);
  radio.startListening();
  return ok;
}
Esempio n. 24
0
/********************************************************************************
	Main
********************************************************************************/
int main(void) {
    // initialize usart module
	usart_init();

    // enable interrupts
    sei();

    // Init GPIO
    initGPIO();

    // Init Timer 1
    initTimer();

    // Init Timer 0 & 2
    initTimers();

	OCR0A = 255;
	OCR0B = 255;
	OCR2A = 255;
	OCR2B = 255;

    _delay_ms(1000);

	OCR0A = 0;
	OCR0B = 0;
	OCR2A = 0;
	OCR2B = 0;

    fixZeroValueOCR();

	// Console friendly output
    printf("Start...");
    printf(CONSOLE_PREFIX);

    // Init NRF24L01+
    radio.begin();
    radio.setRetries(15,15);
    radio.setPayloadSize(8);
    radio.setPALevel(RF24_PA_MAX);
    radio.setChannel(115);

    radio.openWritingPipe(pipes[0]);
    radio.openReadingPipe(1,pipes[1]);

    radio.startListening();

    // Some RF module diagnostics logs
    radio.printDetails();

	// main loop
    while (1) {
    	// main usart loop for console
    	usart_check_loop();
    }
}
void setNodeId(uint8_t id)
{
    // Set the node ID
    addresses[0][0] = clientConfig.nodeId;
    // Stop listening
    radio.stopListening();
    // Open new pipe with new ID
    radio.openReadingPipe(1, addresses[0]);
    // Strart listening for commands
    radio.startListening();
}
Esempio n. 26
0
void setup()
{
  Serial.begin(9600);
  //delay(1000);
  radio.begin();
  print_welcome_message();
  radio.openReadingPipe(1,pipe[0]);//For Receiving Operation
  radio.openWritingPipe(pipe[1]);//For Transmitting Operation
  radio.startListening();

}
Esempio n. 27
0
void COM_24g::listeningPipe(RF24 _radioCom)	//Listen all available pipes
{
  int i;
	for (i=1;i<5;i++) {
		if (_readingPipe[i] != NULL) {
		_radioCom.openReadingPipe(i,_readingPipe[i]);
		}
	}
  _radioCom.startListening();
  _radioCom.powerUp();

}
Esempio n. 28
0
void rf24_init(RF24& radio) {
	const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
	radio.begin();
	//	radio.setChannel(100);
	radio.setRetries(15, 15);
	radio.setPayloadSize(sizeof(report_t));
	radio.setDataRate(RF24_250KBPS);
	radio.openWritingPipe(pipes[1]);
	radio.openReadingPipe(1, pipes[0]);
	radio.startListening();
	radio.printDetails();
}
Esempio n. 29
0
void loop(void)
{
	//
	// Ping out.
	//
	// The payload will always be the same, what will change is how much of it we send.
	static char send_payload[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ789012";

	// First, stop listening so we can talk.
	radio.stopListening();

	// Take the time, and send it.  This will block until complete
	printf("Now sending length %i...",next_payload_size);
	radio.write( send_payload, next_payload_size );

	// Now, continue listening
	radio.startListening();

	// Wait here until we get a response, or timeout
	long started_waiting_at = __millis();

	bool timeout = false;
	while ( ! radio.available() && ! timeout )
		if (__millis() - started_waiting_at > 500 )
			timeout = true;

	// Describe the results
	if ( timeout )
	{
		printf("Failed, response timed out.\n\r");
	}
	else
	{
		// Grab the response, compare, and send to debugging spew
		uint8_t len = radio.getDynamicPayloadSize();
		radio.read( receive_payload, len );

		// Put a zero at the end for easy printing
		receive_payload[len] = 0;

		// Spew it
		printf("Got response size=%i value=%s\n\r",len,receive_payload);
	}

	// Update size for next time.
	next_payload_size += payload_size_increments_by;
	if ( next_payload_size > max_payload_size )
		next_payload_size = min_payload_size;


	sleep(1);
}
Esempio n. 30
0
uint8_t send(uint8_t * data_pointer){
    // Stop listening so we can talk
    radio.stopListening();

    // Send data. This is a blocking call.
    uint8_t result = radio.write(data_pointer, PAYLOADLEN);

    // Resume listening
    radio.startListening();

    // Return the error code. If result is 0, there was a sending failure.
    return (result == 0); 
}