1

I am not able to receive the sent radio packet from the Lora rf95 transceiver.

I have tried declaring the received array as a char, uint8_t along with using len as size, however the size is 7 so i thought what I did was ok. It didn't recieve anything when I used:

uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

    if (rf95.recv(buf, &len))
    {
      digitalWrite(LED, HIGH);
      RH_RF95::printBuffer("Received: ", buf, len);
      Serial.print("Got: ");
      Serial.println((char*)buf);}

It does receive something at the same rate as the transceiver when I use:

uint8_t P;

if(rf95.recv((uint8_t*)P,7)){

  Serial.print((char)P);
Serial.println();

It prints the new line but no data. It was working before but when I started to try to adjust the power it no longer worked so I tried other things. I a new to coding so please don't be mean, I appreciate any help you can give.

1 Answers1

0

You are converting a uint8_t to a uint8_t* this means that your uninitalized variable will be used to point to the location where rf95.recv is going to start storing its data. This means that if P = 5 it will start at memory location 5 and if P = 0 it will result in a null pointer.

What you should be doing is taking the address of P: rf95.recv(&P,7)).

As such these lines should be:

rf95.recv(&buf, &len)

RH_RF95::printBuffer("Received: ", &buf, len);

Serial.println(buf[0]); or even better:

for(uint8_t i = 0; i<len; ++i) {
    Serial.println(buf[i]);
}

Your second code block wasn't printing out any data because P was uninitialized and probably containing the value 0. So your received data was stored at address 0 instead of the address of the variable and as such wasn't changed by your receive because of the first pointer problem.

Tarick Welling
  • 3,119
  • 3
  • 19
  • 44