NRF24.send() function.

Hello,

I am trying to send data across 2 NRF24 which works fine, But the send() function of the nrf24 library expects something like send(uint8_t array, sizeof(uint8_t array)); But how would i send a string across? My current code is:

uint8_t data[] = "test";
nrf24.send(data, sizeof(data));

I tried something like:

String Id = "ABCD1234ABCD";
 char buffer[20];
 uint8_t data[] = Id.toCharArray(buffer, 20);
 nrf24.send(data, sizeof(Id));

but when i do that i get the following error:

error: array must be initialized with a brace-enclosed initializer

exit status 1 initializer fails to determine size of 'data'

This Simple nRF24L01+ Tutorial should illustrate how to do it.

The nRF24 sends a packet of bytes. It does not matter to it what they represent. It could be an int (2 bytes) or a char array up to 32 bytes long.

...R

Thank you for your reply! I will take a look at the tutorial.

Regards,

Robin2:
This Simple nRF24L01+ Tutorial should illustrate how to do it.

The nRF24 sends a packet of bytes. It does not matter to it what they represent. It could be an int (2 bytes) or a char array up to 32 bytes long.

…R

Hi Robin,

I picked this up again and after looking at your tutorial i still dont really know what this error means:

 no known conversion for argument 1 from 'String' to 'const uint8_t* {aka const unsigned char*}'
exit status 1
no matching function for call to 'RH_NRF24::send(String&, unsigned int)'

when i try to do :

  String test = "Hallo";
  nrf24.send(test, sizeof(test));

String is not string and neither use sizeof...

Use strlen(s) for strings for length. Use s.length() for String. For string use strlen(s)

  char * cstring = test.c_str () ;
  nrf24.send(cstring, strlen (cstring));

Fixed

MarkT: String is not string and neither use sizeof...

Use strlen(s) for strings for length. Use s.length() for String. For string use strlen(s)

  char * cstring = test.c_str () ;
  nrf24.send(cstring, strlen (cstring));

Thanks mate got it!

B19920: Hi Robin,

I picked this up again and after looking at your tutorial i still dont really know what this error means:

The examples in my Tutorial do not use the String class or "radio,send()"

When using radio.write() with the TMRh20 RF24 library the second parameter is the number of BYTES to be sent.

...R