An IoT-Based Glucose Monitoring Algorithm to Prevent Diabetes Complications

Diabetes mellitus (DM) is a metabolic disorder characterized by blood glucose levels above normal limits. The impact of this disease on the population has increased in recent years. It is already a public health problem worldwide and one of the leading causes of death. Recently, several proposals have been developed for better and regular monitoring of glucose. However, theses proposals do not discard erroneous readings and they are not able to anticipate a critical condition. In this work, we propose an algorithm based on the double moving average supported by an IoT architecture to prevent possible complications in elderly patients. The algorithm uses historical readings to construct a series. Given a number of periods, it is possible to calculate averages of different subsets and trends for the next periods and, in this way, the prognosis is obtained. With the prognosis, it is possible to notify the doctor and relatives in advance about a possible critical condition in the patient. The aim of our work is to validate the architecture and prognosis algorithm used for elderly persons. Tests of the algorithm and the architecture were performed with different readings and it was shown that the system generated corresponding notifications before the glucose values were higher than those defined by the WHO (World Health Organization), thus avoiding unnecessary alarms.


Introduction
Diabetes is a chronic disease that occurs either when the pancreas does not produce enough insulin or when the body cannot effectively use insulin [1]. Insulin is a hormone that controls the level of blood glucose which is used as an energy source to meet the needs of organs and tissues. Insulin helps our body take advantage of nutrients, especially carbohydrates. When this process is deficient, these nutrients, in addition to lipids and fats, cannot accomplish their goal, which is to be transformed into energy. With this abnormality, the glucose accumulates in the blood causing a significant deterioration in human health.
According to the WHO, in 2014, 422 million people in the world had diabetes, with a prevalence of 8.5% among the adult population [1]. In Latin America, in 2003, the number of cases was estimated at 19 million adults (20 to 79 years old) affecting 10% to 15% of the adult population; this suggests that there could be at least 33 million by the year 2030. This assessment is based only on demographic changes such as population age and urbanization and represents an enormous problem for older adults and a public burden [2].
There are two types of diabetes. Type 1 that can appear at any age and is diagnosed more frequently in children, teenagers, and young adults. It is caused by a loss or alteration of insulin-producing cells, called pancreatic beta cells. The suspicion of type 1 DM is based on the presentation of acute symptoms such as weight loss, major general affectation, ketosis, and hyperglycemia. The absence or insufficient production of insulin by the body is the result of the lack of control of the beta cells. Type 2 DM appears as a result of a defect in insulin secretion in an environment of insulin resistance. In the case of diagnosis in elderly persons, the guidelines provided by the International Diabetes Federation are an excellent reference to consider which suggests a complete assessment and timely follow up that must be carried out according to a category dependency. The role of the caregiver is also defined [2,3].

Methods to Measure Glucose
The main concern of a person with diabetes is to control the blood glucose parameter in order to avoid abnormalities in glucose boundaries. Methods for monitoring these levels are classified into three categories, invasive, minimally invasive, and noninvasive [4] described as follows: • The invasive category includes techniques that are mostly used, because it offers the greatest precision of results due to direct contact with the patient's blood. The traditional procedure is to prick a finger, which is painful for the patient. The measurements must be carried out under a rigorous cleaning regimen, since infections can occur [4,5].

•
The minimally invasive category includes one of the techniques under investigation. This technique makes use of micropores, which are small holes on the skin caused by laser radiation. When the pores are open, a device applies a continuous vacuum pressure that extracts a small amount of transdermal body fluid. With the obtained sample, an enzyme-based electrode processes and measures glucose levels.

•
The noninvasive category includes noninvasive glucometers in which the objective is to replace the blood variable with another to which access is obtained by external means. Its operation consists of placing a sensor on a specific region of the body to obtain a reading of the glucose. The reliability of the values is almost 100%, because experts have been assured that the amount of glucose in the blood is equal to the amount found on the skin of a patient [4,5]. Biofluids such as saliva, urine, sweat, or tears have been studied as noninvasive glucose tests, but with these, it is not possible to continuously track the glucose levels.
It has been proven that continuous glucose monitoring improves metabolic control of the patient and provides a better profile of the glucose variations throughout the entire day. We can avoid critical values with the help of prediction, for example, analyzing the tendency of the levels with intelligent algorithms. Recently, approaches for monitoring patients' glucose parameter have been developed. The proposals make use of noninvasive methods, as well as transmission technology and data processing that provides timely readings. There are areas of opportunity concerning the use of more efficient algorithms for generating appraisals and more effective communication architectures [6-8].

