I am using the radio head library with my Arduinos. both the client and the server codes upload successfully however the server code doesn't print anything in the serial monitor. the client code works perfectly on both my Arduinos. Anyone know why the server won't work?
Do you think it might be a good idea to post your code, both the Tx and Rx sketches ?
Use code tags when you do
Here is the code for the server that isnt working.
#include <SPI.h>
#include <RH_NRF24.h>
// Singleton instance of the radio driver
RH_NRF24 nrf24;
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
void setup()
{
Serial.begin(9600);
while (!Serial)
; // wait for serial port to connect. Needed for Leonardo only
if (!nrf24.init())
Serial.println("init failed");
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
if (!nrf24.setChannel(1))
Serial.println("setChannel failed");
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
Serial.println("setRF failed");
}
void loop()
{
if (nrf24.available())
{
// Should be a message for us now
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (nrf24.recv(buf, &len))
{
// NRF24::printBuffer("request: ", buf, len);
Serial.print("got request: ");
Serial.println((char*)buf);
// Send a reply
uint8_t data[] = "And hello back to you";
nrf24.send(data, sizeof(data));
nrf24.waitPacketSent();
Serial.println("Sent a reply");
}
else
{
Serial.println("recv failed");
}
}
Here is the code for the client, which does work
#include <SPI.h>
#include <RH_NRF24.h>
// Singleton instance of the radio driver
RH_NRF24 nrf24;
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
void setup()
{
Serial.begin(9600);
while (!Serial)
; // wait for serial port to connect. Needed for Leonardo only
if (!nrf24.init())
Serial.println("init failed");
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
if (!nrf24.setChannel(1))
Serial.println("setChannel failed");
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
Serial.println("setRF failed");
}
void loop()
{
Serial.println("Sending to nrf24_server");
// Send a message to nrf24_server
uint8_t data[] = "Hello World!";
nrf24.send(data, sizeof(data));
nrf24.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (nrf24.waitAvailableTimeout(500))
{
// Should be a reply message for us now
if (nrf24.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is nrf24_server running?");
}
delay(400);
}
Both should be wired the same and I assumed using the library it should be simple but I am not sure why the server isn't working
How do you know ?
Have you another NRF24L01 device which confirms the function of the clients ?
to narrwo down the problem more information is needed.
What are the pins you have the nrf24 connected to?
What does the serial monitor of the client show ?
You are calling the function
nrf24.waitPacketSent();
But your code does nothing to analyse the result.
If you look into the RH_NRF24.cpp-file the function waitPacketSent()
gives back true or false
true in case sending was successfull
false in case of a maximum of retries to send failed
So what makes you so sure that sending was successfull.
The implemented messages are just about initialisation but not about sending
best regards Stefan
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.