An IoT-Based Non-Invasive Glucose Level Monitoring System Using Raspberry Pi

: Patients diagnosed with diabetes mellitus must monitor their blood glucose levels in order to control the glycaemia. Consequently, they must perform a capillary test at least three times per day and, besides that, a laboratory test once or twice per month. These standard methods pose di ﬃ culty for patients since they need to prick their ﬁnger in order to determine the glucose concentration, yielding discomfort and distress. In this paper, an Internet of Things (IoT)-based framework for non-invasive blood glucose monitoring is described. The system is based on Raspberry Pi Zero (RPi) energised with a power bank, using a visible laser beam and a Raspberry Pi Camera, all implemented in a glove. Data for the non-invasive monitoring is acquired by the RPi Zero taking a set of pictures of the user ﬁngertip and computing their histograms. Generated data is processed by an artiﬁcial neural network (ANN) implemented on a Flask microservice using the Tensorﬂow libraries. In this paper, all measurements were performed in vivo and the obtained data was validated against laboratory blood tests by means of the mean absolute error (10.37%) and Clarke grid error (90.32% in zone A). Estimated glucose values can be harvested by an end device such as a smartphone for monitoring purposes.


Introduction
The Internet of Things (IoT) is a paradigm in which different devices used on a day-to-day basis have the ability to communicate with other devices, whether or not they are of the same type, with the aim of providing services through the internet. These devices can be household objects (lamps or appliances), street objects, or embedded devices especially created for particular applications; they are all called "things". Things not only acquire information from the environment and interact with the physical world, but also they can be equipped with identification, measurement, and process capabilities to provide context-aware services for achieving specific goals for information analytics, communications and final applications [1][2][3].
Despite the fact that the IoT has been extensively applied to almost every area in everyday life, it has also brought the opportunity to tackle problems in priority domains. Regarding this, the development and modernisation of health services constitute a major challenge for healthcare pressure. For this reason, the search for newly and more accurate non-invasive technologies, is still underway [28,31].
Scientific efforts have been directed to develop non-invasive glucose meters and systems, from which optical technologies have gained attention [30], near infrared (NIR) [33,34], Raman [35,36], and Fourier transform infrared (FTIR) [30] spectroscopy are among the most investigated. On a regular basis, the systems referring to the state-of-the-art share similar components: (i) an energy source by a light beam in certain wavelength, commonly interacting with (ii) a medium or region of interest in the body, (iii) a module with signal acquisition sensors, (iv) a microcontroller or signal processor, and (v) an element where the result will be displayed. However, the choice of both the characteristic of components (i)-(iv) and the physical principle on which the system is built, leads to very different results. Depending on the sensor used for this purpose, optical techniques analyse the medium (e.g., fingertip or ear lobe) based on the reflection, refraction, dispersion or absorption of the light beam provided by the energy source. Previous works have mainly considered the use of energy sources with wavelengths in the near infrared range.
In this paper, an IoT-based monitoring framework for non-invasive blood glucose monitoring is described. Data for the non-invasive monitoring is acquired taking a picture of the user's fingertip using the camera of a Raspberry Pi Zero (RPi), and then data is processed by a neural network implemented using the Tensorflow libraries in a Flask microservice. The estimated glucose values can be harvested by an end device such as a smartphone for monitoring purposes, or by any other end device allowing the opportunity for different potential applications.

Proposed Internet of Things (IoT) Glucose Monitoring System
The glucose estimation method described in the present work consists of a non-invasive optical analysis in which a laser beam is pointed to the user's fingertip, while for capturing the transmitted light response, an RPi camera was used.
Previous works use different body tissues (e.g., forearm, ear lobe, finger, cheek) for non-invasive glucose measurement. However, due to its high capillary density and its ease of implementation [31], the fingertip was selected as the most convenient for the present study. For this reason, the proposed system was instrumented on a glove, where the Raspberry Pi Zero (RPi) board was placed in an acrylic case attached to the carpal area, whereas a 3D-printed case housing the image acquisition setup was placed at the index fingertip.
The proposed system considers four stages, as depicted in Figure 1. Correspondingly, the materials and methods used to this aim are explained in detail below.
Appl. Sci. 2019, 9, x 3 of 13 temperature or pressure. For this reason, the search for newly and more accurate non-invasive technologies, is still underway [28,31]. Scientific efforts have been directed to develop non-invasive glucose meters and systems, from which optical technologies have gained attention [30], near infrared (NIR) [33,34], Raman [35,36], and Fourier transform infrared (FTIR) [30] spectroscopy are among the most investigated. On a regular basis, the systems referring to the state-of-the-art share similar components: (i) an energy source by a light beam in certain wavelength, commonly interacting with (ii) a medium or region of interest in the body, (iii) a module with signal acquisition sensors, (iv) a microcontroller or signal processor, and (v) an element where the result will be displayed. However, the choice of both the characteristic of components (i)-(iv) and the physical principle on which the system is built, leads to very different results. Depending on the sensor used for this purpose, optical techniques analyse the medium (e.g., fingertip or ear lobe) based on the reflection, refraction, dispersion or absorption of the light beam provided by the energy source. Previous works have mainly considered the use of energy sources with wavelengths in the near infrared range.
In this paper, an IoT-based monitoring framework for non-invasive blood glucose monitoring is described. Data for the non-invasive monitoring is acquired taking a picture of the user's fingertip using the camera of a Raspberry Pi Zero (RPi), and then data is processed by a neural network implemented using the Tensorflow libraries in a Flask microservice. The estimated glucose values can be harvested by an end device such as a smartphone for monitoring purposes, or by any other end device allowing the opportunity for different potential applications.

Proposed Internet of Things (IoT) Glucose Monitoring System
The glucose estimation method described in the present work consists of a non-invasive optical analysis in which a laser beam is pointed to the user's fingertip, while for capturing the transmitted light response, an RPi camera was used.
Previous works use different body tissues (e.g., forearm, ear lobe, finger, cheek) for non-invasive glucose measurement. However, due to its high capillary density and its ease of implementation [31], the fingertip was selected as the most convenient for the present study. For this reason, the proposed system was instrumented on a glove, where the Raspberry Pi Zero (RPi) board was placed in an acrylic case attached to the carpal area, whereas a 3D-printed case housing the image acquisition setup was placed at the index fingertip.
The proposed system considers four stages, as depicted in Figure 1. Correspondingly, the materials and methods used to this aim are explained in detail below.

Materials
A Raspberry Pi Zero board was used for image acquisition, histogram calculation and for sending data through the internet. It is a platform based on a Broadcom BCM2835 system on a chip, including an ARM11 1GHz single-core CPU and 512 MB of RAM, with a micro SD slot card memory

Materials
A Raspberry Pi Zero board was used for image acquisition, histogram calculation and for sending data through the internet. It is a platform based on a Broadcom BCM2835 system on a chip, including an ARM11 1GHz single-core CPU and 512 MB of RAM, with a micro SD slot card memory and CSI (camera serial interface) connector. It also includes connectivity with an 802.11 b/g/n wireless LAN (Local Area Network), and Bluetooth 4.1.
Consequently, a Raspberry Pi camera Rev 1.3 was used for taking the pictures. It is plugged directly to the CSI connector in the RPi, and is able to obtain images up to 2592 × 1944 pixels, having a 5 MP resolution with the Omnivision 5647 sensor in a fixed focus mode. The camera size is around 25 mm × 20 mm × 9 mm and weighs 3 g.
The laser used as energy source is a 650 nm visible-wavelength which operates at 5 V with output power of 5 mW. The beam light has a dot shape and estimated useful life of 2000 h. The decision of using a visible light rather than infrared (IR) or near-infrared (NIR) was made on the basis of previous studies demonstrating that lasers in a visible wavelength have a great capability of penetrating the skin of a human finger [37].
With the aim of energizing the RPi board and the laser, a power bank was used as power supply. It has a capacity of 10,000 mAh, 5 V input/output, size of 72.4 mm × 50 mm × 22.6 mm and has enough power to keep running the acquisition module for about 35 h.
In order to house the system, two cases were used: one, 3D-printed, embedding the laser and the camera used for light condition controlling, and other one for enclosing the RPi, both attached to the glove. This glove represents the main embodiment of the system in order to keep the laser-camera and the Raspberry Pi Zero board altogether.

