The example does show how to send and receive unsigned long values, but I cannot get it working when i send a array of type unsigned long.
The codes are as follows:
Cleint Code:
void setup()
{
Serial.begin(9600);
if (!nrf24.init())
Serial.println("NRF24 init failed");
// Defaults after init are 2.402 GHz (channel 2)
// Now be compatible with Mirf ping_server
if (!nrf24.setChannel(1))
Serial.println("setChannel failed");
if (!nrf24.setThisAddress((uint8_t*)"clie1", 5))
Serial.println("setThisAddress failed");
if (!nrf24.setPayloadSize(sizeof(unsigned long)))
Serial.println("setPayloadSize failed");
if (!nrf24.setRF(NRF24::NRF24DataRate2Mbps, NRF24::NRF24TransmitPower0dBm))
Serial.println("setRF failed");
Serial.println("initialised");
}
// With printing commented and delay removed, this can achieve about 666 round trips per second
void loop()
{
// Serial.println("send");
// Send some data to the server
if (!nrf24.setTransmitAddress((uint8_t*)"serv1", 5))
Serial.println("setTransmitAddress failed");
unsigned long time[2];
time[1] = millis();
delay(2);
time[2] = millis();
if (!nrf24.send((uint8_t*)time, sizeof(time)))
Serial.println("send failed");
if (!nrf24.waitPacketSent())
Serial.println("waitPacketSent failed");
}
Sever Code:
void setup()
{
Serial.begin(9600);
if (!nrf24.init())
Serial.println("NRF24 init failed");
// Defaults after init are 2.402 GHz (channel 2)
// Now be compatible with Mirf ping_client
if (!nrf24.setChannel(1))
Serial.println("setChannel failed");
if (!nrf24.setThisAddress((uint8_t*)"serv1", 5))
Serial.println("setThisAddress failed");
if (!nrf24.setPayloadSize(sizeof(unsigned long)))
Serial.println("setPayloadSize failed");
if (!nrf24.setRF(NRF24::NRF24DataRate2Mbps, NRF24::NRF24TransmitPower0dBm))
Serial.println("setRF failed");
Serial.println("initialised");
}
void loop()
{
// Serial.println("waiting");
nrf24.waitAvailable();
// ping_client sends us an unsigned long containing its timestamp
unsigned long data[2];
uint8_t len;
if (!nrf24.recv((uint8_t*)data, &len))
Serial.println("read failed");
}
The headers are included in my code, I have just not included them here. Any suggestions what is wrong.
Regards