Related Work
Platforms for wireless monitoring of glucose levels seek to optimize communication and the inclusion of different types of noninvasive sensors. This section describes the main proposals found in the literature review.
Noninvasive techniques that measure glucose look for variables that substitute blood as the main element, the aim is also to make the system portable for the patient. One of the first efforts was based on the principle of detecting the change in fluorescence resonance energy transfer efficiency of a protein synthesized as a function of analyte concentration [9]. Technologies such as GSM (global system for mobile communications) have been used in glucose monitoring. Different varieties of noninvasive sensors have been proposed to perform the sensing function. An arrangement of nanowires made of ZnO (zinc oxide) and an infrared emitter diode made of GaAs are examples of this category [10,11]. The efforts Appl. Sci. 2020, 10, 921 3 of 12 of the research community are not limited to keeping track of glucose levels. Additional parameters have been added to form a comprehensive system. In [12], besides glucose levels, cardiac-type diseases have been contemplated. Furthermore, communication is improved through the use of Zigbee, and display characteristics of the readings are added.
Real-time communication and low power consumption make WSNs (wireless sensor networks) an attractive technology for monitoring techniques. The integration of a WSN in conjunction with a minimally invasive sensor allows for portability and size reduction. With this application, the sensor is placed in the layer of the body's subcutaneous tissue to determine the amount of oxygen and, as a function of this, the glucose level [13]. Portability is an important factor when we are following up on elderly people. The noninvasive sensors attached to a miniature electronic mechanism allow for better follow up [14]. Sensors of the chronoamperometric type and ASIC (application-specific integrated circuit) designs make up a small battery-free device [15].
Smartphones and the characteristics of their operating system can be utilized for the connection and visualization tasks. The Android OS can be easily adapted to carry out the functions. Invasive and noninvasive sensors can be used for communication with a mobile device. In this way, patients themselves can monitor the readings. Moreover, the results can be sent to the cloud so that they can be viewed anywhere by a patient's doctor and relatives. Noninvasive sensors are still an area of opportunity, and therefore researchers continue to look for alternative designs that are more suitable for patients [16].
In [17], the authors proposed a design that employees an ion-sensitive field-effect transistor which is connected to a microcontroller. The readings are sent to a doctor through a Wi-Fi module. Further research is required to overcome the limitation of the sensor being exposed to contamination. The sending of glucose estimations has been optimized using a wireless body area network (WBAN) [18]. To verify it, the authors used a commercial sensor and communication via Zigbee. Additionally, the system stored the data in a desktop-based application. In this way, the information was available to the doctor, nurse, and a patient's relatives. To achieve better precision in the readings, modifications to the traditional invasive glucose reader are possible. The amount of gluconic acid detected by the sensor produces a current that is converted to voltage, and this variable is processed by a microcontroller to show the glucose value [19].
Architectures based on the IoT have attracted the attention of researchers in recent years [20]. They make use of standardized technologies to monitor glucose levels, as well as body temperature. With this kind of architecture, it is possible to have readings in real time and to store the information in back-end type servers [21]. A patient's caregivers can track his or her evolution from their mobile device or by accessing a web page. The integration of an IoT architecture and noninvasive sensors allows for portability and data accessibility. An example of this interaction is an infrared LED that bases its operation on measuring the concentration of glucose in the blood depending on the intensity of the received light. Due to the LED operation and configuration, its connection to the architecture is very simple [22]. Implantable glucose biosensors for long-term use have been studied with success [23]. These kinds of sensors represent a key element for reliable readings in monitoring systems. They have shown good results as compared with the finger-pricking readings. The impact of a real-time prognosis algorithm has also been analyzed in recent proposals [24]. In the case of wireless technologies, limitations persist for both personal use and short-range technologies, especially when they are handled by older persons. The importance of IoT technologies has been proven in recent studies, for example, in [25], authors developed an architecture based on a Raspberry Pi, and they analyzed the sensor's accuracy and the effectiveness of the transmission. Another example, in [26] proposed a glucose data classification to validate the architecture using data classification techniques for a correct diagnosis bythe prediction system. The authors focused on appropriate transmission through SMS messages and the evaluation of the techniques used. In most cases, the drawbacks of traditional monitoring can be solved with this technology [27]. It is possible to use complex algorithms to perform the prognosis and to store data in the cloud. They are also a good option for closer tracking of many patients, reducing the charge for doctors and caregivers. However, policies and regulations are necessary for privacy and security issues [28]. A study using health information technologies on glycemic control with type 2 diabetes was considered in [29] reporting better control both clinically and statistically. A reduction of HbA1c was observed in all the interventions presented. According to the study, every 1% decrease in HbA1c over a ten-year period was associated with a risk reduction of 21% for diabetes-related death and 37% of microvascular complications. However, long-term studies should be carried out. These findings are a great incentive for future developments. With respect to systems that monitor older adults, an IoT system for heart rate, body temperature, and blood oxygenation was presented in [30]. Although glucose was not considered in the monitoring, the importance of the IoT system and the mobile application were emphasized. Commercial products such as Medtronic Guardian Connect Smart (CGM) also exist that claim to use a sensor based on interstitial fluid. The system transmits the glucose values wirelessly to a smart device to prevent hypoglycemia and hyperglycemia [31].