Methods
The Beer-Lambert law [38] is an optic measure considering the relationship between the absorbance and the amount of a material. It permits to compute the amount of a material in a sample by using its absorbance rate, so the light absorption of a material is proportional to the quantity of the same material. The Beer-Lambert law expresses how the light is absorbed by matter: (a) the intensity of transmitted light decreases exponentially as concentration of the substance in the solution increases, and (b) the intensity of transmitted light decreases exponentially as the distance travelled through the substance increases [38,39]. This formulation was used as the main principle for measuring the glucose concentration in a blood sample by passing a laser-beam through the fingertip. A simplified model of this law is shown in Equation (1): The artificial neural network (ANN) used for estimating the blood glucose concentration was constructed and trained using Tensorflow [40], which is an open-source platform for deep learning and machine learning developed and maintained by Google. It allows the creation of a variety of neural network models applied to multidimensional data arrays, referred to as tensors. Some of its main features include that can run on multiple central processing units (CPUs) but also on GPUs (General purpose Graphical Processing Unit), and can be implemented with C++, Python and Java.
The ANN was implemented on a Flask server [41], a microframework for Python which allows the creation of web APIs (Application Programming Interfaces) for a variety of applications. Here, the Flask server is used to provide Python microservices to be consumed by the end device.

Data Acquisition
It contemplates the incorporation of two elements: the RPi camera and the 650 nm laser both embedded in a 3D-printed case and attached to the index fingertip of the glove, as told before. The laser-beam is fixed internally to the case, facing to the camera lens, with enough space in between for enclosing the fingertip of a person adequately.
This setup is intended for data acquisition but also to characterise how the incident laser-beam interacts with the finger. To this end, there are some things to take into consideration: The laser-beam is used as the energy source to pass throughout the medium.

2.
The finger is the medium through which the light will be transmitted.

3.
The camera acts as the sensor responsible to capture the transmitted light and how it is scattered along the finger.
In this stage, fingertip images of size 640 × 480 px are taken, in time intervals of 8 s for allowing the camera to perform a precise focus. This process is carried out in a period of 2 min, thus acquiring a total of 14 images. Caused by the act of putting and removing the finger, the first and last images may not be captured properly, entailing errors in future stages. For this reason, the system only takes into consideration the central 12 images, discarding the first and last.
The camera configuration used in this proposal was set to night exposure mode, with camera exposure compensation of 25, ISO sensitivity of 800 and values for brightness and contrast of 70.

Histogram Calculation
In general, image histograms provide global information about its intensity values, and are useful for enhancing images. Histograms are also a measure of data distribution that allows, among other things, analysis of its dispersion in different ways.
In the context of the proposed work, the histogram is used as a descriptor of the acquired images that, at that time, represent the intensity values of the light that has been transmitted through the finger. Correspondingly, it is noticeable that by using the histogram as image descriptor, the analysis of light scattering in the finger is inherent.
Major variations on glucose levels can be found in the time interval between fasting and a couple of hours after having a meal. In a previous work [42], a set of experiments with the red, green and blue histograms of fingertip images of users with 8 h fasting and two hours after they had meal were carried out. The blue histograms reported statistically significant variations according to Mann-Whitney statistical test [43]. To this regard, the use of histograms of the blue channel was considered in this paper.
With the aim of performing an efficient data transmission, the histogram of the blue channel in the acquired images is computed directly on the RPi before broadcasting data to the IoT cloud computing stage. With this, instead of transmitting the whole image, i.e., more than three hundred thousand data, only 256 values are sent for each image, substantially reducing the data transmission latency.

