Enable or disable TWT with notification

I am studying Lesson 6/wifi fund_1ess6uexer2 and I can run the provided code normally.

(academy.nordicsemi.com/.../)
But I still want to control whether to send packets by pressing button 2 when turning off the TWT function.
As shown in step 3 of the diagram, when I turn off TWT, I press button 2 to enable the send package, but no data packet is sent. I tried to modify the code as shown in step 4 of the diagram, but couldn't. Could you please provide some help and guidance? Thank you very much!

Parents
  • Hi,

    This is due to how the exercise is implemented in such a way that it only sends a message during the awake state when TWT is enabled:

    static void twt_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event,
    				   struct net_if *iface)
    {
    	switch (mgmt_event) {
    	/* STEP 3.2.1 - Upon a TWT event, call handle_wifi_twt_event() to handle the response */
    	case NET_EVENT_WIFI_TWT:
    		handle_wifi_twt_event(cb);
    		break;
    	/* STEP 3.2.2 -	Upon TWT sleep state event, inform the user of the current sleep state.
    	 * When the device is in the awake state, send a packet to the server and check for any
    	 * received packets if sending packets is enabled. */
    	case NET_EVENT_WIFI_TWT_SLEEP_STATE:
    		int *twt_state;
    		twt_state = (int *)(cb->info);
    		LOG_INF("TWT sleep state: %s", *twt_state ? "awake" : "sleeping");
    		if ((*twt_state == WIFI_TWT_STATE_AWAKE) & sending_packets_enabled) {
    			send_packet();
    			receive_packet();
    		}
    		break;
    	}
    }

    If you want to be able to send packets when TWT is not enabled, you can call the function to send the packet directly in the button_handler() or schedule that it should be called. This code snippet shows how to call it directly in the button_handler():

    static void button_handler(uint32_t button_state, uint32_t has_changed)
    {
    	uint32_t button = button_state & has_changed;
    
    	/* STEP 5.1 - Call wifi_set_twt() to enable or disable TWT when button 1 is pressed. */
    	if (button & DK_BTN1_MSK) {
    		wifi_set_twt();
    	}
    
    	/* STEP 5.2 - Enable or disable sending packets during TWT awake when button 2 is pressed.
    	 */
    	if (button & DK_BTN2_MSK) {
    		send_packet();
    	}
    }

    If you want to schedule it, you can take a look at the TWT example here: https://github.com/martelmy/NCS_examples/blob/main/wifi/twt_provisioning_demo. In this example, pressing button 2 will schedule a ping that will either be sent immediately when TWT is not enabled or during the next wakeup when TWT is enabled. You can use work queue to schedule the UDP packet in the DevAcademy exercise in a similar way.
    Please note that this example is not official and should be considered provided “as-is”.

    Best regards,
    Marte

  • Thank you, . Your guidance is detailed and easy to understand.

    I still have questions, as shown in the picture, TWT mode and DTIM mode. How is the peak in the image caused in TWT mode? 

  • Thank you, . The last question, as you subscribe that, in legacy power save mode, after STA receives the data, the sta will be awake to send "ps-poll", as shown in the figure, so it keeps awake, does not go to sleep, still there is no data, sta then go to sleep, right? 

  • Hi,

    Since the device sent a packet, it will be awake to receive any response and ACKs from the AP. When it receives a frame from the AP informing it that the AP does not have any more data buffered for the device, it will go back to sleep.

    Best regards,
    Marte

  • OK, thank you . So, after it goes back to sleep, How is the peak current in the picture caused?

    I captured the package by the Wireshark and found that there is no package about STA, just about some AP broadcast package.

    As described in the official document "This means that the STA must send a PS-Poll frame for every downlink frame, which is sub-optimal with regards to efficiency and reducing overhead control signaling."https://academy.nordicsemi.com/courses/wi-fi-fundamentals/lessons/lesson-6-wifi-fundamentals/topic/power-save-modes-2/

    So, I think the peak current is caused by the "ps-poll" package, but sta nrf7002dk does not send any package. that is my question.

    And I want to know the the peak current include the package detail, just like the follow picture shows. can you give me some help?

  • Hi,

    ChengQing Zhao said:
    How is the peak current in the picture caused?

    It is the device waking up to see if the AP sends any DTIM beacons, indicating that the AP has data buffered for it.

    Best regards,
    Marte

  • OK, I see. As shown in the picture 1 and 2, the listen interval is 0x000a, and the beacon interval is 100ms.

    The sta will wake up 10 beacons(about 1 second ) to check if AP has data buffered for it.

    but why it is 100ms in the measurement of picture 3:

    picture 1:

    picture 2:

    picture 3:

    The capture package:

    listen interval .pcapng

Reply Children
Related