i2c fixes + server improvements
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
#include <freertos/task.h>
|
||||
#include <esp_system.h>
|
||||
#include <esp_timer.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_http_server.h"
|
||||
#include "i2cdev.h"
|
||||
|
||||
#include "ygg_http_server.h"
|
||||
#include "ygg_http_routes.h"
|
||||
@@ -15,6 +17,7 @@
|
||||
#include "ygg_http_req.h"
|
||||
#include "ygg_state.h"
|
||||
#include "ygg_sh1106.h"
|
||||
#include "ygg_lock.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
|
||||
@@ -25,7 +28,10 @@ bmp280_t dev_bmp_280;
|
||||
|
||||
void lvgl_task(void *pvParameters) {
|
||||
while (1) {
|
||||
lv_timer_handler();
|
||||
if (ygg_lvgl_lock_take(pdMS_TO_TICKS(100))) {
|
||||
lv_timer_handler();
|
||||
ygg_lvgl_lock_give();
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
@@ -34,19 +40,31 @@ void sensor_task(void *pvParameters) {
|
||||
// Wait 1s, to avoid corrupted first sensor readout
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
while (1) {
|
||||
ygg_bmp280_read_sensor(&dev_bmp_280);
|
||||
esp_err_t err = ygg_bmp280_read_sensor(&dev_bmp_280);
|
||||
// Najpierw OLED, potem (blokujący) HTTP — żeby ekran
|
||||
// odświeżył się nawet gdy serwer nie odpowiada.
|
||||
// ygg_bmp280_read_sensor() aktualizuje CURR_READOUT TYLKO przy
|
||||
// sukcesie, więc przy błędzie pokazujemy ostatnie dobre + ERR
|
||||
// i NIE wysyłamy śmieci do bazy.
|
||||
char buf[256];
|
||||
snprintf(buf, sizeof(buf), "Temp: %.1f C\nHumid: %.1f %%\nPress: %.1f hPa",
|
||||
CURR_READOUT.temperature,
|
||||
CURR_READOUT.humidity,
|
||||
CURR_READOUT.pressure / 100.);
|
||||
ygg_set_display_label(sh_display, label, buf);
|
||||
ygg_send_sensor_readouts(BASE_URL,
|
||||
SENSOR_NAME,
|
||||
CURR_READOUT);
|
||||
vTaskDelay(pdMS_TO_TICKS(10000));
|
||||
if (err == ESP_OK) {
|
||||
snprintf(buf, sizeof(buf), "Temp: %.1f C\nHumid: %.1f %%\nPress: %.1f hPa",
|
||||
CURR_READOUT.temperature,
|
||||
CURR_READOUT.humidity,
|
||||
CURR_READOUT.pressure / 100.);
|
||||
ygg_set_display_label(sh_display, label, buf);
|
||||
ygg_send_sensor_readouts(BASE_URL,
|
||||
SENSOR_NAME,
|
||||
CURR_READOUT);
|
||||
} else {
|
||||
snprintf(buf, sizeof(buf), "SENSOR ERR\nTemp: %.1f C\nHumid: %.1f %%\nPress: %.1f hPa",
|
||||
CURR_READOUT.temperature,
|
||||
CURR_READOUT.humidity,
|
||||
CURR_READOUT.pressure / 100.);
|
||||
ygg_set_display_label(sh_display, label, buf);
|
||||
ESP_LOGW(TAG, "skipping HTTP POST, keeping last good readout");
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(60 * 1000));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +95,12 @@ void app_main()
|
||||
httpd_register_uri_handler(server, &ygg_press_uri);
|
||||
httpd_register_uri_handler(server, &ygg_hum_uri);
|
||||
|
||||
// Jedna centralna inicjalizacja: mutexy + magistrala I2C.
|
||||
// Wcześniej i2cdev_init() był wołany w obu ygg_*_init() + bus był
|
||||
// tworzony przez dummy-device OLED, co mieszało.
|
||||
ygg_lock_init();
|
||||
ESP_ERROR_CHECK(i2cdev_init());
|
||||
|
||||
sh_display = ygg_sh1106_init();
|
||||
|
||||
lv_obj_t *scr = lv_display_get_screen_active(sh_display);
|
||||
|
||||
Reference in New Issue
Block a user