Skip to content

Commit 02cf2fc

Browse files
FilipZajdelrlubos
authored andcommitted
zigbee: Handle error while entering identify mode
Add an error handling for a case when device is requested to enter identify mode but is not ready to do so - usually on startup. Signed-off-by: Filip Zajdel <filip.zajdel@nordicsemi.no>
1 parent 9fb5793 commit 02cf2fc

File tree

6 files changed

+59
-27
lines changed

6 files changed

+59
-27
lines changed

applications/zigbee_weather_station/src/main.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,17 @@ static void start_identifying(zb_bufid_t bufid)
177177
*/
178178
if (dev_ctx.identify_attr.identify_time ==
179179
ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE) {
180-
LOG_INF("Manually enter identify mode");
181180

182181
zb_ret_t zb_err_code = zb_bdb_finding_binding_target(
183182
WEATHER_STATION_ENDPOINT_NB);
184-
ZB_ERROR_CHECK(zb_err_code);
183+
184+
if (zb_err_code == RET_OK) {
185+
LOG_INF("Manually enter identify mode");
186+
} else if (zb_err_code == RET_INVALID_STATE) {
187+
LOG_WRN("RET_INVALID_STATE - Cannot enter identify mode");
188+
} else {
189+
ZB_ERROR_CHECK(zb_err_code);
190+
}
185191
} else {
186192
LOG_INF("Manually cancel identify mode");
187193
zb_bdb_finding_binding_target_cancel();

samples/zigbee/light_bulb/src/main.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ ZBOSS_DECLARE_DEVICE_CTX_1_EP(
195195
*/
196196
static void start_identifying(zb_bufid_t bufid)
197197
{
198-
zb_ret_t zb_err_code;
199-
200198
ZVUNUSED(bufid);
201199

202200
if (ZB_JOINED()) {
@@ -205,10 +203,17 @@ static void start_identifying(zb_bufid_t bufid)
205203
*/
206204
if (dev_ctx.identify_attr.identify_time ==
207205
ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE) {
208-
LOG_INF("Enter identify mode");
209206

210-
zb_err_code = zb_bdb_finding_binding_target(DIMMABLE_LIGHT_ENDPOINT);
211-
ZB_ERROR_CHECK(zb_err_code);
207+
zb_ret_t zb_err_code = zb_bdb_finding_binding_target(
208+
DIMMABLE_LIGHT_ENDPOINT);
209+
210+
if (zb_err_code == RET_OK) {
211+
LOG_INF("Enter identify mode");
212+
} else if (zb_err_code == RET_INVALID_STATE) {
213+
LOG_WRN("RET_INVALID_STATE - Cannot enter identify mode");
214+
} else {
215+
ZB_ERROR_CHECK(zb_err_code);
216+
}
212217
} else {
213218
LOG_INF("Cancel identify mode");
214219
zb_bdb_finding_binding_target_cancel();

samples/zigbee/light_switch/src/main.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ static void light_switch_send_on_off(zb_bufid_t bufid, zb_uint16_t on_off);
198198
*/
199199
static void start_identifying(zb_bufid_t bufid)
200200
{
201-
zb_ret_t zb_err_code;
202-
203201
ZVUNUSED(bufid);
204202

205203
if (ZB_JOINED()) {
@@ -208,9 +206,16 @@ static void start_identifying(zb_bufid_t bufid)
208206
*/
209207
if (dev_ctx.identify_attr.identify_time ==
210208
ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE) {
211-
LOG_INF("Enter identify mode");
212-
zb_err_code = zb_bdb_finding_binding_target(LIGHT_SWITCH_ENDPOINT);
213-
ZB_ERROR_CHECK(zb_err_code);
209+
210+
zb_ret_t zb_err_code = zb_bdb_finding_binding_target(LIGHT_SWITCH_ENDPOINT);
211+
212+
if (zb_err_code == RET_OK) {
213+
LOG_INF("Enter identify mode");
214+
} else if (zb_err_code == RET_INVALID_STATE) {
215+
LOG_WRN("RET_INVALID_STATE - Cannot enter identify mode");
216+
} else {
217+
ZB_ERROR_CHECK(zb_err_code);
218+
}
214219
} else {
215220
LOG_INF("Cancel identify mode");
216221
zb_bdb_finding_binding_target_cancel();

samples/zigbee/network_coordinator/src/main.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ static void identify_cb(zb_bufid_t bufid)
142142
*/
143143
static void start_identifying(zb_bufid_t bufid)
144144
{
145-
zb_ret_t zb_err_code;
146-
147145
ZVUNUSED(bufid);
148146

149147
if (ZB_JOINED()) {
@@ -152,9 +150,17 @@ static void start_identifying(zb_bufid_t bufid)
152150
*/
153151
if (dev_ctx.identify_attr.identify_time ==
154152
ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE) {
155-
LOG_INF("Enter identify mode");
156-
zb_err_code = zb_bdb_finding_binding_target(ZIGBEE_COORDINATOR_ENDPOINT);
157-
ZB_ERROR_CHECK(zb_err_code);
153+
154+
zb_ret_t zb_err_code = zb_bdb_finding_binding_target(
155+
ZIGBEE_COORDINATOR_ENDPOINT);
156+
157+
if (zb_err_code == RET_OK) {
158+
LOG_INF("Enter identify mode");
159+
} else if (zb_err_code == RET_INVALID_STATE) {
160+
LOG_WRN("RET_INVALID_STATE - Cannot enter identify mode");
161+
} else {
162+
ZB_ERROR_CHECK(zb_err_code);
163+
}
158164
} else {
159165
LOG_INF("Cancel identify mode");
160166
zb_bdb_finding_binding_target_cancel();

samples/zigbee/shell/src/main.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ static void identify_cb(zb_bufid_t bufid)
124124
*/
125125
static void start_identifying(zb_bufid_t bufid)
126126
{
127-
zb_ret_t zb_err_code;
128-
129127
ZVUNUSED(bufid);
130128

131129
if (ZB_JOINED()) {
@@ -134,10 +132,17 @@ static void start_identifying(zb_bufid_t bufid)
134132
*/
135133
if (dev_ctx.identify_attr.identify_time ==
136134
ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE) {
137-
LOG_INF("Enter identify mode");
138-
zb_err_code = zb_bdb_finding_binding_target(
135+
136+
zb_ret_t zb_err_code = zb_bdb_finding_binding_target(
139137
APP_ZIGBEE_ENDPOINT);
140-
ZB_ERROR_CHECK(zb_err_code);
138+
139+
if (zb_err_code == RET_OK) {
140+
LOG_INF("Enter identify mode");
141+
} else if (zb_err_code == RET_INVALID_STATE) {
142+
LOG_WRN("RET_INVALID_STATE - Cannot enter identify mode");
143+
} else {
144+
ZB_ERROR_CHECK(zb_err_code);
145+
}
141146
} else {
142147
LOG_INF("Cancel identify mode");
143148
zb_bdb_finding_binding_target_cancel();

samples/zigbee/template/src/main.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ static void identify_cb(zb_bufid_t bufid)
127127
*/
128128
static void start_identifying(zb_bufid_t bufid)
129129
{
130-
zb_ret_t zb_err_code;
131-
132130
ZVUNUSED(bufid);
133131

134132
if (ZB_JOINED()) {
@@ -137,10 +135,17 @@ static void start_identifying(zb_bufid_t bufid)
137135
*/
138136
if (dev_ctx.identify_attr.identify_time ==
139137
ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE) {
140-
LOG_INF("Enter identify mode");
141-
zb_err_code = zb_bdb_finding_binding_target(
138+
139+
zb_ret_t zb_err_code = zb_bdb_finding_binding_target(
142140
APP_TEMPLATE_ENDPOINT);
143-
ZB_ERROR_CHECK(zb_err_code);
141+
142+
if (zb_err_code == RET_OK) {
143+
LOG_INF("Enter identify mode");
144+
} else if (zb_err_code == RET_INVALID_STATE) {
145+
LOG_WRN("RET_INVALID_STATE - Cannot enter identify mode");
146+
} else {
147+
ZB_ERROR_CHECK(zb_err_code);
148+
}
144149
} else {
145150
LOG_INF("Cancel identify mode");
146151
zb_bdb_finding_binding_target_cancel();

0 commit comments

Comments
 (0)