 // Data wire is plugged into port 7 on the Arduino
 // Connect a 4.7K resistor between VCC and the data pin (strong pullup)
 #define DHT22_PIN 7
-const int analogInPin = A1;  // LDR Pin
 
+// LDR Pin
+const int ldrInPin = A1; 
+
+// Reseviour level pin
 const int switchPin = 8;
 
-int sensorValue = 0;        // value read from the pot
+// value for the temp sensor
+int rawLightValue = 0;        // value read from the pot
 
-int outputValue = 0;        // value output to the PWM (analog out)
+int outputLightValue = 0;        // value output to the PWM (analog out)
 
 int switchValue = LOW;
 // Setup a DHT22 instance

#include <DHT.h>

/*
  Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 02 Sept 2015
 by Arturo Guadalupi

 */

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

  }
}

void sendResponse(EthernetClient client)
{
   // send a standard http response header
  sendHeader(client);
  client.println("<prtg>");          
  sendLightData(client);          
  sendResevoirData(client);          
  sendTempData(client);
  client.println("</prtg>");
}
void sendHeader(EthernetClient client)
{
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: application/xml");
  client.println("Connection: close");  // the connection will be closed after completion of the response          
  client.println();
  client.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
}

void sendLightData(EthernetClient client)
{
    // read the analog in value:
    rawLightValue = analogRead(ldrInPin);
        
    // map it to the range of the analog out:
    outputLightValue = map(rawLightValue, 0, 800, 0, 100);
    // Cap it at 100%
    if(outputLightValue >100)
    {
      outputLightValue = 100;
    }
    
    client.print("<result><channel>Light</channel><unit>Percent</unit><float>1</float><value>");
    client.print(outputLightValue);
    client.println("</value></result>");
}

void sendTempData(EthernetClient client)
{
    client.print("<result><channel>Temperature</channel><unit>Custom</unit><customUnit>°C</customUnit><float>1</float><value>");
    client.print(myDHT22.readTemperature());
    client.print("</value></result><result><channel>Humidity</channel><unit>Percent</unit><float>1</float><value>");
    client.print(myDHT22.readHumidity());
    client.println("</value></result>");
}
void sendResevoirData(EthernetClient client)
{
  switchValue = digitalRead(switchPin);
  client.print("<result><channel>Reservoir</channel><valueLookup>developingtrends.greenhouse.reservoir</valueLookup><value>");
  client.print(switchValue);
  client.println("</value></result>");
}
