Add Uno -> RFM95 examples from Brian Norman
This commit is contained in:
parent
d822c410c0
commit
2d13729aff
2 changed files with 169 additions and 0 deletions
83
Examples/UNO_rf95_client/UNO_rf95_client.ino
Normal file
83
Examples/UNO_rf95_client/UNO_rf95_client.ino
Normal file
|
@ -0,0 +1,83 @@
|
|||
// rf95_client.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple messageing client
|
||||
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_RF95 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example rf95_server
|
||||
// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with
|
||||
// the RFM95W, Adafruit Feather M0 with RFM95
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(10, 2);
|
||||
|
||||
int led = 7; // do not use SPI pins
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(led, OUTPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
while (!Serial) ; // Wait for serial port to be available
|
||||
|
||||
Serial.println("Client starting");
|
||||
|
||||
if (!rf95.init())
|
||||
{
|
||||
Serial.println("rf95().init failed");
|
||||
while (true) ;
|
||||
}
|
||||
Serial.println("rf95.init() ok");
|
||||
|
||||
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
|
||||
|
||||
rf95.setFrequency(868.0);
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(led, HIGH);
|
||||
|
||||
Serial.println("Sending to rf95_server");
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
|
||||
rf95.send(data, sizeof(data));
|
||||
rf95.waitPacketSent();
|
||||
|
||||
Serial.println("Packet sent");
|
||||
|
||||
// Now wait for a reply
|
||||
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
if (rf95.waitAvailableTimeout(3000))
|
||||
{
|
||||
// Should be a reply message for us now
|
||||
if (rf95.recv(buf, &len))
|
||||
{
|
||||
Serial.print("got reply: ");
|
||||
Serial.println((char*)buf);
|
||||
//Serial.print("RSSI: ");
|
||||
//Serial.println(rf95.lastRssi(), DEC);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("rf95.recv() from server failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Timeout. No reply, is rf95_server running?");
|
||||
}
|
||||
|
||||
digitalWrite(led, LOW);
|
||||
delay(400);
|
||||
}
|
||||
|
||||
|
86
Examples/UNO_rf95_server/UNO_rf95_server.ino
Normal file
86
Examples/UNO_rf95_server/UNO_rf95_server.ino
Normal file
|
@ -0,0 +1,86 @@
|
|||
// rf95_server.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple messageing server
|
||||
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_RF95 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example rf95_client
|
||||
// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with
|
||||
// the RFM95W, Adafruit Feather M0 with RFM95
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(10,2);
|
||||
|
||||
int led = 13; // do not use SPI pins
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Rocket Scream Mini Ultra Pro with the RFM95W only:
|
||||
// Ensure serial flash is not interfering with radio communication on SPI bus
|
||||
// pinMode(4, OUTPUT);
|
||||
// digitalWrite(4, HIGH);
|
||||
|
||||
pinMode(led, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
while (!Serial) ; // Wait for serial port to be available
|
||||
Serial.println("Server starting");
|
||||
|
||||
if (!rf95.init())
|
||||
{
|
||||
Serial.println("init failed");
|
||||
while(true) ;
|
||||
}
|
||||
|
||||
Serial.println("rf95.init() ok");
|
||||
|
||||
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
|
||||
|
||||
|
||||
rf95.setFrequency(868.0);
|
||||
//rf95.setTxPower(10, true);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if (rf95.available())
|
||||
{
|
||||
Serial.print("rf95.available() ok ");
|
||||
|
||||
// Should be a message for us now
|
||||
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
if (rf95.recv(buf, &len))
|
||||
{
|
||||
|
||||
//RH_RF95::printBuffer("request: ", buf, len);
|
||||
|
||||
Serial.print("got request: ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
//Serial.print("RSSI: ");
|
||||
//Serial.println(rf95.lastRssi(), DEC);
|
||||
|
||||
// Send a reply
|
||||
digitalWrite(led, HIGH);
|
||||
Serial.println("Sending a reply");
|
||||
|
||||
uint8_t data[] = "And hello back to you";
|
||||
rf95.send(data, sizeof(data));
|
||||
rf95.waitPacketSent();
|
||||
|
||||
Serial.println("Reply sent");
|
||||
digitalWrite(led, LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("recv failed - empty buffer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue