# Location Based Indoor and Outdoor Lightweight Activity Recognition System
## 4 Indoor Activity Recognition System  
The proposed indoor location system consists of a monitoring device used to gather positioning data inside a building, several Bluetooth Low Energy (BLE) beacons arranged in the monitored indoor environment, and a Cloud server for data collection and processing (see Figure 28). To maintain a low-cost infrastructure, a smartphone or a smartwatch has been chosen as a monitoring device. Moreover, another advantage of these devices is that they are now commonly used by all users, making them ideal candidates for location monitoring in different environments. In particular, a smartwatch can be worn by a user for the whole day ensuring continuous detection. Furthermore, the use of such devices allows to capture also other data using on board sensors and to transmit them using available communication interfaces (e.g., GPS, BLE or Wi-Fi). In the proposed solution, the BLE interface is employed, together with BLE beacons, for indoor localization, whereas the GPS is used to retrieve information about the outdoor position of a user. Finally, the data is sent to the Cloud server for its storage and analysis through the Wi-Fi or Long-Term Evolution (LTE) interfaces.  
BLE beacons can be easily placed within an environment even without the need for any physical connection using battery-powered devices. Then, the BLE interface integrated in the monitoring device allows to detect the beacons placed in the indoor environment in order to identify the user's position inside the building.  
To explain how the indoor tracking system works, a building with multiple rooms has been considered as an indoor environment, where each room is identified by one or more appropriately installed BLE beacons in order to generate as uniform a signal as possible in the room. Each of those rooms could be considered a POI. Figure 29 shows an example of an environment consisting of four rooms with five beacons placed. The monitoring device runs an application that performs repeated Bluetooth scans and detects nearby beacons. When the user moves inside the building, the application will perform at least three consecutive scans, each of them lasting about 10 s. Moreover, the device needs a few seconds so that the integrated BLE interface can detect all nearby beacons. Then, the result of each scan includes a list of detected nearby BLE beacons stored in the device memory. These information is analyzed through an algorithm that performs an approximation based on the measured Received Signal Strength Indication (RSSI) value of each detected beacon.  
Considering that each room is identified by multiple BLE beacons, the POI is approximated by calculating the average of the measured RSSI values and grouped by the POIs identified by them. After that, the application allows to identify the user's entry and exit from each single POI by comparing the results obtained within one minute. Once POI entry and exit events are identified, they are stored in a local database within the device. Every 30 min, if the Internet connection on the device is available (using Wi-Fi or LTE), the latest unsent event will be sent to the web server through the RESTful API interface.  
The web server processes these events and determines the user's behavior inside the indoor environment. The communication with the server is based on a JavaScript Object Notation (JSON) encoded data structure composed of a list of objects, each of them representing a detected event characterized by: (i) timestamp; (ii) user identifier; (iii) location identifier.  
Figure 28: Proposed location system.