 
 void setup() {
   Serial.begin(115200);
+  Wire.begin();
+  pinMode(PIN_CLK, OUTPUT);
+  pinMode(PIN_SOIL, INPUT);
+  pinMode(PIN_LED, OUTPUT);
+  digitalWrite(PIN_LED, HIGH);
   
-  pinMode(pin_clk, OUTPUT);
-  pinMode(pin_soil, INPUT);
-  pinMode(pin_led, OUTPUT);
-  digitalWrite(pin_led, LOW);
+  // device address is specified in datasheet
+  Wire.beginTransmission(TMP_ADDR); // transmit to device #44 (0x2c)
+  Wire.write(byte(0x01));            // sends instruction byte
+  Wire.write(0x60);             // sends potentiometer value byte
+  Wire.endTransmission();     // stop transmitting
   
   analogWriteFreq(40000);
-  analogWrite(pin_clk, 400);
+  analogWrite(PIN_CLK, 400);
   delay(500);
   connectWifi();
 }
 
 void loop() {
-  //char buffer[10];
-  digitalWrite(pin_led, HIGH);
-  delay(500);
-  digitalWrite(pin_led, LOW);
+  digitalWrite(PIN_LED, LOW);
+  delay(100);
+  digitalWrite(PIN_LED, HIGH);
   float hum=0,temp=0,soil_hum=0;
   Serial.println("Requesting Temperature...");
+
+  // Begin transmission
+  Wire.beginTransmission(TMP_ADDR);
+  // Select Data Registers
+  Wire.write(0X00);
+  // End Transmission
+  Wire.endTransmission();
   
+  delay(500);
+  
+  // Request 2 bytes , Msb first
+  Wire.requestFrom(TMP_ADDR, 2 );
   // Read temperature as Celsius (the default)
-  // TODO
-  temp = 25;
+  while(Wire.available()) {  
+    int msb = Wire.read();
+    int lsb = Wire.read();
+    Wire.endTransmission();
+
+    int rawtmp = msb << 8 |lsb;
+    int value = rawtmp >> 4;
+    temp = value * 0.0625 ;
+  }
 
   delay(1000);
   soil_hum = readSoilVal(8);
   Serial.print("Soil_Humidity:");
   Serial.println(soil_hum);
-  delay(1000);
+  Serial.print("Temperature:");
+  Serial.println(temp);
+  delay(5000);
   
-  sendData(temp, soil_hum);
+  //sendData(temp, soil_hum);
   //ESP.deepSleep(SLEEP_TIME, WAKE_RF_DEFAULT);
 }
 

}


void sendData(float temp,float soil_hum) {  
   WiFiClient client;
  
   if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com
       Serial.println("WiFi Client connected ");
       
       String postStr = apiKey;
       postStr += "&field1=0&field2=";
       postStr += String(temp);
       postStr += "&field3=";

#include <ESP8266WiFi.h>
#include <Wire.h>

String API_KEY ="<YOUR-API-KEY>";
const char* MY_SSID = "<YOUR-SSID>"; 
const char* MY_PWD = "<YOUR-PASSWORD>";

const int PIN_CLK = D5;
const int PIN_SOIL = A0; 
const int PIN_LED = D7;
const char* SERVER = "api.thingspeak.com";
const int TMP_ADDR = 0x48;

int sent = 0;

