Developing Cost Effective Smartwatch Heart Rate Monitoring for Android Device

Heart related disease is one of deadly non communicable diseases. In order to detect heart related problems, heart rates must be monitored. Monitoring heart rate can be done with several methods, from stethoscope, to sensors such as PPG and ECG sensors. However, those monitoring can be impractical as it requires doctor visitations. In order to simplify the process, smartwatch is used. Those devices are usually equipped with heart rate monitoring sensors, and many others. However, some previously researched smartwatch-based systems used in monitoring health are cost prohibitive as some requires their own server, high price of smartwatches used, and cumbersome to use. The goal of this research is to build cost effective heart rate monitoring using cheap smartwatches. A proposed system using smartwatch and Android device is used alongside with Whatsapp messaging, with ringtone that plays when emergency situation happened. The message contains GPS location and emergency condition. The resulting system does not require custom made server and nets an acceptable GPS coordinate accuracy outdoors, but not so accurate indoors. It also does not require expensive smartwatches. However, the system requires the device to not be locked due to limitations on Android devices.


Introduction
One of the most undetected health problems is heart related problem.This health problem oftentimes happens unpredictably, leading to fatal consequences.According to World Health Organization's data in 2019, 7 out 10 causes of death are non-communicable diseases [1, p. 10].The most leading cause of death is ischaemic heart disease [2], which can range from nothing is felt, to chest pain, and finally heart attack [3].
The simplest way to detect heart related problem is by monitoring heart rate which utilizes stethoscope, or electrocardiogram (ECG) which detects electrical current on body, or photoplethysmography (PPG) which involves detecting light bouncing from light source.ECG is very accurate and can be used for real time monitoring, but it came at a cost of expensive price [4].Stethoscope is very cheap, but it requires some knowledge for using it, alongside with practicality issue where it cannot be used for real time monitoring [5].PPG is a cheaper priced alternative to stethoscope, offering both ECG usability & practicality, at a cost of accuracy due to moving body parts also known as motion artifacts [6].This necessitates a heart rate monitoring system that does not involves doctor trip and also does monitoring in real-time [4].Hence whys introduction of Internet of Things (IoT) device especially smartwatch wearables are very important, as they can assist users for monitoring health related issues such as heart rate, blood oxygen, body temperature, and many others.Usually, those smartwatches are connected with Bluetooth Low Energy, a protocol specifically designed for lower power consumption and fewer data transmission [7], [8].
Similar research involving heart rate monitoring already been conducted before, such as Wettstein's [9], where it monitors both heart rate and body temperature and also implements machine learning algorithm as unique standpoint.It does not use smartwatch; however, it shares similar component with smartwatch which is the PPG heart rate sensor mounted on ear.
Another research with similar concept also has been conducted before by Pektaş's [10].The differences are the applications are developed on the smartwatch themselves, alongside with usage of additional blood glucose sensor, due to research being focused on Other research for similar system also has developed by Kheirkhahan's [11].This system is much more sophisticated, as the system monitors more than heart rate.The system also questions the users for medical assessments (examples are hospitalizations, falls, scale of pain, mood, fatigue, sleep, and activity) alongside monitoring heart rate.This system also runs on custom servers.The smartwatch used is Samsung Gear S2 and S3, which runs Tizen OS.
Researcher's aim is to develop a heart rate monitoring system that is cheap (under 1 million IDR, or 65 USD or 60 EURvalue as March 2023), easy to use and implement, and easy to develop upon with plenty of documentations.
For this research, The researcher used Xiaomi's Mi Band 5 as the smartwatch device which costs 40 EUR in Europe or 25 EUR equivalent in Indonesia [12], alongside with an Android smartphone Xiaomi's Poco F4, but technically any Android smartphone that can connect to internet and having GPS alongside with Bluetooth will work.
The Mi Band 5 smartwatch has two disadvantages: lack of GPS capabilities, and needs to be paired with generated token to Xiaomi's server.An open source Python based application that generates token already exists (huami-token), however they are not integrated in the application [13], [14].As the result, huami-token must be analyzed for reimplementation.
Although Xiaomi Mi Band smartwatch were bundled with their own application, Zepp Life [15], there is an open source Android application that contains connection reimplementation for Zepp Life.One of them is Gadgetbridge [16].This application already has most of function needed to get started, such as GPS location, connection mechanism, and heart rate detection.
In this research, researcher aims to modify Gadgetbridge application to achieve the goal of informing doctor or special person (important person in charge) whenever emergency condition arose, which in this case, high or low heart rate.The location of the user also will be shared to important person in charge by getting GPS location.Researcher also aims to simplify connection process by reimplementing huami-token for the application.
To inform the important person in charge, researcher used Whatsapp messaging service due to sheer amount of users that used this messaging application (around 2 billion users, outpacing Facebook Messenger which was owned by the same company, Meta, Inc.) [17], ensuring lower barrier to entry.
Modifications made to the application are two of the following: Revision of application's Xiaomi connection system so that users do not need to use another application (huami-token) to pair the smartwatch, and adding Whatsapp sending system.
The unique standpoint of this particular heart rate monitoring system is cost effectiveness, as this system does not involve any custom server hosting, does not require an expensive smartwatch, and does not require specialized equipment for processing the smartwatch data.

