NRF24 String Issue

Hey everyone, I have a bit of a strange issue with my setup of two NRF24 modules. I am transiting one value from a tx to a rx, and then sending back an ACK packet with some more data in it back. That all works fine except for one piece of data being sent back which is a string called RxTime. Whenever I send that data back, it doesn't actually print out the desired string, it produces a garbled mess of random characters, but all the other pieces of data which are integers come back just fine, is the any reason this might be happening? I have put my code here broken down to just what is relevant here, thanks!

TX

#include "RF24.h";
RF24 radio(7,8);

struct packageTx
{
 int TxSlider = 0;
};

struct packageRx
{
 String RxTime = "";
 int RxVoltage = 0;
 int RxTemperature = 0;
};

typedef struct packageTx PackageTx;
PackageTx dataTx;

typedef struct packageRx PackageRx;
PackageRx dataRx;

const uint64_t pipe[1] = {0x3259657830};

void setup() {
  Serial.begin(115200);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setChannel(115);
  radio.setPALevel(RF24_PA_HIGH);
  radio.setDataRate(RF24_1MBPS);
  radio.enableAckPayload();           
  radio.enableDynamicPayloads(); 
  radio.openWritingPipe(pipe[0]); 

}

void loop() {
  
  if(radio.write(&dataTx, sizeof(dataTx)))
  {
        
      if(!radio.available()){  // If nothing in the buffer, we got an ack but it is blank
          
        }
        
      else {      
            while(radio.available() ){        // If an ack with payload was received
                radio.read(&dataRx, sizeof(dataRx));  
                Serial.println(dataRx.RxTime);      //not printing properly, garbeled mess
                }
        }
  }
  else {
    
  }       

}

RX

#include "RF24.h";
RF24 radio(7,8);

struct packageTx
{
 int TxSlider = 0;
};

struct packageRx
{
 String RxTime = "";
 int RxVoltage = 0;
 int RxTemperature = 0;
};

typedef struct packageTx PackageTx;
PackageTx dataTx;

typedef struct packageRx PackageRx;
PackageRx dataRx;

const uint64_t pipe[1] = {0x3259657830};

String testString = "10:20 AM";
void setup() {
  Serial.begin(115200);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setChannel(115);
  radio.setPALevel(RF24_PA_HIGH);
  radio.setDataRate(RF24_1MBPS);
  radio.enableAckPayload();           
  radio.enableDynamicPayloads(); 
  radio.openReadingPipe(1,pipe[0]);
  radio.startListening();
  radio.writeAckPayload(1,&dataRx,sizeof(dataRx));
}

void loop() {

  dataRx.RxTime = testString;
  
  while(radio.available()){              
      radio.read(&dataTx,sizeof(dataTx));                                    
      radio.writeAckPayload(1,&dataRx,sizeof(dataRx)); 
      Serial.println(dataRx.RxTime);        //prints correct string "10:20AM"
        
   }


}

Use of Strings is a bad idea with Arduino. Use fixed-length character arrays instead.

I suggest you don't use the String class. Just put your characters in a char array.

The way you have defined your struct its size will change and probably screw up the Arduino's memory.

...R

Ok, so like this?
char teststring = {"10",":","20","A","M"}

Ok, so like this?
char teststring = {"10",":","20","A","M"}

NO! A string is an ARRAY of chars:

  char time[] = "10:20AM";

Haha, ok thanks. When I try to do it like that I get an error though.

struct packageRx
{
 [color=red]char RxTime[] = "";[/color]
 int RxVoltage = 0;
 int RxTemperature = 0;
};


char testStr[] = "10:20 AM";

It says "initializer-string for array of chars is too long [-fpermissive]" and highlights the RxTime line.

The above would define a useless zero-length character array.

Define RxTime to have a length 1 larger than any character string you will ever encounter. Then when you fill the array with characters, make sure that it is properly zero-terminated.
e.g.

struct packageRx
{
 char RxTime[30];
 int RxVoltage = 0;
 int RxTemperature = 0;
};

Ah ok, I'm almost there to understanding it, thanks

Yeah so I know this isn't right, but I just want to make position 0 in dataRx.RxTime equal to "1"

struct packageRx
{
 char RxTime[30];
 int RxVoltage = 0;
 int RxTemperature = 0;
};


dataRx.RxTime[0] = "1";

Yeah so I know this isn't right, but I just want to make position 0 in dataRx.RxTime equal to "1"

No, you can't do that. You COULD make position 0 in dataRx.RxTime equal to '1', though. Big difference.

ahhh, ok there we go! Got it all working and it is received properly now, thanks for your patience and help everyone!