refactor
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(thermo-sensor)
|
||||
@@ -0,0 +1,77 @@
|
||||
dependencies:
|
||||
esp-idf-lib/bmp280:
|
||||
component_hash: 82b01a37c200ed66a6c451026e2afdbe8046c6f702d41085e5a1d83aec3a90d8
|
||||
dependencies:
|
||||
- name: esp-idf-lib/esp_idf_lib_helpers
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '*'
|
||||
- name: esp-idf-lib/i2cdev
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '*'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
targets:
|
||||
- esp32
|
||||
- esp32c2
|
||||
- esp32c3
|
||||
- esp32c5
|
||||
- esp32c6
|
||||
- esp32c61
|
||||
- esp32h2
|
||||
- esp32p4
|
||||
- esp32s2
|
||||
- esp32s3
|
||||
version: 1.0.7
|
||||
esp-idf-lib/esp_idf_lib_helpers:
|
||||
component_hash: 689853bb8993434f9556af0f2816e808bf77b5d22100144b21f3519993daf237
|
||||
dependencies: []
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
targets:
|
||||
- esp32
|
||||
- esp32c2
|
||||
- esp32c3
|
||||
- esp32c5
|
||||
- esp32c6
|
||||
- esp32c61
|
||||
- esp32h2
|
||||
- esp32p4
|
||||
- esp32s2
|
||||
- esp32s3
|
||||
version: 1.4.0
|
||||
esp-idf-lib/i2cdev:
|
||||
component_hash: ad8981cc64533dcaced5107d72e42bcebe79345e194e82795792af531b300ce3
|
||||
dependencies:
|
||||
- name: esp-idf-lib/esp_idf_lib_helpers
|
||||
registry_url: https://components.espressif.com
|
||||
require: private
|
||||
version: '*'
|
||||
source:
|
||||
registry_url: https://components.espressif.com
|
||||
type: service
|
||||
targets:
|
||||
- esp32
|
||||
- esp32c2
|
||||
- esp32c3
|
||||
- esp32c5
|
||||
- esp32c6
|
||||
- esp32c61
|
||||
- esp32h2
|
||||
- esp32p4
|
||||
- esp32s2
|
||||
- esp32s3
|
||||
version: 2.1.2
|
||||
idf:
|
||||
source:
|
||||
type: idf
|
||||
version: 6.1.0
|
||||
direct_dependencies:
|
||||
- esp-idf-lib/bmp280
|
||||
- idf
|
||||
manifest_hash: e9139083c387eac863d68b0a593ed1c2631dc643670305c76e9d8ac18ee8f285
|
||||
target: esp32
|
||||
version: 3.0.0
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "thermo_sensor.c" "ygg_http_routes.c" "ygg_bmp280.c" "../../common/esp32/ygg_wifi.c" "../../common/esp32/ygg_http_server.c"
|
||||
INCLUDE_DIRS "." "../../common/esp32")
|
||||
@@ -0,0 +1,17 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: '>=4.1.0'
|
||||
# # Put list of dependencies here
|
||||
# # For components maintained by Espressif:
|
||||
# component: "~1.0.0"
|
||||
# # For 3rd party components:
|
||||
# username/component: ">=1.0.0,<2.0.0"
|
||||
# username2/component2:
|
||||
# version: "~1.0.0"
|
||||
# # For transient dependencies `public` flag can be set.
|
||||
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||
# # All dependencies of `main` are public by default.
|
||||
# public: true
|
||||
esp-idf-lib/bmp280: '*'
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <esp_system.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_http_server.h"
|
||||
|
||||
#include "ygg_http_server.h"
|
||||
#include "ygg_http_routes.h"
|
||||
#include "ygg_wifi.h"
|
||||
#include "ygg_http_server.h"
|
||||
#include "ygg_bmp280.h"
|
||||
|
||||
|
||||
static const char *TAG = "thermo_sensor";
|
||||
float last_temperature = 0.0f;
|
||||
bmp280_t dev_bmp_280;
|
||||
|
||||
void main_loop(void *pvParameters) {
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
ygg_bmp280_read_sensor(&dev_bmp_280);
|
||||
}
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
wifi_init_sta();
|
||||
|
||||
httpd_handle_t server = ygg_start_webserver();
|
||||
httpd_register_uri_handler(server, &ygg_temp_uri);
|
||||
|
||||
ESP_ERROR_CHECK(i2cdev_init());
|
||||
ygg_bmp280_init(&dev_bmp_280);
|
||||
xTaskCreatePinnedToCore(main_loop, "bmp280_test", configMINIMAL_STACK_SIZE * 8, NULL, 5, NULL, APP_CPU_NUM);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <bmp280.h>
|
||||
#include "ygg_bmp280.h"
|
||||
|
||||
extern float last_temperature;
|
||||
|
||||
void ygg_bmp280_init(bmp280_t *dev) {
|
||||
bmp280_params_t params;
|
||||
bmp280_init_default_params(¶ms);
|
||||
memset(dev, 0, sizeof(bmp280_t));
|
||||
|
||||
ESP_ERROR_CHECK(bmp280_init_desc(dev, BMP280_I2C_ADDRESS_0, 0, I2C_MASTER_SDA, I2C_MASTER_SCL));
|
||||
ESP_ERROR_CHECK(bmp280_init(dev, ¶ms));
|
||||
|
||||
bool bme280p = dev->id == BME280_CHIP_ID;
|
||||
printf("BMP280: found %s\n", bme280p ? "BME280" : "BMP280");
|
||||
}
|
||||
|
||||
void ygg_bmp280_read_sensor(bmp280_t *dev) {
|
||||
float pressure, temperature, humidity;
|
||||
bool bme280p = dev->id == BME280_CHIP_ID;
|
||||
|
||||
if (bmp280_read_float(dev, &temperature, &pressure, &humidity) != ESP_OK)
|
||||
printf("Temperature/pressure reading failed\n");
|
||||
|
||||
last_temperature = temperature;
|
||||
printf("Pressure: %.2f Pa, Temperature: %.2f C", pressure, temperature);
|
||||
if (bme280p)
|
||||
printf(", Humidity: %.2f\n", humidity);
|
||||
else
|
||||
printf("\n");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef YGG_BMP280_H
|
||||
#define YGG_BMP280_H
|
||||
|
||||
#include <bmp280.h>
|
||||
|
||||
#define I2C_MASTER_SDA 19
|
||||
#define I2C_MASTER_SCL 23
|
||||
|
||||
void ygg_bmp280_init(bmp280_t *dev);
|
||||
void ygg_bmp280_read_sensor(bmp280_t *dev);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "esp_http_server.h"
|
||||
#include "ygg_http_routes.h"
|
||||
|
||||
extern float last_temperature;
|
||||
|
||||
esp_err_t ygg_get_temp_handler(httpd_req_t *req)
|
||||
{
|
||||
float current_temp = last_temperature;
|
||||
char response_json[64];
|
||||
snprintf(response_json, sizeof(response_json), "{\"temperature\": %.1f}", current_temp);
|
||||
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
|
||||
httpd_resp_send(req, response_json, HTTPD_RESP_USE_STRLEN);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
const httpd_uri_t ygg_temp_uri = {
|
||||
.uri = "/temp",
|
||||
.method = HTTP_GET,
|
||||
.handler = ygg_get_temp_handler,
|
||||
.user_ctx = NULL
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef HTTP_ROUTES_H
|
||||
#define HTTP_ROUTES_H
|
||||
|
||||
esp_err_t ygg_get_temp_handler(httpd_req_t *req);
|
||||
|
||||
extern const httpd_uri_t ygg_temp_uri;
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user