When I add vTaskDelay(3000 / portTICK_PERIOD_MS) it seems that the code reads the DHT sensor only once and then skips it (and also it skips the first, but not the second ESP_LOGI()). Where may be the problem? Should I file bug report? What other information should I provide?
Code without vTaskDelay, behaves as I expect: (I assume that E (607) dht: Initialization error, problem in phase 'B' is caused by too fast reading)
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "dht.h"
static const char *TAG = "MOLD-KILLER";
void app_main(void)
{
ESP_LOGI(TAG, "Starting main()");
float temperature = 0;
float humidity = 0;
esp_err_t result;
while (1)
{
result = dht_read_float_data(DHT_TYPE_DHT11, GPIO_NUM_5, &humidity, &temperature);
ESP_LOGI(TAG, "After DHT read, result=%s, temp=%.1f, hum=%.1f", esp_err_to_name(result), temperature, humidity);
}
}
--------------------
I (247) MOLD-KILLER: After DHT read, result=ESP_OK, temp=25.0, hum=69.0
E (607) dht: Initialization error, problem in phase 'B'
I (607) MOLD-KILLER: After DHT read, result=ESP_ERR_TIMEOUT, temp=25.0, hum=69.0
E (1257) dht: Initialization error, problem in phase 'B'
I (1257) MOLD-KILLER: After DHT read, result=ESP_ERR_TIMEOUT, temp=25.0, hum=69.0
...
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "dht.h"
static const char *TAG = "MOLD-KILLER";
void app_main(void)
{
ESP_LOGI(TAG, "Starting main()");
float temperature = 0;
float humidity = 0;
esp_err_t result;
while (1)
{
result = dht_read_float_data(DHT_TYPE_DHT11, GPIO_NUM_5, &humidity, &temperature);
ESP_LOGI(TAG, "After DHT read, result=%s, temp=%.1f, hum=%.1f", esp_err_to_name(result), temperature, humidity);
vTaskDelay(3000 / portTICK_PERIOD_MS);
ESP_LOGI(TAG, "After delay");
}
}
----------------
I (237) main_task: Calling app_main()
I (237) MOLD-KILLER: Starting main()
I (247) MOLD-KILLER: After DHT read, result=ESP_OK, temp=25.0, hum=69.0
I (1247) MOLD-KILLER: After delay
I (2267) MOLD-KILLER: After delay
I (3287) MOLD-KILLER: After delay
I (4307) MOLD-KILLER: After delay
I (5327) MOLD-KILLER: After delay