MQTT Examples and TLS issues

Hi,

New on the forum and relatively new to MBED. I’ve been working with a Nucleeo-H743ZI2 and mbed-os-example-pelion project. Alongside the lwM2M that pelion uses I would like to get mqtt going. To begin with I set up a broker on Hive MQ and used their web and CLI tools to publish and subscribe to data.

I’ve not been able to work out how to get my on-board debugger or segger to work on my target, so I figured it might be easier to do the learning on Linux, so I then checked out the Paho code and got the Linux examples building and publishing data to my Broker on Hive MQ. Once i had this working I was expecting it to be a case of replicating within MBED studio, but I am struggling a little.

The HelloMQTT example is quite old now and doesn’t build out the box, I had a bit of a go at fixing this but, felt like I was spending too much time getting something “old” working. I decdided to imported the mbed-mqtt library from https://github.com/ARMmbed/mbed-mqt into my MBED Studio mbed-os-example-pelion project and then tried to replicate the main.cpp functionality from. HelloMQTT.

Best example(IMO) is this one.

I needed to make a minor change to the init code to make it build as the
ret = socket->connect(MQTT_SERVER_HOST_NAME, MQTT_SERVER_PORT);
to
const SocketAddress sa = {MQTT_SERVER_HOST_NAME,MQTT_SERVER_PORT};
ret = socket->connect(sa);
But at runtime, this is failing
ret = socket->set_root_ca_cert(SSL_CA_PEM); with -3003(NSAPI_ERROR_PARAMETER)

Anyone got and idea’s what the issue might be?

Thanks In Advance

D

I got another issue fixed - after following this example

and reading this
https://os.mbed.com/docs/mbed-os/v6.14/apis/network-socket.html

Socket Address should get initialised like this

    NetworkInterface *net = NetworkInterface::get_default_instance();
    SocketAddress addr;
    ret = net->gethostbyname(server_addr, &addr);  // Resolve server_addr and store into addr
    if (ret != NSAPI_ERROR_OK) {
        mbedtls_printf("gethostbyname() returned %d\n", ret);
        return ret;
    }
    addr.set_port(server_port);
    
    if ((ret = socket.connect(addr)) != NSAPI_ERROR_OK) {
        mbedtls_printf("socket.connect() returned %d\n", ret);
        return ret;
    }

I now have this example connected through tls. I am now off to see what is different between this and my non-working mqtt/tls example

More updates…

If I copy the os-example-tls-tls-client main and HelloHttpsClient files into my pelion project, I get

mbedtls_x509_crt_parse() returned 0x2180, which I think is MBEDTLS_ERR_X509_INVALID_FORMAT

Unless I have stuffed up someplace, source files are idenitcal, so must be an issue in my config some place?

Tired… will look again tomorrow.