Device Sharing

Last Updated on : 2024-02-20 02:11:16download

After a mobile app adds a Matter device, it can generate a sharing code that enables this device to be paired and controlled with third-party Matter-enabled mobile apps.

The TuyaOS Matter over Thread SDK has integrated the Matter sharing feature.

Sharing process

App 1 and App 2 refer to Matter-enabled mobile apps, such as Tuya Smart, Apple Home, Google Home, and Amazon Alexa.
Device refers to a Matter device.

App 1DeviceApp 2Turn on device sharing.Display the QR code or pairing code.Scan the QR code or enter the pairing code.Establish a PASE session.Get the device certificate.Verify if the device is Matter-certified.Configure the network information.Establish a secure session channel using CASE.Get the device information.Pairing succeeds.App 1DeviceApp 2

API description

Network status callback

VOID_T network_change_callback(MATTER_EVT_E event, PVOID_T parg)
{
    switch(event)
    {
        case MATTER_EVT_POWER_ON:
        if(tal_matter_status_get() == MATTER_ST_POWER_ON_CONNECTED)
        {
            TUYA_LOG("### MATTER_ST_POWER_ON_CONNECTED ### ");
            ty_led_action_on(NET_LED_INDEX);
        }else if(tal_matter_status_get() == MATTER_ST_POWER_ON_UNCONNECTED)
        {
            TUYA_LOG("### MATTER_ST_POWER_ON_UNCONNECTED ### ");
            ty_led_action_off(NET_LED_INDEX);
        }
        break;
        case MATTER_EVT_COMMISSION_START:
            if(tal_matter_status_get() == MATTER_ST_CONNECTED)
            {
                TUYA_LOG("### Sharing device  MATTER_EVT_COMMISSION_START ### ");
            }
            else
            {
                TUYA_LOG("### MATTER_EVT_COMMISSION_START ### ");
            }
            ty_led_action_blink(NET_LED_INDEX, 1000, 1000, 0xffff, LED_OFF);
        break;
        case MATTER_EVT_COMMISSION_OK:
            if(tal_matter_status_get() == MATTER_ST_CONNECTED)
            {
                TUYA_LOG("### Sharing device MATTER_EVT_COMMISSION_OK ### ");
            }
            else
            {
                TUYA_LOG("### MATTER_EVT_COMMISSION_OK ### ");
            }
            ty_led_action_on(NET_LED_INDEX);
        break;
        case MATTER_EVT_COMMISSION_FAILED:
            if(tal_matter_status_get() == MATTER_ST_CONNECTED)
            {
                TUYA_LOG("### Sharing device MATTER_EVT_COMMISSION_FAILED ### ");
            }
            else
            {
                TUYA_LOG("### MATTER_EVT_COMMISSION_FAILED ### ");
            }
            ty_led_action_off(NET_LED_INDEX);
        break; 
        case MATTER_EVT_RESET_FACTORY_NEW:
            TUYA_LOG("### MATTER_EVT_RESET_FACTORY_NEW ### ");
            ty_led_action_blink(NET_LED_INDEX, 250, 250, 0xffff, LED_OFF);
        break;  
        case MATTER_EVT_REMOVE_FABRIC:
            TUYA_LOG("### MATTER_EVT_REMOVE_FABRIC %d ### ",tal_get_fabric_num());
        break;  
        default:
        break;     
    }
}

Call MATTER_STATUS_E tal_matter_status_get(VOID_T) in MATTER_EVT_COMMISSION_START, MATTER_EVT_COMMISSION_OK, or MATTER_EVT_COMMISSION_FAILED. If the return value is MATTER_ST_CONNECTED, it indicates that sharing is in progress.

  • MATTER_EVT_COMMISSION_START: Sharing starts.
  • MATTER_EVT_COMMISSION_OK: Sharing succeeds.
  • MATTER_EVT_COMMISSION_FAILED: Sharing fails.

For more information, see Matter functions.

Support and help

If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.