nRF Connect MQTT Sample Not Working as Expected

Hi, when I run the MQTT sample as is, I'm having problems with the TLS and port configuration. The terminal output is:

[00:01:33.046,783] <inf> transport: Connected to MQTT broker
[00:01:33.046,813] <inf> transport: Hostname: test.mosquitto.org
[00:01:33.046,875] <inf> transport: Client ID: 358299840022756
[00:01:33.046,875] <inf> transport: Port: 1883
[00:01:33.046,905] <inf> transport: TLS: No
[00:01:33.046,966] <inf> transport: Subscribing to: 358299840022756/my/subscribe/topic
[00:01:33.175,445] <inf> transport: Subscribed to topic 358299840022756/my/subscribe/topic

That looks correct, but on closer inspection the port is set to 1883 and TLS is turned off - neither of these are expected. I cannot see anywhere in the code where they're configured to those values; all I can find is CONFIG_MQTT_HELPER_PORT=8884 and CONFIG_MQTT_LIB_TLS=y (these appear in the logging function calls that output the above).

Any help or ideas would be much appreciated.

  • Hi, 

    Which NCS version and board are you using?

    How do you build the sample?

    Do you modify the sample? If so, what are the modifications?

    Could you check the value of CONFIG_MQTT_HELPER_PORT=8884 and CONFIG_MQTT_LIB_TLS in the .config under build/zephyr?

    Regards,
    Amanda H.

  • Hi,

    • NCS version: v2.6.1
    • Building with the nRF Toolchain manager terminal (west build -p always -b nrf9161dk_nrf9161_ns nrf/samples/net/mqtt/)
    • The sample is unmodified
    • I can't find CONFIG_MQTT_HELPER_PORT or CONFIG_MQTT_LIB_TLS in build/zephyr/.config (or build/pm.config, in case that helps)

    Hopefully that helps

  • Update: I added some #warning preprocessor directives to the mqtt/src/modules/transport/credentials_provision/credentials_provision.c to check that the certificates & keys were being included only to find they weren't.  I had assumed that mqtt/overlay-tls-nrf91.conf would automatically be used as I'm building for the nRF 9161 DK but it appears it wasn't.  So, I added the contents of that file to prj.conf.  Now I can find CONFIG_MQTT_HELPER_PORT and CONFIG_MQTT_LIB_TLS in build/zephyr/.config, but I'm now getting:

    [00:02:42.741,546] <err> mqtt_helper: mqtt_connect, error: -111
    [00:02:42.741,546] <err> transport: Failed connecting to MQTT, error code: -111

    So, the sample has now been modified, I suppose (I've also update the port and the broker domain)

  • Hi, 

    When building the unmodified MQTT sample with the command line, the following commands can be used for the nRF9161 DK:

    west build -b nrf9161dk_nrf9161_ns -- -DOVERLAY_CONFIG=overlay-tls-nrf91.conf

    Could you try the default setting?

    -Amanda H.

Related