Activity Monitoring and Location Sensory System for People With Mild Cognitive Impairments

Cognitive impairment diseases are becoming more and more prevalent mainly due to population aging and the increase in life expectancy. Sensory and monitoring systems may allow people with mild cognitive impairments (MCIs) or at early stages of dementia to live at home for longer with more independence and security. This work presents a wireless sensor network (WSN) based on wearables that obtains indoor and outdoor location and step information, reporting them over a long-range WAN (LoRaWAN) network. Each wireless wearable sensor (WWS) uses a global navigation satellite system (GNSS) module for outdoor positioning, a proposed indoor room-level localization system based on infrared sensors, an accelerometer for a step detector algorithm, and a long-range (LoRa) radio link to send the measured information with low-power consumption achieving a large coverage range. These sensory data are recorded in a database and presented to the medical services and caregivers through a user web application. This can be used to detect anomalous changes in daily patients’ routines, as well as to know the user’s position in cases where the patient may be disoriented. In addition, alerts are launched in caregivers’ smartphones to report about any risky situation, such as the patient leaving an allowed area or staying in one place for too long. Therefore, the proposed sensory system may support and extend the ability of people with MCI or at early stages of dementia to live independently, it helps detect behavioral changes and it keeps caregivers’ peace of mind.


Activity Monitoring and Location Sensory
System for People With Mild Cognitive Impairments Alejandro García-Requejo , M. Carmen Pérez-Rubio , Senior Member, IEEE, José M. Villadangos , and Álvaro Hernández , Senior Member, IEEE Abstract-Cognitive impairment diseases are becoming more and more prevalent mainly due to population aging and the increase in life expectancy. Sensory and monitoring systems may allow people with mild cognitive impairments (MCIs) or at early stages of dementia to live at home for longer with more independence and security. This work presents a wireless sensor network (WSN) based on wearables that obtains indoor and outdoor location and step information, reporting them over a long-range WAN (LoRaWAN) network. Each wireless wearable sensor (WWS) uses a global navigation satellite system (GNSS) module for outdoor positioning, a proposed indoor room-level localization system based on infrared sensors, an accelerometer for a step detector algorithm, and a long-range (LoRa) radio link to send the measured information with low-power consumption achieving a large coverage range. These sensory data are recorded in a database and presented to the medical services and caregivers through a user web application. This can be used to detect anomalous changes in daily patients' routines, as well as to know the user's position in cases where the patient may be disoriented. In addition, alerts are launched in caregivers' smartphones to report about any risky situation, such as the patient leaving an allowed area or staying in one place for too long. Therefore, the proposed sensory system may support and extend the ability of people with MCI or at early stages of dementia to live independently, it helps detect behavioral changes and it keeps caregivers' peace of mind.

I. INTRODUCTION
T HE World is experiencing a huge increase in population aging mainly due to the rise in life expectancy and the decreasing birth rates. During the next three decades, the global number of elderly (aged 65 and over) is projected to more than double, reaching over 1. 5  worldwide [1]. Associated with this increase, diseases such as dementia are rising significantly. Dementia is the seventh leading cause of death in the World, with approximately 55 million people suffering it [2]. Furthermore, it is one of the main causes of dependency in most developed countries, affecting patients and caregivers psychologically, physically, socially, and financially. Indeed, it reports high levels of stress, anxiety, and depression related to caregiving [3]. Hospitalization and institutionalization due to dementia and other cognitive disorders are also common, what implies an additional burden to the long-term sustainability of public health systems and services. In this context, reducing hospitalizations by applying technological and monitoring solutions in the patients' households may improve their quality of life and that of their caregivers, while reducing the cost of care [4]. systems, particularly in remote or rural environments, where there are more difficulties in accessing common health care services due to depopulation [5], [6].

