mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-11-23 09:50:22 +00:00
temp sensor
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
#include "driver/temperature_sensor.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
|
||||||
|
static temperature_sensor_handle_t temp_sensor;
|
||||||
|
const char *TAGt = "ESP-NOW_Transmitter";
|
||||||
|
|
||||||
|
/*
|
||||||
|
EXP32-C3 Chip built-in temprature sensor
|
||||||
|
Read & display the temperature value
|
||||||
|
*/
|
||||||
|
static void temp_sensor_task (void *arg) {
|
||||||
|
while (true) {
|
||||||
|
ESP_LOGI(TAGt, "Reading sensor temperature");
|
||||||
|
float tsens_value;
|
||||||
|
ESP_ERROR_CHECK(temperature_sensor_get_celsius(temp_sensor, &tsens_value));
|
||||||
|
ESP_LOGW(TAGt, "Temperature value %.02f ℃", tsens_value);
|
||||||
|
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void chip_sensor_init () {
|
||||||
|
temp_sensor = NULL;
|
||||||
|
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50);
|
||||||
|
ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor_config, &temp_sensor));
|
||||||
|
|
||||||
|
ESP_LOGI(TAGt, "Enable temperature sensor");
|
||||||
|
ESP_ERROR_CHECK(temperature_sensor_enable(temp_sensor));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user