## 2 Materials and Methods
### Device Operation and Data Transmission Software  
This software manages the processes of the device collecting sensor data, processing and analyzing these data and transmitting the results via Bluetooth. This process ensures that the device operates effectively and guarantees the accurate and timely transmission of the obtained data. Device initialization and sensor data collection: When the device is initiated, the AS7265x multi-spectral sensor and the Arduino Nano 33 BLE system are activated. Every 5 s, the device collects spectral data from milk samples. The sensor reads data at specified wavelengths, and these data are transmitted to the microcontroller. Data processing and analysis: The collected data are fed into the XGBoost model pre-loaded on the microcontroller. The model uses these data to analyze the chemical components of the milk sample and determine the results. As a previously trained artificial intelligence algorithm, the model ensures the data are processed accurately. Data transmission: At the end of each data processing cycle, the analysis results are transmitted to other devices via Bluetooth. This process is repeated every 5 s, maintaining continuous data flow. The Bluetooth connection allows for low power consumption and reliable data transmission. The diagram (Figure 2) above illustrates the step-by-step operation process of the device. The process starts with system initialization and sensor data collection, followedby data processing and analysis using the XGBoost model. The results are transmitted via Bluetooth, and the device then enters a standby mode to begin the next data collection cycle. This cycle supports the continuous and uninterrupted data collection and transmission process of the device. The edge gateway plays a crucial role in the process of collecting, processing, and transmitting data by receiving data sent via Bluetooth from the edge sensor node and transmitting it over WiFi using the Message Queuing Telemetry Transport (MQTT) protocol to other devices, software, or databases. This device is critical for ensuring the reliable collection, processing, and transmission of data. Bluetooth message detection and collection: The edge gateway continuously monitors and detects messages from nearby Bluetooth devices, which can come from various sources such as the edge sensor node. The device captures specific Bluetooth messages and stores them for processing. The gateway can be configured to recognize only messages formatted in a certain way, enhancing the accuracy and reliability of the data flow. Data Transmission over WiFi as MQTT messages: Once the Bluetooth data are processed on the edge gateway, they are transmitted over WiFi using the MQTT protocol. MQTT is ideal for data transmission with low bandwidth and low power consumption and is widely used in Internet of Things (IoT) applications. The gateway publishes the relevant data as MQTT messages under specific topic headers. These messages are then transmitted to relevant devices, software, or databases. This process establishes a crucial link for real-time data monitoring and analysis. System Integration and User Interface  
The final component of the software setup involves integrating the entire system and developing a user interface that allows users to interact with the edge sensor node easily. System integration: The integration process ensures that all software components and hardware devices work seamlessly together. This includes the edge sensor node, edge gateway, and any connected IoT devices. The integrated system is designed to synchronize data collection, analysis, and transmission processes, ensuring they function as a cohesive unit. User interface development: A user-friendly interface is developed to allow users to monitor and control the edge sensor node. This interface displays real-time data, system status, and analytical results. It also provides tools for setting up and configuring the device, enabling users to customize the operation according to their specific needs.