Hello all,
I'm attempting my first LoRa radio client/server and, while the basic Adafruit radio example works fine (it's not a server, just sends a message), the RadioHead client example I modified does not. I've not included a wiring diagram with this post because the radio initializes just fine and the adafruit example works as well. However, I keep getting the "sendtoWait failed" error from the last else statement with this code.
I'm quite new to coding, any help would be appreciated.
Code:
#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
#define RFM95_CS 4
#define RFM95_RST 2
#define RFM95_INT 3
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 915.0
// Singleton instance of the radio driver
RH_RF95 driver(RFM95_CS, RFM95_INT);
// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
void setup() {
Serial.begin(9600);
while (!Serial)
; // Wait for serial port to be available
if (!manager.init())
Serial.println("init failed");
if (manager.init())
Serial.println("init succeeded");
Serial.print("Set Freq to: ");
Serial.println(RF95_FREQ);
driver.setTxPower(23, false);
}
uint8_t data[] = "Hello World!";
// Dont put this on the stack:
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
void loop() {
delay(1000);
Serial.println("Sending to rf95_reliable_datagram_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 rf95_reliable_datagram_server running?");
}
} else
Serial.println("sendtoWait failed");
delay(500);
}