 /*
 SenseBox Citizen Sensingplatform
-Version: 1.0
-Date: 2014-05-11
+Version: 1.2
+Date: 2015-01-06
 Homepage: http://sensebox.uni-muenster.de/bestellen/fuer-buerger/
 Author: Jan Wirwahn
+Note: Version with additional sensors for GIS-GK@ifgi
 */
-
-//libraries to include
-#include <DHT.h>
-#include <Barometer.h>
 #include <Wire.h>
 #include <SPI.h>
 #include <EthernetV2_0.h>
- 
+#include <DHT.h>
+#include <Barometer.h>
+#include <Digital_Light_TSL2561.h>
+#include <avr/wdt.h>
+
+//SenseBox ID
+
+//Sensor IDs
+
+//Sensor pin settings
+#define NOISEPIN A0
+#define DHTPIN A1
+#define UVPIN A2
+#define DHTTYPE DHT11
 //Ethernet shield settings
 #define W5200_CS  10
 #define SDCARD_CS 4
 
-//Define analog ports used by sensors
-#define NOISEPIN A0
-#define LIGHTPIN A1
-#define DHTPIN A2   
-
-/* 
-* USER SETUP 
-* Provide your SenseBoxID and , if your network does not support DHCP, an IP address!
-*/
-//SenseBox ID
-
-//If DHCP is not enabled, specify an IP according to your network settings:
-IPAddress ip(192,168,178,111);
-
-//Senor IDs
-
 //Network settings
+IPAddress ip(192,168,178,111);//If DHCP is disabled, specify an IP according to your network settings
 byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
 char server[] = "opensensemap.org";
 EthernetClient client;
 
-//Measurement variables
-float temperature, pressure, humidity;
-int analogLightValue, analogNoiseValue;
-float lightResistance; //Resistance of light sensor in K
+String currentSensorId = TEMPERATURESENSOR_ID;
+float temperature;
+float humidity;
+float pressure;
+unsigned long  lux;
+int analogNoise;
+int uvValue;
+
+DHT dht(DHTPIN, DHTTYPE);
+Barometer barometer;
+
+//Variables for time sync and upload intervall
+const unsigned long postingInterval = 10*1000*60; //1 minute
+unsigned long lastConnectionTime = 0;
+boolean lastConnected = false;
+boolean uploadSuccess = true;
 String sensorSample;
-int sampleType = 1;
-String currentSensorId;
-
-//Sensor instances
-Barometer barometer;
-DHT dht(DHTPIN, DHT11);
-
-//Variables for time sync and upload intervall
-const unsigned long postingInterval = 60 * 1000; //post meausrements each 60 seconds
-unsigned long lastConnectionTime = 0;
-unsigned long currentTime = 0;
-boolean lastConnected = false;
-boolean uploadSuccess = false;
+int sampleType = 1; //1=temp,2=humi,3=baro,4=light
 
 void setup(){
-  //Start serial port
+  Wire.begin();
   Serial.begin(9600);
-  
   //Setup chip select and deselect the SD card
   pinMode(SDCARD_CS,OUTPUT);
   digitalWrite(SDCARD_CS,HIGH);
-  
-  // give the ethernet module time to boot up
-  delay(1000);
-  
+  delay(500);
   // start the Ethernet connection 
   if (Ethernet.begin(mac) == 0) {
     Serial.println("Failed to configure Ethernet using DHCP.");
     //If DHCP is disabled, use static IP
     Ethernet.begin(mac, ip);
   }else Serial.println("DHCP setup successful.");
-  
   //Print the IP to serial port
   Serial.print("My IP address: ");
   for (byte thisByte = 0; thisByte < 4; thisByte++) {

    Serial.println("failed...disconnecting.");
    client.stop();
  }
}

String floatToString(float number)
{
  String stringNumber = "";
  int prec;
  //only temperature (case 1) has a decimal place
  if (sampleType == 1) prec = 1; else prec = 0;
  char tempChar[10]; 
  dtostrf(number, 3, prec, tempChar);
  stringNumber += tempChar;
  
  return stringNumber;
}

    client.println(); 
    client.print(valueJson); 
    client.println(); 
    Serial.println("done!");
    uploadSuccess = true;
    //Change case
    if (sampleType == 5) {
      sampleType = 1;
