Initialize MQTT task
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
idf_component_register(SRCS "./main.cpp"
|
idf_component_register(SRCS "./main.cpp"
|
||||||
"./wifi.cpp"
|
"./wifi.cpp"
|
||||||
|
"./mqtt.cpp"
|
||||||
INCLUDE_DIRS "../include"
|
INCLUDE_DIRS "../include"
|
||||||
REQUIRES esp_wifi
|
REQUIRES esp_wifi
|
||||||
nvs_flash
|
nvs_flash
|
||||||
@@ -7,4 +8,5 @@ idf_component_register(SRCS "./main.cpp"
|
|||||||
esp_hw_support
|
esp_hw_support
|
||||||
esp_system
|
esp_system
|
||||||
freertos
|
freertos
|
||||||
log)
|
log
|
||||||
|
mqtt_client)
|
||||||
|
|||||||
@@ -48,4 +48,5 @@ extern "C" void app_main(void)
|
|||||||
|
|
||||||
xTaskCreate(watchdogTask, "watchdogs", 2048, NULL, configMAX_PRIORITIES-1, NULL);
|
xTaskCreate(watchdogTask, "watchdogs", 2048, NULL, configMAX_PRIORITIES-1, NULL);
|
||||||
xTaskCreate(wifiTask, "wifi", 4096, NULL, configMAX_PRIORITIES-4, NULL);
|
xTaskCreate(wifiTask, "wifi", 4096, NULL, configMAX_PRIORITIES-4, NULL);
|
||||||
|
xTaskCreate(wifiTask, "mqtt", 2048, NULL, configMAX_PRIORITIES-8, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/event_groups.h"
|
||||||
|
#include "esp_task_wdt.h"
|
||||||
|
#include "esp_event.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "mqtt_client.h"
|
||||||
|
#include "main.hpp"
|
||||||
|
|
||||||
|
static const char* TAG = "MQTT";
|
||||||
|
|
||||||
|
static void mqtt_init(void) {}
|
||||||
|
|
||||||
|
static void mqtt_publish(void) {}
|
||||||
|
|
||||||
|
void mqttTask(void *pvParameters) {
|
||||||
|
ESP_LOGI(TAG, "Task started");
|
||||||
|
|
||||||
|
mqtt_init();
|
||||||
|
ESP_ERROR_CHECK(esp_task_wdt_add(NULL));
|
||||||
|
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
ESP_LOGI(TAG, "Checking Wi-Fi connection...");
|
||||||
|
xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT, pdFALSE, pdTRUE, portMAX_DELAY);
|
||||||
|
|
||||||
|
if (bits & WIFI_CONNECTED_BIT) mqtt_publish();
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_task_wdt_reset());
|
||||||
|
ESP_LOGI(TAG, "Task reset");
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(6000));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,7 +42,6 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void wifi_init_sta(void) {
|
static void wifi_init_sta(void) {
|
||||||
esp_err_t nvs_err = nvs_flash_init();
|
esp_err_t nvs_err = nvs_flash_init();
|
||||||
|
|
||||||
@@ -83,8 +82,6 @@ void wifiTask(void *pvParameters) {
|
|||||||
ESP_ERROR_CHECK(esp_task_wdt_add(NULL));
|
ESP_ERROR_CHECK(esp_task_wdt_add(NULL));
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
EventBits_t bits = xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT, pdFALSE, pdTRUE, WIFI_TIMEOUT_TICKS);
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_task_wdt_reset());
|
ESP_ERROR_CHECK(esp_task_wdt_reset());
|
||||||
ESP_LOGI(TAG, "Wi-Fi task reset");
|
ESP_LOGI(TAG, "Wi-Fi task reset");
|
||||||
vTaskDelay(pdMS_TO_TICKS(4000));
|
vTaskDelay(pdMS_TO_TICKS(4000));
|
||||||
|
|||||||
Reference in New Issue
Block a user