Hi everyone, so today I’ve decided to create a device which I will monitor my room temperature with when I’m not home. I had an NodeMCU V1 ESP8266 and a DHT22 laying around from previous projects, so I decided to use them both and created a simple temperature sensor, which sends the temperature data to blynk server via virtual pin. I need to admit that I know nearly nothing about programming, so I created the code with the help of AI (Please be understanding). Here it is:
#define BLYNK_TEMPLATE_NAME "Czujnik Temperatury"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
// Ustawienia sieci WiFi
char auth[] = "pmUJZUYw_***********************"; // Tutaj wprowadź swój Auth Token z aplikacji Blynk
char ssid[] = "Veganet_Internet";
char pass[] = "******";
// Ustawienia czujnika DHT22
#define DHTPIN D1 // Pin, do którego jest podłączony czujnik DHT22
#define DHTTYPE DHT22 // Typ czujnika DHT
DHT dht(DHTPIN, DHTTYPE);
// Liczba pomiarów do wykonania w ciągu 1 minuty
#define NUM_READINGS 6
// Interwał pomiędzy pomiarami (w sekundach)
#define MEASUREMENT_INTERVAL 10
// Deklaracja obiektu Blynk
BlynkTimer timer;
// Tablica przechowująca wyniki pomiarów
float readings[NUM_READINGS];
// Licznik wykonanych pomiarów
int readingsCounter = 0;
// Funkcja do wykonywania pomiarów co 10 sekund
void takeMeasurement()
{
float temperature = dht.readTemperature(); // Odczytaj temperaturę z czujnika
// Sprawdź, czy odczytano poprawnie temperaturę
if (!isnan(temperature))
{
Serial.print("Odczytano temperaturę: ");
Serial.println(temperature);
readings[readingsCounter] = temperature;
readingsCounter++;
}
else
{
Serial.println("Błąd odczytu temperatury!");
}
// Jeśli wykonano wystarczającą liczbę pomiarów, oblicz średnią i wyślij do Blynk
if (readingsCounter >= NUM_READINGS)
{
Serial.println("Zbieranie danych zakończone.");
float sum = 0;
for (int i = 0; i < NUM_READINGS; i++)
{
sum += readings[i];
}
float average = sum / NUM_READINGS;
Serial.print("Średnia temperatura: ");
Serial.println(average);
Blynk.virtualWrite(V5, average); // Wyślij średnią temperaturę do serwera Blynk
delay(200); // Dodaj opóźnienie przed deep sleep
// Wyzeruj licznik i tablicę pomiarów
readingsCounter = 0;
memset(readings, 0, sizeof(readings));
delay(200);
// Po wysłaniu danych, wchodzimy w tryb deep sleep na 2 minuty
Serial.println("Wejście w tryb Deep Sleep...");
ESP.deepSleep(2e6 * 60); // 2 minuty w mikrosekundach
}
}
void setup()
{
// Inicjalizacja portu szeregowego
Serial.begin(9600);
Serial.println("Inicjalizacja...");
// Inicjalizacja czujnika DHT
dht.begin();
// Połączenie z siecią WiFi
Blynk.begin(auth, ssid, pass);
delay(100); // Dodaj opóźnienie przed rozpoczęciem pomiarów
// Ustawienie interwału dla funkcji takeMeasurement
timer.setInterval(MEASUREMENT_INTERVAL * 1000, takeMeasurement);
}
void loop()
{
Blynk.run();
timer.run();
}
Believe me or not, but the code was working (and probbably is still working) perfectly fine, Every temperature measurement was succesfully sent to the Blynk server and it was showing correctly on the SuperChart. A Few hours go by, and the SuperChart stopped showing historical data, while the gauge is still working. I haven’t made any changes to the code in these few hours, only thing I Changed is the Decimal value on the Blynk app on android to show more accurate measurements, but it wasn’t simultaneous. Here is the photo of the chart on the Web Dashboard:
I don’t remember the version of the blynk libraries, but i remember the moment Arduino IDE decided to update the libraries to the latest versions, so they are most likely latest, if it will be crucial, i will provide the current version. Also if more info is needed, I will try to provide it too.
I don’t know what the issue could be, so any help would be highly appreciated!