Analysis of Problem
Analysis involves getting user requirements, alongside with analyzing huami-token and Gadgetbridge application.User requirements from the problem above are: application must be able to connect with smartwatch, application must be able to monitor heart rate using the smartwatch, and application must be able to get user's current location, especially during emergency situation.
Analysis on huami-token reveals that in order to generate the token needed to pair for connecting the smartwatch, a HTTP request has to be made, in 3 steps: logging in, obtaining the token, and logging out.Some of variable are static.
Analysis on Gadgetbridge application reveals that the application lacking of token generation necessary for connecting with Xiaomi smartwatches, instead instructing user to use external application (which in this case, huami-token) [14].It also reveals that there is unused low heart rate measurement.Furthermore, there's no function to determine safe heart rate threshold according to age of user, however the application supports birth year to be stored, so calculation can be done easier.

Application Design with BPMN
The flow design of application was made using BPMN.application determines the pairing mechanism according to their make and model, as some devices has specialized pairing mechanism that requires authorization token / key.If the device happens to be made by Xiaomi, the application would generate the key by using user's inputted credentials on that process.But if the device was not made by Xiaomi, it attempts to directly connects to the device until successful.After paired, the device acts as heart rate sensor for heart rate monitoring system.Safe heart rate monitoring threshold depends on several factors such as the age and body condition.During exercising or intense condition, the safe maximum heart rate threshold is higher than usual, which can be calculated with formula (1).
While under normal condition, safe heart rate threshold can be seen in Table 1.Those safe heart rate threshold seen on Table 1 applies for both male and female [18].The Android phone is also used to send emergency message via Whatsapp to important person in charge whenever emergency condition arose.The general architecture of this system will be shown in Figure 5.The smartwatch is paired to user's smartphone via Bluetooth.A modified Gadgetbridge application acts as monitoring service, reading smartwatch data and getting current location.
In order to have smartwatch paired, a token / key must be generated.Researcher used Postman application to replicate the function of huami-token, this application also can be used to generate corresponding programming code for several programming languages for conducting HTTP requests.Afterwards, the essential functions of huami-token are reimplemented from Python programming language to Java programming language.
In order to send Whatsapp message programmatically, researcher followed instruction on this [19] page (sending message via intent), alongside with adding extra intent telephone number (dubbed JID, which is undocumented, but has been found by analyzing the application done by Mikhailov [20]).However, the resulted behavior is the message was not sent automatically.This is not ideal, as in emergency situation, user assumed to have no control to the smartwatch.In order to send Whatsapp message automatically, AccessibilityService were used.This android service can be used to automate touch screen taps and keystroke, which made them ideal for this application [21].
In order to attract people around the user, the application plays ringtone that would not stop until the ringtone file duration actually ends.For instance, if the ringtone file is 10 minutes long, the application would play it for 10 minutes long after emergency situation was triggered.

