Sending array of type unsigned long

594 views
Skip to first unread message

Shiu Kumar

unread,
Jan 13, 2013, 8:02:03 AM1/13/13
to nrf24-...@googlegroups.com
Hello,

I want to send an array that is of type unsigned long. Any hints on how this can be done.

I managed to send arrays of type uint8_t via a single packet but not sure how to go about doing the same for the above.

Regards

Mike McCauley

unread,
Jan 13, 2013, 5:39:08 PM1/13/13
to nrf24-...@googlegroups.com, Shiu Kumar
Hello,


There is an example of how to do this in the examples:

nrf24_ping_client.pde
nrf24_ping_server.pde

Cheers.
--
Mike McCauley mi...@open.com.au
Open System Consultants Pty. Ltd
9 Bulbul Place Currumbin Waters QLD 4223 Australia http://www.open.com.au
Phone +61 7 5598-7474 Fax +61 7 5598-7070

Radiator: the most portable, flexible and configurable RADIUS server
anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald,
Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS,
TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP,
DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, NetWare etc.

Shiu Kumar

unread,
Jan 13, 2013, 8:43:17 PM1/13/13
to nrf24-...@googlegroups.com, Shiu Kumar
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

Mike McCauley

unread,
Jan 13, 2013, 9:12:26 PM1/13/13
to nrf24-...@googlegroups.com
Hello,

In the receiver, you have to initialise the value of len to be the available
space:

unsigned long data[2];
uint8_t len = sizeof(data);
if (!nrf24.recv((uint8_t*)data, &len))
Serial.println("read failed");

Shiu Kumar

unread,
Jan 13, 2013, 10:02:39 PM1/13/13
to nrf24-...@googlegroups.com
Hello,

Thanks, I will also try that. But I managed to get it working by setting a fixed payload.

Cheers
Reply all
Reply to author
Forward
0 new messages