【已解决】zigbee电量一直不上报

Zigbee 子设备开发


Post Reply
wqvbdcb123
Posts: 31

电量一直不上报,请问这是哪里有问题?能否帮我们解决下,谢谢!

tuya-zigbee-sdk-tlsr8258-》tmp_hum_lcd

Code: Select all

"fimwareInfo": {
	"name": "tmp_hum_lcd_sensor",
	"description": "this is a project",
	"version": "1.0.0",
	"bv_version": "1.0",
	"ic": "TLSR8258F1KET",
	"ota_image_type":"0x1602",
	"manufacture_id":"0x1002",
	"model_id":"TS0201",
	"pid": "ncw88jfq",
	"manufacture_name": "_TZ3210_",
	"module_name":"TL8258"
},

下面是配置函数和上报函数,

/* battery_param parameter config! */
#define BATTERY_REPORT_MINUTE 240
#define BATTERY_MAX_MILLIV 3000
#define BATTERY_MIN_MILLIV 2400

void power_sampler_init(void)
{
battery_cfg_t battery_cfg = {
.cap_first_delay_time = 60,
.cap_waitting_silence_time = 5000,
.cap_max_period_time = BATTERY_REPORT_MINUTE601000,
.cap_max_voltage = BATTERY_MAX_MILLIV,
.cap_min_voltage = BATTERY_MIN_MILLIV,
.adc.adc_type = ADC_TYPE_VDD,
.adc.pos_pin = NULL,
.adc.neg_pin = NULL
};

Code: Select all

battery_table_t battery_table[] = {
    BATTERY_DEFAULT_TABLE
};

battery_report_policy_t bat_policy = {
    .type = BATTERY_TYPE_DRY_BATTERY,
    .level = DEV_BUSY_LEVEL_IDLE,
    .report_no_limits_first = TRUE,
    .limits = BATTERY_REPORT_DECREASE_LIMITS_20,
    .ext_limits = 0
};

hal_battery_config(&battery_cfg, battery_table, get_array_len(battery_table));
hal_battery_report_policy_config(&bat_policy);
dev_config_power_source_type(battery_source);           // write power source type

}

/**

  • @description: report battery voltage

  • @param {in} ep: endpoind

  • @return: none
    */
    void zig_report_battery_voltage(uint8_t ep)
    {
    uint8_t battery_percent;
    dev_zigbee_read_attribute(
    TMP_HUM_EP,
    CLUSTER_POWER_CONFIG_CLUSTER_ID,
    ATTR_BATTERY_PERCENTAGE_REMAINING_ATTRIBUTE_ID,
    &battery_percent,
    sizeof(battery_percent)
    );

    dev_send_data_t ret_data;
    attr_key_value_t *ret_attr = ret_data.data.zg.attr;

    memset(&ret_data, 0, sizeof(ret_data));
    /* Don't care
    ret_data.delay_time
    ret_data.random_time
    ret_data.zcl_id
    ret_data.command_type
    ret_data.addr.mode
    */
    ret_data.command_id = CMD_REPORT_ATTRIBUTES_COMMAND_ID;
    ret_data.direction = ZCL_DATA_DIRECTION_SERVER_TO_CLIENT;
    ret_data.qos = QOS_0;


    ret_data.addr.type.gw.src_ep = ep;
    ret_data.addr.type.gw.cluster_id = CLUSTER_POWER_CONFIG_CLUSTER_ID;
    ret_attr[0].attr_id = ATTR_BATTERY_PERCENTAGE_REMAINING_ATTRIBUTE_ID;
    ret_attr[0].type = ATTR_INT8U_ATTRIBUTE_TYPE;
    ret_attr[0].value_size = 1;
    ret_attr[0].value[0] = battery_percent;
    ret_data.data.zg.attr_sum++;
    dev_zigbee_send_data(&ret_data, NULL, 2000);
    }

wqvbdcb123
Posts: 31

Re: zigbee电量一直不上报

SDK1.0.2版本

wqvbdcb123
Posts: 31

Re: zigbee电量一直不上报

上电和正常情况下都不会上报,只是在配网的时候才上报电量一次。

iot_man
Posts: 66

Re: zigbee电量一直不上报

你的需求是什么,需要什么样的节奏上报?默认组件是按照你配置的参数上报。BATTERY_REPORT_MINUTE601000这个值是多少

wqvbdcb123
Posts: 31

Re: 【求助】zigbee电量一直不上报

BATTERY_REPORT_MINUTE 的值是240,我的需求是:上电的时候上报一次电量值,后面再每间隔4小时再上报一次电量值。

wqvbdcb123
Posts: 31

Re: 【求助】zigbee电量一直不上报

现在我们测试出来只有在配网时候才有电量上报,上电后和每间隔4小时都没有电量上报,太奇怪了,不知道问题出现在哪里?

马小勤
Posts: 42

Re: 【求助】zigbee电量一直不上报

旧版本SDK 的demo存在一些问题,可以添加 sdk_cb_register(CALLBACK_TYPE_CAPTURE_BATTERY, battery_sampling_evt_callback); 函数放在 system on的函数中即可,建议使用tuyaos的 wind IDE开发 旧版本SDK 不会更新了

wqvbdcb123
Posts: 31

Re: 【求助】zigbee电量一直不上报

void dev_system_on_init(void)
{
#ifdef APP_DEBUG
user_uart_config_t *default_config = mf_test_uart_config();
user_uart_init(default_config);
app_print("/---------------system up--------------/\r\n");
#endif
per_dev_init(); // peripheral init

Code: Select all

/* set max radio power */
dev_change_power(NORMAL_TX_POWER, MAX_TX_POWER);

dev_heartbeat_set(BATTERY_VOLTAGE, BATTERY_REPORT_MINUTE * 60 * 1000);     // set heart beat interval 240minute 240*60*1000
sdk_cb_register(CALLBACK_TYPE_CAPTURE_BATTERY, battery_sampling_evt_callback);

dev_led_stop_blink(LED_INDEX_0, DEV_IO_ON);
dev_timer_start_with_callback(POWER_UP_3S_SYN_EVT_ID, POWER_UP_LED_ON_TIME, dev_evt_callback);

}

wqvbdcb123
Posts: 31

Re: 【求助】zigbee电量一直不上报

函数sdk_cb_register(CALLBACK_TYPE_CAPTURE_BATTERY, battery_sampling_evt_callback)一直都是放在system on的函数里的.

Post Reply