Implementation
The user required at least once to pair the watch with Zepp Life application (for Xiaomi), after that, the application can be either force stopped or uninstalled [14].If those steps have been done, user can run this application.
Then, user also has to accept several important permissions, most importantly locations, disabling battery optimizations (to ensure the application keeps monitoring the heart rate alongside with making sure Accessibility Services operate as it's should) and adding the application to Android Accessibility, which will be done later.Optionally, user can disable the smartwatch's lock screen in order to allow the application functioning as intended.
In order to prepare for heart rate monitoring, user first must set their birth year by going to the settings and choosing "About You" on options.User can enter birth year here.Setting age is only important if using smart heart detection system.
User then must enable emergency heart rate monitoring, alongside entering telephone number that can be used with Whatsapp messaging service, which belongs to important person in charge.
After all the permission allowed, pairing with smartwatch can be commenced, and key / token can be generated for Xiaomi smartwatch without exiting application.Once connected, the screen would display connected devices as seen in Figure 9.In order to enable emergency heart rate monitoring, user just need to tap heart with exclamation mark symbol.This would ask for accessibility permission.User must add the application to Android Accessibility so that Whatsapp message can be sent automatically.After enabling the accessibility permission, the screen as seen in Figure 10 would be shown.The user just needs to tap start and check the notification if the emergency heart rate monitoring system is running as seen in the Figure 11.Whenever emergency situation occurs and the smartphone is not locked, application would change the notification alongside sending the Whatsapp message.An example of message being sent can be seen the Figure 12.The message contains the GPS location coordinates wrapped on Google Maps link, with emergency status reported.
Figure 12.Example of sent messages.

Application
Due to limitations in heart rate testing, testing is conducted with lower heart rate threshold.However, the smart heart rate measurement (age based) has been found to work correctly according to specifications.The testing is focused on GPS location discrepancies between indoor and outdoor usage.Data used for Table 2 were obtained using Google Maps current location coordinates alongside with coordinates sent from the application.However, there are some factors that caused GPS location discrepancy, including satellite positioning, GPS receiver features (which can differ on each phone models), and user's surrounding obstacles.In some case, the GPS location shown in Google Maps keeps deviating.This situation happens in tall buildings.
The application managed to alert the area surrounding user by playing ringtone that would not stop until the actual ringtone file ended.Whilst this is not a problem for long ringtone files, this caused a problem with shorter ones, as they would stop quickly.
Due to how Android operating system works, this application cannot send message when the phone is locked.In order to send Whatsapp message, it requires the phone number to be saved.If it is not saved, the message would not be sent.The rundown is listed on Table 3.

System Comparisons
This system is being compared with previous and existing systems, listing their advantage alongside with their disadvantage.Comparison can be seen on Table 4.

Conclusion
An Android based heart rate monitoring system have been developed.The system monitors heart rate and also calculates safe range of heart rate based on user age.Then once the heart range is not in the safe range, the system would try to warn important person in charge by sending a Whatsapp message if the device is unlocked, and at the same time, emitting loud noise that can attract attention from surroundings.This emergency heart rate monitoring system designed to be simple to use and also cost effective, as the smartwatch used costs less than 1 million IDR, and can be used with any smartphone with Bluetooth, internet, and GPS capability.This application also useful for elderly and people with higher risk of heart attacks.Researcher hoped this research can advance development on emergency heart rate measurement, especially costeffective ones.
This application still has more room for an improvement.One of them is increasing GPS accuracy, support for lock screen status detection, support for multiple contacts, support for alternative messaging services (especially SMS since it does not require internet connection to report to the important person in charge), improving ringtone alert system to support shorter ringtone by looping, adding a system that detects exercise / sport activity due to higher heart rate threshold, and other capabilities such as generic SOS signal sending.Battery life of both smartwatch and smartphone also must be taken into account, as smartwatch constantly attempting to monitor the heartrate alongside with sending them, and the smartphone continuously received smartwatch data

Figure 1 .
Figure 1.BPMN flowchart for entire application On Figure 1, entire application flowchart was described.The application firstly scans the presence of device every 30 seconds.Then the user selects the device, the

Figure 2 .
Figure 2. BPMN flowchart for pairing On Figure 2, entire pairing mechanism flowchart was described.The pairing flowchart splits due to some smartwatch (especially made by Amazfit and Xiaomi, alongside with Fossil) requires to have server-sided token / key generation for pairing.Researcher only implemented token / key generation for Xiaomi smartwatch due to only focusing on Xiaomi's Mi Band 5.

Figure 3 .
Figure 3. BPMN flowchart for logging to Xiaomi account

Figure 5 .
Figure 5. BPMN flowchart for heart rate monitoring

Figure 7 .
Figure 7. BPMN flowchart for sending message via Whatsapp On Figure 7, the flowchart shows how does application sends Whatsapp message if phone number are present.Clicks must be automated, because by default when the Intent were sent to Whatsapp, the application does not send the message automatically.

Figure 9 .
Figure 9. List of connected devices.

Figure 11 .
Figure 11.Indication of Emergency HR monitor being active.

Table 1 .
Safe heart rate threshold during normal condition

Table 2 .
GPS discrepancy table