ArduinoCloud Not Declared In This Scope

I'm working on a project that I would like to run through the IoT cloud however I'm having some problems getting the code to compile and load from the Cloud editor. The code compiles and loads just fine from the desktop IDE however I keep getting "ArduinoCloud not declared in this scope when I try to compile online. The code and error message are attached. The error populates in line 24 of the 'thingProperties.h' file right after 'void initProperties()
{' in the code. I'm planning to rework some of the code to replace the delay() with millis() just haven't got that far yet. Any help will be greatly appreciated.

.ino file

// ArduinoIoTCloud - Version: Latest 


/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/a7fd2373-5aa4-48e4-a278-598e5273ef78 

  Arduino IoT Cloud Variables description

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

  float humid;
  float irms;
  float temp;
  bool alarm;
  bool gLED;
  bool rLED;
  bool yLED;

  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"

#include <LiquidCrystal.h>
#include <dht.h>
#include <EmonLib.h>

#define dht_apin A0  // analog pin sensor is connected to

dht DHT; 
 
EnergyMonitor emon1;

const int RLED=A3;
const int YLED=A4;
const int GLED=A5;
const int PUMP=A1;
//const int SPEAKER=8;
//const int BUTTON_A=2;
const byte SPEAKER=8;
const byte interruptPin=2;
volatile byte state = LOW;
int note = {490};

LiquidCrystal lcd(4, 6, 10, 11, 12, 13); //lcd(RS,E,D4,D5,D6,D7)


float cm;   //stores distance in cm
float inches; //stores distance in inches


long readUltrasonicDistance(int triggerPin, int echoPin)
{
  pinMode(triggerPin, OUTPUT);  // Clear the trigger
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
   //Sets the trigger pin to HIGH state for 10 microseconds
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  pinMode(echoPin, INPUT);
  // Reads the echo pin, and returns the sound wave travel time in microseconds
  return pulseIn(echoPin, HIGH);
}

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();
  
  emon1.current(A6, 111.1);
  Serial.println("Sump Pump Monitor and Control V.1");
  lcd.begin(16, 2);         // LCD size 16 , 2 
  lcd.print("Water Level");   
  delay(3000);
  pinMode(RLED, OUTPUT);
  pinMode(YLED, OUTPUT);
  pinMode(GLED, OUTPUT);
  pinMode(PUMP, OUTPUT);
  digitalWrite(PUMP, HIGH);
  pinMode (SPEAKER, OUTPUT);
 //pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), alarm, HIGH);
}

  // 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 
   {
  double Irms = emon1.calcIrms(1480);  //calculate Irms only
  //Serial.println(Irms*230.0);
  Serial.print("Amps");
  Serial.print("  ");
  Serial.println(Irms);
 

{
  DHT.read11(dht_apin);

  Serial.print("Current Humidity = ");
  Serial.print(DHT.humidity);
  Serial.print("%  ");
  Serial.print("Temperature = ");
  Serial.print(DHT.temperature);
  Serial.print("C  ");

  delay (1000);
}
{
  cm = 0.01722 * readUltrasonicDistance(5, 3);
  inches = (cm / 2.54);
  //Serial.println (readUltrasonicDistance(5, 3)); //("Distance:"); 
  //Serial.println("\t");
  lcd.setCursor(0,1);
  if (inches >= 24){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("Empty  ");
    lcd.print("EMPTY");
    lcd.print("     ");
    digitalWrite(GLED, HIGH);
    digitalWrite(YLED, LOW);
    digitalWrite(RLED, LOW);
    digitalWrite(PUMP, LOW);
    noTone(SPEAKER);
    

  }
    else if (inches <= 24 && inches >= 18){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("1/4 Full  ");
    lcd.print("1/4 FULL  ");
    lcd.print("       ");
    digitalWrite(GLED, HIGH);
    digitalWrite(YLED, LOW);
    digitalWrite(RLED, LOW);
    digitalWrite(PUMP, LOW);
    noTone(SPEAKER);
    
  }
  
  else if (inches <= 18 && inches >= 12){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("1/2 Full  ");
    lcd.print("1/2 FULL");
    lcd.print("        ");
    digitalWrite(GLED, LOW);
    digitalWrite(YLED, HIGH);
    digitalWrite(RLED, LOW);
    digitalWrite(PUMP, HIGH);
    noTone(SPEAKER);
  
  }
  else if (inches <= 12 && inches >= 6){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("3/4 Full  ");
    lcd.print("3/4 FULL");
    lcd.print("      ");
    digitalWrite(GLED, LOW);
    digitalWrite(YLED, HIGH);
    digitalWrite(RLED, LOW);
    digitalWrite(PUMP, HIGH);
    tone(SPEAKER, note);
  
    
  }
    else if (inches <= 6 && inches >= 0){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("Full  ");
    lcd.print("FULL");
    lcd.print("     ");
    digitalWrite(GLED, LOW);
    digitalWrite(YLED, LOW);
    digitalWrite(RLED, HIGH);
    digitalWrite(PUMP, HIGH);
    tone(SPEAKER, note);    
    
  }
  else{
    digitalWrite(SPEAKER, LOW);
  }

  if(Irms >=30.0){
    digitalWrite(PUMP, LOW);
    digitalWrite(RLED, HIGH);
    digitalWrite(YLED, LOW);
    digitalWrite(GLED, LOW);
    tone(SPEAKER, note);
  }
  
                          
  delay(1000);
}
}  
}

  






