Hi Jeremy, thank you for your reply. Yes, your understanding of my situation is correct.
To determine the time the system takes from publish to callback, I just check the current time using xTaskGetTickCount(). Like so:
TickType_t t0;
static void publish_message(void *ctx)
{
static const char *topic = "MyPublish";
const char* message = "some_data";
err_t err;
LWIP_UNUSED_ARG(ctx);
err = mqtt_publish(mqtt_client, topic, message, strlen(message), 0, 0, mqtt_message_published_cb, (void *)topic);
t0 = xTaskGetTickCount();
if (err != ERR_OK)
{
PRINTF("Publish returned %d\r\n", err);
}
}
static void mqtt_message_published_cb(void *arg, err_t err)
{
const char *topic = (const char *)arg;
TickType_t now = xTaskGetTickCount();
PRINTF("Callback %d, diff: %d\r\n", now, now - t0);
if (err != ERR_OK)
{
PRINTF("Failed to publish to the topic \"%s\": %d.\r\n", topic, err);
}
}