modified: Makefile
deleted: main/include/dht.h new file: main/include/leds.h modified: main/include/sensor.h deleted: main/src/dht.c new file: main/src/leds.c modified: main/src/main.c modified: main/src/sensor.c
This commit is contained in:
1 parent
ccc6e72ea7
commit
9bd0883aeb
8 files changed
+66
-346
No files matched your search
@@ -9,15 +9,14 @@
|
||||
|
||||
#include <esp_err.h>
|
||||
|
||||
#include "dht.h"
|
||||
#include "leds.h"
|
||||
#include "sensor.h"
|
||||
#include "http_client.h"
|
||||
|
||||
#define DHT_GPIO 2 // D1 pin
|
||||
|
||||
const char * TAG = "main.c";
|
||||
static const char * TAG = "main.c";
|
||||
|
||||
void wifi_init(void) {
|
||||
static void wifi_init(void) {
|
||||
tcpip_adapter_init();
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
@@ -33,63 +32,12 @@ void wifi_init(void) {
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
}
|
||||
/*
|
||||
void temperature_task(void *arg)
|
||||
{
|
||||
ESP_ERROR_CHECK(dht_init(DHT_GPIO, false));
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
while (1)
|
||||
{
|
||||
int16_t humidity = 0;
|
||||
int16_t temperature = 0;
|
||||
if (dht_read_data(DHT_TYPE_DHT22, DHT_GPIO, &humidity, &temperature) == ESP_OK) {
|
||||
// e.g. in dht22, 604 = 60.4%, 252 = 25.2 C
|
||||
// If you want to print float data, you should run `make menuconfig`
|
||||
// to enable full newlib and call dht_read_float_data() here instead
|
||||
printf("Humidity: %d.%d%% Temperature: %d.%d\n", humidity/10, humidity%10, temperature/10,temperature%10);
|
||||
} else {
|
||||
printf("Fail to get dht temperature data\n");
|
||||
}
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
*/
|
||||
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#define LED1 GPIO_NUM_4
|
||||
#define LED2 GPIO_NUM_5
|
||||
|
||||
void blink_task(void *pvParameter)
|
||||
{
|
||||
gpio_set_direction(LED1,GPIO_MODE_OUTPUT);
|
||||
gpio_set_direction(LED2,GPIO_MODE_OUTPUT);
|
||||
|
||||
while (1) {
|
||||
ESP_LOGI(TAG, "Blink LEDs...");
|
||||
// Blink the LEDs
|
||||
gpio_set_level(LED1, 0);
|
||||
gpio_set_level(LED2, 0);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
gpio_set_level(LED1, 0);
|
||||
gpio_set_level(LED2, 1);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
gpio_set_level(LED1, 1);
|
||||
gpio_set_level(LED2, 0);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
gpio_set_level(LED1, 1);
|
||||
gpio_set_level(LED2, 1);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void main_task(void* args) {
|
||||
float humidity = 0;
|
||||
float temperature = 0;
|
||||
|
||||
ESP_ERROR_CHECK(dht_init(DHT_GPIO, false));
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
//Register device with Server
|
||||
unsigned id;
|
||||
@@ -97,15 +45,6 @@ void main_task(void* args) {
|
||||
while (1)
|
||||
{
|
||||
hc_send_sensor_data(id,0,0); //test
|
||||
/*
|
||||
if (dht_read_float_data(DHT_TYPE_DHT22, DHT_GPIO, &humidity, &temperature) == ESP_OK) {
|
||||
hc_send_sensor_data(id,humidity,temperature);
|
||||
}
|
||||
else {
|
||||
printf("Fail to get dht temperature data\n");
|
||||
}
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +53,6 @@ void app_main()
|
||||
//ESP_ERROR_CHECK(nvs_flash_init());
|
||||
|
||||
//wifi_init();
|
||||
xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
|
||||
xTaskCreate(&led_blink_task, "led_blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
|
||||
//xTaskCreate(main_task, "main task", 2048, NULL, tskIDLE_PRIORITY, NULL);
|
||||
}
|
||||
Reference in new issue
Block a user