Created
February 18, 2020 21:30
-
-
Save parzibyte/bdf3e41ffb58d066420eeef4ed6a0394 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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