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();
}
Example #2
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));
}
Example #3
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);
}
Example #4
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);
    }
}
Example #5
0
int main(int argc, char** argv){
	radio.begin();

	// optionally, increase the delay between retries & # of retries
	radio.setRetries(0,0);

	// Dump the configuration of the rf unit for debugging
	radio.printDetails();
	string input = "";
	cout << "Choose your node number. #0-6 \n>";
	getline(cin,input);

	int radioNumber = (int)input[0]-48;

	cout << "input" << input << "\n";

	radio.openWritingPipe(pipes[radioNumber]);

	for (int i = 0; i < 6; i++) {
		if (i != radioNumber) {
			cout << i << "\n";
    		radio.openReadingPipe(i,pipes[i]);
		}
	}

}
Example #6
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);
}
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");

}
Example #8
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();
}
Example #9
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;
}
/********************************************************************************
	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();
    }
}
Example #11
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();
}
void setup()
{

    Serial.begin(115200);
    printf_begin();
    Serial.println(F("\n\n** NeoPixelWirelessClient ** \n\n"));

    Serial.println(F("Reading client configuration...."));
    if( !readClientConfiguration( (client_configuration_t *)&clientConfig) )
    {
        Serial.println(F("** Error reading client configuration\n"));
        clientConfig.version = CLIENT_CONFIG_V10;
        clientConfig.nodeId = 0x01;
        if( !writeClientConfiguration((client_configuration_t *)&clientConfig) )
        {
            Serial.println(F("** Error writing client configuration\n"));
        }
        else
        {
            Serial.println(F("Successfully wrote client configuration\n"));
        }
    }
    else
    {
        Serial.println(F("Successfully Read Configuration:\n"));
    }
    dumpClientConfiguration((client_configuration_t *)&clientConfig);

    // Setup and configure radio
    radio.begin();
    radio.enableAckPayload(); // enable payload ack
    radio.enableDynamicPayloads(); // Ack payloads are dynamic payloads

    setNodeId(clientConfig.nodeId);
//	radio.openWritingPipe(addresses[1]);
//	radio.openReadingPipe(1, addresses[0]);
//	radio.startListening(); // we're the client, so start listening
    radio.writeAckPayload(1, &message_count, sizeof(message_count));
    ++message_count;
    radio.printDetails(); // Dump the configuration of the rf unit for debugging
    delay(50);
    attachInterrupt(0, check_radio, LOW); // Attach interrupt handler to interrupt #0 (using pin 2) on BOTH the sender and receiver

    if (controller.initialize(50, 2) == false)
    {

    }
    else
    {
        controller.fill(CRGB::Black, true);
    }

}
void radioSetup() {
  radio.begin();
  radio.setRetries(15, 15);
  radio.setChannel(0x4c); //76
  radio.setPALevel(RF24_PA_MAX);
  radio.setPALevel(RF24_PA_MAX);

  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]);
  radio.startListening();
  radio.printDetails();
  printf("Radio setup is complete!\n");
}
//Initial setup of GPIO Pins and pipe modes (read/write).
void setup(void)
{
  radio.begin();
  radio.setRetries(15,15);
  radio.setChannel(0x4c);
  radio.setPALevel(RF24_PA_MAX);
    radio.openWritingPipe(pipes[0]);
    radio.openReadingPipe(1,pipes[1]);
    radio.openReadingPipe(2,pipes[2]);
    radio.openReadingPipe(3,pipes[3]);

  radio.startListening();
  radio.printDetails();
}
Example #15
0
void setup(void) {
   // init radio for reading
   radio.begin();
   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);
   radio.openReadingPipe(1,pipes[1]);
   radio.startListening();
   radio.printDetails();
   cout << "Listening...\n";
}
Example #16
0
void setup(void){
	//Prepare the radio module
	printf("\nPreparing interface\n");
	radio.begin();
	radio.setRetries( 15, 15);
	radio.setChannel(0x4c);
	radio.setPALevel(RF24_PA_MAX);
	radio.setPALevel(RF24_PA_MAX);

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

}
Example #17
0
void setup(void)
{
  //
  // Print preamble
  //

  //Serial.begin(57600);
  //printf_begin();
  printf("\n\rRF24/examples/scanner/\n\r");

  //
  // Setup and configure rf radio
  //

  radio.begin();
  radio.setAutoAck(false);
//	radio.enableDynamicPayloads();
	radio.setPayloadSize(2);
	radio.setDataRate(RF24_250KBPS);
	radio.setPALevel(RF24_PA_MAX);
//	radio.setChannel(76);
	radio.setCRCLength(RF24_CRC_16);

  // Get into standby mode
  radio.startListening();
  radio.stopListening();

  radio.printDetails();

  // 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");

}
void setup(void)
{
  Serial.begin(115200);

  radio.begin();

  // enable dynamic payloads
  radio.enableDynamicPayloads();

  // optionally, increase the delay between retries & # of retries
  radio.setRetries(5,15);

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

  radio.printDetails();
}
Example #19
0
void setup(void){
  //Prepare the radio module
  printf("\nPreparing interface\n");
  radio.begin();
  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);  

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

}
Example #20
0
void setup(){
  uextPowerOn();
  pinMode(LED, OUTPUT);
  pinMode(OUT, OUTPUT);

  Serial.begin(115200);
  printf_begin();

  radio.begin();
  radio.setCRCLength(RF24_CRC_16);
  radio.setDataRate(RF24_1MBPS);
  radio.setAutoAck(0);
  radio.setRetries(0,0);
  radio.setPayloadSize(3);                
  radio.powerUp();
  radio.printDetails(); 
  setupReceive();
}
Example #21
0
bool switchLight(int action){
  //This function send a message, the 'action', to the arduino and wait for answer
  //Returns true if ACK package is received
  //Stop listening
  radio.stopListening();
  unsigned long message = action;
  printf("Now sending %lu...", message);

  //Send the message
  bool ok = radio.write( &message, sizeof(unsigned long) );
  if (ok)
    printf("ok...");
  else
    printf("failed.\n\r");
  //Listen for ACK
  radio.startListening();
  //Let's take the time while we listen
  unsigned long started_waiting_at = __millis();
  bool timeout = false;
  //if(!radio.available() ){
 //     printf("No hay radio disponible\n");
 // }
  while ( ! radio.available() && ! timeout ) {
    __msleep(10);
    if (__millis() - started_waiting_at > 5000 )
      timeout = true;

  }

  if( timeout ){
    //If we waited too long the transmission failed
      printf("Failed, response timed out.\n\r");
     radio.printDetails();
     return false;

  }else{
    //If we received the message in time, let's read it and print it
    unsigned long got_time;
    radio.read( &got_time, sizeof(unsigned long) );
    printf("Got response %lu, round-trip delay: %lu\n\r",got_time,__millis()-got_time);
    return true;
  }

   }
void RF24Setup( void (*processPacket)(Packet) )
{
  radio.begin();
  radio.setPayloadSize(sizeof(Packet));
  //radio.setChannel(4);
  //radio.setDataRate(RF24_250KBPS);
  //radio.setRetries(0,15);

  radio.openReadingPipe(1,base_pipe);
  radio.setAutoAck(1, false);
  radio.startListening();

//TODO prety print based on --verbose argument
//  printf("\n\rRF24SensorHub!\n");
  radio.printDetails();

  printf("size of packet   = %hu\n", sizeof(Packet));
  
  _processPacket = processPacket;

}
Example #23
0
void setup(void)
{
	time_t now = time(0);
	char* dt = ctime(&now);
	cout << "The local time is: " << dt << endl;

	tm * gmtm = gmtime(&now);
	dt = asctime(gmtm);;
	cout << "The UTC date and time is: " << dt << endl;
	
	//
	// Refer to RF24.h or nRF24L01 DS for settings
	radio.begin();
	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);
}
Example #24
0
void setup(void)
{
  //
  // Print preamble
  //

  //Serial.begin(57600);
  //printf_begin();
  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();

  radio.printDetails();

  // 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");

}
Example #25
0
void setup(void)
{
        radio.begin();
        // enable dynamic payloads
        radio.enableDynamicPayloads();
        // optionally, increase the delay between retries & # of retries
        radio.setRetries(15, 15);
        radio.setDataRate(RF24_2MBPS);
		radio.setPALevel(RF24_PA_HIGH);
		radio.setChannel(50);
        // Open pipes to other nodes for communication
        // Open 'our' pipe for writing
        // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
        radio.openWritingPipe(pipes[0]);
        radio.openReadingPipe(1, pipes[1]);
		radio.setCRCLength(RF24_CRC_16);
		radio.setAutoAck( true ) ;
        // Start listening
        radio.startListening();
        // Dump the configuration of the rf unit for debugging
        radio.printDetails();
}
Example #26
0
void setup(void)
{
  radio.begin();
  radio.setPayloadSize(PAYLOAD_SIZE);
  radio.setAutoAck(1);
  radio.setRetries(15,15);
  radio.setDataRate(RF24_1MBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.setChannel(10);
  radio.setCRCLength(RF24_CRC_16);

  //open the pipe
  radio.openReadingPipe(1,0xF0F0F0F0E1LL);

  // Start Listening
  radio.startListening();

  //print output
  radio.printDetails();
  printf("\n\rOutput below : \n\r");
  usleep(1000);
}
Example #27
0
void setup(void)
{
	// set up the role pin
	pinMode(role_pin, INPUT);
	digitalWrite(role_pin,HIGH);
	delay(20); // Just to get a solid reading on the role pin
	//
	// Setup and configure rf radio
	//
	radio.begin();
	// enable dynamic payloads
	radio.enableDynamicPayloads();

	// optionally, increase the delay between retries & # of retries
	radio.setRetries(15,15);
	
	radio.setDataRate(RF24_250KBPS);
	//
	// Open pipes to other nodes for communication
	//
	// Open 'our' pipe for writing
	// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
	radio.openWritingPipe(pipes[0]);
	radio.openReadingPipe(1,pipes[1]);

	//
	// Start listening
	//

	radio.startListening();

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

	radio.printDetails();
}
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();

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


/********* Role chooser ***********/

  printf("\n ************ Role Setup ***********\n");
  string input = "";
  char myChar = {0};
  cout << "Choose a role: Enter 0 for pong_back, 1 for ping_out (CTRL+C to exit) \n>";
  getline(cin,input);

  if(input.length() == 1) {
	myChar = input[0];
	if(myChar == '0'){
		cout << "Role: Pong Back, awaiting transmission " << endl << endl;
	}else{  cout << "Role: Ping Out, starting transmission " << endl << endl;
		role = role_ping_out;
	}
  }
