How to get the MQTT publisher example working on the nrf7002DK? I also want to test the TLS after that.

Hi,

I am trying to get the MQTT publisher example working on my nrf7002DK board. For this, i have done the following things

- SDK version: 2.6.1

- Board selected: nrf7002dk_nrf5340_cpuapp

- Include the prj.conf, overlay-nrf700x.conf and overlay-sample.conf(not sure if this is required)

- Updated the KConfig entries CONFIG_WIFI_CREDENTIALS_STATIC_SSID and CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD, with my SSID and password

- Build and run the code

This is my terminal output

*** Booting nRF Connect SDK v3.5.99-ncs1 ***
[00:00:00.465,911] <inf> net_config: Initializing network
[00:00:00.465,911] <inf> net_config: Waiting interface 1 (0x20000888) to be up...
uart:~$
[00:00:30.466,583] <inf> net_config: Running dhcpv4 client...
[00:00:30.466,827] <err> net_config: Timeout while waiting network interface
[00:00:30.466,827] <err> net_config: Network initialization failed (-115)
[00:00:30.466,888] <inf> net_mqtt_publisher_sample: attempting to connect:
[00:00:30.467,285] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:00:33.468,048] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:00:33.968,536] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:00:36.969,299] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:00:37.469,757] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:00:40.470,489] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:00:40.970,977] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:00:43.971,740] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:00:44.472,198] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:00:47.472,961] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:00:47.973,419] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:00:50.974,182] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:00:51.474,670] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:00:54.475,433] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:00:54.975,891] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:00:57.976,654] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:00:58.477,111] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:01:01.477,874] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:01:01.978,363] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:01:04.979,125] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:01:05.479,248] <inf> net_mqtt_publisher_sample: try_to_connect: -22 <ERROR>
[00:01:05.479,248] <inf> net_mqtt_publisher_sample: attempting to connect:
[00:01:05.479,644] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:01:08.480,407] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:01:08.980,865] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:01:11.981,628] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:01:12.482,116] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:01:15.482,879] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:01:15.983,337] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9
[00:01:18.984,100] <inf> net_mqtt_publisher_sample: mqtt_connect: -116 <ERROR>
[00:01:19.484,588] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (main): Created socket 9

my prj.conf

CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_TCP=y
CONFIG_NET_LOG=y
CONFIG_MQTT_LOG_LEVEL_DBG=y

CONFIG_NET_IPV6_RA_RDNSS=y
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2

CONFIG_PRINTK=y
CONFIG_STDOUT_CONSOLE=y

# Enable IPv6 support
CONFIG_NET_IPV6=n
# Enable IPv4 support
CONFIG_NET_IPV4=y

# Enable the MQTT Lib
CONFIG_MQTT_LIB=y

CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"

CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"

CONFIG_MAIN_STACK_SIZE=2048

# For IPv6
CONFIG_NET_BUF_DATA_SIZE=256

CONFIG_NET_SHELL=y

CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y

my overlay-nrf700x.conf

# Wi-Fi
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y
CONFIG_WPA_SUPP=y
CONFIG_NET_L2_ETHERNET=y

# DHCPv4
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_DHCPV4=y

# Connection manager
CONFIG_NET_CONNECTION_MANAGER=y

# Credentials
CONFIG_WIFI_CREDENTIALS=y
CONFIG_WIFI_CREDENTIALS_STATIC=y
CONFIG_WIFI_CREDENTIALS_STATIC_SSID="MySSID"
CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="MyPassword"

