XBEE API Mode Receive (data conversion)

Hi,
This is my first pose so please be patient :wink:

I set up a smal network of sensors, my router node sends data by an xbee pro s2b to the coordinator. the data are valid when the arrive. i store them in a byte array. Now i wana convert the data in to a structure by a cast.
But there is still no data in the stuct after the cast. i also tried with memcpy… its all the same. when i print my array to the serial window the data appears just fine :confused: any idee or hint whats wrong with ist ?

#include <SoftwareSerial.h>
#include <XBee.h>

SoftwareSerial mySerial(2, 3); // RX, TX

struct TClimate{
    float h;
    float t;
};

TClimate* data = new TClimate();


uint8_t payload[sizeof(TClimate)];

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();

// create reusable response objects for responses we expect to handle 
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();

void setup() {
  Serial.begin(9600);
  Serial.println("Start");
  mySerial.begin(9600);
  xbee.begin(mySerial);
  memset(data,0,sizeof(TClimate));
}

void loop() {  
  xbee.readPacket();
  if (xbee.getResponse().isAvailable()) {
    Serial.println("isAvailable");
    if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
      Serial.print("API ID: ");
      Serial.println(xbee.getResponse().getApiId());
      xbee.getResponse().getZBRxResponse(rx);
      
      if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
        // the sender got an ACK
        Serial.println("sender got an ACK");
      } else {
        // we got it (obviously) but sender didn't get an ACK
        Serial.println("sender got an nothing");
      }
      
      Serial.print("Data Length: ");
      Serial.println(rx.getDataLength());
     
      for(size_t i= (rx.getDataLength()-9); i<rx.getDataLength()-1;i++){
        //Serial.print(i);
        //Serial.print(":");
        //Serial.print(rx.getData(i),HEX);
        //Serial.print('\t');
        payload[i] = rx.getData(i);
        //Serial.print("Payload :");
        //Serial.println( payload[i],HEX);
      }
      
      data = (TClimate*) payload;
         
      Serial.print("Humidity: ");
      Serial.print(data->h);
      Serial.print(" %\t");
      Serial.print("Temperature: ");
      Serial.print(data->t);
      Serial.println(" *C");
    }
  } 
}
      for(size_t i= (rx.getDataLength()-9); i<rx.getDataLength()-1;i++){
        payload[i] = rx.getData(i);

Where you write data into payload is NOT the same as where you read data from the packet.

Thanks, i figured that out earlier today... stupid mistake... an additional question i was using the getDataLength() and got as a result 27 which is the whole frame i think ? also i was using getDataOffset it returns 11, when i look up the frame structure my data starts at position 19 ? do i understand the methods wrong or do i looking up the wrong frame ?

Thanks in advance.

I am new in the electronics world. I am looking for a code which is capable of sending a string frame one x bee s2b pro to another. If any one could help me i will be thankful.