I am Neal, a customer for Adafruit.
I have this code that is supposed to connect to "Clients" or other RFM69 Radios automatically.
One RFM69 Radio is the Server.
And any other RFM69 Radio are the Clients that Receive from the Server.
Right now the Server RFM69 Radio is Sending the "Hi IMC 4"
But I Want the Client RFM69 Radio to Receive "Hi IMC 4" back.
The Problem is that the Client RFM69 Radio is Not Receiving "Hi IMC 4" back.
Can you tell me how to fix this problem?
I Have my Code Separated in Tabs.
Here is the Main Code Tabs for the Server Code for this project:
First Important Code Tab for the Server:
Code: Select all
#include "Radio_TX_Setup.h"
#include "Radio_TX_Loop.h"
#include "Radio_RX_Setup.h"
#include "Radio_RX_Loop.h"
#include "Sensor_Monitor_Setup.h"
#include "Sensor_Monitor_Loop.h"
// The amount of time the game runs for:
int gameTime = 300000; // 5 min = 300000 milliseconds
const int MAX_CLIENTS = 10;
int clients[MAX_CLIENTS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
void setup()
{
Radio_RX_Setup();
Radio_TX_Setup();
}
void loop()
{
//Sensor_Monitor_Loop();
Radio_RX_Loop();
// if (millis=30000){
// sendMessage("Game is Done");
}
2nd Important Code Tab for Server:
Code: Select all
extern const int MAX_CLIENTS;
extern int clients[];
void Radio_RX_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))
{
if (!len) return;
buf[len] = 0;
// Serial.println(buf[0]);
// Serial.println(buf[1]);
// Serial.println(buf[2]);
// Serial.print("Received [");
// Serial.print(len);
// Serial.print("]: ");
// Serial.println((char*)buf );
// Serial.print("RSSI: ");
// Serial.println(rf69.lastRssi(), DEC);
// Serial.println(buf[0]);
// Serial.println(buf[1]);
// Serial.println(buf[2]);
// if(buf[0] == 73) // 'I' Initial
// if(buf[1] == 77) // 'M' Message
// if(buf[2] == 67) // 'C' Client
// {
// Serial.print("Received [");
// Serial.print(len);
// Serial.print("]: ");
// Serial.println((char*)buf );
// //Serial.print("RSSI: ");
// //Serial.println(rf69.lastRssi(), DEC);
//
// //Loop for buf comparasion
//
// //if buf is the same, then don't include it
//
//// if (clients[i-] == i+){//if added i equals same as past one
//// i++; // skip over it
//// }
//
//
//
// // Add the client to the array of clients:
// for(int i = 0; i < MAX_CLIENTS; i++)
// {
// //char results[3][1];
// //results[0] = { "H", "i", " " }
// char results[4] = { 'H', 'i', ' ', ' ' };
//
// // Check if the client is already in the list:
// if (clients[i] == buf[4])
// {
// //strcpy(results[0], "Hi ");
// //strcpy(results[1], buf[4]);
// char test;
// itoa(buf[4], test, 10);
// results[3] = test;
// sendMessage(results);
// break;
// }
// else
// if(clients[i] == -1)
// {
// clients[i] = buf[4];
// delay(200);
// sendMessage("Hi");
// break;
// }
// }
if(buf[0] == 73) // 'I' Initial
if(buf[1] == 77) // 'M' Message
if(buf[2] == 67) // 'C' Client
{
Serial.print("Received [");
Serial.print(len);
Serial.print("]: ");
Serial.println((char*)buf );
// Add the client to the array of clients:
for(int i = 0; i < MAX_CLIENTS; i++)
{
char results[4] = { 'H', 'i', ' ', ' ' };
// Check if the client is already in the list:
if (clients[i] == buf[4])
{
// Client is IN the list:
sendMessage("Client already registered...");
break;
}
else
{
// Client is NOT IN the list. So, get the first blank spot in the array:
if(clients[i] == -1)
{
clients[i] = buf[4];
//delay(200);
//strcpy(results[0], "Hi ");
//strcpy(results[1], buf[4]);
results[3] = buf[4];
//sendMessage("Hi");
sendMessage(results);
break;
}
}
}
// Loop through the clients and print them out:
for(int i = 0; i < MAX_CLIENTS; i++)
Serial.print(clients[i]);
Serial.println("\n");
}
// buf[4] will be the client ID
//Serial.println(buf[4]);
//Serial.println(clients[0]);
} else {
Serial.println("Receive failed");
}
}
}
Code: Select all
#include "Radio_TX_Setup.h"
#include "Radio_TX_Loop.h"
#include "Radio_RX_Setup.h"
#include "Radio_RX_Loop.h"
#include "Sensor_Monitor_Setup.h"
#include "Sensor_Monitor_Loop.h"
void setup()
{
Radio_RX_Setup();
Radio_TX_Setup();
//Sensor_Monitor_Setup();
//sendMessage("IMC: Client Servo Connected");
sendMessage("IMC:4");
delay(10);
}
void loop()
{
//Sensor_Monitor_Loop();
Radio_RX_Loop();
}
It is just Loop and the Setup of the norma TXRX Radio RFM69 Example Code.
But I have them attached to the Next Posts.
I will have the Server Code attached to the next post.
I will have the Client Code attached to the Next Code after that.