cancel
Showing results for 
Search instead for 
Did you mean: 

Hw to use lwip + mqtt api with mbedtls?

RGais.1
Associate

Hi there. i made stm32 + rtos + lwip/mqtt solution and it works well. Now i want to use it with embed tls secure connection. I did not find any exemples.

lwip mqtt api support tls comunication. But there are no such example like just simple mqtt client using code was here: MQTT client.

I tried to enable embedtls and some options in cubemx, LWIP_ALTCP & LWIP_ALTCP_TLS, add LWIP_ALTCP_TLS_MBEDTLS to Path. It compiled. How to init mbedtls and add tls cert.. this link takes a little info 

Application layered TCP Introduction.

Has anyebody some expirience or working example with mqtt + tls (mbedtls) for stm32 lwip stack?

UPD.

Here is my code of mqtt client setup:

struct mqtt_connect_client_info_t ci;
 
  memset(&ci, 0, sizeof(ci));
 
  ci.client_id = "lwip_test";
 
  ci.client_user = "";
 
  ci.client_pass = "";
 
  ci.keep_alive = 0;
 
  ci.tls_config = altcp_tls_create_config_client((const u8_t*)test_cert, sizeof(test_cert));
 
  // create client
 
  client = mqtt_client_new();
 
  // connect client  
 
  mqtt_client_connect(client, &resolved, port, mqtt_on_connect, (void *)0, &ci);

I give mqtt client ca certificate and length. I have an error in

*altcp_tls_create_config_client_common* function (altcp_tls_mbedtls.c) with code -4480 (Failed to allocate memory).

ret = mbedtls_x509_crt_parse(conf->ca, ca, ca_len);
  if (ret != 0) {
   LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_x509_crt_parse ca failed: %d 0x%x", ret, -1*ret));
   altcp_mbedtls_free_config(conf);
   return NULL;
  }

What i am doing wrong, whitch options else i should set up in mbedtls module?

I use default was generated by CubeMX

1 REPLY 1
AWahd.1
Associate II

Hello @RGais.1​ any progress?