# Voice Assistant Application for Avoiding Sedentarism in Elderly People Based on IoT Technologies
## 3 Proposed System
### Developed Software for the Edge Computing Device
#### 3.3.1 Tracker Thread: Tracking Smart BLE Smart Bracelet  
This thread is in charge of managing the Bluetooth BLE connection of the ECD periodically, detecting nearby smart bracelets. It has two responsibilities: on the one hand to detect the presence of the user, so that s/he can be interacted with correctly through the VA, on the other hand, to obtain the data from his/her smart bracelet so that his/her daily progression can be processed. To fulfil these two responsibilities, the tracker thread periodically scans for Bluetooth devices trying to find the smart bracelet associated with the user, filtering those with a Bluetooth BLE service related to the smart bracelet used, to subsequently to check if among the devices found is the one associated with the user linked to the ECD. Once the desired smart bracelet is found, the tracker thread connects to it in order to obtain the information of the physical activity performed by the user until that moment to be able to upload the user's updated data to the real-time database. At that moment, the changes produced in the database are monitored by a function as a service (FaaS) that is in charge of processing them. Finally, after processing the data, this function will establish through a message whether it is necessary to transmit an encouragement message to the user based on the Gamification strategy implemented in the system. This message will be transmitted and processed by the mailbox thread, which will be detailed later in Section 3.3.2. In the smart bracelet detection algorithm, described in the Algorithm 1, the connection only occurs when the distance based on the Received Signal Strength Indicator (RSSI) exceeds a certain distance threshold. Different types of filtering have been studied for calculating the distance and inferring the presence of the device: (1) basic connection based on the distance from the RSSI without the use of a filter, (2) connection after applying a filter based on the mean, (3) connection after applying a filter based on the median, and (4) application of the 1D Kalman filter. ```
Inputs: distanceThreshold filter userBracelet deviceAdvertisments <- scanDeviceAdvertismentPackets(userBracelet) rssi <- applyRssiiFilter(deviceAdvertisments, filter) distance <- calculateDistance(rssi) ifdistance < distanceThreshold then connectToDevice() braceletInfo <- getDataFromDevice() sendInfoToDB(braceletInfo) endif Outputs: distance braceletInfo
```  
**Algorithm 1** Smart bracelet tracking algorithm. The RSSI metric was processed by obtaining the distance as a reference measure. The Log-distance path loss model, Equation (1) ([PERSON] and [PERSON] [53]), has been used to calculate the distance between the smart bracelet and the ECD (Equation (2)), where \(RSSI(d)\) is the signal strength at a distance \(d\) in dBm, \(RSS_{d0}\) the signal strength at a reference distance \(d_{0}\) in dBm, \(n\) the path loss index of shadow fading whose approximate values were extracted from [PERSON] et al. [54] and can be seen in the Table 1, and \(X_{0}\) is the Gaussian noise with zero mean, which is assumed to be zero. \[RSSI(d)_{dbm}=RSS_{d_{0}}-10n\log_{10}\left(\frac{d}{d_{0}}\right)+X_{0} \tag{1}\]  
\[distance=d_{0}\cdot 10^{\frac{RSS_{d_{0}}-RSSI(d)+X_{0}}{10\times n}} \tag{2}\]  
The average and median filters adjust the RSSI received signal by taking into consideration the last \(n\) measurements, also called the frame size parameter. To obtain the estimated RSSI, the average RSSI of these \(n\) measurements is calculated in the first filter or the median value in the second one is chosen. The value of \(n\) should be small in cases where a short reaction time is desired or the elicitation times between measurements are long, otherwise too much delay will be added to the estimated measurement due to the low density of samples over time. A Kalman filter is an optimal estimation algorithm used to estimate measurements that cannot be obtained directly and correctly. [PERSON] et al.