Model Selection
Before implementing the whole model, a model selection set of experiments were performed. In order to do this, an ANN was trained using the Tensorflow library in Python programming language. In this regard, experiments for model selection were carried out taking into account the following points: • Participants: A total of 514 healthy subjects, with age ranging from 18-44 years, and averaging 28 ± 5.2 years, were invited on a random basis to be part of this study. The training set is constituted by 514 histograms, each representing the average of the 12 histograms acquired for all subjects. Participants of this study were of different skin colour for increasing the variability of the sample, thus making the training data set representative of this region. • ANN structure: The ANN used in this work is composed of 256 input neurons-the histogram values-and 2 hidden layers, each one composed of 1024 neurons, whereas the output layer has only one neuron corresponding to the glucose concentration value. At the end of both hidden layers, a 0.20 dropout was considered. The activation functions used in this model were ReLU [44] in all cases. • ANN configuration: The ANN was trained using the ADAM method for error minimisation [45]. A total of 100 epochs with a 50 batch size were also considered.
• Evaluation metrics: With the aim to evaluate the model performance, the mean absolute error and the Clarke error grid analysis [46] were adopted. The mean absolute error (MAE) is computed as in Equation (2) where y i represents the reference glucose values, andŷ i stands for the estimated values by the algorithm. In the Clarke error grid, the reference glucose concentrations versus the estimated values are plotted and divided into five zones, as shown in Figure 3. Zones A and B represent accurate or acceptable glucose results, respectively; zone C could lead to unnecessary treatments while zones D and E entail potentially dangerous mistreatment. • Cross-validation model: The whole input data set was divided into train/test (for model selection) and validation subsets. For this purpose a 10-fold cross-validation scheme was randomly applied to the 70% of the whole data set, representing the train/test subsets; the remaining 30% were taken as the validation subset, as illustrated in Figure 2. In the 10-fold cross-validation, data is randomly divided into 10 groups or folds of approximately equal number of observations. The first fold is used as a test subset whilst the remaining nine folds serve to train the classifier. This procedure is repeated ten times until every fold is treated as a test subset [47].
• Cross-validation model: The whole input data set was divided into train/test (for model selection) and validation subsets. For this purpose a 10-fold cross-validation scheme was randomly applied to the 70% of the whole data set, representing the train/test subsets; the remaining 30% were taken as the validation subset, as illustrated in Figure 3. In the 10-fold crossvalidation, data is randomly divided into 10 groups or folds of approximately equal number of observations. The first fold is used as a test subset whilst the remaining nine folds serve to train the classifier. This procedure is repeated ten times until every fold is treated as a test subset [47].

System Implementation
The whole system was implemented using a Flask server, which allows performing multiple functions or microservices, through a variety of API calls, and it is structured. This server is running on Windows operating system with 8 GB RAM, Core i7 processor, SSD 240 GB, Python 3.5, Flask 1.02 and MariaDB 10.1.35. Its structure is designed so that it contains the GET and POST interaction methods.
The API structure for the present monitoring system is shown in Table 1, and the main functions implemented on this system, are explained in detail below. the estimated values by the algorithm. In the Clarke error grid, the reference glucose concentrations versus the estimated values are plotted and divided into five zones, as shown in Figure 2. Zones A and B represent accurate or acceptable glucose results, respectively; zone C could lead to unnecessary treatments while zones D and E entail potentially dangerous mistreatment. • Cross-validation model: The whole input data set was divided into train/test (for model selection) and validation subsets. For this purpose a 10-fold cross-validation scheme was randomly applied to the 70% of the whole data set, representing the train/test subsets; the remaining 30% were taken as the validation subset, as illustrated in Figure 3. In the 10-fold crossvalidation, data is randomly divided into 10 groups or folds of approximately equal number of observations. The first fold is used as a test subset whilst the remaining nine folds serve to train the classifier. This procedure is repeated ten times until every fold is treated as a test subset [47].

System Implementation
The whole system was implemented using a Flask server, which allows performing multiple functions or microservices, through a variety of API calls, and it is structured. This server is running on Windows operating system with 8 GB RAM, Core i7 processor, SSD 240 GB, Python 3.5, Flask 1.02 and MariaDB 10.1.35. Its structure is designed so that it contains the GET and POST interaction methods. The API structure for the present monitoring system is shown in Table 1, and the main functions implemented on this system, are explained in detail below. In the user glucose profile generation function (/signUp), the glucose profile of a user is stored for registered users. With the intention of registering new users in the database, a form with username, e-mail and password must be filled.
On the other hand, the glucose estimation function (/glucose/estimation) receives a parameter along with a JSON object with information such as the user ID, and the mean histogram obtained from the 12 fingertip images as computed by the RPi board. This also incorporates an artificial neural network model, trained previously as specified in the model selection section, giving as output the estimated glucose concentration value. Results obtained in this function, i.e., the estimated glucose value, the user ID, so as the current time and hour, are then saved on the database.
Finally, the share data to end device function (/glucose/query) is a function consisting in returning the current estimated glucose value. However, it also allows the retrieval of the glucose historical record of a user by an end device.
Please note that /glucose/estimation and /glucose/query are general purpose functions, so the integration of measurements from other sensors, e.g., ECG (/ecg/estimation and /ecg/query) or SpO2 (/spo2/estimation and /spo2/query) is straightforward, resulting in a flexible and scalable system.

