Matter/Thread event indicating "ready to update status" and "status confirmed updated" ?

Without really delving into the guts of the nrf boilerplate code, are there any sections or events that can inform the application that we are ready to establish connection with the edge router and another event that says "we have updated our status successfully" ??

The idea is to power up a commissioned board (already part of the fabric but turned off) and immediately report to the system the current state of the board. Then go to low power. 

I am not 100% on the "when data" is passed around stage.

Ultimately, I could wait a bit and generate a change state event, but to do that would like to know when the radio is "ready to go", so an event telling me such would be nice. Having the acknowledgement or reception would be nice too.

Maybe I am wagging the dog on this. 

A. M.

  • Hi,

    In our Thread samples we have a callback for when the Thread state changes, for example:

    static void on_thread_state_changed(otChangedFlags flags, struct openthread_context *ot_context,
    				    void *user_data)
    {
    	if (flags & OT_CHANGED_THREAD_ROLE) {
    		switch (otThreadGetDeviceRole(ot_context->instance)) {
    		case OT_DEVICE_ROLE_CHILD:
    		case OT_DEVICE_ROLE_ROUTER:
    		case OT_DEVICE_ROLE_LEADER:
    			k_work_submit(&on_connect_work);
    			is_connected = true;
    			break;
    
    		case OT_DEVICE_ROLE_DISABLED:
    		case OT_DEVICE_ROLE_DETACHED:
    		default:
    			k_work_submit(&on_disconnect_work);
    			is_connected = false;
    			break;
    		}
    	}
    }
    static struct openthread_state_changed_cb ot_state_chaged_cb = {
    	.state_changed_cb = on_thread_state_changed
    };

    This callback is registered with openthread_state_changed_cb_register():

    openthread_state_changed_cb_register(openthread_get_default_context(), &ot_state_chaged_cb);

    The Thread device role, given by otThreadGetDeviceRole(), should give you an indication of whether the device is connected to the network or not. Disabled means that the Thread stack is disabled, while detached means that the Thread stack is enabled but the device is currently not connected to a Thread network. Child, router and leader indicates that the device is connected to a network.

    In Matter, the ChipEventHandler() function will be called when the Thread state changes. You can use this to know when the device has changed role, and also whether the device is connected to a network or not. This is the relevant part of the function:

    case DeviceEventType::kThreadStateChange:
    	sIsNetworkProvisioned = ConnectivityMgr().IsThreadProvisioned();
    	sIsNetworkEnabled = ConnectivityMgr().IsThreadEnabled();

    This should be implemented in the app_task.cpp file, see light_switch/src/app_task.cpp as an example.

    Best regards,
    Marte

  • Some redirect, in the V2.6.0 version of the code base, this is now part of the common 
    void Board::DefaultMatterEventHandler(const ChipDeviceEvent *event, intptr_t /* unused */)

    in the v2.6.0\nrf\samples\matter\common\src\board\board.cpp

Related