Closed saeidbina closed 6 months ago
This is a coding issue, not an issue with the library.
The library will handle a maximum of 32 bytes per payload. Either use multiple payloads, make your payloads smaller, or use RF24Network which supports large payload sizes via fragmentation/reassembly.
This is not a RF24 lib problem, rather it is a combination of misusing c-str data and misunderstanding the hardware limitations of the nRF24L01 radio.
char humidityStr[6];
Here, you allocate 6 bytes for string to represent a percentage (usually ranging [0, 100]) with 2 decimal places. So, max is 100.00
% (6 characters) and min is 0.00
%. At this point, it is important to note that the hunidityStr
does not have enough capacity for the c-str's required null terminating character ('\0'
) when the float value is at max (100.00
).
Using RF24, payloads can only be 32 bytes maximum.
# this is 32 characters (32 bytes of UTF-8 encoded data)
2024/05/07 15:02:07 T:25.90°C H:
# this is 38 characters (38 bytes of UTF-8 encoded data)
2024/05/07 15:02:07 T:25.90°C H:48.90%
Increasing the buffer beyond 32 bytes is pointless because the nRF24L01 will only handle payloads with a maximum of 32-bytes. BTW, increasing the size of a buffer of uninitialized bytes does not guarantee that the c-str data will end in a '\0'
because not all compilers use implicit initialization values (that's up the Arduino core you are using for the Uno R4).
if (!radio.begin())
to detect bad radios or incorrect wiring.sprintf()
instead of dtostrf()
can tell you how many bytes were stored to the c-str. The byte count in turn can be used as the payload length...thank you much for your reply. Could you please help me? the final project will have 12 sensors in a MEGA board that will be sent to UNO using nrf24. I am begginer.
Sorry, but no. We try to focus on actual library problems here. You could try your luck with Arduino forums.
project will have 12 sensors in a MEGA board that will be sent to UNO using nrf24
Sounds like a good scenario for using RF24Network. It allows for payloads greater than 32 bytes and the network can have hundreds of nodes instead of just 7 nodes. The only obstacle for beginners is understanding the network topology
Hello everyone. I am using Arduin mega (with RTC and DH22) and I wanna receive this values in receiver (UNO R4). The main problem is that in the receiver serial monitor does show all characters. When I increase the size of the payload or text in both, does not make change. Here are my code: The only way to include humidity and the rest of the characters is to delete some of the previous characters for example deleting Data or time or some of the empty characters in between.
My Reciever:
Serial monitor: Sender: 2024/05/07 15:02:07 T:25.90°C H:48.90%
reciever: 2024/05/07 15:02:12 T:25.90°C H