XBee + Arduino + DHT11

I am working on a small sensor hub project. What I want to ultimately do is create a sensor hub centred around an arduino Uno and use XBee ZB (S2) to transmit data from the sensor hub to another XBee connected to a RaspberryPi which will host the data online.

I have just 1 arduino uno board, so to check that the XBees and the DHT11 sensor is actually working, I have used a very modular approach. First I tested the DHT11 sensor using the Adafruit DHT Sensor Library (https://github.com/adafruit/DHT-sensor-library) with the arduino. It worked.

Next thing I have done is to configure the XBee ZB modules in AT mode (Testing point-to-point communication first) in XCTU. I configured one as the AT Coordinator and the other as the Router and gave them both the same PAN ID. I configured the DH and DL of the coordinator to broadcast mode and set both fields to 0 for the router so it can communicate with the coordinator.

Next, I connected one XBee to the PIN0 (RX) and one to PIN1 (TX) so I could read the data from the sensor, send it serially through one XBee, transmit the data wirelessly to the other XBee, receive the data from PIN0 and display it.

I used the following code in the arduino IDE:

#include "DHT.h"

#define DHTPIN 2

#define DHTTYPE DHT11


uint8_t ht[] = {0, 0};

void setup() {

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
  ht[0] = (uint8_t) ((int) h);
  ht[1] = (uint8_t) ((int) t);
  Serial.print(ht[0], 1);
  Serial.println(ht[1], 1);  
  Serial.write(ht, 2);
  int incomingByte = 0;
  while (Serial.available() > 0) {
   incomingByte = Serial.read();
   Serial.print(incomingByte, DEC);

This code compiles fine and produces the following results:

OUT 37 26 %IN 798584951559505413103726 OUT 37 26 %IN 737895557565356525753495353575348535249514948515550541310798584951559505413103726 OUT 37 26 %IN 73789555155565753535355535453515354535053555351525753515351535553515256535153505257534952575256534953535348535249514948555756 OUT 37 26 %IN 73789555155565753535349535353545355535153515351535353515352535153495351535253515348535153535351534953505355535153495351534953 OUT 37 26 %IN 73789555155565753535349535353545355535153515351525753515351535153525351535353515349535153495351534953515351535153495351535053 OUT 36 26 $

As you may notice, the last 4 digits in the first 2 outputs correspond to the correct value, before it all becomes random (at least to my eyes). I am stumped as to why this is happening. I am new to the Arduino libraries so maybe its a noob mistake, but any pointers will be much appreciated.

EDIT: I also just noticed, that every time I restart the serial monitor, no matter how long the setup is running, I get the correct (ish) output at the end of the first 2 lines.