// Core 1 è il Core principale utilizzato per default da Setup(), Loop() e ogni altra funzione inserita.
// Core 0 è il Core secondario utilizzato per funzione di sistema che gestiscono WIFI, Bluetooth, ecc.
// Usare Core 0 per funzioni inerenti alla comunicazione wireless che potrebbe avere tempi di attesa
// Usare Core 1 per funzioni che non devono essere ritardate. Tali funzioni non devono avere parti bloccanti
// Task Priority 0 is the lowest, Task Priority 10 is the highest
#define BLYNK_TEMPLATE_ID "TMPL4GiOo7vle"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "1dUEP6bicHzI4FoKNQIYM0fNip2hHjmW"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; //nama hotspot yang digunakan
char pass[] = ""; //password hotspot yang digunakan
#define DHTPIN 26 // Mention the digital pin where you connected
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
float humidity;
float temperature;
const int LED_GREEN = 19;
const int LED_BLU = 4;
const int LED_RED = 2;
TaskHandle_t Task1;
TaskHandle_t Task2;
void setup()
{
Serial.begin(115200);
//Blynk.begin(auth, ssid, pass);
dht.begin();
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLU, OUTPUT);
pinMode(LED_RED, OUTPUT);
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLU, LOW);
digitalWrite(LED_RED, LOW);
xTaskCreatePinnedToCore
(
Task1code, /* Function to implement the task */
"Task1", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
0, /* Priority of the task */
&Task1, /* Task handle. */
1 /* Core where the task should run */
); /* Core where the task should run */
xTaskCreatePinnedToCore
(
Task2code, /* Function to implement the task */
"Task2", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
0, /* Priority of the task */
&Task2, /* Task handle. */
1 /* Core where the task should run */
); /* Core where the task should run */
Serial.println("End of setup");
}
void Task1code(void *arg)
{
int led_status = 0;
for (;;)
{
//humidity = dht.readHumidity();
//temperature = dht.readTemperature();
if (led_status == 0)
{
digitalWrite(LED_RED, HIGH);
led_status = 1;
}
else
{
digitalWrite(LED_RED, LOW);
led_status = 0;
}
Serial.println("Task1");
vTaskDelay(pdMS_TO_TICKS(5000));
}
}
void Task2code(void *arg)
{
int led_status = 0;
for (;;)
{
//Blynk.virtualWrite(V1, humidity);
//Blynk.virtualWrite(V0, temperature);
Serial.print("Temperature : ");
Serial.print(temperature);
Serial.print(" Humidity : ");
Serial.println(humidity);
if(temperature > 30)
{
Blynk.logEvent("temp_alert","Temp above 30 degrees");
}
if (led_status == 0)
{
digitalWrite(LED_BLU, HIGH);
led_status = 1;
}
else
{
digitalWrite(LED_BLU, LOW);
led_status = 0;
}
vTaskDelay(pdMS_TO_TICKS(10000));
}
}
void loop()
{
//Blynk.run();
//timer.run();
}