 
 void loop() 
 {
-  if (!client.connected()) {
-    reconnect();
+  if (WiFi.status() == WL_CONNECTED) {
+    if (!client.connected()) {
+      if (client.connect("ESP8266: Fountain")) {
+        client.subscribe(host);
+        Serial.print("Connected to ");
+        Serial.println(host);
+      }
+    }
+
+    if (client.connected())
+      client.loop();
+  } else {
+    Serial.println("Wifi not connected");
   }
-  client.loop();
 }
 
 unsigned int *integerArray(char *str, unsigned int *out_len) {

  return arr;
}

void sendIR(unsigned int *sequence) 
{  
  const unsigned int hz = 38;
  const unsigned int len = sizeof(sequence) / sizeof(sequence[0]);

  Serial.print("Sending ");
  Serial.print(len);
  Serial.println(" IR commands");

  Serial.print("Parsed sequence with length: ");
  Serial.println(len);
  
  sendIR(sequence, len);
}

