# Localization in Low Power Wide Area Networks Using Wi-Fi Fingerprints
## 2 Methods and Materials
### Localization Approach  
The general approach of Wi-Fi fingerprinting localization can be divided into two steps: the training and operational step. Firstly, the training step is to discover networks or Wireless Access Points (WAP) and store their BSSID in a database, usually linked with the received signal strength at that location. There is no need to connect the Wi-Fi device with these access points. Secondly, the operational step is requesting from the database the location of newly discovered WAP during operation. The database will reply with the location of each WAP. We will not construct the database ourselves, but utilize databases that are available online; thus, we will only look into the operational step. To discover nearby access points, a laptop or a smartphone with a Wi-Fi adapter is required. A Python script saves the BSSID and received signal strength of each discovered access point. In Windows, this can easily be done by running the following command: netsh wlan show networks mode=bssid. The Python script then saves the output to a file, together with the current location. The current location is determined by a GPS module. To be more accurate, all locations are chosen to be recognized on a map, so that a visual check of the GPS location can be performed. This procedure is executed on 36 locations in and around Antwerp, Belgium. When the data is collected, a HTTP-request to a database will be performed for every BSSID. Afterwards, the database will respond with a message, which includes the coordinate of the access point. If the BSSID is not found in the database, an error message will be sent. Subsequently, all possible combinations of two BSSIDs are generated and the mean coordinate of every pair is calculated. If only one of the two BSSIDs was found in the database, the coordinate of that BSSID will be considered as the mean coordinate. Finally, the distance error can be calculated. This is the distance between the coordinate of the position where the measurement took place and the mean coordinate of the pair of BSSIDs. This distance is calculated using the Haversine function, which takes into account the curvature of the Earth [21]. Additionally, we calculate the probability of having no match of the BSSID in the database:  
\[P(\
eg nB)=\frac{\binom{\
eg B}{n}}{\binom{W}{n}}, \tag{1}\]  
where \(P(\cdot)\) is the probability operator; \(W\) is the number of access point seen at a location; \(B\) are the BSSIDs in \(W\) that are found in the database, \(\
eg B\) are the BSSIDs that are not found in the database; \(n\) is the number of BSSIDs that can be used for localization--in our case, this is maximum 2 because of the limitations of Sigfox communication; \(\
eg nB\) are the combinations of \(n\) BSSIDs that are not found in the database. This probability is interesting, because if no BSSIDs of the Wi-Fi access points that are seen at a location can be found in the database, the location of the device cannot be estimated. In an attempt to improve the accuracy of the results, we develop an additional strategy: only sending the combination of BSSIDs that have the strongest signal strength. It is not possible to send the RSSI values together with the BSSIDs in one Sigfox message, but we can use it in the sending device to determine the right combination of BSSIDs. Although this strategy is likely to consume more energy from the device (to pick the right combination of BSSIDs), it may decrease the mean location errors. Another improvement is attempted by combining the WiGLE and LocationAPI databases. The most straightforward combination is to take the average of the locations returned by each database. If a database does not return a location for one or both access points, these locations are simply disregarded in the calculation of the average. Since LocationAPI returns a single location for two BSSIDs, we account for that location twice, so that it receives an equal weight compared to the two results from the WiGLE database.