Smart End Device
As stated above, the data calculated on the IoT server is shared to end devices by means of the query method in the share data to end device function. The end device comprises a mobile application that can be installed on Android devices such as smartphones or tablets. This device is used for visualising data from the glucose profiles estimated previously.

Results
In this section, results including the IoT system setup and the end device implementation, as well as the model selection and validation, are presented.

IoT Sensor Setup
The IoT sensor comprises the image acquisition stage along with the Raspberry Pi Zero board, implemented in the glove embodiment, as shown in the Figure 4.
In this section, results including the IoT system setup and the end device implementation, as well as the model selection and validation, are presented.

IoT Sensor Setup
The IoT sensor comprises the image acquisition stage along with the Raspberry Pi Zero board, implemented in the glove embodiment, as shown in the Figure 4.  In this stage, histograms from the blue channel of acquired images are obtained as stated before. An example of one fingertip image acquired with this system and its corresponding blue channel histogram are depicted in Figure 5. However, in this study, one of the principles for estimating the glucose level is that histograms of the fingertip images differ when users have different glucose concentrations; Figure 6 provides a visual comparative regarding this assumption.
Appl. Sci. 2019, 9, x 8 of 13 In this stage, histograms from the blue channel of acquired images are obtained as stated before. An example of one fingertip image acquired with this system and its corresponding blue channel histogram are depicted in Figure 5. However, in this study, one of the principles for estimating the glucose level is that histograms of the fingertip images differ when users have different glucose concentrations; Figure 6 provides a visual comparative regarding this assumption.

End Device Screens
The end device has three main activities, described as follows: • Activity 1: login and server connection. This function aims for establishing a connection to the Flask IoT server through the port 5000. • Activity 2: shows the current glucose value and graphs the last ten measurements for logged user. This is made by JPLOT, a .aar library to graph static (x, y) coordinate points, time series, among other; which is convenient for showing the results in our application. In this stage, histograms from the blue channel of acquired images are obtained as stated before. An example of one fingertip image acquired with this system and its corresponding blue channel histogram are depicted in Figure 5. However, in this study, one of the principles for estimating the glucose level is that histograms of the fingertip images differ when users have different glucose concentrations; Figure 6 provides a visual comparative regarding this assumption.

End Device Screens
The end device has three main activities, described as follows: • Activity 1: login and server connection. This function aims for establishing a connection to the Flask IoT server through the port 5000. • Activity 2: shows the current glucose value and graphs the last ten measurements for logged user. This is made by JPLOT, a .aar library to graph static (x, y) coordinate points, time series, among other; which is convenient for showing the results in our application.

End Device Screens
The end device has three main activities, described as follows: • Activity 1: login and server connection. This function aims for establishing a connection to the Flask IoT server through the port 5000. • Activity 2: shows the current glucose value and graphs the last ten measurements for logged user. This is made by JPLOT, a .aar library to graph static (x, y) coordinate points, time series, among other; which is convenient for showing the results in our application. • Activity 3: show the glucose record profile estimated on previous days. The graph in this screen also displays two lines representing the limits for hypoglucaemia and hyperglucaemia correspondingly enclosing the healthy glucose values.
Please refer to Figure 7 to see an example of mobile application screens.

Model Selection and Validation
To obtain reliable results regarding the implementation of the ANN model, the input dataset was split into train/test (70%) and external validation (30%) subsets. In the first subset-the train/test split-a 10-fold cross validation scheme was performed. The ANN model was trained using the parameters and configuration determined in the model validation, considering the MAE and the Clarke grid error analysis as the evaluation metrics. For details of the latter, please refer to Section 2.5.1.
The dataset was first divided into train/test subsets to conduct the 10-fold cross-validation process, resulting in an 11.81 mg/dL mean absolute error, and a Clarke error grid zone percentage of A = 83.84%, B = 16.16%, and 0% for the rest of zones. The validation subset was then fed to the trained ANN. After this process the results were a 10.37 mg/dL mean absolute error, with a Clarke error grid zone percentage of A = 90.32% and B = 9.68%; none of the predicted glucose values fell on the C, D, E zones.
Results of the estimated glucose concentrations in comparison to the actual values can be seen in Figure 8 and Table 2, respectively.