billion in 2050
A key factor in the medical follow-up of dementia patients is to examine their performance on basic essential and routine tasks that most healthy people can carry out without assistance. The loss of ability to perform these tasks, known as activities of daily living (ADL), is a defining feature of dementia that results in a progressive loss of independence, thus increasing caregivers' burden [7]. Information and communication technologies (ICT) have a great potential for supporting the measurement and monitoring of patients' ADLs through ambient-assisted living (AAL) solutions, as long as they are implemented thoughtfully, sensitively, and ethically. Real-time location, tracking, and physical activity monitoring through ICTs, both indoors and outdoors, enable human activity recognition (HAR), which can help detect disorientation episodes or changes in the patient's behavior, alerting caregivers or medical services. This supervised autonomy helps enhance the independence, cognition, mood, and social functioning of patients in the early stages of cognitive decline, while providing peace of mind to caregivers [8], [9].
ICT-based AAL solutions should be characterized by a permanent connection between patients, caregivers and smart objects deployed in the environment or carried by the patients. This can leverage the capabilities of the Internet of Things (IoT) systems to develop wireless sensor networks (WSNs) solutions that provide care for people with cognitive impairments [10], [11]. The use of different IoT connectivities allows patients' data to be measured and collected for analysis, to inform caregivers and/or to take early actions [12], [13], [14].
The IoT cameras can be considered for use in monitoring, tracking, and assisting dependent people, either deployed in the environment, carried by users, or embedded in robots. Nevertheless, cameras are often dismissed due to their intrusiveness [15], [16]. In this context, one of the most widespread and least intrusive IoT sensory system for these purposes is based on wireless wearable sensors (WWSs). These devices are a promising solution for multiuser HAR [17], as they provide individualized and identifiable measurement, tracking and assessment of patients' physical location in any environment (outdoors or at home), while supporting patient's independent daily life [18], [19].
Among the different sensory technologies that wearables can integrate, outdoor tracking is already possible with global navigation satellite system (GNSS) sensors that can be easily found in commercial devices, and which allow any possible disorientation to be detected [20]. On the other hand, for indoor tracking, there is no such established solution. The most common approach with wearable devices is the use of RF technologies based on received signal strength (RSS). Nevertheless, there are other technologies that may be involved, such as cameras, acoustic signals, radio frequency identification (RFID), ultra wideband (UWB), visible light, infrared (IR), or other options with different levels of accuracy [21], [22], [23]. Another important aspect, in addition to patient tracking, is the physical activity monitoring that can be obtained through the use of inertial sensors [24], [25]. Daily physical activity improves cognition and mobility, delays psychiatric symptoms, and generally increases the quality of life in patients with cognitive disorders [26].
Tracking and monitoring data should be reported by the wearable at all times, inside the patient's home as well as outdoors. Established IoT solutions do not often satisfy these requirements, since technologies such as Bluetooth low energy (BLE), WiFi, or ZigBee, do not achieve a larger range than 100 m [27]. Cellular networks can provide the long-range (LoRa) required by this type of applications [28], [29]. However, due to their high-power consumption and maintenance cost, innovative low-power wide area networks (LPWANs) are also promising alternatives. These networks enable low-power wireless connectivity over large areas, at the cost of low data rates. This becomes a suitable WSN solution for sending information occasionally in large spaces where patients can move around and with low wearable battery consumption. Narrow-band IoT (NB-IoT), Sigfox, DASH7, or LoRaWAN are possible LPWAN networks to be used [30]. One of the most widespread for this purpose is LoRaWAN, since it allows the transfer of information over long distances (2-5 km in urban areas and up to 15 km in rural areas) with a low transfer rate that could be acceptable for this type of applications [31], [32], [33].
In this context, this work proposes a WSN composed of WWS that allows to estimate the user's position, both outdoors and indoors, using GNSS and IR technology, respectively. For indoor, a novel symbolic or room-level localization sensor system has been deployed, based on a set of IR beacons that emit a unique code that identifies each room. These sequences are received and decoded by a WWS carried by the patient. The WWS also measures the steps taken by the user throughout the day, providing an indication of the patient's daily physical activity, and it includes LoRaWAN connectivity. In addition, several application services are proposed that allow caregivers to visualize the patient's position in real time through an accessible website, as well as recording relevant data to detect changes in the patient's routine in the long term. Therefore, the main contributions of this work are as follows.
1) The design and implementation of an innovative indoor/outdoor low-power, LoRa wearable tracking system to support and extend the ability of people with mild cognitive impairment (MCI) to live in their own households.
2) The definition and implementation of a novel roomaccurate IR-based positioning sensor system, together with the use of a GNSS module, to estimate the location of the person indoors and outdoors.
3) The development of a low-computational step detector algorithm based on the processing of the acceleration cyclic variations of the wearable device generated during walking to monitor the patient's activity. 4) The integration of the innovative LoRaWAN protocol to achieve a wearable device with a low-power consumption and a LoRa communications to enable access to remote locations where mobile network coverage and common health care services may be poor. 5) The integration of several application services for collecting and visualizing measurements and data from multiple patients in a friendly way for relatives and caregivers. For this purpose, a node-red program has been dedicated to gather patients' data, to store them in an InfluxDB database, which is finally displayed through a Grafana web platform, and to launch alert messages via Telegram. This manuscript is organized as follows: Section II presents some related works; Section III describes the architecture of the proposed system, the WWS, the IR room positioning system, and the LoRaWAN gateway; Section IV explains the algorithms and software implemented; Section V shows some experimental tests carried out to validate the proposal; and, finally, conclusions are discussed in Section VI.

