Problem Background:
When a Bluetooth device is added to the gateway and immediately reports data, there may be a loss of DP data.Problem Analysis:
After analysis, when a device is added to the gateway, it is divided into two parts: successful pairing between the sub-device and the gateway, and successful addition of the gateway to the cloud. When the first step of successful pairing between the sub-device and the gateway is completed, the gateway receives data and reports it to the cloud. However, at this time, the interaction between the gateway and the cloud regarding the pairing of the sub-device may not have ended, and the sub-device model has not been established in the cloud and locally. In this case, the reported DP will be discarded.Solution:
Add data caching for sub-devices.Introduction to the Cache Component Interface:
typedef struct {
// Maximum cache byte count
UINT8_T max_dev_nums;
// Maximum number of caches per device
UINT8_T max_dev_items;
// Cache validity time
UINT16_T invalid_second;
} GW_SUBDEV_CACHE_PARAMS;
// Current device status
typedef enum {
GW_SBUDEV_CACHE_START, // When the gateway completes pairing with the sub-device, perform START to inform the component that data can be cached
GW_SUBDEV_CACHE_FINIT, // The gateway completes the binding interaction with the cloud, and the cached data is interacted and reported.
GW_SUBDEV_CACHE_CANCLE, // The gateway fails to interact with the cloud, cancel the cached data
} GW_SUBDEV_CACHE_STATUS;
// Cached device type
typedef enum {
GW_SUBDEV_CACHE_MESH = 0,
GW_SUBDEV_CACHE_BLE,
GW_SBUDEV_CACHE_BEACON,
GW_SUBDEV_CACH_ZIGBEE,
} GW_SUBDEV_CACHE_DEV_TYPE;
typedef void (*TUYA_CACHE_DATA_CBS)(IN CONST CHAR_T *dev_id, IN CONST void *prams, UINT16_T params_len, IN CONST UINT8_T *pdata, UINT16_T data_len, UINT_T timestamp);
// Initialization
OPERATE_RET tuya_subdev_cache_init();
// Set the corresponding cache data reporting method callback
void tuya_subdev_cache_cbs_set(GW_SUBDEV_CACHE_DEV_TYPE type, GW_SUBDEV_CACHE_PARAMS *params, TUYA_CACHE_DATA_CBS cbs);
// Set the current cache device status, START, FINISH, CANCEL...
void tuya_subdev_cache_status_set(GW_SUBDEV_CACHE_DEV_TYPE type, IN CONST UINT8_T *dev_id, GW_SUBDEV_CACHE_STATUS stat);
// Input cache data, can be cached when the current status is START, otherwise an error will be returned. An error will also be returned if the cache count is exceeded.
int tuya_subdev_cache_data_set(GW_SUBDEV_CACHE_DEV_TYPE type, IN CONST UINT8_T *dev_id, IN CONST void *param, UINT16_T param_len, IN CONST UINT8_T *pdata, UINT16_T len);
- Remaining Issues:
For mesh devices, there is fast networking. When the gateway is in fast networking mode, it cannot receive any mesh data that has been networked. Even with caching functionality, the problem of DP loss cannot be solved.