first commit
This commit is contained in:
56
examples/rf22/rf22_client/rf22_client.ino
Normal file
56
examples/rf22/rf22_client/rf22_client.ino
Normal file
@@ -0,0 +1,56 @@
|
||||
// rf22_client.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple messageing client
|
||||
// with the RH_RF22 class. RH_RF22 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_RF22 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example rf22_server
|
||||
// Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shield
|
||||
// Tested on Flymaple with sparkfun RFM22 wireless shield
|
||||
// Tested on ChiKit Uno32 with sparkfun RFM22 wireless shield
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RH_RF22.h>
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 rf22;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!rf22.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Sending to rf22_server");
|
||||
// Send a message to rf22_server
|
||||
uint8_t data[] = "Hello World!";
|
||||
rf22.send(data, sizeof(data));
|
||||
|
||||
rf22.waitPacketSent();
|
||||
// Now wait for a reply
|
||||
uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
if (rf22.waitAvailableTimeout(500))
|
||||
{
|
||||
// Should be a reply message for us now
|
||||
if (rf22.recv(buf, &len))
|
||||
{
|
||||
Serial.print("got reply: ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("recv failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is rf22_server running?");
|
||||
}
|
||||
delay(400);
|
||||
}
|
31
examples/rf22/rf22_cw/rf22_cw.ino
Normal file
31
examples/rf22/rf22_cw/rf22_cw.ino
Normal file
@@ -0,0 +1,31 @@
|
||||
// rf22_cw.ino
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to emit a continuous carrier wave (CW)
|
||||
// for test purposes
|
||||
// Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shieldg
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RH_RF22.h>
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 rf22;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!rf22.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
|
||||
// CW mode:
|
||||
rf22.setModemConfig(RH_RF22::UnmodulatedCarrier);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
rf22.setModeTx();
|
||||
delay(1000);
|
||||
rf22.setModeIdle();
|
||||
delay(1000);
|
||||
}
|
68
examples/rf22/rf22_mesh_client/rf22_mesh_client.ino
Normal file
68
examples/rf22/rf22_mesh_client/rf22_mesh_client.ino
Normal file
@@ -0,0 +1,68 @@
|
||||
// rf22_mesh_client.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging client
|
||||
// with the RHMesh class.
|
||||
// It is designed to work with the other examples rf22_mesh_server*
|
||||
// Hint: you can simulate other network topologies by setting the
|
||||
// RH_TEST_NETWORK define in RHRouter.h
|
||||
|
||||
// Mesh has much greater memory requirements, and you may need to limit the
|
||||
// max message length to prevent wierd crashes
|
||||
#define RH_MESH_MAX_MESSAGE_LEN 50
|
||||
|
||||
#include <RHMesh.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 driver;
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHMesh manager(driver, CLIENT_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
}
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Sending to manager_mesh_server3");
|
||||
|
||||
// Send a message to a rf22_mesh_server
|
||||
// A route to the destination will be automatically discovered.
|
||||
if (manager.sendtoWait(data, sizeof(data), SERVER3_ADDRESS) == RH_ROUTER_ERROR_NONE)
|
||||
{
|
||||
// It has been reliably delivered to the next node.
|
||||
// Now wait for a reply from the ultimate server
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAckTimeout(buf, &len, 3000, &from))
|
||||
{
|
||||
Serial.print("got reply from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is rf22_mesh_server1, rf22_mesh_server2 and rf22_mesh_server3 running?");
|
||||
}
|
||||
}
|
||||
else
|
||||
Serial.println("sendtoWait failed. Are the intermediate mesh servers running?");
|
||||
}
|
||||
|
56
examples/rf22/rf22_mesh_server1/rf22_mesh_server1.ino
Normal file
56
examples/rf22/rf22_mesh_server1/rf22_mesh_server1.ino
Normal file
@@ -0,0 +1,56 @@
|
||||
// rf22_mesh_server1.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHMesh class.
|
||||
// It is designed to work with the other examples rf22_mesh_*
|
||||
// Hint: you can simulate other network topologies by setting the
|
||||
// RH_TEST_NETWORK define in RHRouter.h
|
||||
|
||||
// Mesh has much greater memory requirements, and you may need to limit the
|
||||
// max message length to prevent wierd crashes
|
||||
#define RH_MESH_MAX_MESSAGE_LEN 50
|
||||
|
||||
#include <RHMesh.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 driver;
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHMesh manager(driver, SERVER1_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("RF22 init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
}
|
||||
|
||||
uint8_t data[] = "And hello back to you from server1";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN];
|
||||
void loop()
|
||||
{
|
||||
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) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
}
|
||||
}
|
||||
|
56
examples/rf22/rf22_mesh_server2/rf22_mesh_server2.ino
Normal file
56
examples/rf22/rf22_mesh_server2/rf22_mesh_server2.ino
Normal file
@@ -0,0 +1,56 @@
|
||||
// rf22_mesh_server1.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHMesh class.
|
||||
// It is designed to work with the other examples rf22_mesh_*
|
||||
// Hint: you can simulate other network topologies by setting the
|
||||
// RH_TEST_NETWORK define in RHRouter.h
|
||||
|
||||
// Mesh has much greater memory requirements, and you may need to limit the
|
||||
// max message length to prevent wierd crashes
|
||||
#define RH_MESH_MAX_MESSAGE_LEN 50
|
||||
|
||||
#include <RHMesh.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 driver;
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHMesh manager(driver, SERVER2_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("RF22 init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
}
|
||||
|
||||
uint8_t data[] = "And hello back to you from server2";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN];
|
||||
void loop()
|
||||
{
|
||||
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) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
}
|
||||
}
|
||||
|
56
examples/rf22/rf22_mesh_server3/rf22_mesh_server3.ino
Normal file
56
examples/rf22/rf22_mesh_server3/rf22_mesh_server3.ino
Normal file
@@ -0,0 +1,56 @@
|
||||
// rf22_mesh_server3.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHMesh class.
|
||||
// It is designed to work with the other examples rf22_mesh_*
|
||||
// Hint: you can simulate other network topologies by setting the
|
||||
// RH_TEST_NETWORK define in RHRouter.h
|
||||
|
||||
// Mesh has much greater memory requirements, and you may need to limit the
|
||||
// max message length to prevent wierd crashes
|
||||
#define RH_MESH_MAX_MESSAGE_LEN 50
|
||||
|
||||
#include <RHMesh.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 driver;
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHMesh manager(driver, SERVER3_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("RF22 init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
}
|
||||
|
||||
uint8_t data[] = "And hello back to you from server3";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN];
|
||||
void loop()
|
||||
{
|
||||
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) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,61 @@
|
||||
// rf22_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_RF22 driver to control a RF22 radio.
|
||||
// It is designed to work with the other example rf22_reliable_datagram_server
|
||||
// Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shield
|
||||
// Tested on Flymaple with sparkfun RFM22 wireless shield
|
||||
// Tested on ChiKit Uno32 with sparkfun RFM22 wireless shield
|
||||
|
||||
#include <RHReliableDatagram.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 driver;
|
||||
//RH_RF22 driver(5, 4); // ESP8266
|
||||
|
||||
// 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 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
}
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Sending to rf22_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 rf22_reliable_datagram_server running?");
|
||||
}
|
||||
}
|
||||
else
|
||||
Serial.println("sendtoWait failed");
|
||||
delay(500);
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
// rf22_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_RF22 driver to control a RF22 radio.
|
||||
// It is designed to work with the other example rf22_reliable_datagram_client
|
||||
// Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shield
|
||||
// Tested on Flymaple with sparkfun RFM22 wireless shield
|
||||
// Tested on ChiKit Uno32 with sparkfun RFM22 wireless shield
|
||||
|
||||
#include <RHReliableDatagram.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 driver;
|
||||
//RH_RF22 driver(5, 4); // ESP8266
|
||||
|
||||
// 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 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
}
|
||||
|
||||
uint8_t data[] = "And hello back to you";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_RF22_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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
72
examples/rf22/rf22_router_client/rf22_router_client.ino
Normal file
72
examples/rf22/rf22_router_client/rf22_router_client.ino
Normal file
@@ -0,0 +1,72 @@
|
||||
// rf22_router_client.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging client
|
||||
// with the RHRouter class.
|
||||
// It is designed to work with the other examples rf22_router_server*
|
||||
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
// messages are routed via intermediate nodes to their destination
|
||||
// node. All nodes can act as routers
|
||||
// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 driver;
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(driver, CLIENT_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
|
||||
// Manually define the routes for this network
|
||||
manager.addRouteTo(SERVER1_ADDRESS, SERVER1_ADDRESS);
|
||||
manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);
|
||||
manager.addRouteTo(SERVER3_ADDRESS, SERVER3_ADDRESS);
|
||||
}
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Sending to rf22_router_server3");
|
||||
|
||||
// Send a message to a rf22_router_server
|
||||
// It will be routed by the intermediate
|
||||
// nodes to the destination node, accorinding to the
|
||||
// routing tables in each node
|
||||
if (manager.sendtoWait(data, sizeof(data), SERVER3_ADDRESS) == RH_ROUTER_ERROR_NONE)
|
||||
{
|
||||
// It has been reliably delivered to the next node.
|
||||
// Now wait for a reply from the ultimate server
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAckTimeout(buf, &len, 3000, &from))
|
||||
{
|
||||
Serial.print("got reply from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is rf22_router_server1, rf22_router_server2 and rf22_router_server3 running?");
|
||||
}
|
||||
}
|
||||
else
|
||||
Serial.println("sendtoWait failed. Are the intermediate router servers running?");
|
||||
}
|
||||
|
59
examples/rf22/rf22_router_server1/rf22_router_server1.ino
Normal file
59
examples/rf22/rf22_router_server1/rf22_router_server1.ino
Normal file
@@ -0,0 +1,59 @@
|
||||
// rf22_router_server1.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHRouter class.
|
||||
// It is designed to work with the other example rf22_router_client
|
||||
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
// messages are routed via intermediate nodes to their destination
|
||||
// node. All nodes can act as routers
|
||||
// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
// Singleton instance of the radio
|
||||
RH_RF22 driver;
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(driver, SERVER1_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
|
||||
// Manually define the routes for this network
|
||||
manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);
|
||||
manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);
|
||||
manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);
|
||||
}
|
||||
|
||||
uint8_t data[] = "And hello back to you from server1";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
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) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
}
|
||||
}
|
||||
|
59
examples/rf22/rf22_router_server2/rf22_router_server2.ino
Normal file
59
examples/rf22/rf22_router_server2/rf22_router_server2.ino
Normal file
@@ -0,0 +1,59 @@
|
||||
// rf22_router_server2.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHRouter class.
|
||||
// It is designed to work with the other example rf22_router_client
|
||||
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
// messages are routed via intermediate nodes to their destination
|
||||
// node. All nodes can act as routers
|
||||
// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
// Singleton instance of the radio
|
||||
RH_RF22 driver;
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(driver, SERVER2_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
|
||||
// Manually define the routes for this network
|
||||
manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);
|
||||
manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);
|
||||
manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);
|
||||
}
|
||||
|
||||
uint8_t data[] = "And hello back to you from server2";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
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) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
}
|
||||
}
|
||||
|
59
examples/rf22/rf22_router_server3/rf22_router_server3.ino
Normal file
59
examples/rf22/rf22_router_server3/rf22_router_server3.ino
Normal file
@@ -0,0 +1,59 @@
|
||||
// rf22_router_server3.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHRouter class.
|
||||
// It is designed to work with the other example rf22_router_client
|
||||
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF22.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
// messages are routed via intermediate nodes to their destination
|
||||
// node. All nodes can act as routers
|
||||
// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
// Singleton instance of the radio
|
||||
RH_RF22 driver;
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(driver, SERVER3_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
|
||||
// Manually define the routes for this network
|
||||
manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);
|
||||
manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);
|
||||
manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);
|
||||
}
|
||||
|
||||
uint8_t data[] = "And hello back to you from server3";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
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) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
}
|
||||
}
|
||||
|
102
examples/rf22/rf22_router_test/rf22_router_test.ino
Normal file
102
examples/rf22/rf22_router_test/rf22_router_test.ino
Normal file
@@ -0,0 +1,102 @@
|
||||
// rf22_router_test.pde
|
||||
// -*- mode: C++ -*-
|
||||
//
|
||||
// Test code used during library development, showing how
|
||||
// to do various things, and how to call various functions
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF22.h>
|
||||
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define ROUTER_ADDRESS 2
|
||||
#define SERVER_ADDRESS 3
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 driver;
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(driver, CLIENT_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("RF22 init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
}
|
||||
|
||||
void test_routes()
|
||||
{
|
||||
manager.clearRoutingTable();
|
||||
// manager.printRoutingTable();
|
||||
manager.addRouteTo(1, 101);
|
||||
manager.addRouteTo(2, 102);
|
||||
manager.addRouteTo(3, 103);
|
||||
RHRouter::RoutingTableEntry* e;
|
||||
e = manager.getRouteTo(0);
|
||||
if (e) // Should fail
|
||||
Serial.println("getRouteTo 0 failed");
|
||||
|
||||
e = manager.getRouteTo(1);
|
||||
if (!e)
|
||||
Serial.println("getRouteTo 1 failed");
|
||||
if (e->dest != 1)
|
||||
Serial.println("getRouteTo 2 failed");
|
||||
if (e->next_hop != 101)
|
||||
Serial.println("getRouteTo 3 failed");
|
||||
if (e->state != RHRouter::Valid)
|
||||
Serial.println("getRouteTo 4 failed");
|
||||
|
||||
e = manager.getRouteTo(2);
|
||||
if (!e)
|
||||
Serial.println("getRouteTo 5 failed");
|
||||
if (e->dest != 2)
|
||||
Serial.println("getRouteTo 6 failed");
|
||||
if (e->next_hop != 102)
|
||||
Serial.println("getRouteTo 7 failed");
|
||||
if (e->state != RHRouter::Valid)
|
||||
Serial.println("getRouteTo 8 failed");
|
||||
|
||||
if (!manager.deleteRouteTo(1))
|
||||
Serial.println("deleteRouteTo 1 failed");
|
||||
// Route to 1 should now be gone
|
||||
e = manager.getRouteTo(1);
|
||||
if (e)
|
||||
Serial.println("deleteRouteTo 2 failed");
|
||||
|
||||
Serial.println("-------------------");
|
||||
|
||||
// manager.printRoutingTable();
|
||||
delay(500);
|
||||
|
||||
}
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
//uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];
|
||||
|
||||
void test_tx()
|
||||
{
|
||||
manager.addRouteTo(SERVER_ADDRESS, ROUTER_ADDRESS);
|
||||
uint8_t errorcode;
|
||||
errorcode = manager.sendtoWait(data, sizeof(data), 100); // Should fail with no route
|
||||
if (errorcode != RH_ROUTER_ERROR_NO_ROUTE)
|
||||
Serial.println("sendtoWait 1 failed");
|
||||
errorcode = manager.sendtoWait(data, 255, 10); // Should fail too big
|
||||
if (errorcode != RH_ROUTER_ERROR_INVALID_LENGTH)
|
||||
Serial.println("sendtoWait 2 failed");
|
||||
errorcode = manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS); // Should fail after timeouts to 110
|
||||
if (errorcode != RH_ROUTER_ERROR_UNABLE_TO_DELIVER)
|
||||
Serial.println("sendtoWait 3 failed");
|
||||
Serial.println("-------------------");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// test_routes();
|
||||
test_tx();
|
||||
}
|
||||
|
||||
|
53
examples/rf22/rf22_server/rf22_server.ino
Normal file
53
examples/rf22/rf22_server/rf22_server.ino
Normal file
@@ -0,0 +1,53 @@
|
||||
// rf22_server.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple messageing server
|
||||
// with the RH_RF22 class. RH_RF22 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_RF22 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example rf22_client
|
||||
// Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shield
|
||||
// Tested on Flymaple with sparkfun RFM22 wireless shield
|
||||
// Tested on ChiKit Uno32 with sparkfun RFM22 wireless shield
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RH_RF22.h>
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF22 rf22;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!rf22.init())
|
||||
Serial.println("init failed");
|
||||
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (rf22.available())
|
||||
{
|
||||
// Should be a message for us now
|
||||
uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
if (rf22.recv(buf, &len))
|
||||
{
|
||||
// RF22::printBuffer("request: ", buf, len);
|
||||
Serial.print("got request: ");
|
||||
Serial.println((char*)buf);
|
||||
// Serial.print("RSSI: ");
|
||||
// Serial.println(rf22.lastRssi(), DEC);
|
||||
|
||||
// Send a reply
|
||||
uint8_t data[] = "And hello back to you";
|
||||
rf22.send(data, sizeof(data));
|
||||
rf22.waitPacketSent();
|
||||
Serial.println("Sent a reply");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("recv failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user