Device Reset

Last Updated on : 2024-03-07 07:47:33download

This topic describes Bluetooth mesh device reset and how to use the APIs. Users can reset a device remotely by removing it from the mobile app or locally using physical buttons or power cycling. After a reset, the device enters pairing mode.

Data structure

MESH_PROVISION_TYPE_T

typedef enum {
    MESH_PB_GATT = 0x00,           /**< Enable PB-GATT, device can be provisioned by GATT connect (mobile phone use). */
    MESH_PB_ADV,                   /**< Enable PB-ADV, device can be provisioned by ADV (Gateway use). */
    MESH_PB_GATT_AND_PB_ADV,       /**< Enable PB-ADV and PB_ADV, device can be provisioned by ADV and GATT connect (Gateway use). */
    MESH_PROVISION_DISABLE,        /**< Disable provision, close the unprovision beacon and GATT unprovision adv. */
} MESH_PROVISION_TYPE_T;

This is the request parameter for the pairing enablement API. You can enable or disable unprovisioned device advertising. If you select MESH_PROVISION_DISABLE, the unprovisioned device will not advertise its presence to the provisioner and thus will not be discovered and paired.

MESH_NETWORK_STATE_SET_T

typedef enum {
    MESH_NETWORK_RESET = 0x00,            /**< Kick out, mesh node will be in the unprovision state, and it will clear the mesh provision data in RAM and flash */
    MESH_NETWORK_RESET_WITH_RECOVER,      /**< Node reset in RAM, mesh node will be in the unprovision state, and it will clear the mesh provision data in RAM. The provision data is still stored in flash */
    MESH_NETWORK_RECOVER,                 /**< Recover the network, mesh node will be in the provision state, it will restore the provision data from flash into RAM */
} MESH_NETWORK_STATE_SET_T;

This is the request parameter for device reset and recovery.

  • MESH_NETWORK_RESET resets a device irreversibly. This method applies when the mobile app or gateway sends a reset command.

  • MESH_NETWORK_RESET_WITH_RECOVER resets a device without erasing the Bluetooth mesh data from flash memory, only updating the network information in RAM. Therefore, the mesh network can be restored with the data stored in the flash memory. This method applies when a device is reset locally, especially through power cycling. This method can restore the network connection without pairing the device.

  • After a reset with MESH_NETWORK_RESET_WITH_RECOVER, set MESH_NETWORK_RECOVER as the request parameter to immediately restore the mesh network to its previous state before the reset. Alternatively, restart the device to restore the pairing information before the reset.

TAL_MESH_NET_STATE_T

typedef enum{
    TAL_MESH_POWER_ON_UNPROVISION = 0x00,
    TAL_MESH_POWER_ON_PROVISIONED,
    TAL_MESH_PROVISION_SUCCESS,

    TAL_MESH_RESET,
    TAL_MESH_RESET_IN_RAM,
    TAL_MESH_REVERT_IN_MESH,

    TAL_MESH_GROUP_SUB_ADD,
    TAL_MESH_GROUP_SUB_DEL,

    TAL_GATT_OTA_START,
    TAL_GATT_OTA_SUCCESS,
    TAL_GATT_OTA_FAIL,

    TAL_STATE_UNKONWN
}TAL_MESH_NET_STATE_T;

This parameter represents the event type for device status callbacks. The SDK will notify the application layer through a callback whenever there are any changes in status.

API description

Device reset and recovery

OPERATE_RET tal_mesh_network_state_set(MESH_NETWORK_STATE_SET_T net_state);

You can specify whether to use the network recovery feature based on how the device is reset.

Bluetooth mesh network status callback

TUYA_WEAK_ATTRIBUTE VOID tal_mesh_state_callback(TAL_MESH_NET_STATE_T state);

The Bluetooth mesh status callback is implemented with a weak function. If a function instance is not created in the service layer, the bottom layer will link a null function to the firmware. You need to create an instance of this function in the application layer so that the SDK can inform the service layer about the action it has performed.

Enable pairing

VOID tal_mesh_node_provision_enable(MESH_PROVISION_TYPE_T enable);

When the device is not paired, you can use this API to disable or enable pairing. After MESH_PROVISION_DISABLE is invoked, the device will stop advertising its presence to the mobile app or gateway and thus will not be discovered and paired.

This function typically works with a pairing timeout. For example, a device stays in pairing mode for 10 minutes after a reset. After a timeout, the pairing mode will be turned off.