## 4 Network Self-Organization
### Topology Discovery  
The topology discovery of the network aims to determine the positions of all nodes within the network. We establish a Cartesian coordinate system with the area's bottom edge as the \(x\)-axis and the left edge as the \(y\)-axis, as shown in Figure 3. It is well-known that determining the position of a point in a plane typically requires at least three known points. However, when anchor nodes are evenly distributed along the area's bottom edge, only two anchor nodes are sufficient to determine a node's position uniquely. As illustrated in Figure 4, if the distances from the unknown node \(N_{i}\) to two anchor nodes are \(d_{1}\) and \(d_{2}\), respectively, the possible positions of node \(N_{i}\) are at points \(O_{1}\) and \(O_{2}\). Since the anchor nodes are located along the area's bottom edge, and the unknown node \(N_{i}\) is within the area, the position of \(N_{i}\) must be at point \(O_{1}\).  
Figure 4: The unique location of node \(N_{i}\).  
Figure 3: Monitoring area in Cartesian coordinate system.  
The distance between anchor nodes is \(L\). When \(L\) is too large, some sensor nodes may fail to establish connections with at least two anchor nodes. When \(L\) is too small, the anchor nodes increase, leading to data redundancy and higher costs. To meet the self-organizing requirements and minimize the number of anchor nodes, \(L\) should be set reasonably. As shown in Figure 5, when sensor node \(N_{i}\) is located above anchor node \(A_{j}\), \(N_{i}\) is farthest from \(A_{j-1}\) and \(A_{j+1}\). Therefore, \(L\) should satisfy the following formula:  
\[L=\lfloor\sqrt{R_{max}^{2}-H^{2}}\rfloor \tag{4}\]  
Since the anchor nodes are evenly spaced, the following equation gives the number of anchor nodes \(a\):  
\[a=\lceil\frac{W}{L}+1\rceil \tag{5}\]  
During the topology discovery phase, all nodes will broadcast using their maximum communication radius, \(R_{max}\). At least two anchor nodes will discover each node. The anchor nodes will determine their distance to the node using Formula (6), then reply with the distance \(d_{ij}\) and their identifier \(A_{j}\). When receiving data from anchor nodes, nodes will select the two nearest anchor nodes to determine their positions.  
\[d=10^{\frac{|\text{RSSI}-A|}{10\times N}} \tag{6}\]  
\(A\) represents the signal strength when the transmitter and receiver are one meter apart, and \(N\) is the environmental attenuation factor. Subsequently, the anchor nodes return the distance to the sensor node, which calculates its coordinates \((x_{i},y_{i})\). The sensor node selects the two closest anchor nodes, as shown in Figure 6. Sensor node \(N_{i}\) forms a triangle with the anchor nodes \(A_{j}\) and \(A_{j+1}\), and the area of this triangle can be calculated using [PERSON]'s formula.  
\[S=\sqrt{p(p-d_{ij})(p-d_{i(j+1)})(p-L)} \tag{7}\]  
where \(p\) is the semiperimeter of the triangle, which is \(\frac{d_{ij}+d_{i(j+1)}+L}{2}\). Since the length of the triangle base is \(L\), we can determine the \(y\)-coordinate \(y_{i}\) of \(N_{i}\) according to the triangle area formula:  
Figure 5: The maximum distance \(L\) between anchor nodes.  
\[y_{i}=\frac{2S}{L} \tag{8}\]  
and the following equation determines the \(x\)-coordinate \(x_{i}\) of node \(N_{i}\).  
\[x_{i}=j\times L+\sqrt{d_{ij}^{2}-y_{i}^{2}} \tag{9}\]  
After determining their positions, the nodes send their coordinates and identifiers to the nearest anchor node, which forwards this information to the sink.