 
 
 // Métodos auxiliares
-
+ 
 void conectar_mosquitto() {
-//  client.setServer(server, PORTA_MQTT);
 
   while (!client.connected()) {
     Serial.print("Conectando com mosquitto broker...");
-    if (client.connect("casa", "mdzjtvif", "snX5gG5TJs8P")) {
-//    if (client.connect("casa")) {
+    if (client.connect("casa", USUARIO_MQTT, SENHA_MQTT)) {
       Serial.println(" conectado!");
+      client.subscribe("casa/ar/status");
     } else {
       Serial.print("falha, rc=");
       Serial.println(client.state());
+      delay(TEMPO_NOVA_TENTATIVA);
     }
-    delay(TEMPO_NOVA_TENTATIVA);
   }
 }
 

#define USUARIO_MQTT "mdzjtvif"
#define SENHA_MQTT "snX5gG5TJs8P"

void callback(char* topic, byte* payload, unsigned int length) {}

PubSubClient client(server, PORTA_MQTT, callback, ethClient);


  {
    conectar_mosquitto();
  }
  client.loop();
  ler_temperatura();
  Narcoleptic.delay(5000);
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}


