Error porting paho_mqtt_embedded_c client with freeRTOS on esp32 devKitC

Arkaik
Posts: 13
Joined: Mon Jun 12, 2017 12:36 pm

Error porting paho_mqtt_embedded_c client with freeRTOS on esp32 devKitC

Postby Arkaik » Mon Nov 27, 2017 1:26 pm

Hi,

I'm trying to use paho_mqtt_embedded_c client on my esp32 DevKitC running freeRTOS.

I'm using Kolban's esp32 port available here https://github.com/nkolban/esp32-snippe ... embedded_c

The library compile well as a component. However when I try to use the function NetworkConnect I have the following error :

Code: Select all

$ make
CC main.o
AR libmain.a
LD app-template.elf
<project_path>/build/paho_mqtt_embedded_c/libpaho_mqtt_embedded_c.a(MQTTLinux.o):(.literal.NetworkConnectSSL+0x38): undefined reference to `mbedtls_debug_set_threshold'
<project_path>/build/paho_mqtt_embedded_c/libpaho_mqtt_embedded_c.a(MQTTLinux.o): In function `NetworkConnectSSL':
<project_path>/components/paho_mqtt_embedded_c/MQTTClient-C/src/linux/MQTTLinux.c:203: undefined reference to `mbedtls_debug_set_threshold'
collect2: error: ld returned 1 exit status
<esp-idf_path>/make/project.mk:322 : la recette pour la cible « <project_path>/build/app-template.elf » a échouée
make: *** [<project_path>/build/app-template.elf] Erreur 1
Here is my code

Code: Select all

#include <esp_event.h>
#include <esp_event_loop.h>
#include <esp_system.h>
#include <esp_wifi.h>
#include <freertos/FreeRTOS.h>
#include <lwip/sockets.h>
#include <nvs_flash.h>

#include "MQTTClient.h"

// The IP address that we want our device to have.
#define DEVICE_IP          "192.168.128.186"

// The Gateway address where we wish to send packets.
// This will commonly be our access point.
#define DEVICE_GW          "192.168.128.161"

// The netmask specification.
#define DEVICE_NETMASK     "255.255.255.0"

#define SSID     "<ssid>"
#define PASSWORD "<ap_password>"

esp_err_t esp32_wifi_eventHandler(void *ctx, system_event_t *event) {
	// Your event handling code here...
	if (event->event_id == SYSTEM_EVENT_STA_GOT_IP) {
            //Do nothing
	}
	return ESP_OK;
}

void app_main(void)
{
    nvs_flash_init();
    tcpip_adapter_init();

    tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); // Don't run a DHCP client
    tcpip_adapter_ip_info_t ipInfo;

    inet_pton(AF_INET, DEVICE_IP, &ipInfo.ip);
    inet_pton(AF_INET, DEVICE_GW, &ipInfo.gw);
    inet_pton(AF_INET, DEVICE_NETMASK, &ipInfo.netmask);
    tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);

    ESP_ERROR_CHECK( esp_event_loop_init(esp32_wifi_eventHandler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
    wifi_config_t sta_config = {
        .sta = {
            .ssid = SSID,
            .password = PASSWORD,
            .bssid_set = false
        }
    };
    ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
    ESP_ERROR_CHECK( esp_wifi_connect() );
    
    Network network;
    
    NetworkInit(&network);
    NetworkConnect(&network, "192.168.128.161", 1883);

}
The problem seems to come from the symbol mbedtls_debug_set_threshold which is not defined. After having a look at source code, this symbol only appears in MQTTClient-C/src/linux/MQTTLinux.c at line 218.

Code: Select all

 mbedtls_debug_set_threshold(4); // Log at verbose only 
After commenting this line the compilation worked. However even if it's not a big modification I'd prefer not modifying the source code. Should I compile with a specific verbosity variable to be able to link with this symbol?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Error porting paho_mqtt_embedded_c client with freeRTOS on esp32 devKitC

Postby ESP_Angus » Tue Nov 28, 2017 4:41 am

I believe this will work if you enable mbedTLS debugging in "make menuconfig":
https://esp-idf.readthedocs.io/en/lates ... dtls-debug

If you wanted to update the code and send a Pull Request to kolban, you could put a "#ifdef CONFIG_MBEDTLS_DEBUG" check around this call.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Error porting paho_mqtt_embedded_c client with freeRTOS on esp32 devKitC

Postby kolban » Tue Nov 28, 2017 5:09 am

Ahh ... I see the original author also raised an issue on github which was also responded to. See:

https://github.com/nkolban/esp32-snippets/issues/233
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Arkaik
Posts: 13
Joined: Mon Jun 12, 2017 12:36 pm

Re: Error porting paho_mqtt_embedded_c client with freeRTOS on esp32 devKitC

Postby Arkaik » Tue Nov 28, 2017 1:22 pm

Hi,

@ESP_Angus

Indeed I had to enable the mbedTLS debugging, seems I read the readme without enough attention ù_ù.

@Kolban

Yes I oppened an issue too. As proposed by Angus, wouldn't it be better to surround the line with "#ifdef CONFIG_MBEDTLS_DEBUG" "#endif" ?
Maybe there is a specific reason to not doing it.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Error porting paho_mqtt_embedded_c client with freeRTOS on esp32 devKitC

Postby kolban » Sun Mar 11, 2018 12:41 am

Thank you sir. The code change has been made and pushed/committed.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 62 guests