Hello,
i played around with the mqtt demo and extend it just for webserver. Everything worked. Suddenly i cant compile again and get the following error
Target 'component-xtensa-debug-module-build' responsible for 'C:/Workbench/ESP32/esp32-webserver/build/xtensa-debug-module/libxtensa-debug-module.a'
C:/Workbench/ESP32/esp32-webserver/build/main\libmain.a(main.o):(.literal._ZL18mqtt_event_handlerP16esp_mqtt_event_t+0x44): undefined reference to `esp_mqtt_client_subscribe(esp_mqtt_client*, char const*, int)'
C:/Workbench/ESP32/esp32-webserver/build/main\libmain.a(main.o):(.literal._ZL18mqtt_event_handlerP16esp_mqtt_event_t+0x48): undefined reference to `esp_mqtt_client_unsubscribe(esp_mqtt_client*, char const*)'
C:/Workbench/ESP32/esp32-webserver/build/main\libmain.a(main.o):(.literal._ZL18mqtt_event_handlerP16esp_mqtt_event_t+0x4c): undefined reference to `esp_mqtt_client_publish(esp_mqtt_client*, char const*, char const*, int, int, int)'
C:/Workbench/ESP32/esp32-webserver/build/main\libmain.a(main.o):(.literal.mqtt_app_start+0x14): undefined reference to `esp_mqtt_client_init(esp_mqtt_client_config_t const*)'
C:/Workbench/ESP32/esp32-webserver/build/main\libmain.a(main.o):(.literal.mqtt_app_start+0x18): undefined reference to `esp_mqtt_client_start(esp_mqtt_client*)'
C:/Workbench/ESP32/esp32-webserver/build/main\libmain.a(main.o): In function `mqtt_event_handler(esp_mqtt_event_t*)':
C:/Workbench/ESP32/esp32-webserver/main/main.cpp:491: undefined reference to `esp_mqtt_client_subscribe(esp_mqtt_client*, char const*, int)'
C:/Workbench/ESP32/esp32-webserver/main/main.cpp:491: undefined reference to `esp_mqtt_client_subscribe(esp_mqtt_client*, char const*, int)'
C:/Workbench/ESP32/esp32-webserver/main/main.cpp:491: undefined reference to `esp_mqtt_client_unsubscribe(esp_mqtt_client*, char const*)'
C:/Workbench/ESP32/esp32-webserver/main/main.cpp:491: undefined reference to `esp_mqtt_client_publish(esp_mqtt_client*, char const*, char const*, int, int, int)'
C:/Workbench/ESP32/esp32-webserver/build/main\libmain.a(main.o): In function `mqtt_app_start':
C:/Workbench/ESP32/esp32-webserver/main/main.cpp:507: undefined reference to `esp_mqtt_client_init(esp_mqtt_client_config_t const*)'
C:/Workbench/ESP32/esp32-webserver/main/main.cpp:508: undefined reference to `esp_mqtt_client_start(esp_mqtt_client*)'
C:/Workbench/ESP32/esp32-webserver/main/main.cpp:511: undefined reference to `esp_mqtt_client_publish(esp_mqtt_client*, char const*, char const*, int, int, int)'
SRC
#include "mqtt_client.h"
extern "C" void mqtt_app_start(void)
{
esp_mqtt_client_config_t mqtt_cfg = {};
strncpy(mqtt_cfg.uri, "mqtt://192.168.178.22", sizeof(mqtt_cfg.uri));
mqtt_cfg.event_handle = mqtt_event_handler;
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_start(client);
mqttclient = client;
int msg_id = esp_mqtt_client_publish(mqttclient, "/topic/qos0", "test Loop first", 0, 0, 0);
}
static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
{
esp_mqtt_client_handle_t client = event->client;
int msg_id;
// your_context_t *context = event->context;
switch (event->event_id) {
case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
msg_id = esp_mqtt_client_unsubscribe(client, "/topic/qos1");
ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
break;
case MQTT_EVENT_SUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);
break;
case MQTT_EVENT_ERROR:
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
break;
}
return ESP_OK;
}
And the line numbers in the Error Messages don´t match to the real line nr.
Of course the library is included.
i don´t know why
MQTT_Client Problem
-
- Posts: 26
- Joined: Wed Dec 20, 2017 9:39 am
Re: MQTT_Client Problem
after i put this in, it works.
extern "C" {
#include "mqtt_client.h"
}
i just don´t understand why before it worked without this. For me its like try and error.
extern "C" {
#include "mqtt_client.h"
}
i just don´t understand why before it worked without this. For me its like try and error.
Re: MQTT_Client Problem
Howdy,
In your first post you said you were working with "the" MQTT demo. Where would that be found? I think there might be a few MQTT ESP32 libraries and I'm curious which one you were looking at.
In your first post you said you were working with "the" MQTT demo. Where would that be found? I think there might be a few MQTT ESP32 libraries and I'm curious which one you were looking at.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Who is online
Users browsing this forum: No registered users and 92 guests