Here is my aproach. What am I doing wrong?
Initially I get undefined reference to `outbox_set_pending'
Then I add this
CMakeList.txt
idf_component_register(SRCS "main.cpp" "outbox.cpp"
INCLUDE_DIRS "."
REQUIRES driver freertos u8g2
PRIV_REQUIRES esp-mqtt)
and then I get Failed to resolve component 'esp-mqtt'
I have checked, that the esp-mqtt is indeed in my package - I just upgraded to 5.2.1.
I have implemented the outbox like this (preliminary code)
Code: Select all
#ifndef OUTBOX_H
#define OUTBOX_H
#include "mqtt_client.h"
void setup_outbox();
void publish_message(const char* topic, const char* payload, int qos);
void outbox_set_pending(const char* topic, const char* payload, int qos);
void outbox_destroy();
#endif // OUTBOX_H
Code: Select all
#include <esp_log.h>
#include <esp_heap_caps.h>
#include "mqtt_client.h"
#include "outbox.h"
#include "sdkconfig.h"
static const char* TAG = "Outbox";
extern esp_mqtt_client_handle_t client;
// Example structure to hold messages, using PSRAM
typedef struct {
char* topic;
char* payload;
int qos;
} outbox_message_t;
void setup_outbox() {
ESP_LOGI(TAG, "Outbox setup complete");
}
void outbox_set_pending(const char* topic, const char* payload, int qos) {
// Allocate memory in PSRAM for the outbox message
outbox_message_t* message = (outbox_message_t*) heap_caps_malloc(sizeof(outbox_message_t), MALLOC_CAP_SPIRAM);
if (message == NULL) {
ESP_LOGE(TAG, "Failed to allocate memory for outbox message");
return;
}
// Allocate memory for the topic and payload in PSRAM
message->topic = (char*) heap_caps_malloc(strlen(topic) + 1, MALLOC_CAP_SPIRAM);
message->payload = (char*) heap_caps_malloc(strlen(payload) + 1, MALLOC_CAP_SPIRAM);
if (message->topic == NULL || message->payload == NULL) {
ESP_LOGE(TAG, "Failed to allocate memory for message content");
heap_caps_free(message);
return;
}
strcpy(message->topic, topic);
strcpy(message->payload, payload);
message->qos = qos;
// Store the message in the outbox
ESP_LOGI(TAG, "Stored message in outbox: topic=%s, payload=%s, QoS=%d", topic, payload, qos);
// Add code to manage the storage and retrieval of outbox messages
}
void outbox_destroy() {
// Implementation for destroying the outbox and freeing memory
ESP_LOGI(TAG, "Destroying outbox");
// Add code to release resources used by the outbox
}
void process_outbox() {
// Implementation to process and resend messages from the outbox
ESP_LOGI(TAG, "Processing outbox");
// Add code to handle processing of outbox messages
}
I should mention, that I have set 'Enable custom outbox implementation' in the menuconfig. I have NOT set the 'MQTT using custom configurations'.