Issue with Simple sketch in Iot Cloud

I've been around Arduino IDE for years. Primarily using ESP32's. So I bought a Arduino 33 Iot and thought Id give the Arduino Iot Cloud a go.

The follow is the Thing that was created. To me it's very straight forward.:
Thing Variable Names:
Zone1CloudSwitch zone1; true
Zone2CloudSwitch zone2; false
Zone3CloudSwitch zone3; false
Zone4CloudSwitch zone4; false

The following is the Scetch:

/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/94b8d542-8cb9-4849-a9dc-dca3fa393e14

Arduino IoT Cloud Variables description

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

CloudSwitch zone1;
CloudSwitch zone2;
CloudSwitch zone3;
CloudSwitch zone4;

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"

//################################################
//LED's on GPIO PINS for Relay
const byte led1 = 2;
const byte led2 = 3;
const byte led3 = 4;
const byte led4 = 5;

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);

//***************** Sets up Output pins for relay GPIO 16,17,18,19
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);

digitalWrite(led1, HIGH);//Sets LED's to LOW
digitalWrite(led2, HIGH);//Sets LED's to LOW
digitalWrite(led3, HIGH);//Sets LED's to LOW
digitalWrite(led4, HIGH);//Sets LED's to LOW
//******************************************************

// 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 Zone1 is READ_WRITE variable, onZone1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onZone1Change() {

if (zone1 = true) {
digitalWrite(led1, LOW);
}
else
digitalWrite(led1, HIGH);
// Add your code here to act upon Zone1 change
}
/*
Since Zone2 is READ_WRITE variable, onZone2Change() is
executed every time a new value is received from IoT Cloud.
/
void onZone2Change() {
// Add your code here to act upon Zone2 change
}
/

Since Zone3 is READ_WRITE variable, onZone3Change() is
executed every time a new value is received from IoT Cloud.
/
void onZone3Change() {
// Add your code here to act upon Zone3 change
}
/

Since Zone4 is READ_WRITE variable, onZone4Change() is
executed every time a new value is received from IoT Cloud.
*/
void onZone4Change() {
// Add your code here to act upon Zone4 change
}

/.



Note: My relay board activates to a low state and I have only coded for Zone 1. The moment I put any code in the call routine "onZone1Change" routine the relay activates and the Zone1 Switch in the Dashboard won't turn off.

As I'm new to the Arduino Iot Cloud, perhaps I'm missing something. Thanks in advance for taking the time to read this topic.

Veronica

= is an assignment. This assigns the value of true to the variable zone1. Use == for a comparison.

You want

if(zone1 == true)

That did it. Thank you very much. Silly thing is I knew that. Tired eyes I suppose.
Thanks,

Thanks. Please mark as the solution so the thread will be marked solved.

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