Getting Zero Values using IOT Cloud and DHT22

My board works fine in non-cloud mode. As soon as I go to the cloud, I get constant zeros for temp on the dashboard. I read in this forum that it could be a mixup in global vs. local variables, but my code declares a global (at least I think so). Any advice would be much appreciated.
Variable for temperature is temp used for both the code below and my Cloud Variable.

Code is below:

//Libraries
#include "DHT.h";

//Constants
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value

void setup()

{
Serial.begin( 9600);
dht.begin();
}

void loop()
{
//Read data and store it to variables hum and temp
hum= dht.readHumidity();
temp= dht.readTemperature(true);

// Print temp and humidity values to serial monitor
Serial.print(temp);
Serial.println(" Fahrenheit");
Serial.print(hum);
Serial.println("  Humidity");

delay(3000); //Delay 3 sec.

}

Your code is not setup to interface with the cloud.
In your setup, you are missing

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

you will also need to update it in your loop

 ArduinoCloud.update();

I would also wrap your complete code in the following manner, its hard to read from the OP.
Use code tags to format code for the forum

Take a look at this example about interfacing with Arduino IoT Cloud

I got it to work. Thanks for your suggestion.

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