benscammell
Well-known member
Hello All,
I have two custom teensy's with an RFM69 connected to them.
SERVER
and CLIENT
Here is the output I get from the SERVER
Here is the output I get from the CLIENT
Why are the messages getting corrupted?
Thank in advance to anyone that helps me out!
Cheers, Ben
I have two custom teensy's with an RFM69 connected to them.
SERVER
Code:
#include <SPI.h>
#include <RH_RF69.h>
// Singleton instance of the radio driver
RH_RF69 rf69(20, 2);
int led = 33;
void setup()
{
Serial.begin(9600);
if (!rf69.init())
Serial.println("init failed");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
// No encryption
if (!rf69.setFrequency(434.0))
Serial.println("setFrequency failed");
rf69.setModemConfig(RH_RF69::GFSK_Rb57_6Fd120);
rf69.setPreambleLength(4);
uint8_t syncwords[] = { 0x2d, 0xd4 };
rf69.setSyncWords(syncwords, sizeof(syncwords));
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf69.setEncryptionKey(key);
pinMode(led, OUTPUT);
}
void loop()
{
if (rf69.available())
{
// Should be a message for us now
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf69.recv(buf, &len))
{
digitalWrite(led, HIGH);
RH_RF69::printBuffer("request: ", buf, len);
Serial.print("got request: ");
Serial.println((char*)buf);
Serial.print("RSSI: ");
Serial.println(rf69.lastRssi(), DEC);
// Send a reply
uint8_t data[] = "And hello back to you";
rf69.send(data, sizeof(data));
rf69.waitPacketSent();
Serial.println("Sent a reply");
}
else
{
Serial.println("recv failed");
}
}
digitalWrite(led, LOW);
}
and CLIENT
Code:
#include <SPI.h>
#include <RH_RF69.h>
// Singleton instance of the radio driver
RH_RF69 rf69(20, 2);
int led = 33;
void setup()
{
Serial.begin(9600);
if (!rf69.init())
Serial.println("init failed");
if (!rf69.setFrequency(434.0))
Serial.println("setFrequency failed");
rf69.setModemConfig(RH_RF69::GFSK_Rb57_6Fd120);
rf69.setPreambleLength(4);
uint8_t syncwords[] = { 0x2d, 0xd4 };
rf69.setSyncWords(syncwords, sizeof(syncwords));
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf69.setEncryptionKey(key);
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH);
Serial.println("Sending to rf69_server");
// Send a message to rf69_server
uint8_t data[] = "Hello World!";
rf69.send(data, sizeof(data));
rf69.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf69.waitAvailableTimeout(500))
{
// Should be a reply message for us now
if (rf69.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is rf69_server running?");
}
digitalWrite(led, LOW);
delay(1000);
}
Here is the output I get from the SERVER
Code:
request:
58 75 7C 7C 7F 30 57 7F 72 7C 74 31 10
got request: Xu||0Wr|t1��
RSSI: -40
Sent a reply
Here is the output I get from the CLIENT
Code:
Sending to rf69_server
got reply: Q~t0xu||0rqs{0t0yu
Why are the messages getting corrupted?
Thank in advance to anyone that helps me out!
Cheers, Ben