#include "thingProperties.h"
#include "WiFi.h"
#include "DHTesp.h"
DHTesp dht;
float valueTemperature;
float valueHumidity;
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);
pinMode(12, OUTPUT);
//pinMode(15, INPUT);
dht.setup(15, DHTesp::DHT22);
// 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
TempAndHumidity data = dht.getTempAndHumidity();
valueTemperature = data.temperature;
valueHumidity = data.humidity;
}
/*
Since VarREDLED is READ_WRITE variable, onVarREDLEDChange() is
executed every time a new value is received from IoT Cloud.
*/
void onVarREDLEDChange() {
// Add your code here to act upon VarREDLED change
if(var_REDLED==1){
digitalWrite(12, HIGH);
Serial.println("LED is on");
}
else{
digitalWrite(12, LOW);
Serial.println("LED is off");
}
}
void onHumidityChange() {
// Add your code here to act upon Humidity change
humidity = valueHumidity;
Serial.print("Humidity is: ");
Serial.println(humidity);
}
/*
Since Temperature is READ_WRITE variable, onTemperatureChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTemperatureChange() {
// Add your code here to act upon Temperature change
temperature = valueTemperature;
Serial.print("Temperature is: ");
Serial.println(temperature);
}