 
 void getSensorData()
 {
-	dht.temperature().getEvent(&sensorTemperature);
-	dht.humidity().getEvent(&sensorHumidity);
+	sensors_event_t localTemperature;
+	sensors_event_t localHumidity;
+	dht.temperature().getEvent(&localTemperature);
+	dht.humidity().getEvent(&localHumidity);
+	if (isnan(localTemperature.temperature) || isnan(localHumidity.relative_humidity))
+	{
+		DEBUG_PRINTLN("Error reading temperature or humidity!");
+		lastCollectionOk = false;
+	} else
+	{
+		DEBUG_PRINT("Temperature: ");
+		DEBUG_PRINT(localTemperature.temperature);
+		DEBUG_PRINT("°C , Humidity: ");
+		DEBUG_PRINT(localHumidity.relative_humidity);
+		DEBUG_PRINTLN("%");
+		sensorTemperature[sampleIndex] = localTemperature.temperature;
+		sensorHumidity[sampleIndex]    = localHumidity.relative_humidity;
+		sampleIndex                    = (sampleIndex + 1) % NUM_LAST_SAMPLES;
+		lastCollectionOk               = true;
+	}
 }
 
 void postData()
 {
-	postStatus = false;
+	lastPostOk = false;
 
 	if (!wifiClient.connect(API_HOSTNAME, API_PORT))
 	{

	drawScreen();

	synchronizeTime();
#if !defined(API_NO_HTTPS)
	wifiClientSecure.setCACert_P(LECertRoot, LECertRootSize);
#endif
}

extern "C" void esp_schedule();

DHT_Unified                            dht(DHTPIN, DHTTYPE);
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);

unsigned long lastButtonPressed                   = 0;
bool          displayOn                           = true;
float         sensorTemperature[NUM_LAST_SAMPLES] = { 0 };
float         sensorHumidity[NUM_LAST_SAMPLES]    = { 0 };
unsigned int  sampleIndex                         = 0;
bool          lastCollectionOk                    = false;
bool          lastPostOk                          = false;

void synchronizeTime()
{
