A complete solution for simultaneous data collection from multiple biosensors, supporting real-time data acquisition, transmission, and storage from devices suMQTT message format for all sensors:
这是一个用于同时采集多种生物传感器数据的完整解决方案,支持眼动仪、脑电图(EEG)和腕带(PPG)等设备的实时数据采集、传输和存储。
.
├── source/
│ ├── common/ # Common utilities and data structures
│ ├── sensors/ # Sensor device implementations
│ │ ├── include/ # Sensor interface definitions
│ │ └── src/ # Concrete sensor implementations
│ │ ├── eye/ # Eye tracker device
│ │ ├── egg/ # EEG device
│ │ └── wristband/ # Wristband device
│ └── testCase/ # Test cases
├── script/ # Build and utility scripts
├── server/ # Server implementation
│ ├── src/ # Server source code
│ └── README.md # Server documentation
├── thirdParty/ # Third-party dependencies
└── build/ # Build output directory
- Eye Tracker (眼动仪)
- EEG Device (脑电图设备)
- Biosensor Wristband (生物传感器腕带)
The system uses SQLite for data storage with the following schema:
-- Device registration table
CREATE TABLE devices (
device_id INTEGER PRIMARY KEY,
device_type TEXT,
name TEXT,
channels INTEGER,
sampling_rate REAL,
description TEXT,
created_at DATETIME
);
-- Sensor data table
CREATE TABLE sensor_data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp DATETIME,
device_id INTEGER,
channel_number INTEGER,
value REAL,
FOREIGN KEY(device_id) REFERENCES devices(device_id)
);
{
"device_id": "string",
"timestamp": "ISO8601 string",
"values": [ ]
}
- CMake (>= 3.10)
- C++17 Compatible Compiler
- Windows: Visual Studio 2019 or 2022
- Linux: GCC 7.0 or higher
- macOS: Clang 8.0 or higher
- MQTT Broker (Mosquitto)
- Python 3.7+
- paho-mqtt
- sqlite3
- Ensure Visual Studio 2019/2022 is installed (with C++ development tools) 确保已安装 Visual Studio 2019 或 2022(需要包含 C++ 开发工具)
- Install CMake (download from https://cmake.org/download/) 安装 CMake(可从 https://cmake.org/download/ 下载)
- Use build script:
使用构建脚本:
# Normal build 普通构建 script\build.bat # Clean and rebuild 清理并重新构建 script\build.bat -c
-
Using build script (recommended): 使用构建脚本(推荐):
# Normal build 普通构建 ./script/build.sh # Clean and rebuild 清理并重新构建 ./script/build.sh -c
-
Manual build: 手动构建:
mkdir -p build cd build cmake .. make
-
Install MQTT broker: 安装 MQTT 服务器:
sudo apt-get install mosquitto mosquitto-clients
-
Install Python dependencies: 安装 Python 依赖:
cd server pip install -r requirements.txt
-
Start the MQTT broker: 启动 MQTT 服务器:
sudo systemctl start mosquitto sudo systemctl enable mosquitto
-
Start the data collection server: 运行数据采集服务器:
cd server ./script/server.sh start
-
Run comprehensive test: 运行综合测试:
cd build/source ./test_all
-
Individual sensor tests: 单个传感器测试:
# Eye tracker test 眼动仪测试 ./test_eye # EEG device test 脑电图测试 ./test_egg # Wristband test 腕带测试 ./test_wristband
MQTT message format for all sensors: 所有传感器的 MQTT 消息格式:
{
"device_id": "string",
"timestamp": "ISO8601 string",
"values": ["", "", ""]
}
Database schema: 数据库结构:
-- Device registration table 设备注册表
CREATE TABLE devices (
device_id INTEGER PRIMARY KEY,
device_type TEXT,
name TEXT,
channels INTEGER,
sampling_rate REAL,
description TEXT,
created_at DATETIME
);
-- Sensor data table 传感器数据表
CREATE TABLE sensor_data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp DATETIME,
device_id INTEGER,
channel_number INTEGER,
value REAL,
FOREIGN KEY(device_id) REFERENCES devices(device_id)
);
-
MQTT Connection Issues MQTT连接问题
- Check if the MQTT broker is running:
systemctl status mosquitto
- Verify MQTT port (default 1883) is open:
netstat -an | grep 1883
- Check MQTT logs:
tail -f /var/log/mosquitto/mosquitto.log
- Check if the MQTT broker is running:
-
Device Connection Issues 设备连接问题
- Check USB permissions (for eye tracker)
- Verify Bluetooth is enabled (for EEG and wristband)
- Check device battery level
- Ensure correct device IDs are configured
-
Database Issues 数据库问题
- Verify database file exists:
server/data/sensor_data.db
- Check file permissions
- Run integrity check:
sqlite3 server/data/sensor_data.db "PRAGMA integrity_check;"
- Verify database file exists:
-
Build Issues 编译问题
- Verify CMake version:
cmake --version
- Check compiler version:
g++ --version # Linux clang++ --version # macOS
- Ensure all dependencies are installed
- Verify CMake version: