## 4 EDETA Protocol Description
### Initialization Phase  
First of all, network initialization is performed. This phase lasts a maximum of two TIME_CONFIG. In this step, nodes select their CHs and a tree is built between CHs to send the collected data to the sink. The exact instant for the initialization phase can be scheduled offline at a given calendar point, or can be forced by means of special signals. Both mechanisms are being studied. On one hand, the availability of a RTC clock in each leaf node allows the inclusion of a \"first start\" event at design phase. On the other hand, remote wake-up of nodes by means of radio signals is being considering. Although some prototypes of this mechanism are currently working, it was considered a bit risky to include them in the real system. In this phase the network structure is built, consisting of three sub-phases. In the first part, with duration of half TIME_CONFIG, each node decides on its own if it is going to be a CH, based on the following procedure:  
Every node calculates a probability threshold based on several parameters. Some of them are pre-defined in analysis time, such as the desired percentage of active CH's in the network. Other change with time, such as remaining energy of the node, in comparison with the energy of the rest of the nodes in its environment, and the existence of nodes in the neighbor without access to any CH node. By means of this threshold, every node will decide randomly if it must become a CH or remain as a leaf node. When a node decides to be a CH it sends HEAD messages to announce its role to the rest. Initially, the sink node is the only one to offer connectivity to the rest, and also publishes it by means of its HEAD message. At the same time, a CH starts receiving HEAD messages from the others and decides which CH it will join in order to send its data to the sink. At this level, a CSMA (Carrier Sense Multiple Access) protocol is utilized in order to try to avoid collisions, but collisions are still possible. A CH will try to join another CH if the latter has established a path to the sink. That is, it can communicate with CHs that can reach the sink directly or through other CHs. This procedure will finally build a routing tree, where the \"root\" is occupied by the Sink node. Each CH in the tree should have one \"parent\" CH node--which will route its messages to the Sink node--and a bounded set of \"son\" CH's nodes, which deliver their messages through current CH node, Following with the \"family\" terminology, the \"grandfather\" CH node will be the \"father\" of a \"father\" node. Meanwhile, nodes which will become leaf nodes, start receiving HEAD messages as well. They store them to decide which CH to join in the second part of this phase. The selection of the CH for these nodes is based on factors such as energy requirements and RF distance to CHs. If a CH does not receive any HEAD messages, it sends a NEED_CH message. When a leaf node receives it, it reruns the procedure to decide whether it is going to be a CH or not, but with an increased probability of becoming a CH. In this case, the probability is increased in order to get the network to be built as fast as possible. This mechanism, along with the first random distribution of CHs, allows the protocol to rapidly adapt the CH population to the needs of the network. At the end of this sub-phase, the tree structure is built and leaf nodes have the necessary information to decide which clusters they are going to join. In the second sub-phase, with duration of half TIME_CONFIG, leaf nodes start to join their selected clusters and the CH sends, in the response message, the time schedule in which each node has to send its data. After that, leaf nodes enter sleep state. A CH can only allow a limited number of nodes to join. This number is given by the parameters MaxSoft and MaxHard. A CH accepts all join request petitions until it reaches its MaxSoft. After that, it will only accept join petitions that have activated a last resort bit. When a CH reaches the MaxHard threshold, it will no longer allow new joins.