 		digitalWrite(GREENLED, LOW);
 		ESP.deepSleep(sleepinterval * 1000000);
 	}
+  }
+  //  Setup mqtt
+  if (setupMQTT() == 1){
+    // Ignore this outcome it hasn't done anything
+  } else {
+    // We have setupMQTT
+    if( mqttconnect() != 0 ){
+      // Haven't been able to connect :|
+      // Handle this exception. Probably reload?
+      Serial.println("Unable to connect to MQTT after reset");
+
+    }
   }
   dhtinit();
   dhtmeasure();

  if (!configloaded) {
    loadconfig();
  }
  int sleepinterval = 10; // seconds
  
  if ( !trySTAWiFi() ) {
    // STA Failed so load softAP

	  
	
	// We need to report to the MQTT Server
	while (!mqtttimeout) {
	  if(mqttconnect() != 0){
		  Serial.println("Unable to connect to MQTT Server " + mqttfailcount + " tries");
		  delay(1000);
	      mqttfailcount++;
	  } else {
		  Serial.println("MQTT Successfully Connected");
		  mqtttimeout = true;
		  mqttsuccess = true;
	  }
	  
	  if(mqttfailcount >= 30 ){
		  Serial.println("Giving up MQTT connection after "+ mqttfailcount + " tries" );
		  mqtttimeout = true;
	  }
	  
	  
	}
	
	if(mqttsuccess){
	  // Connect to MQTT Server
	  //client.connect(mqttclientname.c_str(), mqttusername.c_str(), mqttpassword.c_str() );
	  //Following is original