/***********************************/
  // This simple sketch opens two pipes for these two nodes to communicate
  // back and forth.

    if ( !radioNumber )    {
      radio.openWritingPipe(pipes[0]);
      radio.openReadingPipe(1,pipes[1]);
    } else {
      radio.openWritingPipe(pipes[1]);
      radio.openReadingPipe(1,pipes[0]);
    }
	
	radio.startListening();
	
	// forever loop
	while (1)
	{
		if (role == role_ping_out)
		{
			// First, stop listening so we can talk.
			radio.stopListening();

			// Take the time, and send it.  This will block until complete

			printf("Now sending...\n");
			unsigned long time = millis();

			bool ok = radio.write( &time, sizeof(unsigned long) );

			if (!ok){
				printf("failed.\n");
			}
			// Now, continue listening
			radio.startListening();

			// Wait here until we get a response, or timeout (250ms)
			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
			{
				// Grab the response, compare, and send to debugging spew
				unsigned long got_time;
				radio.read( &got_time, sizeof(unsigned long) );

				// Spew it
				printf("Got response %lu, round-trip delay: %lu\n",got_time,millis()-got_time);
			}
			sleep(1);
		}

		//
		// Pong back role.  Receive each packet, dump it out, and send it back
		//

		if ( role == role_pong_back )
		{
			
			// 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
				
			}
		
		}

	} // forever loop

  return 0;
}
/**
 * Handles serial commands and changing configuration
 */
