#include #include // Replace with your network credentials const char* ssid = "iPhone Ernesto (2)"; //ssid network const char* password = "****"; //Password to ssid network const char* mqtt_server = "broker.hivemq.com"; // Address MQTT server WiFiClient espClient; // Client WiFi to connect MQTT server PubSubClient client(espClient); // Client MQTT that uses client WiFi void setup() { Serial.begin(115200); / Inicializa la comunicaciĆ³n serial a 115200 baudios delay(10); // Connect to Wi-Fi WiFi.begin(ssid, password); // Start connection to wifi red while (WiFi.status() != WL_CONNECTED) { / Wait until the connection is successful delay(500); Serial.print("."); // Print a dot every 500 ms while connecting } Serial.println("WiFi connected"); // Print a message when the Wi-Fi connection is successful // Connect to MQTT Broker client.setServer(mqtt_server, 1883); // Set the MQTT client to connect to the server at port 1883 while (!client.connected()) { // Try to connect to the MQTT broker until successful Serial.print("Attempting MQTT connection..."); if (client.connect("ESP32S3Client")) { // Try to connect with the ID "ESP32S3Client" Serial.println("connected"); // Print a message when the MQTT connection is successful } else { Serial.print("failed, rc="); Serial.print(client.state()); // Print the MQTT client state if the connection fails Serial.println(" try again in 5 seconds"); // Wait 5 seconds before trying to reconnect delay(5000); } } } void loop() { // Send a test message client.loop(); client.publish("arduino/uno", "Hello from Arduino Uno WiFi"); // Publish a message to the topic "arduino/uno" delay(5000); // Wait 5 seconds before sending the next message }