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! 

Parents
  • Hi,

     

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

    I would recommend that you first try with a low TWT_INTERVAL, and then increase this when you have a working setup.

    We are continuously improving our handling in this case. Have you looked at the recently updated twt sample in main? It includes handling for this scenario:

    https://github.com/nrfconnect/sdk-nrf/commit/e05d9c964c8d7a5f77418347deda6f5795cf9b7e

     

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

    Q1: Does the firmware run as expected here?

    Q2: Does the current consumption drop after 60 seconds?

    Q3: Which AP are you testing against?

    Kind regards,

    Håkon

  • Hi,

    I decreased the TWT interval to 200ms but the problem remained (I did not detect the wake up and sleep events).

    Regarding your questions:

    • Q1: What is seen in Image 5 does not occur every time. Although the code is always the same, sometimes it presents the result shown in Image 3 and other times it presents the result in Image 5.
    • Q2: When I obtain the result shown in Figure 5, the current consumption always remains around 173mA and never decreases again (even after those 60 seconds).
    • Q3: I'm testing with a Ubiquiti AP. I'm using the UniFi 6+.

    I was also testing the recently updated twt sample in main and I still can't detect the events. In fact, it seems that it doesn't even enter the NET_EVENT_WIFI_TWT_SLEEP_STATE case.

    In this sample I made the following changes:

    • main.c :
      1. Added the NET_EVENT_WIFI_TWT_SLEEP_STATE to the WIFI_SHELL_MGMT_EVENTS:
      2. Added LOG_WRN to the switch...case to check if these events occurred:

    • Kconfig (samples/wifi/twt) :
      1. As I want to use TWT, I changed the default value for SCHEDULED_TX

    • prj.conf :
      1. Added the following configugurations:
        CONFIG_TRAFFIC_GEN_CLIENT=y
        CONFIG_TRAFFIC_GEN_SERVER=n
        CONFIG_TRAFFIC_GEN_DURATION=10
        CONFIG_TRAFFIC_GEN_TYPE_TCP=y
        CONFIG_TRAFFIC_GEN_REMOTE_IPV4_ADDR="10.10.10.76"
        #
        CONFIG_TWT_TRIGGER_ENABLE=y
        CONFIG_TWT_ANNOUNCED_MODE=y
        CONFIG_SCHEDULED_TX=y

    The result is as follows:

    So my questions are:

    • With the changes I've made, if TWT was working correctly, shouldn't I have gotten the LOG_WRN("NET_EVENT_WIFI_TWT_SLEEP_STATE event")?
    • And the LOG_INF("SLEEP state") and LOG_INF("AWAKE state")?

    As far as I can see, I'm still not able to detect these events. Right?

  • Hi,

     

    Yes, as far as I see, you should now have gotten TWT events.

     

    As your log output shows "wrn", it should be configured with the correct. Are you certain you set CONFIG_SCHEDULED_TX for this build? Could you try removing that ifdef and see if it starts printing? Here's the output when I tried adding the same events and added a LOG_INF print in the event:

    ...
    [00:00:08.700,500] <inf> twt: DHCP IP address: 192.168.32.128
    [00:00:08.703,063] <inf> twt: ==================
    [00:00:08.703,094] <inf> twt: State: COMPLETED
    [00:00:08.703,094] <inf> twt: Interface Mode: STATION
    [00:00:08.703,125] <inf> twt: Link Mode: WIFI 6 (802.11ax/HE)
    [00:00:08.703,155] <inf> twt: SSID: OpenWrt                         
    [00:00:08.703,186] <inf> twt: BSSID: FC:34:97:0B:F6:DC
    [00:00:08.703,216] <inf> twt: Band: 5GHz
    [00:00:08.703,216] <inf> twt: Channel: 44
    [00:00:08.703,247] <inf> twt: Security: WPA2-PSK
    [00:00:08.703,247] <inf> twt: MFP: Optional
    [00:00:08.703,277] <inf> twt: RSSI: -55
    [00:00:08.703,277] <inf> twt: TWT: Supported
    [00:00:10.703,369] <inf> twt: AP is TWT capable, establishing TWT
    [00:00:10.715,850] <inf> twt: TWT setup requested
    [00:00:10.817,718] <inf> twt: TWT response: TWT accept
    [00:00:10.817,749] <inf> twt: == TWT negotiated parameters ==
    [00:00:10.817,749] <inf> twt: TWT Dialog token: 1
    [00:00:10.817,749] <inf> twt: TWT flow ID: 0
    [00:00:10.817,779] <inf> twt: TWT negotiation type: TWT individual negotiation
    [00:00:10.817,810] <inf> twt: TWT responder: false
    [00:00:10.817,840] <inf> twt: TWT implicit: true
    [00:00:10.817,840] <inf> twt: TWT announce: false
    [00:00:10.817,871] <inf> twt: TWT trigger: false
    [00:00:10.817,901] <inf> twt: TWT wake interval: 65024 us
    [00:00:10.817,901] <inf> twt: TWT interval: 524000 us
    [00:00:10.817,901] <inf> twt: ========================
    [00:00:10.818,664] <inf> twt: NET_EVENT_WIFI_TWT_SLEEP_STATE
    [00:00:10.818,725] <inf> twt: NET_EVENT_WIFI_TWT_SLEEP_STATE
    [00:00:11.015,960] <inf> twt: TWT Setup success
    [00:00:11.195,495] <inf> twt: NET_EVENT_WIFI_TWT_SLEEP_STATE
    [00:00:11.654,846] <inf> twt: NET_EVENT_WIFI_TWT_SLEEP_STATE
    ...

    d_7 said:
    Q2: When I obtain the result shown in Figure 5, the current consumption always remains around 173mA and never decreases again (even after those 60 seconds).

    173 mA? That is alot. I have seen RX current levels for 60 seconds if a operation fails (on-air) on previous ncs versions, but this seems like a larger scale problem. If you have an algorithm, or a sample, where this can be seen, I would be very interested in replicating and reporting it internally.

     

    Kind regards,

    Håkon

  • Hi,

    Yes, I can send the algorithm.

    twtUpdated.zip

    The AP that I'm using is the UniFi 6+.

     

  • Hi,

     

    My apologies, but I've been testing on the devtag "v2.4.99-dev1" (dev2 is also out now), which includes this specific fix for the TWT sleep:

    https://github.com/nrfconnect/sdk-nrf/pull/11488/files

     

    Are you testing on NCS v2.4.2 or older? If yes, could you try to test on tag v2.4.99-dev2 and see if you are able to get the sleep events?

     

    Kind regards,

    Håkon

  • 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.

Reply Children
  • 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

  • Hi,

     

    I set the TWT to 5.24 seconds, and wake interval to 65 ms, and this is my observed current during TWT:

    Are you certain that you actually enter TWT? TWT shall have a floor current of less than 20 uA.

     

    Kind regards,

    Håkon

Related