I have two 32u4 LoRa radios that I am using to send the state of a switch from the transmitter in order to move a motor on the receiver. I have used strings to act as a kind of checksum to hopefully prevent unwanted noise from activating the motor. So far I have been unable to assign the contents of the receiver buffer to a string in order to compare to the assigned prowords.
I have declared a string that will be used to accept the buffer contents but they are received as hex and then serial print with a char pointer. I have been trying to accomplish this with iterators and Serial functions but it has not been working for me. Any suggestions would be appreciated. Below is my code;
#include <SPI.h>
#include <RH_RF95.h>
/* for feather32u4 */
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 7
// 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 rf95(RFM95_CS, RFM95_INT);
// Blinky on receipt
#define LED 13
//Declaring comparator strings (Open & Shut) and the received Tx string
char strOpen[5] = "Open";
char strShut[5] = "Shut";
char strReceived[5];
void setup()
{
//Identifying pin modes
pinMode(LED, OUTPUT);
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
Serial.begin(9600);
delay(100);
// Manually RESET radio
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
// Initialize Radio
while (!rf95.init()) {
Serial.println("LoRa radio init failed");
while (1);
}
Serial.println("LoRa radio init OK!");
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false);
}
void loop()
{
if (rf95.available())
{
// Identifies size of buffer and assigns var to it
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
RH_RF95::printBuffer("Received: ", buf, len);
Serial.print("Got: ");
Serial.println((char*)buf); // <------ This is where I want to store the received string to compare
delay(10);
//If Tx switch is ON, then indicate claw is opened and send return to Tx
if (strReceived == strOpen)
{
uint8_t data[] = "Motor has been opened";
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent a reply");
digitalWrite(LED, HIGH);
}
//If Tx switch is OFF, then indicate claw is closed and send return to Tx
else if (strReceived == strShut)
{
uint8_t data[] = "The motor has been closed";
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent a reply");
digitalWrite(LED, LOW);
}
// Send a reply
delay(200); // may or may not be needed
}
}
else
{
delay(500);
Serial.println("Receive failed");
}
}