/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/2ce65d48-e84c-4cc8-a648-70a66da00ce3
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int random_value;
bool led_switch;
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 <Arduino.h>
#include <HTTPClient.h>
#include <DHT.h>
#include <ESP32Servo.h>
#define DHTPIN 2
const int servoPin = 5;
Servo SERVO;
DHT dht(DHTPIN, DHT22);
const char* ssid = "Wokwi-GUEST";
const char* password = "";
HTTPClient client;
int LED=13;
void setup() {
dht.begin();
SERVO.attach(servoPin, 500, 2400);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid,password);
// Wait for connection
while(WiFi.status() != WL_CONNECTED) {
delay(500);
}
pinMode(LED, 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();
// Your code here
dHTt = dht.readTemperature();
dHTh = dht.readHumidity();
delay(500);
}
/*
Since LedSwitch is READ_WRITE variable, onLedSwitchChange() is
executed every time a new value is received from IoT Cloud.
*/
/*
Since DHTh is READ_WRITE variable, onDHThChange() is
executed every time a new value is received from IoT Cloud.
*/
void onDHThChange() {
// Add your code here to act upon DHTh change
dht.readHumidity(dHTh);
}
/*
Since DHTt is READ_WRITE variable, onDHTtChange() is
executed every time a new value is received from IoT Cloud.
*/
void onDHTtChange() {
// Add your code here to act upon DHTt change
dht.readTemperature(dHTt);
}
/*
Since Ledx is READ_WRITE variable, onLedxChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedxChange() {
// Add your code here to act upon Ledx change
digitalWrite(LED,ledx);
}
/*
Since Pwm is READ_WRITE variable, onPwmChange() is
executed every time a new value is received from IoT Cloud.
*/
void onPwmChange() {
// Add your code here to act upon Pwm change
analogWrite(14, pwm);
}
/*
Since Servo is READ_WRITE variable, onServoChange() is
executed every time a new value is received from IoT Cloud.
*/
void onServoChange() {
// Add your code here to act upon Servo change
SERVO.write(servo);
}