STM32WB Zigbee: How to set the PowerSource to Battery and report Battery Voltage and Remaining percentage
Hello, I'm trying to make a Zigbee application for a battery powered device (currently using the ZHA integration on Home Assistant) and I am having trouble to set the attribute for a battery power source, (it seems to be stuck on the default of Mains), however setting the manufacturer and model strings are working.
static const struct ZbZclAttrT optional_attr_list[] =
{
{
ZCL_POWER_CONFIG_ATTR_BATTERY_VOLTAGE,
ZCL_DATATYPE_UNSIGNED_8BIT,
ZCL_ATTR_FLAG_REPORTABLE | ZCL_ATTR_FLAG_PERSISTABLE,
0,
NULL,
{0, 100},
{10, 300}
},
{
ZCL_POWER_CONFIG_ATTR_BATTERY_PCT,
ZCL_DATATYPE_UNSIGNED_8BIT,
ZCL_ATTR_FLAG_REPORTABLE | ZCL_ATTR_FLAG_PERSISTABLE,
0,
NULL,
{0, 100},
{10, 300}
}
};
static void APP_ZIGBEE_ConfigEndpoints(void)
{
struct ZbApsmeAddEndpointReqT req;
struct ZbApsmeAddEndpointConfT conf;
memset(&req, 0, sizeof(req));
/* Endpoint: SW1_ENDPOINT */
req.profileId = ZCL_PROFILE_HOME_AUTOMATION;
req.deviceId = ZCL_DEVICE_SIMPLE_SENSOR;
req.endpoint = SW1_ENDPOINT;
ZbZclAddEndpoint(zigbee_app_info.zb, &req, &conf);
assert(conf.status == ZB_STATUS_SUCCESS);
/* Power config server */
zigbee_app_info.power_config_server_1 = ZbZclPowerConfigServerAlloc(zigbee_app_info.zb, SW1_ENDPOINT);
assert(zigbee_app_info.power_config_server_1 != NULL);
ZbZclAttrAppendList(zigbee_app_info.power_config_server_1, optional_attr_list, ZCL_ATTR_LIST_LEN(optional_attr_list)); //not working...
ZbZclClusterEndpointRegister(zigbee_app_info.power_config_server_1);
APP_ZIGBEE_ConfigBasic();
} static void APP_ZIGBEE_ConfigBasic(void) {
char *mfr_str = "stm32";
uint8_t zb_mfr_str[10];
memcpy(&zb_mfr_str[1], mfr_str, strlen(mfr_str));
zb_mfr_str[0] = strlen(mfr_str);
ZbZclBasicWriteDirect(zigbee_app_info.zb, SW1_ENDPOINT,
ZCL_BASIC_ATTR_MFR_NAME, zb_mfr_str, 6);
char *model_str = "wb55";
uint8_t zb_model_str[7];
memcpy(&zb_model_str[1], model_str, strlen(model_str));
zb_model_str[0] = strlen(model_str);
ZbZclBasicWriteDirect(zigbee_app_info.zb, SW1_ENDPOINT,
ZCL_BASIC_ATTR_MODEL_NAME, zb_model_str, 5);
uint8_t power_source = ZCL_BASIC_POWER_BATTERY;
ZbZclBasicWriteDirect(zigbee_app_info.zb, SW1_ENDPOINT,
ZCL_BASIC_ATTR_POWER_SOURCE, &power_source, 1); //not working...
ZbZclAttrIntegerWrite(zigbee_app_info.power_config_server_1,
ZCL_BASIC_ATTR_POWER_SOURCE, ZCL_BASIC_POWER_BATTERY); //also not working...
struct ZbZclBasicServerDefaults basic_config;
basic_config.power_source = ZCL_BASIC_POWER_BATTERY;
ZbZclBasicServerConfigDefaults(zigbee_app_info.zb, &basic_config); //also not working...
}
I am using the following stack:
[M4 APPLICATION] WIRELESS COPROCESSOR FW:
[M4 APPLICATION] VERSION ID = 1.14.0
[M4 APPLICATION] FW Type : FFD Zigbee stack
Thank you.