II. RELATED WORK
Several wearable systems for tracking and monitoring patients with cognitive impairments have been presented in the literature using different connectivity and positioning technologies. One of the most common indoor localization solutions in wearable devices is the use of RF technologies based on RSS, such as BLE or WiFi. Although these solutions are low-cost and easily deployed, continuous RSS scanning consumes a large power, which limits their use in wearables [34], [35]. Furthermore, many of these solutions are often inaccurate and require machine learning (ML) algorithms to estimate the user's location, which implies an additional challenge when dealing with real-time running and power consumption [36], [37].
Other RF-based alternatives are also available for this type of systems. Lin et al. [38] propose a sensory system that applies RFID technology to a surveillance system, by placing tags in indoor and outdoor spaces. The system can automatically warn caregivers whenever an elderly person approaches a dangerous area or wanders too far away. NOTECASE [39] is another use case; it is a real-time tracking system to monitor elderly people, both indoors and outdoors, by combining the RFID technology and a global positioning system (GPS) receiver in the wearable. Data are presented to caregivers on both mobile and web applications, whereas communications are based on WiFi, which constrains the range of the system. UWB solutions offer more accurate people tracking estimations. The NITICS [40] system allows the coordinates of the patient's position to be obtained in indoor environments, based on the distribution of some encoded beacons, as well as on measuring the times-of-arrival (TOA) between the beacons and the receiver for later multilateration. This proposal achieves an accuracy below one meter. Indeed, better accuracies (10-30 cm) can be achieved using UWB [41]. On the other hand, some works merge UWB with additional technologies, such as BLE or inertial navigation systems, by means of fusion filters to improve the final performance [42], [43].
Apart from RF solutions, Escort [44] is a sensory system where patients carry network cards that obtain indoor room-level localization through a modulated lighting-based system. Fluorescent and night lights deployed in a building transmit a unique identification code that is measured by a phototransistor integrated in the patient's card. This information is sent in real time via Zigbee to a central server that delivers a short message service text when a user is at risk.
Another approach for monitoring and tracking users deals with motion sensors, such as accelerometers, gyroscopes, or even magnetometers [45], [46]. In [47], they are used to identify ADLs by merging the pose estimated from the magnetometer and the distance traveled during the activity transition. ML algorithms are applied here to recognize the user's current activity.
All the aforementioned alternatives based on different sensory technologies present some drawbacks outdoors. When they are out of the coverage range from the WiFi access point in the household under study, it is necessary to provide the system with a communication channel to upload measurements, while keeping a low-power consumption to maximize the duration of batteries in portable devices. In this context, solutions based on LPWAN networks, such as LoRaWAN, achieve longer battery life, as well as larger range. Hadwen et al. [48] propose a LoRa GPS tracker capable of supporting up to 40 h with a location update rate of 60 s, and a range of 3 km, what allows effective monitoring of patient's position. A comprehensive solution is shown in [49], where an indoor and outdoor localization system is proposed using UWB, GNSS, and LoRaWAN as the communication protocol. This provides sub-meter accuracy indoors, positioning outdoors, and the advantages of using LoRaWAN. Fig. 1 summarizes the architecture of the proposed system. As can be observed, a different coded IR beacon is deployed for each room/space in the monitored patients' home or care facility. The WWS worn by each patient acquires the IR signal, then identifies the transmitting beacon and the associated room. Hence, the individual estimation of the patient's position within the indoor space is achieved. In addition, the user's position can be obtained outdoors by means of a GNSS receiver embedded in the WWS. All these data, together with the steps walked by the user, the battery level, and the environmental information, are transmitted to a gateway via LoRaWAN at a 868.9 MHz frequency. Then the data are uploaded to the cloud. An application server is in charge of gathering this information, storing it in a database to be displayed through a web service, and issuing alarms to caregivers under certain circumstances. Note that a non-limited number of users can be monitorized simultaneously, each one carrying its own unique wearable that will estimate independently the location and activity of the person. Hereinafter, the details of the hardware components in this architecture are discussed below.

