Client side of simple client/server pair using RF22Datagram class
#include <RF22Datagram.h>
#include <RF22.h>
#include <SPI.h>
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
void setup()
{
Serial.begin(9600);
if (!rf22.init())
Serial.println("RF22 init failed");
}
uint8_t buf[RF22_MAX_MESSAGE_LEN];
void loop()
{
while (1)
{
Serial.println("Sending to rf22_datagram_server");
uint8_t data[] = "Hello World!";
rf22.sendto(data, sizeof(data), SERVER_ADDRESS);
rf22.waitPacketSent();
if (rf22.waitAvailableTimeout(500))
{
uint8_t len = sizeof(buf);
uint8_t from;
uint8_t to;
if (rf22.recvfrom(buf, &len, &from, &to))
{
Serial.print("got reply from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is rf22_datagram_server running?");
}
}
}