XBee API mode receive data from DHT22 sensor

Hi everyone

I want to send and receive data of temperature and humidity from DHT22 sensor. I’m already write a transmitter code. The program can compile. I think XBee transmitter side can send temperature and humidity data correctly

XBee transmitter side (router) code

#include <XBee.h>
#include <Printers.h>
#include <AltSoftSerial.h>
#include <SoftwareSerial.h>
#include <DHT.h>
#define DHTPIN 2     
#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE);
#include "binary.h"
XBeeWithCallbacks xbee;
SoftwareSerial XBee(2,3);
AltSoftSerial SoftSerial;
#define DebugSerial Serial
#define XBeeSerial SoftSerial

struct PayloadStruct
{
  uint8_t  Index;
  float fTemperature;
  float fHumidity;     
} __attribute__((packed));
  
PayloadStruct
  payload;


void setup() {
   //Setup debug serial output
  DebugSerial.begin(9600);
  dht.begin();
  DebugSerial.println(F("Starting..."));

  // Setup XBee serial communication
  XBee.begin(9600);
  xbee.begin(XBee);
  delay(1);

  // Send a first packet right away
  sendPacket();

}

void sendPacket() {
    // Prepare the Zigbee Transmit Request API packet
    ZBTxRequest txRequest;
    txRequest.setAddress64(0x000000000000FFFF);
    payload.Index = 1;
    payload.fTemperature = dht.readTemperature();
    payload.fHumidity = dht.readHumidity();
    txRequest.setPayload((uint8_t *)&payload, sizeof( struct PayloadStruct ) );
    xbee.send(txRequest);
    DebugSerial.print(F("Temperature"));
    DebugSerial.print(payload.fTemperature);
    DebugSerial.print(F("Humidity"));
    DebugSerial.print(payload.fHumidity);
    DebugSerial.println();

    
}


unsigned long last_tx_time = 0;

void loop() {
  // Check the serial port to see if there is a new packet available
  xbee.loop();

  // Send a packet every 10 seconds
  if (millis() - last_tx_time > 10000) {
    last_tx_time = millis();
    sendPacket();
  }
}

But I cannot write a code in receiver side correctly. The code in receiver side that I write is

XBee receiver side (Coordinator) code

#include <XBee.h>
#include <Printers.h>
#include <AltSoftSerial.h>
#include <SoftwareSerial.h>
#include "binary.h"

XBeeWithCallbacks xbee;
SoftwareSerial XBee(2,3);
AltSoftSerial SoftSerial;
#define DebugSerial Serial
#define XBeeSerial SoftSerial

void setup() {
  DebugSerial.begin(9600);
  DebugSerial.println(F("Starting..."));
  XBee.begin(9600);
  xbee.begin(XBee);
  delay(1);

  // Setup callbacks
  xbee.onZBExplicitRxResponse(processRxPacket);
  xbee.onZBRxResponse(processRxPacket);
}

void processRxPacket(ZBRxResponse& rx, uintptr_t) {
  Buffer b(rx.getData(), rx.getDataLength());
  uint8_t type = b.remove<uint8_t>();
  if (type == 1 && b.len() == 8) {
  DebugSerial.print(F("Received packet from "));
  printHex(DebugSerial, rx.getRemoteAddress64());
  DebugSerial.println();
  DebugSerial.print(F("Temperature: "));
  DebugSerial.println(b.remove<float>());
  DebugSerial.print(F("Humidity: "));
  DebugSerial.println(b.remove<float>());
  return;
}
DebugSerial.println(F("Unknown or invalid packet"));
printResponse(rx, DebugSerial);
}


void loop() {
  // Check the serial port to see if there is a new packet available
  xbee.loop();
}

How can I change this code to receive the temperature and humidity data from XBee transmitter side. Please help me

The configuration in XBee is

  1. XBee XB24-ZB Coordinator API: ID = 123, AP = 2, DH =13A200 , DL = 40A933C5 , BD = 9600
    XBee XBP24BZ7 Router API: ID = 123, AP = 2, DH = 13A200 = , DL = 4052A6F5 , BD 9600

Thank you

On the rcv side:

does xbee.loop() return anything
How does processRxPacket() get called ?

On xmr side:
why does it look at the serial port for a packet?
Are you sending when you want it to measure and send data?

I do not know anything about xbee, so I may not be helpfull