/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/9096b579-fb96-4476-be78-0605ac7da00a
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudTemperatureSensor temperatura;
bool encendido_de_led;
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.
*/
int led_pin = 2;
//#define DHTTYPE DHT22
#include "DHTesp.h"
#include "thingProperties.h"
#include "DHT.h"
const int DHT_PIN = 15;
//DHT dht(4, DHTTYPE, 22);
DHTesp dhtSensor;
void setup() {
//dht.begin();
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(2, OUTPUT);
// 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);
// 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();
TempAndHumidity data = dhtSensor.getTempAndHumidity();
temperatura = data.temperature;
}
/*
Since EncendidoDeLed is READ_WRITE variable, onEncendidoDeLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onEncendidoDeLedChange() {
// Add your code here to act upon EncendidoDeLed change
if (encendido_de_led){
digitalWrite(led_pin, HIGH);
}
else {
digitalWrite(led_pin, LOW);
}
}
void onTemperaturaChange() {
// Add your code here to act upon Temperatura change
TempAndHumidity data = dhtSensor.getTempAndHumidity();
temperatura = data.temperature;
}