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 Reply Children
  • I got the issue resolved. the invalid argument issue was due to the wrong build configuration 

    changing the board to the cpu_app_ns worked.

    is it possible to get the TLS working on the cpu_app build? 

  • 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

Related