Sending data from DHT11 to Xively using Xbees [SOLVED]

Hi Rob and others.

I have modified the code as you suggested however still no luck. I cannot seem to get the temperature and humidity values to be read into the datastreams for Xively. Here is the code I am now using.

#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>



// MAC address for your Ethernet shield
byte mac[] = { xxxxxx };

char inData[24]; // for reading serial from tx
byte index;  // for reading serial from tx
boolean started = false; // for reading serial from tx
boolean ended  = false; // for reading serial from tx

// Your Xively key to let you upload data
char xivelyKey[] = "xxxxx";

// Analog pin which we're monitoring (0 and 1 are used by the Ethernet shield)
//int sensorPin = 2;

// Define the strings for our datastream IDs
char sensorId[] = "humidity";
char sensorId2[] = "temperature";

const int bufferSize = 140;
char bufferValue[bufferSize]; // enough space to store the string we're going to send
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
  XivelyDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),

};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xxxxxx, datastreams, 2 /* number of datastreams */);

EthernetClient client;
XivelyClient xivelyclient(client);


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  Serial.println("Starting multiple datastream upload to Xively...");
  Serial.println();

  while (Ethernet.begin(mac) != 1)
  {
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(15000);
  }
}


 void handleINcomingSerial()
{

//start of code to read from transmitter
while(Serial.available() > 0)
  {
    char aChar = Serial.read();
    if(aChar == '<')
    {
      started = true;
      index = 0;
      inData[index] = '\0';
    }
    else if(aChar == '>')
    {
      ended = true;
    }
    else if(started)
    {
      inData[index] = aChar;
      index++;
      inData[index] = ',';
    }
  }  
}

void printValues()
{
  // Use the value
  if(inData[0] == 'T')
  {
    inData[0] = ' ';
    int temp = atoi(inData);
    Serial.println(" ");
    Serial.print("Temp:");
    Serial.print(inData);
    Serial.print("C");
    Serial.println(" ");
  }
  else if(inData[0] == 'H')
  {
    inData[0] = ' ';
    int hum = atoi(inData); 
    Serial.println(" ");
    Serial.print("Humidity:");
    Serial.print(inData);
    Serial.print("%");
    Serial.println(" ");
  }
}


void sendoToXively()
{
  float t = temp;  //already in tx code
  float h = hum;   // already in tx code

  
  datastreams[0].setFloat(temp);
  datastreams[1].setFloat(hum);
  
  Serial.print("Read sensor value temp ");
  Serial.println(datastreams[0].getFloat());
  Serial.print("Read sensor value hum ");
  Serial.println(datastreams[1].getFloat());


  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);

  Serial.println();
}


void loop() 
{
  handleINcomingSerial();



  if(started && ended)
  {
    printValues();
    
    sendoToXively();

    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }

  delay(15000);
}

When I compile this code I get a "temp is not definded in this scope" error message. If I define "temp" and "hum" as global variables the sketch then compiles and runs ok but I get 0 as values for temperature and humidity so I suspect the values are not getting into the "sendoToXively" function.

I'm sure I am doing something wrong but I hope another set of eyes could spot my error!

Many thanks,

Steve