System Architecture
According to the literature review, recently, IoT architectures have shown remarkable results when they are used for glucose monitoring. Our proposal is supported by an architecture of this type, as shown in Figure 1. The principle of operation is based on a wireless sensor worn by an elderly patient. No intervention of other people is required. Due to restrictions, the readings were obtained from a patient using a traditional glucometer and the values were send to the sensing stage. It is necessary to define the period for each reading. The sensor is connected to an IoT device (NodeMCU) using a wired connection. We configured our device and router to create a home area network. Once the chip is connected to the network, it handles the readings obtained by the sensor and sends them using Wi-Fi to a router with an Internet connection. The information is received by a server based on Raspberry Pi, where the algorithm is stored. Here the data is processed to produce a prognosis using historical values. Each reading is sent to a web server to be displayed. Finally, the glucose level is shown to relatives and caregivers through a web page. Depending on the readings values, the system sends the pertinent notifications. For a better understanding, we divide the proposal into the following three layers: (1) perception, (2) network, and (3) application.
Appl. Sci. 2020, 10, x FOR PEER REVIEW 4 of 12 reduction of HbA1c was observed in all the interventions presented. According to the study, every 1% decrease in HbA1c over a ten-year period was associated with a risk reduction of 21% for diabetesrelated death and 37% of microvascular complications. However, long-term studies should be carried out. These findings are a great incentive for future developments. With respect to systems that monitor older adults, an IoT system for heart rate, body temperature, and blood oxygenation was presented in [30]. Although glucose was not considered in the monitoring, the importance of the IoT system and the mobile application were emphasized. Commercial products such as Medtronic Guardian Connect Smart (CGM) also exist that claim to use a sensor based on interstitial fluid. The system transmits the glucose values wirelessly to a smart device to prevent hypoglycemia and hyperglycemia [31].

