Page 194 - MDP2022-2
P. 194
client.subscribe("iot/led");
client.subscribe("iot/curtain");
client.subscribe("iot/heating_pad");
client.subscribe("iot/door");
client.subscribe("iot/door/keypad");
client.subscribe("iot/pir");
client.subscribe("iot/music");
}
else
{
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup()
{
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void loop()
{
if (!client.connected())
{
reconnect();
}
client.loop();
unsigned long now = millis();
if (now - lastMsg > 2000)
{
lastMsg = now;
}
String str = Serial.readStringUntil('\n');