The Arduino loT cloud Generated Sketch returns errors

Hi i've been trying to use the Arduino loT cloud and the sketch that you have to start with to get the arduino loT cloud started won't work. It returns these errors and this is the sketch:

/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/34e733c9-8f26-4421-8678-c07fcd855920

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  - No variables have been created, add cloud variables on the Thing Setup page
    to see them declared here

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"



void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here


}


/*
  Since OnOff is READ_WRITE variable, onOnOffChange() is
  executed every time a new value is received from IoT Cloud.
*/

This is the second sketch:

// Code generated by Arduino IoT Cloud, DO NOT EDIT.

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



void initProperties(){


}

Here are the last errors

/usr/local/bin/arduino-cli compile --fqbn arduino:avr:ethernet --build-cache-path /tmp --output-dir /tmp/2938109266/build --build-path /tmp/arduino-build-22427CDC28F732843B1EAB1C58D815EE --library /mnt/create-efs/webide/f7/cf/f7cf2c9d73ce35efab2bf2d6ac490142:zm476/libraries_v2/DS1307RTC --library /mnt/create-efs/webide/f7/cf/f7cf2c9d73ce35efab2bf2d6ac490142:zm476/libraries_v2/HCSR04 ultrasonic sensor --library /mnt/create-efs/webide/f7/cf/f7cf2c9d73ce35efab2bf2d6ac490142:zm476/libraries_v2/Servo /tmp/2938109266/Untitled_aug04a

WARNING: library ArduinoIoTCloud claims to run on mbed, samd, esp8266, mbed_nano, mbed_portenta, mbed_nicla, esp32, mbed_opta, mbed_giga, renesas_portenta, renesas_uno architecture(s) and may be incompatible with your current board which runs on avr architecture(s).

WARNING: library Arduino_ConnectionHandler claims to run on samd, esp32, esp8266, mbed, megaavr, mbed_nano, mbed_portenta, mbed_nicla, mbed_opta, mbed_giga, renesas_portenta, renesas_uno architecture(s) and may be incompatible with your current board which runs on avr architecture(s).

/tmp/2938109266/Untitled_aug04a/Untitled_aug04a.ino: In function 'void setup()':

/tmp/2938109266/Untitled_aug04a/Untitled_aug04a.ino:31:3: error: 'ArduinoCloud' was not declared in this scope

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

^~~~~~~~~~~~

/tmp/2938109266/Untitled_aug04a/Untitled_aug04a.ino:31:3: note: suggested alternative: 'Arduino_h'

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

^~~~~~~~~~~~

Arduino_h

/tmp/2938109266/Untitled_aug04a/Untitled_aug04a.ino:31:22: error: 'ArduinoIoTPreferredConnection' was not declared in this scope

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/tmp/2938109266/Untitled_aug04a/Untitled_aug04a.ino: In function 'void loop()':

/tmp/2938109266/Untitled_aug04a/Untitled_aug04a.ino:45:3: error: 'ArduinoCloud' was not declared in this scope

ArduinoCloud.update();

^~~~~~~~~~~~

/tmp/2938109266/Untitled_aug04a/Untitled_aug04a.ino:45:3: note: suggested alternative: 'Arduino_h'

ArduinoCloud.update();

^~~~~~~~~~~~

Arduino_h

Error during build: exit status 1

You are compiling it for an avr base board (Uno, Mega, Nano) and those are not supported. What board are you actually using?

I'm using all three of the boards that you said. Arduino Uno, Arduino Mega, and Arduino RP2040 Connect.

is there a fix to the code??

@zm476 you can see the list of boards that are supported for use with Arduino IoT Cloud here:

https://docs.arduino.cc/arduino-cloud/getting-started/iot-cloud-getting-started#compatible-hardware

That the classic Arduino Uno ("R3") and Mega boards are not compatible, so there is no chance you will ever be able to compile that sketch for those boards. But the Nano RP2040 Connect is, so you can use that board!

Note that, even though you can't use the Uno and Mega boards with Arduino IoT Cloud, you can still use them with Arduino Cloud for non-IoT sketches via the Arduino Web Editor.

okay so will the code work if I just use the Nano RP2040 Connect board because I think it showed an error that the ArduinoCloud variable wasn't delcared so is there a fix for that

Thanks
@ptillisch

Don't waste time speculating. Instead, just go ahead and try uploading the sketch to your Nano RP2040 Connect board. If you run into a problem then you can come back here with a detailed report and we'll try to help you out.

So here are the errors that I got:

/usr/local/bin/arduino-cli compile --fqbn arduino:mbed_nano:nanorp2040connect --build-cache-path /tmp --output-dir /tmp/424116849/build --build-path /tmp/arduino-build-22427CDC28F732843B1EAB1C58D815EE --library /mnt/create-efs/webide/f7/cf/f7cf2c9d73ce35efab2bf2d6ac490142:zm476/libraries_v2/DS1307RTC --library /mnt/create-efs/webide/f7/cf/f7cf2c9d73ce35efab2bf2d6ac490142:zm476/libraries_v2/HCSR04 ultrasonic sensor --library /mnt/create-efs/webide/f7/cf/f7cf2c9d73ce35efab2bf2d6ac490142:zm476/libraries_v2/Servo /tmp/424116849/Untitled_aug04a

/tmp/424116849/Untitled_aug04a/Untitled_aug04a.ino: In function 'void setup()':

/tmp/424116849/Untitled_aug04a/Untitled_aug04a.ino:31:22: error: 'ArduinoIoTPreferredConnection' was not declared in this scope

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Multiple libraries were found for "WiFiNINA.h"

Used: /home/builder/opt/libraries/wifinina_1_8_14

Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1

Multiple libraries were found for "SPI.h"

Used: /home/builder/.arduino15/packages/arduino/hardware/mbed_nano/4.0.2/libraries/SPI

Not used: /home/builder/opt/libraries/eventethernet_1_0_0

Multiple libraries were found for "ArduinoECCX08.h"

Used: /home/builder/opt/libraries/arduinoeccx08_1_3_7

Not used: /home/builder/opt/libraries/rak5814_atecc608a_1_0_0

Error during build: exit status 1

Although these are different errors than before so that might mean the Nano RP2040 connect changed some of it.

@zm476

The error

/tmp/424116849/Untitled_aug04a/Untitled_aug04a.ino:31:22: error: 'ArduinoIoTPreferredConnection' was not declared in this scope

is occurring because you have probably changed your thingProperties.h file deleting ArduinoIoTPreferredConnection object.

Recreate your thing following this guide and do not manually change the thingProperties.h file

Thank you @pennam it worked.

Best,
zm476

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