Expand description
§emotiv
Async Rust client for streaming EEG and BCI data from Emotiv headsets via the Cortex API WebSocket (JSON-RPC 2.0).
§Supported hardware
| Model | EEG ch | BCI | Notes |
|---|---|---|---|
| EPOC X | 14 | ✓ | Full EEG, motion, performance metrics, mental commands |
| EPOC+ | 14 | ✓ | Same protocol as EPOC X |
| Insight | 5 | ✓ | Lightweight 5-channel headset |
| EPOC Flex | 32 | ✓ | Research-grade flexible cap |
§API credentials
To connect to a real headset you need a Client ID and Client Secret from the Emotiv developer portal:
- Install and log into the EMOTIV Launcher.
- Create a Cortex App at https://www.emotiv.com/my-account/cortex-apps/.
- Pass the credentials via
CortexClientConfigor theEMOTIV_CLIENT_ID/EMOTIV_CLIENT_SECRETenvironment variables.
On the first connection the Cortex service will prompt you to approve the app inside the EMOTIV Launcher (one-time only).
§Quick start
use emotiv::prelude::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = CortexClientConfig {
client_id: std::env::var("EMOTIV_CLIENT_ID")
.expect("set EMOTIV_CLIENT_ID"),
client_secret: std::env::var("EMOTIV_CLIENT_SECRET")
.expect("set EMOTIV_CLIENT_SECRET"),
..Default::default()
};
let client = CortexClient::new(config);
let (mut rx, handle) = client.connect().await?;
while let Some(event) = rx.recv().await {
match event {
CortexEvent::SessionCreated(_) => {
handle.subscribe(&["eeg", "mot", "met", "pow"]).await?;
}
CortexEvent::Eeg(data) => {
println!("EEG: {:?}", &data.samples[..5.min(data.samples.len())]);
}
CortexEvent::Disconnected => break,
_ => {}
}
}
Ok(())
}§Simulation mode (feature = simulate)
For testing without hardware or API keys, enable the simulate feature:
[dependencies]
emotiv = { version = "0.0.1", features = ["simulate"] }Then use [simulator::spawn_simulator] to generate synthetic data
through the same CortexEvent channel.
§Module overview
| Module | Purpose |
|---|---|
prelude | One-line glob import of the most commonly needed types |
client | WebSocket connection, auth flow, and the CortexHandle command API |
types | All event and data types (CortexEvent, EegData, etc.) |
protocol | JSON-RPC request builders and Cortex API constants |
[simulator] | Signal simulator for offline testing (feature = simulate) |
Modules§
- client
- Cortex WebSocket client for Emotiv headsets.
- config
- Configuration
- error
- Error Types
- health
- Connection Health Monitor
- prelude
- Convenience re-exports for downstream crates.
- protocol
- Cortex API JSON-RPC 2.0 protocol definitions and request builders.
- reconnect
- Resilient Client
- retry
- Retry Policies
- types
- All data types produced and consumed by the Emotiv Cortex client.