LowPowerLab/RFM69

radio.DATALEN always 0

Closed this issue · 9 comments

jLynx commented

Hi, I am having an issue where I am already getting 0 returned from radio.DATALEN

This is from and ESP32 to an ATMEGA328P.
The code on the receiving end (ATMEGA) is:

        Serial.println((char *)radio.DATA);
        Serial.println(radio.PAYLOADLEN);
        Serial.println(radio.DATALEN);
        Serial.println(sizeof(radio.DATA));

Which prints

123456789abcdefg,1,2,3
0
0
62

The code from the sending ESP32 side is:

sprintf(buff, "123456789abcdefg,1,2,3");
radio.sendWithRetry(TONODEID, buff, 22);

Do you have any ideas on what I am doing wrong here?

See examples how DATALEN is used. Also check the sprintf specification for use of arguments.

jLynx commented

See examples how DATALEN is used. Also check the sprintf specification for use of arguments.

I was just hard coding values in sprintf for ease of use in the example. I don't mean to be rude, but just pointing to the examples does not answer my question, as that's what I believe have done, yet it returns 0. Can you please re open this issue @LowPowerLab

It would help if you could say where I have gone wrong with my example I posted above. As far as I am aware it should contain the length when it it send and receive it on the other side, so I am very confused on why it's set to 0. For example over here in this example

if (radio.DATALEN==4)
you are able to check the length is equal to 4. I don't understand how this use differs from mine.

jLynx commented

RFM69/RFM69.cpp

Line 329 in 06a4a7b

bool RFM69::sendWithRetry(uint16_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries, uint8_t retryWaitTime) {
specifies that the 3rd parameter is the size, which is what I was including. Which means datalen should be populated, correct?

The library has examples so you can follow those and have a reference to using the library components. Also the header files show how functions are specified and used.
When you're dealing with c++ memory buffers and strings you have to be careful how they are defined and consumed, or strange things can happen. If there is a issue with the library that can be replicated then opening an issue is appropriate.
However this is not an issue, but rather a C++/coding question, hence the issue was closed. The space for c++/coding questions would be better suited in the support forum. Or since it's not really related to this library, maybe on the c++ forums.
DATALEN is a field that is populated on RECEIPT of a packet, look in the interruptHandler()

jLynx commented

Thanks I'll have another look when I get back. Will post full code examples if I can replicate

I will add that as long as the library examples work as intended, I'd rather you start with that and build ontop known working code, rather than show code that apparently doesn't work and spend the time to point out the errors. Again this is not the place to learn c++ in an issue feed, but rather point library problems and fix them if there is indeed a problem.

jLynx commented

I'm talking about the examples themselves

Right, if an example is broken you have my attention.

jLynx commented

So for anyone else who runs into this issue, the problem was that I was calling radio.DATALEN after I had called radio.sendACK() which caused the length to be set back to 0.


But back onto the broken examples @LowPowerLab .
The struct example seems to be broken for me:

if (radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData)))

Serial.print("Invalid payload received, not matching Payload struct!");

I get the error: Invalid payload received, not matching Payload struct

When I debug it further I see Sending struct (12 bytes) from the sender side and then on the receiver side radio.DATALEN is 12 bytes, but sizeof(Payload) is only 10 bytes, hence why I am seeing that message.

So what's odd is it seems to be sending the correct information since it sent 12 bytes and received 12 bytes, but when it try's to see the size of the struct type its only 10 bytes.

If I disable that check and force it to cast to Payload I get the following response
nodeId=1 uptime=3960143872 temp=ovf when it should be nodeId=1 uptime=3960143872 temp=91.23

Let me know if you need any more information.

Note: I have changed the NODEID, NETWORKID and GATEWAYID