Initial commit

This commit is contained in:
Sven Luethi committed 2024-07-01 21:16:26 +02:00
commit 87e828962b
51 files changed
+34212

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "esp_wifi.h"
#include "esp_http_client.h"
#include <esp_err.h>
#include "dht.h"
#include "sensor.h"
#include "http_client.h"
#define DHT_GPIO 2 // D1 pin
void wifi_init(void) {
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
wifi_config_t sta_config = {
.sta = {
.ssid = CONFIG_ESP_WIFI_SSID,
.password = CONFIG_ESP_WIFI_PASSWORD,
},
};
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &sta_config));
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 Temperature: %d\n", humidity, temperature);
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);
}
void main_task(void* args) {
while (1)
{
hc_send_sensor_data(50,25);
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}
void app_main()
{
ESP_ERROR_CHECK(nvs_flash_init());
xTaskCreate(main_task, "main task", 2048, NULL, tskIDLE_PRIORITY, NULL);
// WIFI
wifi_init();
//hc_test();
}