A. Description of the IR Beacons
Every deployed beacon emits a 4-bit coded IR signal that can identify up to 16 different indoor spaces. The IR signal is transmitted every 2 s, and it is received and processed by the wearable worn by the user to identify its location.    [50], developed by Espressif Systems Company Ltd., which generates a 4-bit pulsewidth modulated (PWM) signal with a 38 kHz carrier, using a general-purpose input-output (GPIO) port. This PWM signal drives an IR led through a resistor. The emission power of each beacon can be adjusted depending on the value of that resistor, since it may be interesting to have different powers depending on the region to be identified. For instance, it may be advisable to transmit at low power within two adjacent small rooms, so that they do not interfere each other; whereas it is better to emit at higher power in large isolated rooms.

B. Description of the WWS
The WWS prototype is based on the RAK5205 commercial board [51], to which an external battery and an IR receiver module have been added. This receiver enables the signals emitted by the beacons to be acquired, then being possible to identify the position of the user after processing them. On the other hand, the battery is a 1-cell lithium polymer (LiPo) of 2 Ah, which enables the device to last up to 24 h without being recharged. All these components have been packaged in a 64 × 44 × 25 mm 3 box as shown in Fig. 3(a).
The RAK5205 contains several sensors that have been involved here. The Ublox Max-7Q GNSS module handles multiple satellite constellations and has a maximum positioning error of 2.5 m [52]. In addition, it incorporates the BME680 environmental sensor, which provides information on temperature, humidity, atmospheric pressure, and gas resistance [53]. Finally, the three-axis linear accelerometer LIS3DH [54] has been devoted to the detection of the user's steps. The design also includes the RAK811 SoC module [55], which integrates the SX1276 LoRa transceiver [56], used for the information transmission, and the ultralow-power ARM Cortex-M3 STM32L1 microcontroller [57], considered as the core. It is worth noting that both the LoRa and the GNSS antennas have also been connected to the design through the UFL connectors. Fig. 3(b) represents the WWS block diagram.

C. Description of the LoRaWAN Gateway
The sensory data collected by the aforementioned blocks are sent to a gateway using the inbuilt LoRa module, which manages the physical communication layer, through the LoRaWAN 1.0.2 Class A protocol at 868.9 MHz. The gateway works as a transparent bridge, relaying messages from the wearables to a network server over regular IP connections. For this purpose, it converts LoRa packets into IP packets and vice versa.
The gateway used is the Lorix-One 868 MHz model [58], which implements the LoRaWAN specifications, and it is especially designed to be installed outdoors, reaching from 2 km in urban areas to 12 km in rural areas. This is a relevant feature whether the patient is outdoors. Furthermore, it incorporates an operating system to facilitate its configuration, and it includes a power over Ethernet (PoE) module for power supply and connectivity.

