 DHT dht(DHTPIN, DHTTYPE);
 ESP8266WebServer server(80);
 
-float setTeperature = 0;
-float setHumidity = 0;
+int AIRING_PIN = 4;
+int FURNACE_PIN = 3;
+
+float temperatureToLaunch = 0;
+float humidityToLaunch = 0;
+boolean autoMode = false;
+boolean airing = false;
+boolean furnace = false;
 
 void handleRoot() {
   server.send(200, "text/plain", "hello from esp8266!");
 }
 
-void handleNotFound(){
+void handleNotFound() {
   String message = "File Not Found\n\n";
   message += "URI: ";
   message += server.uri();
   message += "\nMethod: ";
-  message += (server.method() == HTTP_GET)?"GET":"POST";
+  message += (server.method() == HTTP_GET) ? "GET" : "POST";
   message += "\nArguments: ";
   message += server.args();
   message += "\n";
-  for (uint8_t i=0; i<server.args(); i++){
+  for (uint8_t i = 0; i < server.args(); i++) {
     message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
   }
   server.send(404, "text/plain", message);
 }
 
-void setup(void){
+void handlePutCurrentSet() {
+
+  if (server.hasArg("plain") == false) {
+
+    server.send(200, "text/plain", "Body not received");
+    return;
+
+  }
+
+  autoMode = true;
+
+  String message = "Body received:\n";
+  message += server.arg("plain");
+  message += "\n";
+
+  server.send(200, "text/plain", message + " autoMode: " + String(autoMode));
+}
+
+void setup(void) {
   Serial.begin(9600);
+  pinMode(AIRING_PIN, OUTPUT);
+  pinMode(FURNACE_PIN, OUTPUT);
   WiFi.begin(ssid, password);
   Serial.println("");
   dht.begin();


  server.on("/", handleRoot);

  server.on("/getCurrentWeather", [](){
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    server.send(200, "text/plain", "{temperature: " + String(t) + ", humidity: " + String(h) + "}");
  });

  server.on("/getCurrentSet", [](){
    server.send(200, "text/plain", "{temperature: " + String(setTeperature) + ", humidity: " + String(setHumidity) + "}");
  });

  server.on("/setTemperature/", [](){
    setTeperature = temperature;
    server.send(200, "text/plain", "{temperature: " + String(setTeperature) + ", humidity: " + String(setHumidity) + "}");
  });

  server.onNotFound(handleNotFound);

  Serial.println("HTTP server started");
}

void loop(void) {
  server.handleClient();

  float currentHumidity = dht.readHumidity();
  float currentTemperature = dht.readTemperature();

  if (autoMode) {
    if (currentTemperature < temperatureToLaunch) {
      furnace = true;
      digitalWrite(FURNACE_PIN, HIGH);
    } else {
      furnace = false;
      digitalWrite(FURNACE_PIN, LOW);
    }

    if (currentHumidity > humidityToLaunch) {
      airing = true;
      digitalWrite(AIRING_PIN, HIGH);
    } else {
      airing = false;
      digitalWrite(AIRING_PIN, LOW);
    }
  }

}

