 int senseMode = 0;
 char message_buff[100];
 //setup MQTT
-  WiFiClient wifiClient;
+WiFiClient wifiClient;
+//MQTT
+PubSubClient client(serverRabbit, 1883, callback, wifiClient);
   
 void setup() {
   // initialize serial and wait for the port to open:
   Serial.begin(9600);
-  while (!Serial) ;
-
-  // check for the presence of the shield:
-  if (WiFi.status() == WL_NO_SHIELD) {
-    Serial.println("WiFi shield not present");
-    // don't continue:
-    while (true);
-  }
-
-  // scan for existing networks:
-  Serial.println("Scanning available networks...");
-
-  // attempt to connect to Wifi network:
-  while ( status != WL_CONNECTED) {
-    Serial.print("Attempting to connect to WPA SSID: ");
-    Serial.println(ssid);
-    // Connect to WPA/WPA2 network:
-    status = WiFi.begin(ssid, pass);
-
-    // wait 10 seconds for connection:
-    delay(5000);
-  }
-
-  // you're connected now, so print out the data:
-  Serial.print("You're connected to the network");
-  printCurrentNet();
-  printWifiData();
-
+  while (!Serial);
+  
+  connectToWifi();
+  
   // set the LED pins as outputs
   // the for() loop saves some extra coding
   for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
     pinMode(pinNumber, OUTPUT);
     digitalWrite(pinNumber, LOW);
   }
-
-  
-//  client = PubSubClient(serverRabbit, 1883, callback, wifiClient);
+  connectToMQTT();
+}
+
+void loop() {
+  Serial.println("loop");
+  float tempVar = readTemperature();
+  char temp[10];
+  dtostrf(tempVar, 2, 2, temp);
+  Serial.print("DEBUG :: Temp value return is : ");
+  Serial.println(temp);
+  publishTempHumMsg(temp, "0");
+  
+  // MQTT client loop processing
+  client.loop();
+}
+
+void connectToMQTT() {
+    
 // if (!client.connected()) {
 //    delay(1000);
 //    Serial.println("Connecting to RabbitMQ");


  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type:");
  Serial.println(encryption, HEX);
  Serial.println();
  Serial.println("------> printCurrentNet e");
}



#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <PubSubClient.h>
#include <SPI.h>

// named constant for the pin the sensor is connected to
const int sensorPin = A0;
