2016-04-20 22:03:18 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* This sample code is in the public domain.
|
|
|
|
*/
|
2016-07-06 12:57:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-04-20 22:03:18 +00:00
|
|
|
#include "espressif/esp_common.h"
|
|
|
|
#include "esp/uart.h"
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
2016-10-26 13:41:08 +00:00
|
|
|
#include <dht/dht.h>
|
2016-04-20 22:03:18 +00:00
|
|
|
#include "esp8266.h"
|
|
|
|
|
|
|
|
/* An example using the ubiquitous DHT** humidity sensors
|
|
|
|
* to read and print a new temperature and humidity measurement
|
|
|
|
* from a sensor attached to GPIO pin 4.
|
|
|
|
*/
|
2016-07-06 18:01:44 +00:00
|
|
|
uint8_t const dht_gpio = 4;
|
2016-10-26 13:41:08 +00:00
|
|
|
const dht_sensor_type_t sensor_type = DHT_TYPE_DHT22;
|
2016-04-20 22:03:18 +00:00
|
|
|
|
|
|
|
void dhtMeasurementTask(void *pvParameters)
|
|
|
|
{
|
2016-07-06 12:57:00 +00:00
|
|
|
int16_t temperature = 0;
|
|
|
|
int16_t humidity = 0;
|
|
|
|
|
|
|
|
// DHT sensors that come mounted on a PCB generally have
|
|
|
|
// pull-up resistors on the data pin. It is recommended
|
|
|
|
// to provide an external pull-up resistor otherwise...
|
|
|
|
gpio_set_pullup(dht_gpio, false, false);
|
|
|
|
|
|
|
|
while(1) {
|
2016-10-26 13:41:08 +00:00
|
|
|
if (dht_read_data(sensor_type, dht_gpio, &humidity, &temperature)) {
|
2016-07-06 18:01:44 +00:00
|
|
|
printf("Humidity: %d%% Temp: %dC\n",
|
|
|
|
humidity / 10,
|
|
|
|
temperature / 10);
|
2016-07-06 12:57:00 +00:00
|
|
|
} else {
|
|
|
|
printf("Could not read data from sensor\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Three second delay...
|
2016-11-05 10:04:03 +00:00
|
|
|
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
2016-04-20 22:03:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void user_init(void)
|
|
|
|
{
|
|
|
|
uart_set_baud(0, 115200);
|
2016-10-21 09:40:36 +00:00
|
|
|
xTaskCreate(dhtMeasurementTask, "dhtMeasurementTask", 256, NULL, 2, NULL);
|
2016-04-20 22:03:18 +00:00
|
|
|
}
|
|
|
|
|