void commandMode()
{
    uint8_t id = 0;

    // Read first character - discard since it just gets us into command mode
    char c = toupper(Serial.read());
    Serial.println(F("COMMAND MODE:"));
    Serial.println(F("C - Change Node ID"));
    Serial.println(F("D - Dump Configuration"));
    Serial.println(F("E - exit"));
    while(!Serial.available() ) {}

    c = toupper(Serial.read());
    switch( c )
    {
    case 'C':
        Serial.print(F("** Change Node Id **\nCurrent "));
        dumpClientConfiguration(&clientConfig);

        Serial.print(F("\nEnter 1 digit node ID: "));
        while(!Serial.available() ) {}
        id = Serial.read();
        Serial.println( (char)id ); // echo what the user typed
        Serial.println(F("\nProcessing...\n"));
        if( id >= '0' && id <= '9' )
        {
            // set node id
            clientConfig.nodeId = id;
            dumpClientConfiguration(&clientConfig);
            if( writeClientConfiguration(&clientConfig) )
            {
                Serial.print(F("Node ID accepted: "));
                Serial.println( clientConfig.nodeId, HEX);

                setNodeId(id);
//				radio.stopListening();
//				addresses[0][0] = clientConfig.nodeId;
//				radio.openReadingPipe(1, addresses[0]);
//				radio.startListening(); // we're the client, so start listening
                radio.printDetails(); // Dump the configuration of the rf unit for debugging

            }
            else
            {
                Serial.println(F("Error saving configuration information."));
            }
        }
        else
        {
            Serial.print(F("Illegal node value entered:"));
            Serial.println(id);
        }
        break;
    case 'D':
        dumpClientConfiguration(&clientConfig);
        radio.printDetails();
        break;
    case 'E':
        break;
    }
}
Example #30
0
int main(int argc, char* argv[])
{

	// Setup connection to Postgres SQL
	pqxx::connection conn("dbname=sensornodes user=postgres password=postgres");
	pqxx::work db(conn);

  // Setup radio
  radio.begin();
  delay(5);

  // Setup network on channel 90 with our id as zero (0)
  network.begin(90, 00);
  radio.printDetails();

  printf("starting server...\n");

  while (true)
  {
    network.update();

    if (false) {
      command cmd;
      strncpy(cmd.message, "SET INTERVAL=10", sizeof(cmd.message));
      RF24NetworkHeader h(02, payloadCommand);
      network.write(h, &cmd, sizeof(cmd));
    }

    while (network.available())
    {
      RF24NetworkHeader header;
      network.peek(header);

      // Generate time for better display
      time_t rawtime;
      struct tm * timeinfo;
      char ts[32];
      time (&rawtime);
      timeinfo = localtime(&rawtime);
      strftime(ts, 32, "[%X]", timeinfo);

      // And some coloring
      char info[64];
      sprintf(info, "%s [\x1b[33mnode %i\x1b[0m]", ts, header.from_node);

      if (header.type == payloadReadingFloat) {
        readingFloat reading;
        network.read(header, &reading, sizeof(reading));
        printf("%s %s\t\x1b[37m%f\x1b[0m\n", info, reading.name, reading.value);
      }

      if (header.type == payloadReadingInteger) {
        readingInt reading;
        network.read(header, &reading, sizeof(reading));
        printf("%s %s\t%i\n", info, reading.name, reading.value);
      }

      if (header.type == payloadReadingChar) {
        readingChar reading;
        network.read(header, &reading, sizeof(reading));
        printf("%s %s: %s\n", info, reading.name, reading.value);
      }
    }
  }

	return 0;
}