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!