IV. PROPOSED ALGORITHMS AND METHODS
The principle of operation of the proposed system involves three software modules, corresponding to the aforementioned hardware elements: the wearable device software, the IR beacon software for the room-level localization, and the high-level application services for data management, alert generation, and visualization. Fig. 4 depicts the tasks running on the ARM Cortex-M3 microcontroller available in the wearable. The main routine initializes all its sensors, establishes a connection with the Gateway and leaves the ARM in an idle state. A timer is set to wake it up every 10 s, so it reads the data from the sensors, creates the payload, and sends them through LoRaWAN. The IR code from the beacons is processed by an interrupt service routine (ISR) that is run when the IR receiver module is triggered, thus processing the incoming IR signal, and updating the code information. If the WWS is not in any room, and therefore no code is obtained, the position is determined through the GNSS module. This might imply an issue if some rooms are not beaconed, thus resulting in a GNSS position with a significant error due to signal attenuation indoors. In this situation, the GNSS module may even fail to obtain a position, so the final location sent is flagged as unknown. Finally, the battery level and the environmental sensor information are also transmitted, as well as the number of steps estimated by the step detector algorithm. This step detection algorithm, together with the symbolic localization system and the application services, are discussed in detail hereinafter for clarity's sake.

A. IR-Based Indoor Symbolic Localization System
The proposed indoor symbolic or room-level localization system is based on the reception of encoded IR signals emitted by a set of beacons deployed in the household's rooms under analysis. These signals are received and decoded by the IR wearable sensor to identify the room where it is located over time. This system, similar to the well-known active badge system [59], may be especially useful for room-level localization when dealing with wearable devices, since it provides a low-battery consumption compared to other technologies, as well as a high room hit rate at low updating frequencies. This performance is possible thanks to the fact that the emitted IR signals are confined into the room and, therefore, they cannot be acquired in other rooms. In cases where rooms are open concept (with no doors), it is advisable to place the beacons facing away from the entrances, so that there is no interference between adjacent rooms. On the other hand, there is also a main constraint to be considered for its operation: the WWS should be worn in a visible area, so the receiver can acquire the IR signals without issues.
As an example, Fig. 5 shows a test for a four-room positioning system with a beacon emission period of 2 s during an interval of 10 min. It is worth noting the high accuracy, although some errors can be observed in the positioning during transitions from one room to another when the rooms have their door opened. This aspect is more noticeable between the hall and the corridor since they are open rooms. In this example, worst case room hit percentages over 80% are obtained in all the rooms (Laboratory: 88.33%, Bathroom: 96.66%, Hall: 93%, Corr: 80.33%). Further evidence and discussions will be presented in Section V, dedicated to experimental results.

B. Step Detector Algorithm
The readings from the three-axis accelerometer available in the WWS are obtained by the ARM processor at a rate of 10 Hz to detect the user's steps. This updating rate has been selected to avoid any prior low-pass filtering in the processing of the incoming signals. In addition, it does not increase either the computational load or the wearable's power consumption significantly.
First, the step detector algorithm (Algorithm 1) computes the Euclidean norm acc k of the three-axis acceleration to minimize the dependency on the orientation from the x, y, and z axes. The average mean k of the last ten samples (1 s) of the norm signal acc (k−10):k is obtained to discard any possible offset and make it possible to analyze if there is a zero crossing between the last two previous samples. In this case, the number Z C of zero crossings is increased, and the last sample at Algorithm 1 Step Detector Algorithm acc k = a 2 x,k + a 2 y,k + a 2 z,k if(k > 10) then mean k = mean (acc (k−10):k ) StepSignal k = acc k − mean k if (ZeroCrossing(StepSignal (k−1):k )) then which the zero crossing has been detected is stored in N Z C . Afterward, when two consecutive zero crossings are identified, the signal is analyzed between the samples N Z C1 and N Z C2 at which the crossings were detected to obtain its maximum and minimum. Finally, if the difference between the maximum and minimum of the signal exceeds a predefined threshold, a new step is validated and the number N step is increased. Fig. 6 shows the norm signal without offset (StepSignal in Agorithm 1), together with the maximum and minimum peaks detected during a seven test in which ten steps were performed. This signal proves the cyclic nature of the steps while walking, thus implying an easily identifiable pattern. This algorithm, based only on the accelerometer, has been derived from [25], [60] and it has been adapted for the case of the WWS worn in the arm.

C. Application Services Diagram
The application services used for the wearable sensory data management have been implemented into several stages, using different software tools that run in a remote server on the cloud network and an application server in the user network, as illustrated in Fig. 7(a). The data collected by the gateway are transmitted to the network server, the things stack (TTS) [61]. TTS is an open and decentralized LoRaWAN network server that supports the use of different integrations to process the data. In this scenario, it has been attached to a message queuing telemetry transport (MQTT) server or broker. This allows to communicate with an MQTT client, which can subscribe to uplinks and publish downlinks.
The MQTT client, as well as the decoding of the payload sent by the WWS, the generation of alerts for caregivers, and the registration of these information in the database have been implemented with the node-red tool [62]. This is a flow-based programming IoT tool developed by IBM to connect hardware devices, APIs, and online services. Fig. 7(b) shows the flowchart in the node-red-based approach. The alarms are triggered when the patient crosses a perimeter-defined outdoors, spends a certain amount of time in a room, or does not enter a room for a specific time interval previously defined. All the parameters to fire the alarms are fully configurable depending on the application. They give useful information to caregivers and allow to detect changes in routines. For instance, it can send warnings if the patient remains an unusual amount of time in the bathroom or if the number of visits to the bathroom per day differs significantly from the usual patterns; another example might be to trigger an alarm if the patient does not go to the kitchen in the expected timetable associated with lunch. These alarms are sent to the caregivers' smartphones via Telegram messages. Note that the proposal is flexible enough to support new definitions of alarms, according to the specialists and caregivers needs.
The database used here is InfluxDB [63], which has been chosen for its optimization for IoT, its easy integration with the node-red tool, and the visualization tool Grafana [64]. Grafana allows the monitoring of the information stored in the database through a web application with a powerful user interface. The application updates the information to be displayed in panels as it is stored in the database. It also allows the user to choose different time slots and days to consult the information. In this way, caregivers and health care assistants can plot all the data measured since the beginning to the present day on different dashboards or panels, allowing the patient's routines to be evaluated over time and to track the real-time positioning of the user.

A. Indoor Localization Results
To measure the accuracy of the IR-based localization system, five different tests have been carried out at the School of Engineering from the University of Alcalá. For this purpose, four IR beacons emitting every 2 s have been deployed in different areas, corresponding to a laboratory, a bathroom, a hall, and a corridor, as shown in Fig. 8. Each test was carried out for 1000 s (what leads to 500 samples per test) following the different trajectories shown in Fig. 9(a), where the accuracy for each room was derived in the worst case, i.e., when the doors are open and, therefore, there might be confusion in the codes received. Fig. 9(b) illustrates the occupancy results obtained for each sample, while Table I shows the percentage of times the system is able to correctly estimate the room with respect to the ground truth. The system mostly identifies the rooms correctly; whereas the misdetections come when signals from two adjacent rooms are simultaneously received, as it can happen when the user is in the entrance of a room and still close to the corridor. Thus, the hit percentage decreases in the corridor, which is an open and a transition area. Also, location rates below the average can be observed in test no. 3, since during this test in the laboratory, the user was close to the entrance and in some occasions the detected signals were those from the corridor. Still, the system offers high enough results to ensure the localization of the patient in the building with low deviation. Note that many errors can be later corrected by filtering spurious measurements and by considering the information from the accelerometer as well (if there is no movement of the user, the room may remain the same). For comparison's sake, after having described the architecture and algorithms proposed, Table II provides a qualitative analysis between our proposal based on IR and some previous works using technologies such as ultrasound (US), RFID, BLE, WiFi, or even LoRa for room-level positioning [39], [65], [66], [67], [68], [69]. Our proposal offers wide coverage, in contrast to RFID, low sensor prices, and suitable localization results at low-computational cost through the code identification method run in the wearable itself. This is due to the confinity of IR signals, what is not fulfilled by RF technologies such as BLE, WiFi or Lora. These require RSS indicator (RSSI) fingerprinting techniques with previous training stages. As a result, portable devices must send the RSSI obtained to a localization server where these techniques are run for power saving. The aforementioned RF technologies are widely used in wearable devices since clothing does not hinder their reception. On the other hand, technologies with similar properties to IR, such as US, allow better results to be obtained by correlating the encoded signals, thus making the system more robust with open doors, despite a higher computational cost. It is worth noting that, to the best of authors' knowledge, the aforementioned active badge system [59], is one of the most relevant works proposing a room-level positioning system based on IR, although it does not provide any detail about reliability. This work [59] is based on certain devices carried by users that emit IR codes every 15 s, whereas some beacons distributed in the environment receive them.

B. Experimental Results for the Step Detector
Four different tests have been performed following different gaits to evaluate the step detector in a variety of situations, where a user has worn the WWS on the arm. The different considered gaits correspond to a normal, a fast way of walking, a slow one, and a random one, while daily activities, such as opening doors or picking up objects, were carried out. To assess the step detector, the count success CS has been defined as the hit percentage between the number of steps N step counted by the WWS and the reference steps N ref (ith test performed)  The results obtained are shown in Table III, where each test has been repeated five times, while executing 100 steps at every repetition. The CS in the tests performed is around 90% in all the cases, decreasing, as expected, when random movements are performed. Note that, in this type of application, where caregivers or medical services want to have information about the patient's level of physical activity over time, the accuracy provided by this step detection algorithm should be enough. The obtained accuracy is comparable to the one in [25].

C. Experimental Results Visualization
To evaluate the functionality of the visualization system, some initial tests were carried out by a volunteer that wore the  Snapshot of alert messages received on caregivers' smartphones.
sensed areas are the same as those shown in Fig. 8, with the addition of the outdoor area around the building to monitor the patient out of home.
The first panel shown in Fig. 10(a) displays the patient's location and the number of steps walked during the selected time slot when the user took a route on the first test day. Initially, the user was at the laboratory, then he came into the hall, through the corridor, and went outdoors where he stayed for about 20 min. Afterward, he returned to the laboratory, passing through the hall, the bathroom, and the corridor. It can be observed how the user increased his steps during the test, until he reached the laboratory, where he remained seated. Finally, the user returned to the bathroom where he stayed for 8 min, until he came back again to the laboratory. It should be noted that some slots present some missing data due to LoRaWAN communication or GNSS signal failures caused by possible building obstructions. Fig. 10(b) illustrates the three different routes taken by the user over the days in a map (test 1, test 2, and test 3). It is worth noting that the user took an unexpected trajectory on the third test to get from one point to another, which can indicate caregivers or medical services that the user may be disoriented, to take action in response. Finally, the panel in Fig. 10(c) shows the occupancy percentage in the different areas while the tests were performed. This can provide information about possible routines followed by the patient that may be indicative of an evolution in the disease. For instance, on the third day test, it can be also observed that the user spent too much time in the corridor compared to the other days, which may be indicative of unusual behavior. It may also be observed that on the first day he used the bathroom longer than the rest of the days, which can be also translated into a variation in the hygiene routines if it persists in the long term. Finally, as an example of the generated alerts that can be sent to the caregivers' smartphones via the instant messaging software Telegram, a screenshot of their content is shown in Fig. 11.

VI. CONCLUSION
This work presents a WSN for location and activity monitoring of people with MCI, such as dementia in the early stages, by wearing a WWS. For this purpose, a prototype of a WWS has been developed based on a commercial board. The wearable contains an IR receiver module for indoor roomlevel location, a GNSS module for outdoor positioning, and an accelerometer to measure patient's steps using a proposed algorithm, which is also detailed. LoRaWAN communications are used to transmit the information indoors and outdoors. Room-level sensor localization is achieved by deploying IR coding beacons at each room in the house, whose periodic sequences are detected by the IR receiver module in the wearable and decoded to estimate the location. More than 90% of the times the system is able to correctly estimate in which room the patient is. On the other hand, the proposed step detector, based on a low sampling rate (10 Hz) of the accelerometer data, achieves a 92.8% accuracy. The use of LoRaWAN results in a low-power consumption with a battery life of up to 24 h and LoRa coverage, thus allowing the patient to move freely in and around the home without the need for other communication. The sensory information is displayed over time via a user-friendly web application that allows to analyze the evolution of the patient's routines. Furthermore, alerts can be launched to caregivers' smartphones, whether the patient might be in danger. In this way, the proposed WSN enhances independent living for multiple patients in the early stages of cognitive diseases, provides caregivers with peace of mind, and supports further follow-ups by the medical services. Future works will deal with reducing the dimensions of the proposed IR wearable prototype for better acceptance by users. Furthermore, experimental tests will be extended to households with multiple MCI tenants, to validate how the proposal behaves in a real case scenario.