/*
  Since Alarm is READ_WRITE variable, onAlarmChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onAlarmChange()  {
  // Add your code here to act upon Alarm change
  note = !note;
  noTone(SPEAKER);

  delay(5000);
  }
}

'thingProperties.h'

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

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

const char DEVICE_LOGIN_NAME[]  = "ec2fb9d6-6757-4330-86fe-3ec1654bcf3b";

const char SSID[]               = SECRET_SSID;    // Network SSID (name)
const char PASS[]               = SECRET_PASS;    // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[]  = SECRET_DEVICE_KEY;    // Secret device password

void onAlarmChange();

float humid;
float irms;
float temp;
bool alarm;
bool gLED;
bool rLED;
bool yLED;

void initProperties()
{

  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.addProperty(humid, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(irms, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(temp, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(alarm, READWRITE, ON_CHANGE, onAlarmChange);
  ArduinoCloud.addProperty(gLED, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(rLED, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(yLED, READ, ON_CHANGE, NULL);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Error

/usr/local/bin/arduino-cli compile --fqbn arduino:avr:mega:cpu=atmega2560 --libraries /home/builder/opt/libraries/latest --build-cache-path /tmp --output-dir /tmp/536493846/build --build-path /tmp/arduino-build-ABAE4016073CEDD8F04783F65598FA0C /tmp/536493846/Sump_Pump_mar29a

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

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

Using library dhtlib_0_1_35 at version 0.1.35 in folder: /home/builder/opt/libraries/dhtlib_0_1_35

Using library emonlib_1_1_0 at version 1.1.0 in folder: /home/builder/opt/libraries/emonlib_1_1_0

In file included from /tmp/536493846/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:26:0:

/tmp/536493846/Sump_Pump_mar29a/thingProperties.h: In function 'void initProperties()':

/tmp/536493846/Sump_Pump_mar29a/thingProperties.h:24:3: error: 'ArduinoCloud' was not declared in this scope

ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);

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

/tmp/536493846/Sump_Pump_mar29a/thingProperties.h:25:3: note: suggested alternative: 'Arduino_h'

ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);

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

Arduino_h

/tmp/536493846/Sump_Pump_mar29a/thingProperties.h: At global scope:

/tmp/536493846/Sump_Pump_mar29a/thingProperties.h:37:1: error: 'WiFiConnectionHandler' does not name a type; did you mean 'ConnectionHandler'?

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

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

ConnectionHandler

/tmp/536493846/Sump_Pump_mar29a/Sump_Pump_mar29a.ino: In function 'void setup()':

/tmp/536493846/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:92:67: error: cannot convert 'bool' to 'void (*)()' for argument '2' to 'void attachInterrupt(uint8_t, void (*)(), int)'

attachInterrupt(digitalPinToInterrupt(interruptPin), alarm, HIGH);

^

/tmp/536493846/Sump_Pump_mar29a/Sump_Pump_mar29a.ino: At global scope:

/tmp/536493846/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:96:3: error: 'ArduinoCloud' does not name a type; did you mean 'Arduino_h'?

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

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

Arduino_h

/tmp/536493846/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:105:23: error: expected constructor, destructor, or type conversion before '(' token

setDebugMessageLevel(2);

^

/tmp/536493846/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:106:3: error: 'ArduinoCloud' does not name a type; did you mean 'Arduino_h'?

ArduinoCloud.printDebugInfo();

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

Arduino_h

/tmp/536493846/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:107:1: error: expected declaration before '}' token

}

^

Error during build: exit status 1

Hi @hsolum. You have a stray closing brace (}) in the setup function of your .ino file:

Thank You for looking at this. Unfortunately, I am still having problems with the file not compiling after removing the stray brace. I have gone through it with a fine-toothed comb and still can't identify anything else that is causing the problem.

Please post your full updated sketch.

Please also post the full error output you get from compiling the updated sketch.

// ArduinoIoTCloud - Version: Latest 


/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/a7fd2373-5aa4-48e4-a278-598e5273ef78 

  Arduino IoT Cloud Variables description

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

  float humid;
  float irms;
  float temp;
  bool alarm;
  bool gLED;
  bool rLED;
  bool yLED;

  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"
//#include "arduino.h"
#include <LiquidCrystal.h>
#include <Arduino_AVRSTL.h>
#include <dht.h>
#include <EmonLib.h>
#define dht_apin A0  // analog pin sensor is connected to

dht DHT; 
 
EnergyMonitor emon1;

const int RLED=A3;
const int YLED=A4;
const int GLED=A5;
const int PUMP=A1;
//const int SPEAKER=8;
//const int BUTTON_A=2;
const byte SPEAKER=8;
const byte interruptPin=2;
volatile byte state = LOW;
int note = {490};

LiquidCrystal lcd(4, 6, 10, 11, 12, 13); //lcd(RS,E,D4,D5,D6,D7)


float cm;   //stores distance in cm
float inches; //stores distance in inches


long readUltrasonicDistance(int triggerPin, int echoPin)
{
  pinMode(triggerPin, OUTPUT);  // Clear the trigger
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
   //Sets the trigger pin to HIGH state for 10 microseconds
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  pinMode(echoPin, INPUT);
  // Reads the echo pin, and returns the sound wave travel time in microseconds
  return pulseIn(echoPin, HIGH);
}

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();
  
  emon1.current(A6, 111.1);
  Serial.println("Sump Pump Monitor and Control V.1");
  lcd.begin(16, 2);         // LCD size 16 , 2 
  lcd.print("Water Level");   
  delay(3000);
  pinMode(RLED, OUTPUT);
  pinMode(YLED, OUTPUT);
  pinMode(GLED, OUTPUT);
  pinMode(PUMP, OUTPUT);
  digitalWrite(PUMP, HIGH);
  pinMode (SPEAKER, OUTPUT);
 //pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), alarm, HIGH);


  // 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 
 {
  double Irms = emon1.calcIrms(1480);  //calculate Irms only
  //Serial.println(Irms*230.0);
  Serial.print("Amps");
  Serial.print("  ");
  Serial.println(Irms);
 }
{

  DHT.read11(dht_apin);

  Serial.print("Current Humidity = ");
  Serial.print(DHT.humidity);
  Serial.print("%  ");
  Serial.print("Temperature = ");
  Serial.print(DHT.temperature);
  Serial.print("C  ");

  delay (1000);
}
{
  cm = 0.01722 * readUltrasonicDistance(5, 3);
  inches = (cm / 2.54);
  //Serial.println (readUltrasonicDistance(5, 3)); //("Distance:"); 
  //Serial.println("\t");
  lcd.setCursor(0,1);
  if (inches >= 24){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("Empty  ");
    lcd.print("EMPTY");
    lcd.print("     ");
    digitalWrite(GLED, HIGH);
    digitalWrite(YLED, LOW);
    digitalWrite(RLED, LOW);
    digitalWrite(PUMP, LOW);
    noTone(SPEAKER);
    

  }
    else if (inches <= 24 && inches >= 18){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("1/4 Full  ");
    lcd.print("1/4 FULL  ");
    lcd.print("       ");
    digitalWrite(GLED, HIGH);
    digitalWrite(YLED, LOW);
    digitalWrite(RLED, LOW);
    digitalWrite(PUMP, LOW);
    noTone(SPEAKER);
    
  }
  
  else if (inches <= 18 && inches >= 12){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("1/2 Full  ");
    lcd.print("1/2 FULL");
    lcd.print("        ");
    digitalWrite(GLED, LOW);
    digitalWrite(YLED, HIGH);
    digitalWrite(RLED, LOW);
    digitalWrite(PUMP, HIGH);
    noTone(SPEAKER);
  
  }
  else if (inches <= 12 && inches >= 6){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("3/4 Full  ");
    lcd.print("3/4 FULL");
    lcd.print("      ");
    digitalWrite(GLED, LOW);
    digitalWrite(YLED, HIGH);
    digitalWrite(RLED, LOW);
    digitalWrite(PUMP, HIGH);
    tone(SPEAKER, note);
  
    
  }
    else if (inches <= 6 && inches >= 0){
    Serial.print("Water Level  ");
    Serial.print(inches);
    Serial.print("  in  ");
    Serial.print("Full  ");
    lcd.print("FULL");
    lcd.print("     ");
    digitalWrite(GLED, LOW);
    digitalWrite(YLED, LOW);
    digitalWrite(RLED, HIGH);
    digitalWrite(PUMP, HIGH);
    tone(SPEAKER, note);    
    
  }
  else{
    digitalWrite(SPEAKER, LOW);
  }

  if(irms >=30.0){
    digitalWrite(PUMP, LOW);
    digitalWrite(RLED, HIGH);
    digitalWrite(YLED, LOW);
    digitalWrite(GLED, LOW);
    tone(SPEAKER, note);
  }
  
//random_value=random(0,1000);
  delay(500);

} 
}


  






/*
  Since Alarm is READ_WRITE variable, onAlarmChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onAlarmChange()  {
  // Add your code here to act upon Alarm change
  note = !note;
  noTone(SPEAKER);

  delay(5000);
  }

Error

/usr/local/bin/arduino-cli compile --fqbn arduino:avr:mega:cpu=atmega2560 --libraries /home/builder/opt/libraries/latest --build-cache-path /tmp --output-dir /tmp/847250092/build --build-path /tmp/arduino-build-ABAE4016073CEDD8F04783F65598FA0C /tmp/847250092/Sump_Pump_mar29a

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

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

Using library dhtlib_0_1_35 at version 0.1.35 in folder: /home/builder/opt/libraries/dhtlib_0_1_35

Using library emonlib_1_1_0 at version 1.1.0 in folder: /home/builder/opt/libraries/emonlib_1_1_0

In file included from /tmp/847250092/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:26:0:

/tmp/847250092/Sump_Pump_mar29a/thingProperties.h: In function 'void initProperties()':

/tmp/847250092/Sump_Pump_mar29a/thingProperties.h:24:3: error: 'ArduinoCloud' was not declared in this scope

ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);

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

/tmp/847250092/Sump_Pump_mar29a/thingProperties.h:25:3: note: suggested alternative: 'Arduino_h'

ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);

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

Arduino_h

/tmp/847250092/Sump_Pump_mar29a/thingProperties.h: At global scope:

/tmp/847250092/Sump_Pump_mar29a/thingProperties.h:37:1: error: 'WiFiConnectionHandler' does not name a type; did you mean 'ConnectionHandler'?

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

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

ConnectionHandler

/tmp/847250092/Sump_Pump_mar29a/Sump_Pump_mar29a.ino: In function 'void setup()':

/tmp/847250092/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:96:3: error: 'ArduinoCloud' was not declared in this scope

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

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

/tmp/847250092/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:96:3: note: suggested alternative: 'Arduino_h'

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

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

Arduino_h

/tmp/847250092/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:96:22: error: 'ArduinoIoTPreferredConnection' was not declared in this scope

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

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

/tmp/847250092/Sump_Pump_mar29a/Sump_Pump_mar29a.ino: In function 'void loop()':

/tmp/847250092/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:110:3: error: 'ArduinoCloud' was not declared in this scope

ArduinoCloud.update();

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

/tmp/847250092/Sump_Pump_mar29a/Sump_Pump_mar29a.ino:110:3: note: suggested alternative: 'Arduino_h'

ArduinoCloud.update();

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

Arduino_h

Error during build: exit status 1

Not sure how much it matters but I'm trying to configure this on a Mega 2560 with a generic ESP8266 WiFi module.

That is the cause of the error. The library and Arduino IoT Cloud in general do not support this. You can use it when programming the ESP8266 directly, but you can not use it in sketches that run on the Mega 2560 board, even if that board is using the ESP8266 as a Wi-Fi adapter.

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