JUST CURIOUS WHY, want to fix error - NodeMCU 1.0

ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to iot.arduino.cc:8883 Error: -2

I get this in my serial when I try to use my code
(Tab 1

//tab 1

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include <ESP8266WiFi.h>

// Define your WiFi credentials
const char* ssid = "Tony"; // Replace with your WiFi SSID
const char* password = "XXXXX"; // Replace with your WiFi password

// Create a connection handler
WiFiConnectionHandler ArduinoIoTPreferredConnection(ssid, password);

// Include the properties header
#include "thingProperties.h"

void updateInjuryMessage(const String& message) {
    injuryMessage = message;
    // Manually trigger the update to the cloud
    ArduinoCloud.update();
}

void setup() {
    Serial.begin(9600);
    
    // Initialize IoT Cloud connection
    ArduinoCloud.begin(ArduinoIoTPreferredConnection);
    setDebugMessageLevel(2);
    ArduinoCloud.printDebugInfo();
}

void loop() {
    ArduinoCloud.update();

    // Check if 30 seconds have passed
    static unsigned long timerStart = millis();
    const unsigned long timerDuration = 30000; // 30 seconds

    if (millis() - timerStart >= timerDuration) {
        // Update the injury message and trigger cloud update
        updateInjuryMessage("Worker A is injured.");
        
        // Reset the timer
        timerStart = millis();
    }
}

Tab 2

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

// Declare the character string property
String injuryMessage;

void initProperties() {
  // Initialization code can go here if needed
}

)

Simply put it, I want my code to use my NodeMCU 1.0 (12E) to send a string message (Worker A is injured) after 30 seconds to my Arduino Cloud. My Arduino Cloud has a String text Thing, but it isn't updating/changing value. It also prints the following in my serial monitor (ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to iot.arduino.cc:8883 Error: -2) after it conects to my WiFi. All my credentials are correct. Anyone can help? Sounds like lots of people have encountered this issue, for those who have solved it, how? Thanks a lot!

Post the full error log in code tags.

It doesn't directly hav an error tag, for example "No such file or directory". It only prints this in my Serial Monitor as it is part of the library. (ArduinoIoTCloud and Arduino_ConnectionHandler)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.