So as far as I know, from what I read on the IoT site, if you put your code under the Arduino cloud .update section of the sketch it should reflect. Why can I not get the widgets to reflect anything? I linked the variables to the widgets and still nothing.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/1bc1aa78-30b0-4260-bf67-8c0b7a5bc923
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int humidity;
int temperature;
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 "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F("DHT11 Test"));
dht.begin();
// 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();
delay(2000); //wait a few seconds between measurements//
int humidity = dht.readHumidity();
int temperature = dht.readTemperature();
int f = dht.readTemperature(true);
if (isnan(humidity) || isnan(temperature) || isnan(f)) {
Serial.println(F("Failed to read DHT sensor"));
return;
}
float hif = dht.computeHeatIndex(f,humidity); //comoute heat index in F//
float hic = dht.computeHeatIndex(temperature,humidity,false); //compute HI in C (isFarenheit = false)
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}
/*
Since Humidity is READ_WRITE variable, onHumidityChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHumidityChange() {
delay(2000);
int humidity = dht.readHumidity();
int temperature = dht.readTemperature();
int f = dht.readTemperature(true);
if (isnan(humidity) || isnan(temperature) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, humidity);
float hic = dht.computeHeatIndex(temperature, humidity, false);
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}
/*
Since Temperature is READ_WRITE variable, onTemperatureChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTemperatureChange() {
delay(2000);
int humidity = dht.readHumidity();
int temperature = dht.readTemperature();
int f = dht.readTemperature(true);
if (isnan(humidity) || isnan(temperature) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, humidity);
float hic = dht.computeHeatIndex(temperature, humidity, false);
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}