Remove Sub-Devices

Last Updated on : 2023-09-22 03:13:05download

This topic describes how to remove a sub-device from the cloud.


There are two approaches to removing a sub-device:

  • After end-users Disconnect or Disconnect and Wipe Data on the mobile app, the SDK will trigger a callback to notify the application of this event.
  • The application then initiates a remove event.

How to

  • Remove a sub-device using the mobile app:

    Remove Sub-Devices

    The application calls tuya_subdev_user_sigle_type_reg to register the device management callback and implement the callback for dev_del and dev_reset.

  • The application initiates a remove event:

    The application calls tuya_iot_gw_unbind_dev.

Data structure

 * @brief sub-device management callback
typedef struct __ty_gw_subdev_mgr_cbs_s {
    GW_PERMIT_ADD_DEV_CB                dev_add;            // permit joining callback, see GW_PERMIT_ADD_DEV_CB
    GW_DEV_DEL_CB                       dev_del;            // remove callback, see GW_DEV_DEL_CB
    DEV_RESET_IFM_CB                    dev_reset;          // reset callback, see DEV_RESET_IFM_CB
    GW_BIND_DEV_INFORM_CB               dev_bind;           // bind result callback, see GW_BIND_DEV_INFORM_CB

    DEV_OBJ_DP_CMD_CB                   dp_cmd_obj;         // obj DP command, see DEV_OBJ_DP_CMD_CB
    DEV_RAW_DP_CMD_CB                   dp_cmd_raw;         // raw DP command, see DEV_RAW_DP_CMD_CB
    DEV_DP_QUERY_CB                     dp_query;           // DP query, see DEV_DP_QUERY_CB

    DEV_HEARTBEAT_SEND_CB               dev_hb;             // heartbeat query callback, see DEV_HEARTBEAT_SEND_CB
    DEV_UG_INFORM_CB                    dev_upgrade;        // upgrade callback, see DEV_UG_INFORM_CB
    GW_DEV_WAKEUP_CB                    dev_wakeup;         // low power device wakeup callback, see GW_DEV_WAKEUP_CB
    GW_DEV_GRP_INFM_CB                  dev_grp_info;       // group control callback, see GW_DEV_GRP_INFM_CB
    GW_DEV_SCENE_INFM_CB                dev_sce_info;       // scene control callback, see GW_DEV_SCENE_INFM_CB

    GW_DEV_SIGMESH_TOPO_UPDAET_CB       bt_topo_update;     // Bluetooth LE device added callback, see GW_DEV_SIGMESH_TOPO_UPDAET_CB
    GW_DEV_SIGMESH_DEV_CACHE_DEL_CB     bt_cache_del;       // Bluetooth LE device removed callback, see GW_DEV_SIGMESH_DEV_CACHE_DEL_CB
    GW_DEV_SIGMESH_CONN_CB              bt_conn;            // Bluetooth LE device event callback, see GW_DEV_SIGMESH_CONN_CB

    DEV_ONLINE_STAT_SEND_CB             dev_online;         // online state changed callback, see DEV_ONLINE_STAT_SEND_CB

API description

Unbind sub-devices

 * @brief unbind a sub-device from the gateway, which will be blocked in the process.
 * @param id sub-device id
 * @return OPERATE_RET OPRT_OK is success
OPERATE_RET tuya_iot_gw_unbind_dev(IN CONST CHAR_T *id);

If a sub-device is removed with a hard reset locally, the application calls tuya_iot_gw_unbind_dev to notify the server of unbinding from the sub-device. OPRT_OK is returned on a successful request.


  * @brief The callback to invoke when to delete a device.
  * @param[in]     dev_id      : The device ID
  * @param[in]     type        : The delete mode
  STATIC VOID __dev_del_cb(CONST CHAR_T *dev_id, CONST GW_DELDEV_TYPE type)
      * TODO:
      *   type == GWDEV_DELTYPE_MQTT: MQTT(real time)
      *   type == GWDEV_DELTYPE_SYNC: device not in the cloud, need delete.

  * @brief The callback to invoke when to reset a device.
  * @param[in]     dev_id      : The device ID
  * @param[in]     type        : The reset mode
  STATIC VOID __dev_reset_cb(CONST CHAR_T *dev_id, DEV_RESET_TYPE_E type)
      * TODO
      *   type == DEV_REMOTE_RESET_FACTORY: App remote
      *   type == DEV_RESET_DATA_FACTORY: need clear local data when bind

  TY_GW_SUBDEV_MGR_CBS_S  dev_mgr_cbs = {
      .dev_del       = __dev_del_cb,
      .dev_reset     = __dev_reset_cb,

  tuya_subdev_user_sigle_type_reg( &dev_mgr_cbs , DEV_ATTACH_MOD_1 );