Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <sstream>
- #include <string>
- #include "./RF24.h"
- #include <ctime>
- using namespace std;
- //
- // Hardware configuration
- // Configure the appropriate pins for your connections
- /****************** Raspberry Pi ***********************/
- // Setup for GPIO 15 CE and CE0 CSN with SPI Speed @ 8Mhz
- RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
- // Radio pipe addresses for the 2 nodes to communicate.
- //const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
- const uint64_t pipes[1] = { 0xCAFECAFEA1LL };
- const int max_payload_size = 32;
- char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char
- // Time
- time_t rawtime;
- struct tm* timeinfo;
- char time_buffer[80];
- void update_time(char* time_buffer) {
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- strftime(time_buffer,80,"%d-%m-%Y %I:%M:%S",timeinfo);
- }
- int main(int argc, char** argv) {
- // Setup and configure rf radio
- radio.begin();
- radio.enableDynamicPayloads();
- radio.setDataRate(RF24_250KBPS);
- radio.setPALevel(RF24_PA_MAX);
- //radio.disableCRC();
- radio.printDetails();
- /***********************************/
- radio.openReadingPipe(1,pipes[0]);
- radio.startListening();
- // forever loop
- while (1)
- {
- // if there is data ready
- if ( radio.available() )
- {
- // Dump the payloads until we've gotten everything
- uint8_t len = 0;
- while (radio.available())
- {
- // Fetch the payload, and see if this was the last one.
- len = radio.getDynamicPayloadSize();
- radio.read( receive_payload, len );
- // Put a zero at the end for easy printing
- receive_payload[len] = 0;
- // Spew it
- update_time(time_buffer);
- printf("%s Got payload size=%i value=%s\n\r",time_buffer,len,receive_payload);
- }
- usleep(100000);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement