Wake up event of Target Wake Time (TWT) on nRF7002-DK

Hi,

I'm developing an application to send data via UDP. In order to minimize the power consumption of my application, my idea is to send data during the wake time of TWT.

I start by connecting to the AP. To do this, I based myself on the Wi-Fi: Station sample where I get the following output (Image 1) :

  (Image 1 )

After this, I set up the TWT based on the Wi-Fi: TWT sample with the TWT_WAKE_INTERVAL and TWT_INTERVAL set to 20000us and 5000000us, respectively. I'm obtaining the following output (Image 2):

  ( Image 2 )

I was expecting that I would get an event when the wake up time and sleep time started. However, from what we can see in Image 2, it appears that I'm not obtaining any NET_EVENT_WIFI_TWT_SLEEP_STATE event. For this reason, I thought that my TWT application was not working (since there were no active or sleeping events), but after a quick test with the Joulescope JS110, I was able to verify that these events were being generated as we can see in the following image (Image 3) and  the TWT_WAKE_INTERVAL and TWT_INTERVAL are correct (Image 4):

  ( Image 3 )

  ( Image 4 )

At this moment, my wifi_mgmt_event_handler looks like:

static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
									uint32_t mgmt_event, struct net_if *iface)
{
	switch (mgmt_event)
	{
	case NET_EVENT_WIFI_CONNECT_RESULT:
		LOG_INF(" ========================= NET_EVENT_WIFI_CONNECT_RESULT event ========================= " );
		handle_wifi_connect_result(cb);
		break;
		
	case NET_EVENT_WIFI_DISCONNECT_RESULT:
		LOG_INF(" ========================= NET_EVENT_WIFI_DISCONNECT_RESULT ========================= ");
		handle_wifi_disconnect_result(cb);
		break;

	case NET_EVENT_WIFI_TWT:
		LOG_INF(" ========================= NET_EVENT_WIFI_TWT event ========================= ");
		handle_wifi_twt_event(cb);
		break;

	case NET_EVENT_WIFI_TWT_SLEEP_STATE:
		LOG_INF(" ========================= NET_EVENT_WIFI_TWT_SLEEP_STATE event ========================= ");
		handle_wifi_twt_state_event(cb);
		break;

	default:
		LOG_ERR("(WIFI) Unknown event: %d ", mgmt_event);
		break;
	}
}

My main function looks like:

int main(void)
{
	int i, ret;

	memset(&context, 0, sizeof(context));

	net_mgmt_init_event_callback(&wifi_shell_mgmt_cb,
								 wifi_mgmt_event_handler,
								 WIFI_SHELL_MGMT_EVENTS);

	net_mgmt_add_event_callback(&wifi_shell_mgmt_cb);

	net_mgmt_init_event_callback(&net_shell_mgmt_cb,
								 net_mgmt_event_handler,
								 NET_EVENT_IPV4_DHCP_BOUND);

	net_mgmt_add_event_callback(&net_shell_mgmt_cb);

	LOG_INF("Starting %s with CPU frequency: %d MHz", CONFIG_BOARD, SystemCoreClock / MHZ(1));
	k_sleep(K_SECONDS(1));

	LOG_INF("Static IP address (overridable): %s/%s -> %s",
			CONFIG_NET_CONFIG_MY_IPV4_ADDR,
			CONFIG_NET_CONFIG_MY_IPV4_NETMASK,
			CONFIG_NET_CONFIG_MY_IPV4_GW);

	while (1)
	{

		wifi_connect();

		for (i = 0; i < CONNECTION_TIMEOUT; i++)
		{
			k_sleep(K_MSEC(STATUS_POLLING_MS));
			cmd_wifi_status();
			if (context.connect_result)
			{
				break;
			}
		}

		if (context.connected)
		{
			LOG_INF("============ Connected to wifi ============");
			break;
		}
		else if (!context.connect_result)
		{
			LOG_ERR("Connection Timed Out");
		}

		k_sleep(K_MSEC(300));
	}

	k_sleep(K_SECONDS(2));

	if (!twt_supported)
	{
		LOG_INF("AP is not TWT capable, exiting the sample\n");
		return 1;
	}
	else
	{
		LOG_INF("AP is TWT capable, establishing TWT");
	}

	ret = setup_twt(true);
	if (ret)
	{
		LOG_ERR("Failed to establish TWT flow: %d\n", ret);
		return 1;
	}

	k_sleep(K_FOREVER);

	return 0;
}

And my setup_twt function looks like:

static int setup_twt(bool enable)
{
	struct net_if *iface = net_if_get_default();
	struct wifi_twt_params params = { };
	int ret;

	params.operation = WIFI_TWT_SETUP;
	params.negotiation_type = WIFI_TWT_INDIVIDUAL;
	params.setup_cmd = WIFI_TWT_SETUP_CMD_REQUEST;
	params.dialog_token = 1;
	params.flow_id = 1;
	params.setup.responder = 0;
	params.setup.implicit = 1;
	params.setup.trigger = IS_ENABLED(CONFIG_TWT_TRIGGER_ENABLE);
	params.setup.announce = IS_ENABLED(CONFIG_TWT_ANNOUNCED_MODE);
	params.setup.twt_wake_interval = CONFIG_TWT_WAKE_INTERVAL;
	params.setup.twt_interval = CONFIG_TWT_INTERVAL;

	ret = net_mgmt(NET_REQUEST_WIFI_TWT, iface, &params, sizeof(params));
	if (ret)
	{
		LOG_INF("TWT setup failed: %d", ret);
		return ret;
	}
	else
	{
		LOG_INF("TWT setup requested");
	}

	return 0;
}

What I want to know is:

  • What am I doing wrong in the wake up and sleep events detection (in order to send data via UDP during the wake time)?
  • How can I fix the problem?

P.S.:

Sometimes looks like the TWT is not set (Image 5):

Thanks a lot! 

  • Hi,

    Yes, I'm testing on NCS v2.4.2. 

    What you are telling me is to replace the nrf folder (inside v2.4.2) with sdk-nrf-2.4.99-dev2?  If yes, I get multiple errors when I create new build configuration in vscode.

  • Hi,

     

    you will need to use a terminal or a command prompt, which has "west" and "git" in the path. This can be done by opening the toolchain manager and selecting command line or git bash, or "terminal" on mac/linux:

     

    You should be placed in the "root" of ncs, where you have to change to the "nrf" directory:

    cd nrf
    git fetch
    git checkout v2.4.99-dev2
    west update

     

    The above commands can take some time, depending on your internet connection and so forth.

     

    Note: your repositories must be clean, ie. no changed files or uncommited changes.

     

    Kind regards,

    Håkon

  • HI,

    I didn't understand what I was supposed to do because using the Toolchain Manager, I could only install up to SDK v2.4.2.

    I managed to install v2.4.99-dev2 through vscode, but now I have more questions.

    While through v2.4.2 I got an output saying that the AP supported TWT, the output I have now is the following:


    Therefore, my questions are the following:

    • Since TWT is a wifi 6 feature, if the AP has wifi 6, shouldn't it support TWT?
    • What AP are you using to test this?
    • Do you have any AP list that allows TWT?
  • Hi,

     

    I'm using a Asus RT-AX53U, where I have enabled TWT on both 2.4 GHz and 5 GHz bands.

    Their firmware requires to enable it explicitly on both bands, where the default is "disabled":

     

    d_7 said:
    Since TWT is a wifi 6 feature, if the AP has wifi 6, shouldn't it support TWT?

    Yes, but this is a feature that most access points need to explicitly enable.

    d_7 said:
    Do you have any AP list that allows TWT?

    Most wifi-6 capable APs support it. I have both the Google nest wifi pro and the above mentioned Asus (most Asus wifi 6 capable routers have this feature)

     

    Kind regards,

    Håkon

  • Hello again,

    Now I can get the TWT events, but I have a question. At sleep time I'm supposed to have a uA consumption, right?

    I've been looking at the power consumption with the Joulescoupe and the result is as follows:

    From the image above, I can see that the average current consumption is 2,697mA (approx).

    If I only pay attention to the sleep time, we have an average current consumption of 1.96mA (approx), as we can see in the following image:

    Isn't this too much? Shouldn't it be in the order of the uA?

    I'm testing with CONFIG_TWT_INTERVAL=5 sec and CONFIG_TWT_WAKE_INTERVAL=65 ms. I've tested with the default values (524ms and 65ms) and I have the same results.

    Thank you

Related