new file: main/include/functions.h
modified: main/include/sht31.h renamed: main/include/lib.h -> main/src/functions.c modified: main/src/http_client.c modified: main/src/main.c modified: main/src/sht31.c
This commit is contained in:
1 parent
1341a1000a
commit
f4436308dc
6 files changed
+53
-60
No files matched your search
+22
-20
@@ -4,6 +4,7 @@
|
||||
//#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <esp_log.h>
|
||||
#include "functions.h"
|
||||
|
||||
#define SDA_PIN GPIO_NUM_2
|
||||
#define CLK_PIN GPIO_NUM_14
|
||||
@@ -24,6 +25,27 @@ static const i2c_config_t config = {
|
||||
.clk_stretch_tick = 5
|
||||
};
|
||||
|
||||
void sht31_sensor_test_task(void *pvParameters)
|
||||
{
|
||||
ESP_ERROR_CHECK(sht31_init());
|
||||
|
||||
//float temperature, humidity;
|
||||
float temperature, humidity, temp_dec_part, hum_dec_part;
|
||||
int temp_int_part, hum_int_part;
|
||||
|
||||
while (1) {
|
||||
if (sht31_read_temp_hum(&temperature, &humidity) == ESP_OK) {
|
||||
split_float(temperature, &temp_int_part, &temp_dec_part);
|
||||
split_float(humidity, &hum_int_part, &hum_dec_part);
|
||||
//ESP_LOGI(TAG, "Temperature: %.2f°C, Humidity: %.2f%%", temperature, humidity);
|
||||
ESP_LOGI(TAG, "Temperature: %i.%i°C, Humidity: %i.%i%%", temp_int_part, (int)(temp_dec_part*1000), hum_int_part, (int)(hum_dec_part*1000));
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to read from SHT31 sensor");
|
||||
}
|
||||
vTaskDelay(2000 / portTICK_RATE_MS);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to initialize the sensor
|
||||
esp_err_t sht31_init(void) {
|
||||
esp_err_t install_rc = i2c_driver_install(I2C_NUM_0, config.mode);
|
||||
@@ -36,26 +58,6 @@ esp_err_t sht31_init(void) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// Function to get the current humidity level
|
||||
// Returns the humidity as a percentage (0-100)
|
||||
float sht31_get_humidity(void) {
|
||||
// Read humidity data from the sensor
|
||||
// This is a dummy value for the purpose of this example
|
||||
float humidity = 50.0; // Replace with actual sensor reading
|
||||
printf("Humidity read: %.2f%%\n", humidity);
|
||||
return humidity;
|
||||
}
|
||||
|
||||
// Function to get the current temperature
|
||||
// Returns the temperature in degrees Celsius
|
||||
float sht31_get_temperature(void) {
|
||||
// Read temperature data from the sensor
|
||||
// This is a dummy value for the purpose of this example
|
||||
float temperature = 22.0; // Replace with actual sensor reading
|
||||
printf("Temperature read: %.2f°C\n", temperature);
|
||||
return temperature;
|
||||
}
|
||||
|
||||
esp_err_t sht31_read_temp_hum(float *temperature, float *humidity)
|
||||
{
|
||||
uint8_t data[6];
|
||||
|
||||
Reference in new issue
Block a user