Parents
  • Hi,

     

    The  zephyr/samples/net/mqtt_publisher sample does not incorporate the net_mgmt or wifi-related calls, as seen in the nrf/samples/wifi/sta (and other nRF7002 samples):

    https://github.com/nrfconnect/sdk-nrf/blob/v2.6.1/samples/wifi/sta/src/main.c#L290-L306

     

    Have you had a look at the ../ncs/nrf/samples/net/mqtt sample? This sample is setup to run with the nRF7002-DK.

     

    Kind regards,

    Håkon

  • Thanks for the quick reply. I ll try out this example and update 

  • Hi,

     

    I tested your latest .zip file, and it seems to work with nrf7002dk_nrf5340_cpuapp board at my end when using NCS v2.5.3:

    [00:00:07.897,766] <inf> sta: State: AUTHENTICATING
    [00:00:08.008,483] <inf> sta: Connected
    [00:00:08.202,697] <inf> sta: ==================
    [00:00:08.202,728] <inf> sta: State: COMPLETED
    [00:00:08.202,758] <inf> sta: Interface Mode: STATION
    [00:00:08.202,789] <inf> sta: Link Mode: WIFI 6 (802.11ax/HE)
    [00:00:08.202,789] <inf> sta: SSID: OpenWrt
    [00:00:08.202,819] <inf> sta: BSSID: FC:34:97:0B:F6:DC
    [00:00:08.202,850] <inf> sta: Band: 5GHz
    [00:00:08.202,850] <inf> sta: Channel: 36
    [00:00:08.202,880] <inf> sta: Security: WPA2-PSK
    [00:00:08.202,911] <inf> sta: MFP: Optional
    [00:00:08.202,911] <inf> sta: RSSI: -55
    [00:00:16.209,197] <inf> net_dhcpv4: Received: 192.168.32.209
    [00:00:16.209,350] <inf> net_config: IPv4 address: 192.168.32.209
    [00:00:16.209,350] <inf> net_config: Lease time: 600 seconds
    [00:00:16.209,381] <inf> net_config: Subnet: 255.255.255.0
    [00:00:16.209,411] <inf> net_config: Router: 192.168.32.1
    [00:00:16.209,533] <inf> sta: DHCP IP address: 192.168.32.209
    [00:00:16.209,899] <inf> mqtt: Connecting to MQTT broker
    [00:00:16.838,073] <inf> net_mqtt: Connect completed
    [00:00:16.894,256] <inf> mqtt: MQTT client connected
    [00:00:16.894,287] <inf> mqtt: Subscribing to sensors
    [00:00:16.956,604] <inf> mqtt: SUBACK packet id: 1234
    

     

    When using NCS v2.6.1, I get this warning printed:

    warning: MBEDTLS_RSA_C (defined at /opt/ncs/nrf/subsys/net/openthread/Kconfig.defconfig:174,
    /opt/ncs/nrf/subsys/nrf_security/Kconfig.legacy:669) was assigned the value 'y' but got the value
    'n'. Check these unsatisfied dependencies: (NET_L2_OPENTHREAD || ((PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
    || !MBEDTLS_USE_PSA_CRYPTO) && MBEDTLS_LEGACY_CRYPTO_C && NRF_SECURITY)) (=n). See
    http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_MBEDTLS_RSA_C and/or look up MBEDTLS_RSA_C
    in the menuconfig/guiconfig interface. The Application Development Primer, Setting Configuration
    Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful too.

    Adding these two configurations will fix this and make it connect to the broker:

    CONFIG_PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY=y
    CONFIG_PSA_WANT_RSA_KEY_SIZE_2048=y
    

     

    Could you try this and see if it also works on your end?

     

    Kind regards,

    Håkon

  • Do i still have to add nrf5340dk_nrf5340_cpuapp_ns.conf file?

  • No. I just took the .zip file that you posted approx. 3 hours ago:

    Arjun Kariat said:

    I have created a mosquitto_ca_cert.h file using the python script provided in the git link. This is the .h file created from the crt file of the ca certificate of the test.mosquitto.org.

    Here is the updated code

    /cfs-file/__key/communityserver-discussions-components-files/4/5228.wifistaMqtt.zip

    Please Note: I have only added the subscribe part here right now.

    Please let me know if you want to know anything else

     

    Kind regards,

    Håkon

  • Its working thanks a lot Slight smile

    Updated prj.conf

    #
    # Copyright (c) 2022 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    CONFIG_WIFI=y
    CONFIG_WIFI_NRF700X=y
    
    # WPA supplicant
    CONFIG_WPA_SUPP=y
    
    # Below configs need to be modified based on security
    # CONFIG_STA_KEY_MGMT_NONE=y
    CONFIG_STA_KEY_MGMT_WPA2=y
    # CONFIG_STA_KEY_MGMT_WPA2_256=y
    # CONFIG_STA_KEY_MGMT_WPA3=y
    CONFIG_STA_SAMPLE_SSID="YourSSID"
    CONFIG_STA_SAMPLE_PASSWORD="Your_Password"
    
    # System settings
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_NANO=n
    
    # Networking
    CONFIG_NETWORKING=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_LOG=y
    # CONFIG_MQTT_LOG_LEVEL_DBG=y
    CONFIG_NET_IPV4=y
    CONFIG_NET_IPV6=n
    CONFIG_NET_UDP=y
    CONFIG_NET_TCP=y
    CONFIG_NET_DHCPV4=y
    
    CONFIG_NET_PKT_RX_COUNT=8
    CONFIG_NET_PKT_TX_COUNT=8
    
    # Below section is the primary contributor to SRAM and is currently
    # tuned for performance, but this will be revisited in the future.
    CONFIG_NET_BUF_RX_COUNT=16
    CONFIG_NET_BUF_TX_COUNT=16
    CONFIG_NET_BUF_DATA_SIZE=128
    CONFIG_HEAP_MEM_POOL_SIZE=153600
    CONFIG_NET_TC_TX_COUNT=1
    
    CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
    CONFIG_NET_MAX_CONTEXTS=5
    CONFIG_NET_CONTEXT_SYNC_RECV=y
    
    CONFIG_INIT_STACKS=y
    
    CONFIG_NET_L2_ETHERNET=y
    
    CONFIG_NET_CONFIG_SETTINGS=y
    CONFIG_NET_CONFIG_INIT_TIMEOUT=0
    
    CONFIG_NET_SOCKETS_POLL_MAX=10
    
    # Memories
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    CONFIG_NET_TX_STACK_SIZE=4096
    CONFIG_NET_RX_STACK_SIZE=4096
    
    # Debugging
    CONFIG_STACK_SENTINEL=y
    CONFIG_DEBUG_COREDUMP=y
    CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y
    CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
    CONFIG_SHELL_CMDS_RESIZE=n
    
    
    # Kernel options
    CONFIG_ENTROPY_GENERATOR=y
    
    # Logging
    CONFIG_LOG=y
    CONFIG_LOG_BUFFER_SIZE=2048
    CONFIG_POSIX_CLOCK=y
    
    CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.168.1.99"
    CONFIG_NET_CONFIG_MY_IPV4_NETMASK="255.255.255.0"
    CONFIG_NET_CONFIG_MY_IPV4_GW="192.168.1.1"
    
    # printing of scan results puts pressure on queues in new locking
    # design in net_mgmt. So, use a higher timeout for a crowded
    # environment.
    CONFIG_NET_MGMT_EVENT_QUEUE_TIMEOUT=5000
    
    #MQTT
    CONFIG_MQTT_LIB=y
    CONFIG_MQTT_LIB_TLS=y
    CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
    CONFIG_MQTT_KEEPALIVE=5
    CONFIG_MBEDTLS_ENABLE_HEAP=y
    CONFIG_MBEDTLS_HEAP_SIZE=81920
    CONFIG_TLS_CREDENTIALS=y
    CONFIG_MBEDTLS_RSA_C=y
    CONFIG_PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY=y
    CONFIG_PSA_WANT_RSA_KEY_SIZE_2048=y

    For nrf7002DK board:

    • Board selected: nrf7002dk_nrf5340_cpuapp 

    For nrf7002EK Board

    • Board selected: nrf5340dk_nrf5340_cpuapp 
    • Extra Cmake Argument: -DSHIELD="nrf7002ek"
