 // specfic DHT22 unit on your board
 const float temperatureCoef = 1;
 
-float dhtTemperature = 0;
-float dhtHumidity = 0;
-float dsTemperature = 0;
+//Configure I2C sensor for light
+const int sensorBH1750 = 0x23;
 
 // For random generation of MQTT client ID
 static const char alphanum[] ="0123456789"
                               "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                               "abcdefghijklmnopqrstuvwxyz";
 
+String txtTemperature = "";
+String txtHumidity = "";
+String txtWater="";
+String txtLight = "";
+
 void drawDisplay(const char *line1, const char *line2 = "", const char *line3 = "")
 {
-    // Write on OLED display
-    // Clear the internal memory
-    u8g2.clearBuffer();
-    // Set appropriate font
-    u8g2.setFont(u8g2_font_ncenR14_tr);
-    u8g2.drawStr(0,14, line1);
-    u8g2.drawStr(0,39, line2);
-    u8g2.drawStr(0,64, line3);
-    // Transfer internal memory to the display
-    u8g2.sendBuffer();
-}
-
-void connectWiFi() {
-
+  // Write on OLED display
+  // Clear the internal memory
+  u8g2.clearBuffer();
+  // Set appropriate font
+  u8g2.setFont(u8g2_font_ncenR14_tr);
+  u8g2.drawStr(0,14, line1);
+  u8g2.drawStr(0,39, line2);
+  u8g2.drawStr(0,64, line3);
+  // Transfer internal memory to the display
+  u8g2.sendBuffer();
+}
+
+void connectWiFi()
+{
   delay(10);
   // We start by connecting to a WiFi network
   Serial.println();

  mqttClient.publish(topicBuffer, msgBuffer);
}

void loop()
{
    // Reconnect if MQTT client is not connected.
    if (!mqttClient.connected()) 
    {
      reconnect();
    }
  
    float humidity = dht.readHumidity();
    float temp = dht.readTemperature();
    if (isnan(humidity) || isnan(temp))
    {
      delay(sensorInterval);
      return;
    }
    
    // Adjust temperature depending on the calibration coefficient
    temp = temp*temperatureCoef;
    dhtTemperature = temp;
    dhtHumidity = humidity;
    
    String txtTemperature = String(dhtTemperature, 1);
    String air="Air "+txtTemperature+"C ";
    Serial.println(air);
    String txtHumidity = String(dhtHumidity, 0);
    String hum="Humidity "+txtHumidity+"%";
    Serial.println(hum);

    String txtWater="";
    String water="";
    if (0 < sensors.getDeviceCount())
    {
        sensors.requestTemperatures();
        float wtemp = sensors.getTempCByIndex(0);
        dsTemperature = wtemp;
        txtWater = String(dsTemperature,1);
        water="Water "+String(dsTemperature,1)+"C";
        Serial.println(water);
    }
    drawDisplay(air.c_str(), hum.c_str(), water.c_str());

    // Publish data to thingspeak.com over MQTT
    const unsigned long currentMillis = millis();
    if (publishInterval <= (currentMillis - sensorPreviousMillis))
    {
        sensorPreviousMillis = currentMillis;
        mqttpublish(txtTemperature, txtHumidity, txtWater);
    }

    // Read data from the sensor every 3 seconds
    delay(sensorInterval);
}

#define ONE_WIRE_BUS 12
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// Configure the interval in milliseconds to read data
// from the sensors and to publish it to thingspeak.com
