@@ -50,7 +50,7 @@ bool ZigbeeCore::begin(esp_zb_cfg_t *role_cfg, bool erase_nvs) {
50
50
if (xSemaphoreTake (lock, _begin_timeout) != pdTRUE) {
51
51
log_e (" ZigbeeCore begin failed or timeout" );
52
52
if (_role != ZIGBEE_COORDINATOR) { // Only End Device and Router can rejoin
53
- resetChannelMask ();
53
+ resetNVRAMChannelMask ();
54
54
}
55
55
}
56
56
return started ();
@@ -85,7 +85,7 @@ bool ZigbeeCore::begin(zigbee_role_t role, bool erase_nvs) {
85
85
if (!status || xSemaphoreTake (lock, _begin_timeout) != pdTRUE) {
86
86
log_e (" ZigbeeCore begin failed or timeout" );
87
87
if (_role != ZIGBEE_COORDINATOR) { // Only End Device and Router can rejoin
88
- resetChannelMask ();
88
+ resetNVRAMChannelMask ();
89
89
}
90
90
}
91
91
return started ();
@@ -261,9 +261,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
261
261
esp_zb_bdb_open_network (Zigbee._open_network );
262
262
} else {
263
263
// Save the channel mask to NVRAM in case of reboot which may be on a different channel after a change in the network
264
- Zigbee.setPrimaryChannelMask (1 << esp_zb_get_current_channel ());
265
- esp_zb_set_channel_mask (1 << esp_zb_get_current_channel ());
266
- zb_nvram_write_dataset (ZB_NVRAM_COMMON_DATA);
264
+ Zigbee.setNVRAMChannelMask (1 << esp_zb_get_current_channel ());
267
265
Zigbee._connected = true ;
268
266
}
269
267
Zigbee.searchBindings ();
@@ -309,9 +307,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
309
307
);
310
308
Zigbee._connected = true ;
311
309
// Set channel mask and write to NVRAM, so that the device will re-join the network faster after reboot (scan only on the current channel)
312
- Zigbee.setPrimaryChannelMask (1 << esp_zb_get_current_channel ());
313
- esp_zb_set_channel_mask (1 << esp_zb_get_current_channel ());
314
- zb_nvram_write_dataset (ZB_NVRAM_COMMON_DATA);
310
+ Zigbee.setNVRAMChannelMask (1 << esp_zb_get_current_channel ());
315
311
} else {
316
312
log_i (" Network steering was not successful (status: %s)" , esp_err_to_name (err_status));
317
313
esp_zb_scheduler_alarm ((esp_zb_callback_t )bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000 );
@@ -506,12 +502,20 @@ void ZigbeeCore::searchBindings() {
506
502
esp_zb_zdo_binding_table_req (mb_req, bindingTableCb, (void *)mb_req);
507
503
}
508
504
509
- void ZigbeeCore::resetChannelMask () {
505
+ void ZigbeeCore::resetNVRAMChannelMask () {
510
506
_primary_channel_mask = ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK;
511
507
esp_zb_set_channel_mask (_primary_channel_mask);
512
508
zb_nvram_write_dataset (ZB_NVRAM_COMMON_DATA);
513
509
log_v (" Channel mask reset to all channels" );
514
510
}
511
+
512
+ void ZigbeeCore::setNVRAMChannelMask (uint32_t mask) {
513
+ _primary_channel_mask = mask;
514
+ esp_zb_set_channel_mask (_primary_channel_mask);
515
+ zb_nvram_write_dataset (ZB_NVRAM_COMMON_DATA);
516
+ log_v (" Channel mask set to 0x%08x" , mask);
517
+ }
518
+
515
519
// Function to convert enum value to string
516
520
const char *ZigbeeCore::getDeviceTypeString (esp_zb_ha_standard_devices_t deviceId) {
517
521
switch (deviceId) {
0 commit comments