--- name: ble-device description: > Connects to a Scentience Reconnaisscent or Scentinel device via BLE Bluetooth, then samples or streams real-time chemical sensor readings (over 5 dozen+ compounds) alongside temperature, humidity, pressure, and battery telemetry. Use when initializing hardware, collecting sensor data, building data-logging pipelines, or debugging a Scentience device connection. version: 1.0.0 author: kordelfrance license: Apache 2.0 compatibility: > Python: pip install scentience (BLE only) or pip install "scentience[models]" (adds torch/transformers). JS: npm install scentience (Node >=16; add webbluetooth peer dep for BLE in Node). Rust: cargo add scentience. C++: Conan scentience/2.0.0. API key required: obtain from dashboard.scentience.ai or the Sigma iOS app. metadata: domain: olfaction hardware: [Reconnaisscent, Scentinel, Olfactory Development Board] tags: [ble, bluetooth, hardware, sensor, streaming, iot, sampling] sdk_versions: {python: ">=0.2.0", js: ">=2.0.0", rust: ">=0.2.1"} docs: https://scentience.github.io/docs-api/ble-api allowed-tools: Bash Read --- ## Goal Establish a BLE connection to a physical Scentience OPU device and retrieve structured sensor readings — either a single snapshot or a continuous stream — ready for downstream navigation, embedding, or logging workflows. ## Instructions ### 1. Authenticate All SDK constructors require an API key issued by Scentience. ```python # Python from scentience import ScentienceDevice device = ScentienceDevice(api_key="SCN_...") ``` ```javascript // JavaScript (ESM) import { ScentienceDevice } from 'scentience'; const device = new ScentienceDevice("SCN_..."); ``` ```rust // Rust use scentience::ScentienceDevice; let device = ScentienceDevice::new("SCN_..."); ``` Obtain keys at [dashboard.scentience.ai](https://dashboard.scentience.ai) or via the Sigma iOS app. Keys are prefixed `SCN_`. ### 2. Connect via BLE `connect_ble` / `connectBLE` requires the BLE characteristic UUID for your device. Optionally pin to a specific device UID when multiple units are in range. ```python # Python — required: char_uuid; optional: device_uid await device.connect_ble(char_uuid="") await device.connect_ble(char_uuid="", device_uid="") ``` ```javascript // JavaScript await device.connectBLE({ charUuid: "" }); await device.connectBLE({ charUuid: "", deviceUid: "" }); ``` ```rust // Rust device.connect_ble("").await?; device.connect_ble_with_uid("", "").await?; ``` Characteristic UUIDs are in the [BLE API docs](https://scentience.github.io/docs-api/ble-api). ### 3. Sample or Stream **Single sample** — one reading, blocks until available: ```python reading = await device.sample_ble(async_=True) # async Python reading = device.sample_ble(False) # sync Python ``` ```javascript const reading = await device.sampleBLE({ async: true }); ``` ```rust let reading = device.sample_ble(true).await?; ``` **Continuous stream** — yields readings until the connection is closed: ```python async for reading in device.stream_ble(async_=True): process(reading) ``` ```javascript for await (const reading of device.streamBLE({ async: true })) { process(reading); } ``` ```rust let mut stream = device.stream_ble(true).await?; while let Some(reading) = stream.next().await { process(reading?); } ``` ### 4. Parse the Response Payload All readings share a consistent JSON schema (BLE MTU ≤ 512 bytes). Chemical fields are in ppm; trace compounds may be sub-ppm — confirm units in device firmware docs. ```json { "UID": "SCN-REC-0042", "TIMESTAMP": 1743379200000, "ENV_temperatureC": 22.4, "ENV_humidity": 48.1, "ENV_pressureHpa": 1013.2, "BATT_health": "good", "BATT_v": 3.85, "BATT_charge": 87, "BATT_time": "3h 22m", "STATUS_opuA": "active", "CO2": 412.0, "NH3": 0.08, "NO": 0.01, "NO2": 0.02, "CO": 0.30, "C2H5OH": 0.00, "H2": 0.05, "CH4": 1.80, "C3H8": 0.00, "C4H10": 0.00, "H2S": 0.002, "HCHO": 0.01, "SO2": 0.00, "VOC": 0.45 } ``` **Key fields:** - `STATUS_opuA` — must be `"active"` before using chemical readings for analysis. - `ENV_*` — SI units: °C, % RH, hPa. - Chemical fields — Reconnaisscent returns 14 compounds from 1 OPU (16 programmable slots); Scentinel returns more from 8 OPUs. Schema shape is the same. ### 5. Log to File (Optional) The JS SDK includes `ScentienceLogger` for JSON/CSV export: ```javascript import { ScentienceDevice, ScentienceLogger } from 'scentience'; const logger = new ScentienceLogger({ format: 'csv', path: './readings.csv' }); for await (const reading of device.streamBLE({ async: true })) { logger.append(reading); } await logger.flush(); ``` ## Examples ### One-shot Python sample with status check ```python import asyncio from scentience import ScentienceDevice async def main(): device = ScentienceDevice(api_key="SCN_...") await device.connect_ble(char_uuid="") reading = await device.sample_ble(async_=True) if reading["STATUS_opuA"] != "active": raise RuntimeError(f"OPU not ready: {reading['STATUS_opuA']}") print(f"VOC={reading['VOC']} ppm CO2={reading['CO2']} ppm NH3={reading['NH3']} ppm") asyncio.run(main()) ``` ### 10-second streaming window in JavaScript ```javascript import { ScentienceDevice } from 'scentience'; const device = new ScentienceDevice("SCN_..."); await device.connectBLE({ charUuid: "" }); const deadline = Date.now() + 10_000; for await (const reading of device.streamBLE({ async: true })) { console.log(`t=${reading.TIMESTAMP} VOC=${reading.VOC} CO2=${reading.CO2}`); if (Date.now() >= deadline) break; } ``` ### Rust: stream with COLIP feature gate ```rust // Cargo.toml: scentience = { version = "0.2", features = ["colip"] } use scentience::ScentienceDevice; use futures_util::StreamExt; let device = ScentienceDevice::new("SCN_..."); device.connect_ble("").await?; let mut stream = device.stream_ble(true).await?; while let Some(Ok(reading)) = stream.next().await { println!("VOC: {} ppm", reading["VOC"]); } ``` ## Constraints - **API key is required** — constructors fail without a valid `SCN_...` key. - **Sensor warm-up** — Metal oxide sensors drift for 30–90 s after power-on. Discard readings until `BATT_charge` has stabilized and at least 90 s have elapsed. Do not use early readings for calibrated analysis. - **Absolute concentrations are uncalibrated** — Raw ppm values are sensor-specific and affected by temperature, humidity, and cross-sensitivity. Use for trend detection and relative comparisons; do not report as certified analytical measurements. - **BLE range** — Nominal range is ~10 m; streaming quality degrades beyond this. - **MTU limit** — BLE payload is ≤ 512 bytes; the full 14-compound schema fits within this limit at default precision. Extended Scentinel payloads may require chunking. - **`STATUS_opuA` check** — Always verify `"active"` before consuming chemical fields. Other states indicate initialization, fault, or sleep mode. - **Single device per connection** — Each `ScentienceDevice` instance manages one BLE connection. Instantiate multiple objects for multi-device setups.