// DHT Climate Sensor
//
#include <DHT.h>
#define DHTPIN 6 // Define DHT Connected Data Pin
#define DHTTYPE DHT22 // Define DHT Sensor Type
DHT dht_main(DHTPIN, DHTTYPE); // Initialize dht Object

//
// Climate Sensors
//

void initClimateSensors() {
  // Init Main Climate Sensor
  dht_main.begin();
}

float getClimateTemperature(char* uuid) {
  if(strcmp(uuid, "aa50-48fd") == 0){
    return dht_main.readTemperature();
  }
  return 0.0;
}

float getClimateHumidity(char* uuid) {
  if(strcmp(uuid, "aa50-48fd") == 0){
    return dht_main.readHumidity();
  }
  return 0.0;
}

void climateSensorCommand(char* deviceUUID, char* command, char* data) {
  if (strcmp(command, "gather_climate_data") == 0) {
    char currentTemp[10]; 
    dtostrf(getClimateTemperature(deviceUUID), 9, 1, currentTemp);
    char currentHumidity[10];
    dtostrf(getClimateHumidity(deviceUUID), 9, 1, currentHumidity);
    char returnCommand[20] = "climate_data";
    char dataBuffer[40];
    sprintf(dataBuffer, "%s,%s", currentTemp, currentHumidity);
    sendSerialCommand(deviceUUID, returnCommand, dataBuffer);
  }
}