System Architecture
According to the literature review, recently, IoT architectures have shown remarkable results when they are used for glucose monitoring. Our proposal is supported by an architecture of this type, as shown in Figure 1. The principle of operation is based on a wireless sensor worn by an elderly patient. No intervention of other people is required. Due to restrictions, the readings were obtained from a patient using a traditional glucometer and the values were send to the sensing stage. It is necessary to define the period for each reading. The sensor is connected to an IoT device (NodeMCU) using a wired connection. We configured our device and router to create a home area network. Once the chip is connected to the network, it handles the readings obtained by the sensor and sends them using Wi-Fi to a router with an Internet connection. The information is received by a server based on Raspberry Pi, where the algorithm is stored. Here the data is processed to produce a prognosis using historical values. Each reading is sent to a web server to be displayed. Finally, the glucose level is shown to relatives and caregivers through a web page. Depending on the readings values, the system sends the pertinent notifications. For a better understanding, we divide the proposal into the following three layers: (1) perception, (2) network, and (3) application. The perception layer is responsible for obtaining the patient's glucose levels. A noninvasive wireless sensor is proposed. The glucose sensor is connected to an open-source platform, such as NodeMCU. This device has a microcontroller and a 10-bit resolution A/D converter. With the A/D converter it is possible to transform the readings to digital values. The connection is shown in Figure  2. The perception layer is responsible for obtaining the patient's glucose levels. A noninvasive wireless sensor is proposed. The glucose sensor is connected to an open-source platform, such as NodeMCU. This device has a microcontroller and a 10-bit resolution A/D converter. With the A/D converter it is possible to transform the readings to digital values. The connection is shown in Figure 2. The network layer takes advantage of the NodeMCU Wi-Fi feature to communicate wirelessly to the router. The function of this device is to provide communication over the Internet and to send glucose values to the server.
The application layer has a web server based on Raspberry Pi and a database developed in SQL (structured query language). The elements that make up the server, as well as the suggested sequence of installation of each of the packages, are presented in Figure 3. All these elements are supported in an open environment such as Linux. We can access the database locally and remotely to consult the records of different users, as well as the history of the readings without depending on a hosting service. The prognosis algorithm is also stored in the server and will be responsible for analyzing the history of the appraisals. With the algorithm, we can predict a trend and determine if it is necessary to send an alert via SMS to the doctor and relatives or if it is simply a peak that could be a false alarm. The system can take readings of the glucose level of diverse patients for a given period previously determined by the doctor (minutes or hours). The values obtained are stored in the data base. The algorithm uses the readings (Yt), to calculate an average of the historical readings through the double moving average technique. First, it performs an average ( ) over n periods from the readings.
Given M1 = . Next, a second average M't is calculated as the average of the first.
The following equation is used to calculate the difference between the averages: Subsequently, an additional adjustment factor is calculated, such as the measurement of a slope that changes over time.
Finally, the following equation is used to make the prognosis of p periods in the future. , where n = number of periods defined to calculate the average. Yt = series real value in period t p = number of periods to be prognosticated in the future The network layer takes advantage of the NodeMCU Wi-Fi feature to communicate wirelessly to the router. The function of this device is to provide communication over the Internet and to send glucose values to the server.
The application layer has a web server based on Raspberry Pi and a database developed in SQL (structured query language). The elements that make up the server, as well as the suggested sequence of installation of each of the packages, are presented in The network layer takes advantage of the NodeMCU Wi-Fi feature to communicate wirelessly to the router. The function of this device is to provide communication over the Internet and to send glucose values to the server.
The application layer has a web server based on Raspberry Pi and a database developed in SQL (structured query language). The elements that make up the server, as well as the suggested sequence of installation of each of the packages, are presented in Figure 3. All these elements are supported in an open environment such as Linux. We can access the database locally and remotely to consult the records of different users, as well as the history of the readings without depending on a hosting service. The prognosis algorithm is also stored in the server and will be responsible for analyzing the history of the appraisals. With the algorithm, we can predict a trend and determine if it is necessary to send an alert via SMS to the doctor and relatives or if it is simply a peak that could be a false alarm. The system can take readings of the glucose level of diverse patients for a given period previously determined by the doctor (minutes or hours). The values obtained are stored in the data base. The algorithm uses the readings (Yt), to calculate an average of the historical readings through the double moving average technique. First, it performs an average ( ) over n periods from the readings. … … .
Given M1 = . Next, a second average M't is calculated as the average of the first.
The following equation is used to calculate the difference between the averages: Subsequently, an additional adjustment factor is calculated, such as the measurement of a slope that changes over time.
Finally, the following equation is used to make the prognosis of p periods in the future. , where n = number of periods defined to calculate the average. Yt = series real value in period t p = number of periods to be prognosticated in the future We can access the database locally and remotely to consult the records of different users, as well as the history of the readings without depending on a hosting service. The prognosis algorithm is also stored in the server and will be responsible for analyzing the history of the appraisals. With the algorithm, we can predict a trend and determine if it is necessary to send an alert via SMS to the doctor and relatives or if it is simply a peak that could be a false alarm. The system can take readings of the glucose level of diverse patients for a given period previously determined by the doctor (minutes or hours). The values obtained are stored in the data base. The algorithm uses the readings (Y t ), to calculate an average of the historical readings through the double moving average technique. First, it performs an average (Ŷ t+1 ) over n periods from the readings.
Given M 1 =Ŷ t+1 . Next, a second average M' t is calculated as the average of the first.
The following equation is used to calculate the difference between the averages: Subsequently, an additional adjustment factor is calculated, such as the measurement of a slope that changes over time.
Finally, the following equation is used to make the prognosis of p periods in the future.
where n = number of periods defined to calculate the average. Y t = series real value in period t p = number of periods to be prognosticated in the future Tests were performed in a private and controlled environment. Several trials were carried out to validate the correct sending of the interpretations. The algorithm takes readings every thirty minutes, this periodicity was consulted with a specialist. It requires three historical readings (n = 3). In a first round, the first average is calculated using these values. Then, the same period, n, is used to calculate the second average of the first round. We propose a third period for p (this period can be adapted according to the patient's profile) to produce a prognosis. The prognosis obtained is used by the system to determine whether a critical condition exists or not. It is important to clarify that the caregiver must provide the time considered for each meal and it should be considered for the system. The visualization of the information is based on a web page. To develop it, tools such as Adobe Dreamweaver, JavaScript, and Jquery libraries were used. Ajax methods play an important role in maintaining asynchronous communication between the browser and the server, adding flexibility to the page.
To validate the values obtained from the system, we characterized our sensing stage through a comparison with a traditional glucometer. A variation of less than a digit was achieved (one mg/dL). To ensure end to end functionality, we divided the tests into three stages as with the architecture. In the first stage, we confirmed the sensor and embedded device assigned to the patient (identifier) and the value obtained at the output. The second stage refers to the verification of the network configuration, the transmission between the embedded device and the router, and how the reading within messages are forwarded. In the third stage, we verified correct data reception and profile authentication in the servers. Afterwards, the information is processed by the prognosis algorithm. Furthermore, the appraisals are displayed on the web page for the defined period and the assigned profile. We also checked notifications when they existed. The web page shows a message when no data is received or if there is a communication problem. Thus, we assure the delivery of the proper reading.

Results
To assess the operation of the proposal, tests were carried out on each of the stages and the whole system. Initially, we checked the sending of the glucose reading by the NodeMCU. After that, the connection to the previously defined Wi-Fi network was made. Then, it connected with the server, and thus began to transfer the information.
To verify the result of the template, the most popular browsers, i.e., Internet Explorer or Microsoft Edge, Mozilla Firefox and Google Chrome, were used, obtaining similar results in all three cases. Figure 4 displays the home page in the Chrome browser. It can be seen that the image is fully loaded, and the elements placed in their correct position. The marquee works properly, and the menu and the remaining elements are deployed successfully.
Appl. Sci. 2020, 10, x FOR PEER REVIEW 6 of 12 Tests were performed in a private and controlled environment. Several trials were carried out to validate the correct sending of the interpretations. The algorithm takes readings every thirty minutes, this periodicity was consulted with a specialist. It requires three historical readings (n = 3). In a first round, the first average is calculated using these values. Then, the same period, n, is used to calculate the second average of the first round. We propose a third period for p (this period can be adapted according to the patient's profile) to produce a prognosis. The prognosis obtained is used by the system to determine whether a critical condition exists or not. It is important to clarify that the caregiver must provide the time considered for each meal and it should be considered for the system. The visualization of the information is based on a web page. To develop it, tools such as Adobe Dreamweaver, JavaScript, and Jquery libraries were used. Ajax methods play an important role in maintaining asynchronous communication between the browser and the server, adding flexibility to the page.
To validate the values obtained from the system, we characterized our sensing stage through a comparison with a traditional glucometer. A variation of less than a digit was achieved (one mg/dL). To ensure end to end functionality, we divided the tests into three stages as with the architecture. In the first stage, we confirmed the sensor and embedded device assigned to the patient (identifier) and the value obtained at the output. The second stage refers to the verification of the network configuration, the transmission between the embedded device and the router, and how the reading within messages are forwarded. In the third stage, we verified correct data reception and profile authentication in the servers. Afterwards, the information is processed by the prognosis algorithm. Furthermore, the appraisals are displayed on the web page for the defined period and the assigned profile. We also checked notifications when they existed. The web page shows a message when no data is received or if there is a communication problem. Thus, we assure the delivery of the proper reading.

Results
To assess the operation of the proposal, tests were carried out on each of the stages and the whole system. Initially, we checked the sending of the glucose reading by the NodeMCU. After that, the connection to the previously defined Wi-Fi network was made. Then, it connected with the server, and thus began to transfer the information.
To verify the result of the template, the most popular browsers, i.e., Internet Explorer or Microsoft Edge, Mozilla Firefox and Google Chrome, were used, obtaining similar results in all three cases. Figure 4 displays the home page in the Chrome browser. It can be seen that the image is fully loaded, and the elements placed in their correct position. The marquee works properly, and the menu and the remaining elements are deployed successfully.  The patient "Juan Carlos López" with device serial number "111" was taken as an example, and ten values were considered, as listed in Table 1. We proposed a noninvasive wireless sensor to be used in the system. However, due to restrictions, the readings were obtained using a traditional glucometer for an older patient before and after the intake. The values of the table were considered in the double average technique to make a prognosis in a three-hour period. According to the food intake and the peak that this generates, this period is considered to be appropriate. The obtained graph is presented in Figure 5.
Appl. Sci. 2020, 10, x FOR PEER REVIEW 7 of 12 The patient "Juan Carlos López" with device serial number "111" was taken as an example, and ten values were considered, as listed in Table 1. We proposed a noninvasive wireless sensor to be used in the system. However, due to restrictions, the readings were obtained using a traditional glucometer for an older patient before and after the intake. The values of the table were considered in the double average technique to make a prognosis in a three-hour period. According to the food intake and the peak that this generates, this period is considered to be appropriate. The obtained graph is presented in Figure 5. We followed the recommendations of the International Diabetes Federation and the American Diabetes Association, which state that glycemic control in an older adult corresponds to preprandial plasma glucose (before eating) of 90 to 130 mg/dL and lower postprandial plasma glucose up to 180 mg/dL. We also considered both categories of dependency, independent and depend functionally defined by the International Diabetes Federation. No intervention is required to make the readings. The actions of the caregivers after the notification should be defined by the specialist.
Examining the graph, we notice that there are no peaks or variations in the prognosis generated by the system, there is no critical state, and therefore no alert must be issued. According to the readings analyzed, the early hours fell within the preprandial stage. Subsequently, there was a food intake that caused an increase in the level of glucose, but without exceeding 180 mg/dL, including the prognosis. In the absence of values that exceeded 180 mg/dL, it was not necessary to send an orange alert. If the prognosis exceeds 200 mg/dL, it means that there is an upward tendency and the system sends a red alert indicating a critical condition. It is worth mentioning that the algorithm takes into consideration the condition of when the patient ingests food and does not issue a false notification.  We followed the recommendations of the International Diabetes Federation and the American Diabetes Association, which state that glycemic control in an older adult corresponds to preprandial plasma glucose (before eating) of 90 to 130 mg/dL and lower postprandial plasma glucose up to 180 mg/dL. We also considered both categories of dependency, independent and depend functionally defined by the International Diabetes Federation. No intervention is required to make the readings. The actions of the caregivers after the notification should be defined by the specialist.
Examining the graph, we notice that there are no peaks or variations in the prognosis generated by the system, there is no critical state, and therefore no alert must be issued. According to the readings analyzed, the early hours fell within the preprandial stage. Subsequently, there was a food intake that caused an increase in the level of glucose, but without exceeding 180 mg/dL, including the prognosis. In the absence of values that exceeded 180 mg/dL, it was not necessary to send an orange alert. If the prognosis exceeds 200 mg/dL, it means that there is an upward tendency and the system sends a red alert indicating a critical condition. It is worth mentioning that the algorithm takes into consideration the condition of when the patient ingests food and does not issue a false notification.
A critical behavior was simulated, we manually changed the readings in order to test the functionality of the algorithm under this situation, as shown in Figure 6. When detecting an upward tendency in the readings that is consistent for several hours (i.e., not due to an intake of food), the system activates the mechanisms for sending notifications, i.e., first a medium alert and, then, a high alert. The prognosis is located above the critical value for three hours, thus, the notification is correct, as there is a critical condition with a tendency to decrease. The system was validated with the creation of profiles for different cases. The personal page of the patient "Juan Carlos López" with serial number "111" used in previous tests was stored. In the upper left-hand corner, we find a search engine similar to in the "online" section, but for our case it will be useful so that the doctor can find specific values, either by dates or by glucose levels. Figure 7 shows all the elements that make up the page and the user's analyzed data. When a relative looks at the page, only the profile of the related patient appears.
Appl. Sci. 2020, 10, x FOR PEER REVIEW 8 of 12 A critical behavior was simulated, we manually changed the readings in order to test the functionality of the algorithm under this situation, as shown in Figure 6. When detecting an upward tendency in the readings that is consistent for several hours (i.e., not due to an intake of food), the system activates the mechanisms for sending notifications, i.e., first a medium alert and, then, a high alert. The prognosis is located above the critical value for three hours, thus, the notification is correct, as there is a critical condition with a tendency to decrease. The system was validated with the creation of profiles for different cases. The personal page of the patient "Juan Carlos López" with serial number "111" used in previous tests was stored. In the upper left-hand corner, we find a search engine similar to in the "online" section, but for our case it will be useful so that the doctor can find specific values, either by dates or by glucose levels. Figure 7 shows all the elements that make up the page and the user's analyzed data. When a relative looks at the page, only the profile of the related patient appears.  With the system database, it is possible to obtain the patient's data for each day. With this information, we can generate a report and visualize it through a graph (on the same page or exported to Excel) to interpret the readings either by day, by week, or by month. This is shown in the lower part of Figure 7. In the upper central part, two buttons are located: "Stop SMS" (red), whose function is to stop the messaging service or SMS alerts, and "Send SMS" (green) for sending. When the critical condition was simulated, the system sent the corresponding alerts. Figure 8 shows how two alert messages were sent to the cell phone with an interval of five minutes; then the button was pressed to Appl. Sci. 2020, 10, x FOR PEER REVIEW 8 of 12 A critical behavior was simulated, we manually changed the readings in order to test the functionality of the algorithm under this situation, as shown in Figure 6. When detecting an upward tendency in the readings that is consistent for several hours (i.e., not due to an intake of food), the system activates the mechanisms for sending notifications, i.e., first a medium alert and, then, a high alert. The prognosis is located above the critical value for three hours, thus, the notification is correct, as there is a critical condition with a tendency to decrease. The system was validated with the creation of profiles for different cases. The personal page of the patient "Juan Carlos López" with serial number "111" used in previous tests was stored. In the upper left-hand corner, we find a search engine similar to in the "online" section, but for our case it will be useful so that the doctor can find specific values, either by dates or by glucose levels. Figure 7 shows all the elements that make up the page and the user's analyzed data. When a relative looks at the page, only the profile of the related patient appears.  With the system database, it is possible to obtain the patient's data for each day. With this information, we can generate a report and visualize it through a graph (on the same page or exported to Excel) to interpret the readings either by day, by week, or by month. This is shown in the lower part of Figure 7. In the upper central part, two buttons are located: "Stop SMS" (red), whose function is to stop the messaging service or SMS alerts, and "Send SMS" (green) for sending. When the critical condition was simulated, the system sent the corresponding alerts. Figure 8 shows how two alert messages were sent to the cell phone with an interval of five minutes; then the button was pressed to  With the system database, it is possible to obtain the patient's data for each day. With this information, we can generate a report and visualize it through a graph (on the same page or exported to Excel) to interpret the readings either by day, by week, or by month. This is shown in the lower part of Figure 7. In the upper central part, two buttons are located: "Stop SMS" (red), whose function is to stop the messaging service or SMS alerts, and "Send SMS" (green) for sending. When the critical condition was simulated, the system sent the corresponding alerts. Figure 8 shows how two alert messages were sent to the cell phone with an interval of five minutes; then the button was pressed to stop the service, correctly ending the sending of alerts. The mode can be configured to automatic and the periodicity can also be changed.
We evaluated the accuracy of our proposal through a comparison with the exponential smoothing technique. We calculated the mean absolute percentage error (MAPE) for both cases using the values of Table 1 and the prognosis values. We obtained about 6% in both cases. One disadvantage of the exponential attenuation is that for previous readings, either high increasing or low decreasing, the next prediction follows the tendency, causing a false warning. Our proposal avoids this situation by considering more than one historical value, producing a smoother prognosis. In addition, the exponential smoothing requires to find a weight factor (alpha) previously. It was not possible to compare with other proposals because they do not present similar results. In [26], the accuracy is oriented to the classification using different algorithms.
In terms of delay, we compared our approach to similar proposals in terms of sending readings. The authors in [27] report an average delay of 33.96 s to receive it. In [26] a delay of about 32 s using SMS messages was found. In our case, a delay of 30 s was obtained using the Twilio tool to send the notifications. The results are very similar, as shown in Figure 9.
Appl. Sci. 2020, 10, x FOR PEER REVIEW 9 of 12 stop the service, correctly ending the sending of alerts. The mode can be configured to automatic and the periodicity can also be changed. We evaluated the accuracy of our proposal through a comparison with the exponential smoothing technique. We calculated the mean absolute percentage error (MAPE) for both cases using the values of Table 1 and the prognosis values. We obtained about 6% in both cases. One disadvantage of the exponential attenuation is that for previous readings, either high increasing or low decreasing, the next prediction follows the tendency, causing a false warning. Our proposal avoids this situation by considering more than one historical value, producing a smoother prognosis. In addition, the exponential smoothing requires to find a weight factor (alpha) previously. It was not possible to compare with other proposals because they do not present similar results. In [26], the accuracy is oriented to the classification using different algorithms.
In terms of delay, we compared our approach to similar proposals in terms of sending readings. The authors in [27] report an average delay of 33.96 s to receive it. In [26] a delay of about 32 s using SMS messages was found. In our case, a delay of 30 s was obtained using the Twilio tool to send the notifications. The results are very similar, as shown in Figure 9.   Appl. Sci. 2020, 10, x FOR PEER REVIEW 9 of 12 stop the service, correctly ending the sending of alerts. The mode can be configured to automatic and the periodicity can also be changed. We evaluated the accuracy of our proposal through a comparison with the exponential smoothing technique. We calculated the mean absolute percentage error (MAPE) for both cases using the values of Table 1 and the prognosis values. We obtained about 6% in both cases. One disadvantage of the exponential attenuation is that for previous readings, either high increasing or low decreasing, the next prediction follows the tendency, causing a false warning. Our proposal avoids this situation by considering more than one historical value, producing a smoother prognosis. In addition, the exponential smoothing requires to find a weight factor (alpha) previously. It was not possible to compare with other proposals because they do not present similar results. In [26], the accuracy is oriented to the classification using different algorithms.
In terms of delay, we compared our approach to similar proposals in terms of sending readings. The authors in [27] report an average delay of 33.96 s to receive it. In [26] a delay of about 32 s using SMS messages was found. In our case, a delay of 30 s was obtained using the Twilio tool to send the notifications. The results are very similar, as shown in Figure 9.

Conclusions and the Future
Our contributions focus on the use of an IoT architecture that includes a prognosis algorithm for better notification to doctors and patients' relatives. The proposal is a new technique for detecting, in advance, the highs and lows of glucose levels. It takes previous readings to create the tendency. With this value it is possible to know if an elder patient is in a short period of staying or if it is a preprandial or postprandial condition, and therefore avoid false notifications. Our proposal only takes into account long periods of staying, according to the prognosis to send a warning. The architecture uses a Raspberry Pi as a main server where the algorithm is located, and the prognosis is calculated. As far as we know, few studies involving techniques such as the one we propose have been oriented to elderly adults, and thus the relevance of our proposal. Compared with recent proposals found in the literature, our work comprises a complete IoT architecture with the addition of a real-time prognosis algorithm. We present an innovative algorithm to perform the prognosis without notifications, therefore, preventing overload of the network. The task of sending messages is assigned to the server. The sensor stage consumes little energy in contrast to that consumed for an application on a smartphone. Because the server is local, no delay is present, as in [26], where SMS messages are used. Contrary to [25], we do not use proprietary applications in order to obtain a more economical system with multiple connections (patients). We validated the operation of the architecture, the prognosis algorithm, and the sending of alerts for two conditions, normal (a patient with intake) and critical. For privacy, the system uses an ID assigned for each patient within an embedded system. The security aspect is addressed by introducing secure protocols in each stage of the architecture.
This approach contributes to improving the quality of life of elderly patients who, due to their condition, are unable to attend appointments in a hospital. Through the system, caregivers would have remote knowledge of any situation that occurs using a mobile device with an Internet connection. The intention of the proposal is to provide a tool to help caregivers. When the system is used with an elder person, the specialist should carry out a complete assessment following the guidelines mentioned in [3]. We reviewed the Guardian Connect CGM web page and we consider that, in comparison with commercial products, our proposal has a more flexible architecture, is easier to add new profiles, and is more economical. In future work, we hope to integrate a small noninvasive wireless sensor that could be portable for the elderly.