## 4 Routing Protocol  
Traditional SPIN is a data-centric [11] routing protocol for WSN. It disseminates all the information from each node to every other node in the network. It includes two aspects: Firstly, the sensor nodes negotiate with each other before transmitting the actual data. Meanwhile, the node confirms whether it has received the same information for the metadata. Second, each node in the network must monitor the consumption of energy. It is basically a three-way handshake protocol. This enables a user to query any node and get the required information immediately.  
SPIN takes advantages of the three-way handshake mechanism to transmit the data information [12]. As Figure 3 shows, the grey nodes represent that they are under data transmission. There are three types of message structure in SPIN: ADV, REQ and DATA. The ADV message can broadcast the information and the size of ADV is much smaller than the actual data, if no neighbor nodes are interested in the data, probing with an ADV message costs less energy than sending data directly. When a sensor node has data to share, it will notice its neighbor via the ADV message first. A REQ message is used to request the transmission of data, if a sensor node is interested in the data after receiving ADV, it responds with a REQ to the sending node. DATA message is the packet involving the original sensing data. When the source node receives REQ, it starts to send DATA to the next node.  
The depiction of SPIN is as follow.  
* The source, node A, broadcasts the ADV to all its neighbors while it collects new data information.
* If its neighbor, node B, is interested in the data and it has not already received the same data, it responds with a REQ to node A.
* After node A receives the REQ from node B, it starts to send the DATA to B.
* Node B repeats node A's procedure to transmit data to the next hop until the sink node receives the data.  
It is possible that a data packet is transmitted in the opposite direction of sink node in SPIN, so a large amount of energy is wasted by some unnecessary multi-hop transmissions and it also increases the network transfer delay resulting from network congestion. If it is possible to control the number of transmissions and receipt of messages, a significant amount of energy can be saved. When an event occurs, it is always desirable that the data is sent through the nodes in the direction of the sink node rather than in the opposite direction. This saves energy for transmission of a piece of data from an event node to the sink node. However, such selective transmission is not supported in the existing SPIN protocols. Data will have to travel to more hops if they are sent via the nodes in the opposite direction. In addition, it is possible that a node refuses to receive the data because of low energy or no interest. As a result, the data fails to transmit to sink node. To overcome these problems, we propose an ESPIN protocol.  
In our proposed protocol, we add a new phase called distance discovery to measure the distance of each sensor node in the network from the sink node in terms of hops. This means that nodes having a higher value of hop distance are further away from the sink node. What is more, we set compulsory advice (CA) when the sending node fails to receive a REQ message, in order to improve the data delivery success ratio. We divide ESPIN protocol in three parts: Distance discovery phase, negotiation phase and data transmission phase. On the basis of hop distance, negotiation is done for sending actual data. Therefore, use of hop value controls dissemination of data in the network. Finally, data is transmitted to the sink node.