 
 boolean reconnect()
 {
-  if (client.connect((char*) clientName.c_str(), willTopic, 0, true, willMessage)) {
-    client.publish(willTopic, "1", true);
-    client.publish(hellotopic, "hello again 1 from ESP8266 s02");
-    client.subscribe(subtopic);
-    Serial.println("connected");
-  } else {
-    Serial.print("failed, rc=");
-    Serial.println(client.state());
+  if (!client.connected()) {
+    if (client.connect((char*) clientName.c_str(), willTopic, 0, true, willMessage)) {
+      client.publish(willTopic, "1", true);
+      client.publish(hellotopic, "hello again 1 from ESP8266 s02");
+      client.subscribe(subtopic);
+      Serial.println("connected");
+    } else {
+      Serial.print("failed, rc=");
+      Serial.println(client.state());
+    }
   }
   //timemillis = millis();
   return client.connected();

      client.subscribe(subtopic);
    }
  }

  if (client.connected()) {
    Serial.print("Sending payload: ");

  lightpayload += relaystatus;
  lightpayload += "}";

  sendmqttMsg(rslttopic, lightpayload);
}

void sendmqttMsg(char* topictosend, String payload)
{
  /*
  if (!client.connected()) {
    if (client.connect((char*) clientName.c_str(), willTopic, 0, true, willMessage)) {
      client.publish(willTopic, "1", true);