Reply
  • Its working thanks a lot Slight smile

    Updated prj.conf

    #
    # Copyright (c) 2022 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    CONFIG_WIFI=y
    CONFIG_WIFI_NRF700X=y
    
    # WPA supplicant
    CONFIG_WPA_SUPP=y
    
    # Below configs need to be modified based on security
    # CONFIG_STA_KEY_MGMT_NONE=y
    CONFIG_STA_KEY_MGMT_WPA2=y
    # CONFIG_STA_KEY_MGMT_WPA2_256=y
    # CONFIG_STA_KEY_MGMT_WPA3=y
    CONFIG_STA_SAMPLE_SSID="YourSSID"
    CONFIG_STA_SAMPLE_PASSWORD="Your_Password"
    
    # System settings
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_NANO=n
    
    # Networking
    CONFIG_NETWORKING=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_LOG=y
    # CONFIG_MQTT_LOG_LEVEL_DBG=y
    CONFIG_NET_IPV4=y
    CONFIG_NET_IPV6=n
    CONFIG_NET_UDP=y
    CONFIG_NET_TCP=y
    CONFIG_NET_DHCPV4=y
    
    CONFIG_NET_PKT_RX_COUNT=8
    CONFIG_NET_PKT_TX_COUNT=8
    
    # Below section is the primary contributor to SRAM and is currently
    # tuned for performance, but this will be revisited in the future.
    CONFIG_NET_BUF_RX_COUNT=16
    CONFIG_NET_BUF_TX_COUNT=16
    CONFIG_NET_BUF_DATA_SIZE=128
    CONFIG_HEAP_MEM_POOL_SIZE=153600
    CONFIG_NET_TC_TX_COUNT=1
    
    CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
    CONFIG_NET_MAX_CONTEXTS=5
    CONFIG_NET_CONTEXT_SYNC_RECV=y
    
    CONFIG_INIT_STACKS=y
    
    CONFIG_NET_L2_ETHERNET=y
    
    CONFIG_NET_CONFIG_SETTINGS=y
    CONFIG_NET_CONFIG_INIT_TIMEOUT=0
    
    CONFIG_NET_SOCKETS_POLL_MAX=10
    
    # Memories
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    CONFIG_NET_TX_STACK_SIZE=4096
    CONFIG_NET_RX_STACK_SIZE=4096
    
    # Debugging
    CONFIG_STACK_SENTINEL=y
    CONFIG_DEBUG_COREDUMP=y
    CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y
    CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
    CONFIG_SHELL_CMDS_RESIZE=n
    
    
    # Kernel options
    CONFIG_ENTROPY_GENERATOR=y
    
    # Logging
    CONFIG_LOG=y
    CONFIG_LOG_BUFFER_SIZE=2048
    CONFIG_POSIX_CLOCK=y
    
    CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.168.1.99"
    CONFIG_NET_CONFIG_MY_IPV4_NETMASK="255.255.255.0"
    CONFIG_NET_CONFIG_MY_IPV4_GW="192.168.1.1"
    
    # printing of scan results puts pressure on queues in new locking
    # design in net_mgmt. So, use a higher timeout for a crowded
    # environment.
    CONFIG_NET_MGMT_EVENT_QUEUE_TIMEOUT=5000
    
    #MQTT
    CONFIG_MQTT_LIB=y
    CONFIG_MQTT_LIB_TLS=y
    CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
    CONFIG_MQTT_KEEPALIVE=5
    CONFIG_MBEDTLS_ENABLE_HEAP=y
    CONFIG_MBEDTLS_HEAP_SIZE=81920
    CONFIG_TLS_CREDENTIALS=y
    CONFIG_MBEDTLS_RSA_C=y
    CONFIG_PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY=y
    CONFIG_PSA_WANT_RSA_KEY_SIZE_2048=y

    For nrf7002DK board:

    • Board selected: nrf7002dk_nrf5340_cpuapp 

    For nrf7002EK Board

    • Board selected: nrf5340dk_nrf5340_cpuapp 
    • Extra Cmake Argument: -DSHIELD="nrf7002ek"