Model Selection and Validation
To obtain reliable results regarding the implementation of the ANN model, the input dataset was split into train/test (70%) and external validation (30%) subsets. In the first subset-the train/test split-a 10-fold cross validation scheme was performed. The ANN model was trained using the parameters and configuration determined in the model validation, considering the MAE and the Clarke grid error analysis as the evaluation metrics. For details of the latter, please refer to Section 2.5.1.
The dataset was first divided into train/test subsets to conduct the 10-fold cross-validation process, resulting in an 11.81 mg/dL mean absolute error, and a Clarke error grid zone percentage of A = 83.84%, B = 16.16%, and 0% for the rest of zones. The validation subset was then fed to the trained ANN. After this process the results were a 10.37 mg/dL mean absolute error, with a Clarke error grid zone percentage of A = 90.32% and B = 9.68%; none of the predicted glucose values fell on the C, D, E zones.
Results of the estimated glucose concentrations in comparison to the actual values can be seen in Figure 8 and Table 2, respectively. A = 83.84%, B = 16.16%, and 0% for the rest of zones. The validation subset was then fed to the trained ANN. After this process the results were a 10.37 mg/dL mean absolute error, with a Clarke error grid zone percentage of A = 90.32% and B = 9.68%; none of the predicted glucose values fell on the C, D, E zones.
Results of the estimated glucose concentrations in comparison to the actual values can be seen in Figure 8 and Table 2, respectively.

Discussion
The presented results (Clark grid error = 90.32% in zone A, MAE = 10.37) suggests that our approach is competitive with those found in the literature: E. Monte-Moreno et al. [48] reported 87.7% of points in zone A, Y. Segman et al. [49] 81.2% for zone A, and I. Harman-Boehm et al. [50] reported a 96% of the points are in zones A and B, but only 57% are in zone A [50]. Despite the fact that non-invasive glucose meters have been presented previously, most of their applications are implemented locally, and the measurements are carried out in vitro or using a robust setup. Even with the promising results that IoT technology could bring, there are no new works that suggest the methodology for its implementation in a cloud device or devices of daily use. Our proposal was implemented and instrumented as an IoT system, in which all our measurements were carried out in vivo. The obtained data was validated by making comparisons with standard blood tests by means of the MAE and Clarke grid error.
The use of Raspberry Pi Zero has advantages: it has a powerful microprocessor running a special Linux distribution, with digital I/O as Arduino has, but with more communications modules.
The use of optical methodologies for quantifying glucose levels is currently one of the leading techniques conducting the major research in the field of non-invasive glucose estimation. In this regard, this work aimed to estimate the glucose level from histograms of pictures taken with the RPi Zero board by means of an intelligent algorithm based on an ANN. To this end, sensors for the final setup were embedded in a glove and are in charge of data acquisition, but also perform a pre-processing step by computing the histograms of acquired pictures, thus reducing the amount of data to be sent but leaving the whole neural network computing process to the server. As a result, a high scalability of the system is achieved, allowing other things to be attached, e.g., oximeter, ECG, temperature or blood pressure sensors could be added.
All the above was validated by the system functionality, but also, in terms of accuracy as stated in the results section. The glucose estimation readings recorded by the present approach could be particularly useful to provide further user health information, permitting the medical specialist to perform a better diagnostic.
Despite the variation of skin colour of participants not being studied in this work, it would be of great interest to take it into consideration for further research in which we propose to incorporate this new variable along with the histogram to feed the ANN.
One limitation of the present proposal is that the instrumentation can be considered bulky for use during daily activities. However, the size of the system can be improved by using smaller batteries and designing PCB (Printed Circuit Board) circuits for integrating the whole system. Furthermore, the incorporation of more sensors connected to the RPi Zero could turn the current system in a health care platform, for this reason, this work can serve as a starting point towards a full smart health care service.