# LaRaWAN Metering Infrastructure Planning in Smart Cities
## 4 New Proposals and Results
### K-Means-Based Gateway Deployment  
Messages from the individual nodes are sent several times a day and contain compressed AMI profiles and basic measurement values (e.g., voltage, current value of energy consumed, or cosine fi). Minimal downlink traffic is generated for real-time clock synchronization in order to schedule the timing of messages sent by each node (a process in the application server manages the scheduling process to avoid collisions). From the point of view of the efficiency of the designed network, it is important to select the location of the gateway and to establish the radio coverage of the individual nodes.  
As mentioned in the previous section, the K-means algorithm will be used to cluster the points representing the end nodes of the LoRaWAN network and determine the optimal placement of gateways. To determine the value of the \(K\) parameter, two methods were used: elbow method, by determining WCSS and cluster quality, and _silhouette coefficient_. The so-called _elbow method_ is based on the principle that as the number of clusters increases, the WCSS coefficient, which is the sum of the squares of the Euclidean distances from each node to the centroid, decreases. The silhouette coefficient, on the other hand, measures how well nodes are assigned to their own cluster, yet how far they are from other clusters. This parameter close to 1 means that the data points are in the right cluster, while a silhouette coefficient close to \(-1\) means that the nodes are in the wrong cluster. In both cases, \(K=4\) was determined as the optimal number of gateways to ensure that each node belonged to the designated clusters (Figure 2).  
Figure 3 shows the application of the K-means algorithm for LoRaWAN end nodes randomly distributed over a \(6\times 6\) km square area. Some simplifications have been adopted in this model. All nodes have the same radio range and operate with \(SF=7\). They were randomly distributed on the plane. The Euclidean distance was used to determine the distance between each node and the centroid, which was determined from geographical coordinates. The presentation of network coverage and visualization is taken from the TTN Mapper project [40]. The colour of the line and point reflects the value of the RSSI parameter (e.g., red for RSSI \(>-100\) dBm and blue for RSSI \(<-120\) dB). The hypothetical range of the gateway has been marked for the clarity of the figure (the ranges of the nodes would obscure the figure). Note that all nodes were assigned to individual clusters; no noise remained in the clustering process.  
Despite the assignment of nodes to the cluster, the radio loss model used (COST-231 Hata) determines the ability to communicate with the gateway. Figure 2(a) shows grey-colored nodes whose transmit power is too low for the gateway to receive messages or for the gateway to send an uplink message in the first transmission window (RX1) [14]. If the number of clusters is increased to 4 in the same network, full radio coverage can be achieved (Figure 2(b)). Figure 2 shows two ways to determine the optimal number of clusters (elbow collapse and the maximum value of the form factor occurs for \(K=4\)).  
Figure 3: An example of a network topology using the K-means algorithm to determine LoRaWAN gateway locations.  
Figure 2: Determination of the optimal number of clusters using the elbow method **(a)** and silhouette coefficient **(b)**.