Children
  • Hi,

     

    Arjun Kariat said:
    Its working thanks a lot Slight smile

    Great to hear that it is working as expected! Always happy to help out.

     

    Hope you have a wonderful day!

     

    Kind regards,

    Håkon

  • Hi @

    I was trying to add TLS client certificate support to this code. i am getting an error

    [00:00:10.666,046] <inf> mqtt: Connecting to MQTT broker
    [00:00:11.825,683] <err> net_pkt: Data buffer (1035) allocation failed.
    [00:00:11.825,714] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=987
    [00:00:11.973,724] <err> net_pkt: Data buffer (1110) allocation failed.
    [00:00:11.973,754] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1062
    [00:00:12.177,917] <err> net_pkt: Data buffer (1110) allocation failed.
    [00:00:12.177,917] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1062
    [00:00:12.177,917] <err> net_tcp: TCP failed to allocate buffer in retransmission
    [00:00:12.656,158] <err> net_pkt: Data buffer (1110) allocation failed.
    [00:00:12.656,158] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1062
    [00:00:12.656,158] <err> net_tcp: TCP failed to allocate buffer in retransmission
    [00:00:13.323,364] <err> net_pkt: Data buffer (1110) allocation failed.
    [00:00:13.323,364] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1062
    [00:00:13.323,364] <err> net_tcp: TCP failed to allocate buffer in retransmission
    [00:00:14.273,559] <err> net_pkt: Data buffer (1110) allocation failed.
    [00:00:14.273,559] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1062
    [00:00:14.273,559] <err> net_tcp: TCP failed to allocate buffer in retransmission
    [00:00:15.648,803] <err> net_pkt: Data buffer (1328) allocation failed.
    [00:00:15.648,803] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1280
    [00:00:15.648,834] <err> net_tcp: TCP failed to allocate buffer in retransmission
    [00:00:17.661,041] <err> net_pkt: Data buffer (1328) allocation failed.
    [00:00:17.661,041] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1280
    [00:00:17.661,071] <err> net_tcp: TCP failed to allocate buffer in retransmission
    [00:00:20.629,272] <err> net_pkt: Data buffer (1328) allocation failed.
    [00:00:20.629,302] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1280
    [00:00:20.629,302] <err> net_tcp: TCP failed to allocate buffer in retransmission
    [00:00:25.031,494] <err> net_pkt: Data buffer (1328) allocation failed.
    [00:00:25.031,494] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1280
    [00:00:25.031,524] <err> net_tcp: TCP failed to allocate buffer in retransmission
    [00:00:31.584,716] <err> net_pkt: Data buffer (1328) allocation failed.
    [00:00:31.584,747] <err> net_tcp: conn: 0x20050ba4 packet allocation failed, len=1280
    [00:00:31.584,747] <err> net_tcp: TCP failed to allocate buffer in retransmission
    [00:00:31.837,738] <err> mqtt: Error in mqtt_connect: -5

    This is my updated code: /cfs-file/__key/communityserver-discussions-components-files/4/2570.wifistaMqtt.zip

    Please let me know if you want any thing else

    in brief

    i added the client certificate as well as the private key files

    static const unsigned char ca_certificate[] = {
    #include "mosquitto_ca_cert.h"
    };
    
    static const unsigned char client_certificate[] = {
    #include "mosquitto_client_cert.h"
    };
    
    static const unsigned char priv_key[] = {
    #include "mosquitto_priv_key.h"
    };

    I have called the tls_credential_add as shown below

        // CA Certificate
        err = tls_credential_add(MQTT_TLS_SEC_TAG, TLS_CREDENTIAL_CA_CERTIFICATE, ca_certificate, sizeof(ca_certificate));
    	if (err < 0)
        {
    		LOG_ERR("Failed to add TLS credentials CA Certificate, err: %d", err);
    		return err;
    	}
    
    	// Client Certificate
        err = tls_credential_add(MQTT_TLS_SEC_TAG, TLS_CREDENTIAL_SERVER_CERTIFICATE, client_certificate, sizeof(client_certificate));
    	if (err < 0)
        {
    		LOG_ERR("Failed to add TLS credentials Client Certificate, err: %d", err);
    		return err;
    	}
    
    	// Private Key
        err = tls_credential_add(MQTT_TLS_SEC_TAG, TLS_CREDENTIAL_PRIVATE_KEY, priv_key, sizeof(priv_key));
    	if (err < 0)
        {
    		LOG_ERR("Failed to add TLS credentials Private Key, err: %d", err);
    		return err;
    	}

    Updated the Broket Port to 8884

    I have used this link to create the client certificate: test.mosquitto.org/.../

Related