From 49cf49db875a424d57823ae975162ff487f134be Mon Sep 17 00:00:00 2001 From: Erick Ahmed Date: Sat, 29 Nov 2025 14:13:18 +0100 Subject: [PATCH] Create boilerplate for task - To change even group - To create i2c_read and i2c_write functions --- firmware/esp32/main/i2c.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/firmware/esp32/main/i2c.cpp b/firmware/esp32/main/i2c.cpp index c61c17d..9573042 100644 --- a/firmware/esp32/main/i2c.cpp +++ b/firmware/esp32/main/i2c.cpp @@ -45,18 +45,22 @@ static void i2c_init(void) { register_slave(0x30); } -void i2c_read() {} -void i2c_write() {} +static void i2c_read() {} //should read from i2c and if necessary call i2c_write +static void i2c_write() {} void i2cTask(void *pvParameters) { ESP_LOGI(TAG, "Task started"); i2c_init(); for(;;) { - // first thing: check evengroup for wifi and/or mqqt if tre continue - // Logic: - // avr will talk only if spoken by esp32 - // so keep reading from mqtt (mqtt.cpp): - // if get told from mqtt to read/write from/to avr -> i2c_write() -> loop i2c_read() until get response -> if needed mqtt_respond() + // TODO: this should check for MQTT connection (which in turn checks for WI-FI) + ESP_LOGI(TAG, "Checking Wi-Fi connection..."); + xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT, pdFALSE, pdTRUE, portMAX_DELAY); + + if (bits & WIFI_CONNECTED_BIT) i2c_read(); + + ESP_ERROR_CHECK(esp_task_wdt_reset()); + ESP_LOGI(TAG, "Task reset"); + vTaskDelay(pdMS_TO_TICKS(2000)); } }