diff --git a/RF24Mesh.cpp b/RF24Mesh.cpp index be6ef20..d781ee3 100644 --- a/RF24Mesh.cpp +++ b/RF24Mesh.cpp @@ -16,7 +16,8 @@ ESBMesh::ESBMesh(radio_t& _radio, network_t& _network) : rad setCallback(NULL); meshStarted = false; #if !defined(MESH_NOMASTER) - addrMemAllocated = false; + addrList = nullptr; + addrListTop = 0; #endif } @@ -42,14 +43,6 @@ bool ESBMesh::begin(uint8_t channel, rf24_datarate_e data_ra } } else { -#if !defined(MESH_NOMASTER) - if (!addrMemAllocated) { - addrMemAllocated = true; - addrList = (addrListStruct*)malloc((MESH_MEM_ALLOC_SIZE * sizeof(addrListStruct))); - addrListTop = 0; - loadDHCP(); - } -#endif mesh_address = 0; network.begin(mesh_address); } @@ -438,6 +431,12 @@ template void ESBMesh::setNodeID(uint8_t nodeID) { _nodeID = nodeID; +#if !defined(MESH_NOMASTER) + if (!nodeID && addrList == nullptr) { + addrList = (addrListStruct*)malloc((MESH_MEM_ALLOC_SIZE * sizeof(addrListStruct))); + loadDHCP(); + } +#endif } /*****************************************************/ diff --git a/RF24Mesh.h b/RF24Mesh.h index 603adcb..1673306 100644 --- a/RF24Mesh.h +++ b/RF24Mesh.h @@ -369,8 +369,6 @@ class ESBMesh #if !defined(MESH_NOMASTER) /** Indicator that an address request is available. */ bool doDHCP; - /** Just ensures we don't re-allocate the memory buffer if restarting the mesh on master. **/ - bool addrMemAllocated; #endif /** Starts up the network layer with default address. */