Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 18, 2020 21:30
Show Gist options
  • Save parzibyte/bdf3e41ffb58d066420eeef4ed6a0394 to your computer and use it in GitHub Desktop.
Save parzibyte/bdf3e41ffb58d066420eeef4ed6a0394 to your computer and use it in GitHub Desktop.
// Y ahora intentamos conectarnos al servidor MQTT
clienteMqtt.setServer(DIRECCION_SERVIDOR_MQTT, PUERTO_SERVIDOR_MQTT);
// Establecer la función que se invoca al recibir mensajes
clienteMqtt.setCallback(callback);
Serial.print("Conectando a servidor MQTT...");
while (!clienteMqtt.connected())
{
if (clienteMqtt.connect("ClienteESP8266", USUARIO_MQTT, PASSWORD_MQTT))
{
Serial.println("Conectado");
}
else
{
Serial.print("Error conectando. Estado: ");
Serial.println(clienteMqtt.state());
delay(2000);
}
}
// Después de habernos conectado al servidor MQTT nos suscribimos
clienteMqtt.subscribe("casa/sala/iluminacion");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment