MQTT sample problem

I' m using custom board of nrf5340 with nrf7002, and the SDK version is ncs v2.5.2.

I've tried to build and run, but the log in RTT viewer is only print the line "Bringing network interface up and connecting to the network", It seems the program is stuck, and it didn't proceed to execute.

  

and I wondered it is because of the MAC address, so I added the "set_mac _address" function into "network.c" and executed it in the function "network_task", but it printed other errors below.

prj.conf

#prj.conf
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Common configurations for all boards

CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y
CONFIG_NET_L2_WIFI_MGMT=y
CONFIG_HEAP_MEM_POOL_SIZE=25000

# System settings
CONFIG_NEWLIB_LIBC=y

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_NATIVE=y
CONFIG_NET_OFFLOAD=y

CONFIG_INIT_STACKS=y

# Memories
CONFIG_MAIN_STACK_SIZE=4096

# General
CONFIG_HW_ID_LIBRARY=y
CONFIG_ASSERT=y
CONFIG_WIFI_CREDENTIALS_STATIC_SSID="allen"
CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="123" 
CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_OPEN=y

CONFIG_MQTT_SAMPLE_TRANSPORT_BROKER_HOSTNAME="test.mosquitto.org"
CONFIG_MQTT_SAMPLE_TRANSPORT_PUBLISH_TOPIC="my/publish/topic"
CONFIG_MQTT_SAMPLE_TRANSPORT_SUBSCRIBE_TOPIC="my/subscribe/topic"

CONFIG_MQTT_SAMPLE_LED=n
CONFIG_DK_LIBRARY=n

# CONFIG_MQTT_SAMPLE_TRIGGER_THREAD_STACK_SIZE=2048
# Logging
CONFIG_LOG=y
# CONFIG_NET_LOG=y
# CONFIG_MQTT_LOG_LEVEL_DBG=y
# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_IPV4=y
CONFIG_NET_TCP=y
CONFIG_NET_NATIVE=y
CONFIG_NET_CONNECTION_MANAGER=y

# ZBus
CONFIG_ZBUS=y

# Zephyr state framework
CONFIG_SMF=y

# MQTT
CONFIG_MQTT_HELPER=y
CONFIG_MQTT_CLEAN_SESSION=y

#config RTT
CONFIG_LOG=y
CONFIG_LOG_PRINTK=y
# CONFIG_LOG_MODE_DEFERRED=y
CONFIG_SERIAL=n
CONFIG_UART_CONSOLE=n
CONFIG_USE_SEGGER_RTT=y
CONFIG_CONSOLE=y
CONFIG_RTT_CONSOLE=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=n
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=4096
CONFIG_LOG_BUFFER_SIZE=4096
# Disable internal DCDC
CONFIG_BOARD_ENABLE_DCDC_APP=n
CONFIG_BOARD_ENABLE_DCDC_NET=n
CONFIG_BOARD_ENABLE_DCDC_HV=n

# Use internal capacitor for 32M xtal and set capacitor value to 8.5pF 
# (ranging from 7.0 pF to 20.0 pF in 0.5 pF steps
# can be enabled on pins XC1 and XC2. This option specifies doubled
# capacitance value for the two capacitors. Set it to 14 to get 7.0 pF
# for each capacitor, 15 to get 7.5 pF, and so on.
# )
CONFIG_SOC_HFXO_CAP_INTERNAL=y
CONFIG_SOC_HFXO_CAP_INT_VALUE_X2=17
 
#  Use internal capacitor for 32k xtal and set capacitor value to 7pF 
# (only 4 options of internal capacitor value settings for 32k xtal
#   -INT_6PF
#   -INT_7PF
#   -INT_9PF
#   - USE external capacitor)
CONFIG_SOC_ENABLE_LFXO=y
CONFIG_SOC_LFXO_CAP_INT_7PF=y

Below is the function what I added. And this function is executed normally in the Scan sample.

int8_t wifi_set_mac_address()
{
	struct net_if *iface = net_if_get_default();
	uint8_t mac_addr[6] = {0xF0, 0xCE, 0x36, 0x00, 0x00, 0x4A};

	struct ethernet_req_params eth_param;
	memcpy(eth_param.mac_address.addr, mac_addr, 6);

	// if (net_if_down(iface))
	// {
	// 	printk("<Err> Couldn't shutdown WiFi interface\n");
	// 	return -1;
	// }
	printk("<Inf> Setting MAC address\n");
	if (net_mgmt(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, iface, &eth_param, sizeof(struct ethernet_req_params)))
	{
		printk("<Err> Couldn't set new MAC Address\n");
		return -2;
	}

	int ret = memcmp(net_if_get_link_addr(iface)->addr, mac_addr, sizeof(mac_addr));
	if (ret)
	{
		printk("<Err> Couldn't change MAC address\n");
	}

	if (net_if_up(iface))
	{
		printk("<Err> Couldn't wake up interface\n");
		return -3;
	}

	return 0;
}

How can I run the MQTT sample correctly?

Parents Reply Children
No Data
Related