Nano 33 IoT to Arduino Cloud returns Error: -2, but Uno R4 Wifi board works fine with same code!

Hello everyone,

I am venturing into the world of Arduino Cloud with my Nano 33 board but I have been running into an issue when connecting to the MQTT broker. I have used the Thing creation to generate the thingProperties.h and arduino_secrets.h files, and have uploaded my own version of the main sketch, where I am essentially just sending through a random number to a "thing" from the board.

I am able to obtain a wi-fi connection successfully, the value is generated and printed to the serial. But I am continually being met with "Could not connect to iot.arduino.cc on port 8883 (Error -2)." The Arduino Cloud device list also shows the device as offline (I think this is probably expected because the device is not connecting)

Along with the default files for properties and secrets generated from the thing creation, the code I have uploaded to both boards is.

#include "thingProperties.h"

void setup() {
  Serial.begin(9600);
  delay(1500); 
  initProperties();
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  randomTemperature = 1.0 * random(1, 100);
  Serial.println("random temperature: " + String(randomTemperature));
  delay(5*1000);
}

void onRandomTemperatureChange()  {
  Serial.println("--onRandomTemperatureChange");
}

The output I get is:

***** Arduino IoT Cloud - configuration info *****
Device ID: xxxxxx
MQTT Broker: iot.arduino.cc:8883
WiFi.status(): 0
Current WiFi Firmware: 1.5.0
random temperature: 66.00
Connected to "wifi-network"
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to iot.arduino.cc:8883 Error: -2

I am at my limit of basic troubleshooting where I have done;

  • Reinstalls of the relevant libraries and the board firmware multiple times
  • I have uploaded the exact same code to an an Uno R4 Wi-Fi board which works without problem
  • Verified that the ATECC608A crypto chip is functioning correctly
  • Used the PubSubClient library to test connection, where I get an error: -4, indicating a timeout I believe?
  • I have checked the Cloud Agent debug console which doesn't show any output.
  • I have tried uploading/monitoring the code from both the IDE and Arduino Cloud both of which have the same error.

The only thing I have noticed is that in my device list on Arduino Cloud, the Nano shows the connectivity module firmware as "1.4.8", but when opening the device it says the firmware is "1.5.0", which matches the output from the IDE. I am unsure if this is relevant.

Thanks in advance for anybody who replies!

Please check this:

  1. If you are not already, log in to your Arduino account:
    https://login.arduino.cc/login
  2. Click the following link to open the list of your Arduino Cloud Things in the web browser:
    https://app.arduino.cc/things
  3. Look for the Thing you created in the list.

Do you see the Thing there?

The reason I ask is because I get this specific error message if delete the Thing from my Arduino Cloud account:

I can imagine a user deleting the Thing when they are prevented from creating another Thing due to having reached the allocation of Things provided by their Arduino Cloud plan, without realizing that deleting the Thing will cause their Arduino board to no longer be able to connect to Arduino Cloud when running that Thing's sketch.

Hey, thanks for your reply.

I had setup the Thing and deleted it before adding it again where it still did not work.

Your response prompted me to delete all Devices, Things and Sketches from my Arduino Cloud and try again.

This time it worked! I'm not 100% why exactly, but perhaps there were sketches or the Thing was not deleted as expected.

Thanks :slight_smile:

You are welcome. I'm glad it is working now.

Regards, Per

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