the error massege is ''ArduinoIoTPreferredConnection' was not declared in this scope''
I am trying to conntrol 3 relays using ArduinoCloud
this is my code:
#include "arduino_secrets.h"
#include "thingProperties.h"
#include <ArduinoIoTCloud.h>
bool relay1;
bool relay2;
bool relay3;
const int RELAY1_PIN = 2;
const int RELAY2_PIN = 3;
const int RELAY3_PIN = 4;
void setup() {
Serial.begin(9600);
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
initProperties();
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
pinMode(RELAY3_PIN, OUTPUT);
// Initialize Arduino IoT Cloud library
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
// Set debug message level
setDebugMessageLevel(DBG_INFO);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Control relay 1
digitalWrite(RELAY1_PIN, relay1);
// Control relay 2
digitalWrite(RELAY2_PIN, relay2);
// Control relay 3
digitalWrite(RELAY3_PIN, relay3);
}
void onRelay1Change() {
Serial.print("Relay 1 set to ");
Serial.println(relay1);
}
void onRelay2Change() {
Serial.print("Relay 2 set to ");
Serial.println(relay2);
}
void onRelay3Change() {
Serial.print("Relay 3 set to ");
Serial.println(relay3);
}
C:\Users\Jure\Desktop\zaklucnaDejansk\zaklucnaDejansk.ino: In function 'void setup()':
C:\Users\Jure\Desktop\zaklucnaDejansk\zaklucnaDejansk.ino:22:22: error: 'ArduinoIoTPreferredConnection' was not declared in this scope
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit status 1
Compilation error: 'ArduinoIoTPreferredConnection' was not declared in this scope
Hi @soulslayer. Please post the contents of the "thingProperties.h" tab of your sketch.
When you set up a Thing on Arduino Cloud, it automatically adds a declaration for ArduinoIoTPreferredConnection in the thingProperties.h file it generates. So this error message is unexpected.
Sure enough, the declaration/instantiation of ArduinoIoTPreferredConnection is missing. Did you write this code by hand? It doesn't look like the generated code from the Thing sketches that are automatically generated when you initialize a Thing via the Arduino Cloud website.
It might be best to create a new Thing on Arduino Cloud. You should be able to copy the code from your .ino file into the new sketch as long as you make sure to use the same names for the Cloud Variables.
There is a tutorial for setting up an Arduino Cloud Thing here: