# Off-Cloud Anchor Sharing Framework for Multi-User and Multi-Platform Mixed Reality Applications
## 3 Design and Implementation of the System
### System Design
#### 3.3.3 IoT Interaction Module  
An additional layer of immersion was added by implementing a Bluetooth-based system that allows the connection of external devices with the HoloLens 2 application. Specifically, an ESP32 board was used [38]. This board acts as a controller that is used as a physical switch that reacts with some virtual element in the scene. This approach combines the real and virtual world, providing a more immersive UX. For example, in the use case proposed in this article, which is detailed later in Section 4, a button attached to the controller would act as a physical \"fire extinguisher\" that, when activated, extinguishes the fire in the virtual world when a frying pan burns in the game.  
The ESP32 was configured to establish a Bluetooth connection in serial mode with the HoloLens 2. This controller is connected to a physical button that, when pressed, sends a signal to the HoloLens 2 device, indicating that the fire should be turned off. The application on the HoloLens 2 is prepared to receive the message sent by the ESP32 and trigger the corresponding action.  
In addition, the HoloLens 2 is configured to automatically scan for and find Bluetooth devices in its environment. Using \"auto-discovery\" capabilities, whose protocol can be seen in Figure 5, the HoloLens 2 smart glasses detect devices designed for this application and connects to them without any manual intervention. This simplifies the UX, as users do not need to perform any additional configuration to establish the connection with the IoT device.  
To facilitate the integration with heterogeneous IoT devices while minimizing manual configuration, an allowlist mechanism was used during the Bluetooth auto-discovery process. This allows us to apply a flexible naming convention in which compatible devices are recognized by their broadcast device name, following the pattern \"APP_NAME_<device-id>\". This approach allows the application to dynamically detect devices intended for this MR system without hardcoding any Universally Unique Identifier (UUID) or device identifiers, thereby improving scalability. In addition, a locally stored configurable list of trusted devices could be added. This list would contain accepted name prefixes, and only devices whose device name includes one of these prefixes in their Bluetooth advertisement beacons are considered eligible for connection. This system would provide an extra layer of filtering to ensure that only validated and expected devices could interact with the application.  
Specifically, the method used to detect nearby Bluetooth devices is based on the following system call: \"DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector-FromPairingState())\". This function retrieves all discoverable devices that are not yet paired with the HoloLens 2. Once a compatible device is identified based on its name pattern, the application establishes the connection using \"BluetoothDevice.FromIdAsync(device.Id)\", which initiates the pairing and communication process.  
The interaction process that occurs when running the \"auto-discovery\" of IoT devices is detailed below:  
1. Initial Connection: When the application is first started on the HoloLens 2, the application automatically scans the environment for compatible Bluetooth devices(i.e., devices that are included in a previously defined white list of trusted devices). Once detected, the connection is established without the need of manual intervention.
2. Physical Action: Pressing the physical button connected to the ESP32 sends a message to the HoloLens 2 device.
3. Virtual Action: The HoloLens 2 receives the message and executes the assigned function, ensuring a fast and consistent response to the user's physical interaction.