forked and modified initial value for return values and changed timer definition to TIM1 instead of int(1)
This commit is contained in:
67
examples/nrf24/nrf24_client/nrf24_client.pde
Normal file
67
examples/nrf24/nrf24_client/nrf24_client.pde
Normal file
@@ -0,0 +1,67 @@
|
||||
// nrf24_client.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple messageing client
|
||||
// with the RH_NRF24 class. RH_NRF24 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_NRF24 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example nrf24_server.
|
||||
// Tested on Uno with Sparkfun NRF25L01 module
|
||||
// Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module
|
||||
// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RH_NRF24.h>
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_NRF24 nrf24;
|
||||
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
|
||||
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
|
||||
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
if (!nrf24.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
|
||||
if (!nrf24.setChannel(1))
|
||||
Serial.println("setChannel failed");
|
||||
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
|
||||
Serial.println("setRF failed");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Sending to nrf24_server");
|
||||
// Send a message to nrf24_server
|
||||
uint8_t data[] = "Hello World!";
|
||||
nrf24.send(data, sizeof(data));
|
||||
|
||||
nrf24.waitPacketSent();
|
||||
// Now wait for a reply
|
||||
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
if (nrf24.waitAvailableTimeout(500))
|
||||
{
|
||||
// Should be a reply message for us now
|
||||
if (nrf24.recv(buf, &len))
|
||||
{
|
||||
Serial.print("got reply: ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("recv failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is nrf24_server running?");
|
||||
}
|
||||
delay(400);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// nrf24_client.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple encrypted messageing client
|
||||
// with the RH_NRF24 class. RH_NRF24 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_NRF24 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example nrf24_encrypted_server.
|
||||
// Tested on Duemilanove with Sparkfun NRF25L01 module
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RH_NRF24.h>
|
||||
#include <RHEncryptedDriver.h>
|
||||
#include <Speck.h>
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_NRF24 nrf24;
|
||||
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
|
||||
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
|
||||
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
|
||||
|
||||
// You can choose any of several encryption ciphers
|
||||
Speck myCipher; // Instantiate a Speck block ciphering
|
||||
// The RHEncryptedDriver acts as a wrapper for the actual radio driver
|
||||
RHEncryptedDriver driver(nrf24, myCipher);
|
||||
// The key MUST be the same as the one in the server
|
||||
unsigned char encryptkey[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
if (!nrf24.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
|
||||
if (!nrf24.setChannel(1))
|
||||
Serial.println("setChannel failed");
|
||||
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
|
||||
Serial.println("setRF failed");
|
||||
|
||||
// Now set up the encryption key in our cipher
|
||||
myCipher.setKey(encryptkey, sizeof(encryptkey));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Sending to nrf24_encrypted_server");
|
||||
// Send a message to nrf24_server
|
||||
uint8_t data[] = "Hello World!"; // Dont make this too long
|
||||
driver.send(data, sizeof(data));
|
||||
|
||||
driver.waitPacketSent();
|
||||
// Now wait for a reply
|
||||
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
if (driver.waitAvailableTimeout(500))
|
||||
{
|
||||
// Should be a reply message for us now
|
||||
if (driver.recv(buf, &len))
|
||||
{
|
||||
Serial.print("got reply: ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("recv failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is nrf24_encrypted_server running?");
|
||||
}
|
||||
delay(400);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// nrf24_server.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple encrypted messageing server
|
||||
// with the RH_NRF24 class. RH_NRF24 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_NRF24 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example nrf24_encrypted_client
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RH_NRF24.h>
|
||||
#include <RHEncryptedDriver.h>
|
||||
#include <Speck.h>
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_NRF24 nrf24;
|
||||
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
|
||||
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
|
||||
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
|
||||
|
||||
// You can choose any of several encryption ciphers
|
||||
Speck myCipher; // Instantiate a Speck block ciphering
|
||||
// The RHEncryptedDriver acts as a wrapper for the actual radio driver
|
||||
RHEncryptedDriver driver(nrf24, myCipher); // Instantiate the driver with those two
|
||||
// The key MUST be the same as the one in the client
|
||||
unsigned char encryptkey[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
if (!nrf24.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
|
||||
if (!nrf24.setChannel(1))
|
||||
Serial.println("setChannel failed");
|
||||
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
|
||||
Serial.println("setRF failed");
|
||||
|
||||
// Now set up the encryption key in our cipher
|
||||
myCipher.setKey(encryptkey, sizeof(encryptkey));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (driver.available())
|
||||
{
|
||||
// Should be a message for us now
|
||||
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
if (driver.recv(buf, &len))
|
||||
{
|
||||
// RH_NRF24::printBuffer("request: ", buf, len);
|
||||
Serial.print("got request: ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply
|
||||
uint8_t data[] = "And hello back"; // Dont make this too long
|
||||
driver.send(data, sizeof(data));
|
||||
driver.waitPacketSent();
|
||||
Serial.println("Sent a reply");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("recv failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// nrf24_reliable_datagram_client.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, reliable messaging client
|
||||
// with the RHReliableDatagram class, using the RH_NRF24 driver to control a NRF24 radio.
|
||||
// It is designed to work with the other example nrf24_reliable_datagram_server
|
||||
// Tested on Uno with Sparkfun WRL-00691 NRF24L01 module
|
||||
// Tested on Teensy with Sparkfun WRL-00691 NRF24L01 module
|
||||
// Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module
|
||||
// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module
|
||||
|
||||
#include <RHReliableDatagram.h>
|
||||
#include <RH_NRF24.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_NRF24 driver;
|
||||
// RH_NRF24 driver(8, 7); // For RFM73 on Anarduino Mini
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
|
||||
}
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Sending to nrf24_reliable_datagram_server");
|
||||
|
||||
// Send a message to manager_server
|
||||
if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))
|
||||
{
|
||||
// Now wait for a reply from the server
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
|
||||
{
|
||||
Serial.print("got reply from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is nrf24_reliable_datagram_server running?");
|
||||
}
|
||||
}
|
||||
else
|
||||
Serial.println("sendtoWait failed");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// nrf24_reliable_datagram_server.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, reliable messaging server
|
||||
// with the RHReliableDatagram class, using the RH_NRF24 driver to control a NRF24 radio.
|
||||
// It is designed to work with the other example nrf24_reliable_datagram_client
|
||||
// Tested on Uno with Sparkfun WRL-00691 NRF24L01 module
|
||||
// Tested on Teensy with Sparkfun WRL-00691 NRF24L01 module
|
||||
// Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module
|
||||
// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module
|
||||
|
||||
#include <RHReliableDatagram.h>
|
||||
#include <RH_NRF24.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_NRF24 driver;
|
||||
// RH_NRF24 driver(8, 7); // For RFM73 on Anarduino Mini
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHReliableDatagram manager(driver, SERVER_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
|
||||
}
|
||||
|
||||
uint8_t data[] = "And hello back to you";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (manager.available())
|
||||
{
|
||||
// Wait for a message addressed to us from the client
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAck(buf, &len, &from))
|
||||
{
|
||||
Serial.print("got request from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply back to the originator client
|
||||
if (!manager.sendtoWait(data, sizeof(data), from))
|
||||
Serial.println("sendtoWait failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
60
examples/nrf24/nrf24_server/nrf24_server.pde
Normal file
60
examples/nrf24/nrf24_server/nrf24_server.pde
Normal file
@@ -0,0 +1,60 @@
|
||||
// nrf24_server.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple messageing server
|
||||
// with the RH_NRF24 class. RH_NRF24 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_NRF24 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example nrf24_client
|
||||
// Tested on Uno with Sparkfun NRF25L01 module
|
||||
// Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module
|
||||
// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RH_NRF24.h>
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_NRF24 nrf24;
|
||||
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
|
||||
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
|
||||
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
if (!nrf24.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
|
||||
if (!nrf24.setChannel(1))
|
||||
Serial.println("setChannel failed");
|
||||
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
|
||||
Serial.println("setRF failed");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (nrf24.available())
|
||||
{
|
||||
// Should be a message for us now
|
||||
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
if (nrf24.recv(buf, &len))
|
||||
{
|
||||
// NRF24::printBuffer("request: ", buf, len);
|
||||
Serial.print("got request: ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply
|
||||
uint8_t data[] = "And hello back to you";
|
||||
nrf24.send(data, sizeof(data));
|
||||
nrf24.waitPacketSent();
|
||||
Serial.println("Sent a reply");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("recv failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user