// #include <gpio_viewer.h> // Must me the first include in your project
// GPIOViewer gpio_viewer;
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
#include <DHT.h>
#include <WiFi.h>
#include "time.h"
#ifndef LED_BUILTIN
#define LED_BUILTIN 2 // Specify the on which is your LED
#endif
// Sensor
#define DHTPIN 23 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT22
DHT dht(DHTPIN, DHTTYPE);
const char *ssid = "Wokwi-GUEST";
const char *password = "";
const char *ntpServer = "0.id.pool.ntp.org";
const long gmtOffset_sec = 25200;
const int daylightOffset_sec = 0;
// pins
const int LED1 = 18;
const int LED2 = 19;
const int LED3 = 21;
// Global value
int humidity_value = 0;
int temperature_value = 0;
// Define tasks.
TaskHandle_t TaskLed1;
TaskHandle_t TaskLed2;
TaskHandle_t TaskLed3;
TaskHandle_t TaskSensor;
void setup() {
Serial.begin(115200);
// Inspect our own high water mark on entering the task
UBaseType_t uxHighWaterMark;
uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);
Serial.print("HighWaterMark : ");
Serial.println(uxHighWaterMark);
// connect to WiFi
unsigned long StartTime = millis();
Serial.printf("Connecting to %s ", ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
WiFi.persistent(false);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print(" Connected: ");
Serial.println(WiFi.localIP());
unsigned long CurrentTime = millis();
unsigned long ElapsedTime = CurrentTime - StartTime;
Serial.print("Elapsed Time to Connect: ");
Serial.println(ElapsedTime);
// init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
// Set up tasks to run independently.
uint32_t blink_delay = 1000; // Delay between changing state on LED pin
xTaskCreate(
TaskBlink,
"Task Blink", // A name just for humans
2048, // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);`
(void *)&blink_delay, // Task parameter which can modify the task behavior. This must be passed as pointer to void.
3, // Priority
NULL); // Task handle is not used here - simply pass NULL
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
xTaskCreatePinnedToCore(
TaskLed1code, // Task function.
"TaskLed1", // name of task.
2048, // Stack size of task
NULL, // parameter of the task
1, // priority of the task
&TaskLed1, // Task handle to keep track of created task
CONFIG_ARDUINO_RUNNING_CORE); // Core on which the task will run
//0); // pin task to core 0
xTaskCreatePinnedToCore(
TaskLed2code, // Task function.
"TaskLed2", // name of task.
2048, // Stack size of task
NULL, // parameter of the task
1, // priority of the task
&TaskLed2, // Task handle to keep track of created task
CONFIG_ARDUINO_RUNNING_CORE); // Core on which the task will run
//1); // pin task to core 1
xTaskCreatePinnedToCore(
TaskLed3code, // Task function.
"TaskLed3", // name of task.
2048, // Stack size of task
NULL, // parameter of the task
1, // priority of the task
&TaskLed3, // Task handle to keep track of created task
CONFIG_ARDUINO_RUNNING_CORE); // Core on which the task will run
xTaskCreatePinnedToCore(
TaskSensorcode, // Task function.
"TaskSensor", // name of task.
2048, // Stack size of task
NULL, // parameter of the task
6, // priority of the task
&TaskSensor, // Task handle to keep track of created task
CONFIG_ARDUINO_RUNNING_CORE); // Core on which the task will run
//gpio_viewer.begin();
}
void loop() {
}