Download examples/bluetooth/react-native/README.md from Anirudh1950/MentraOS: direct link, hf CLI and curl.
- Browser
- Download file 13 kB
-
https://huggingface.co/Anirudh1950/MentraOS/resolve/main/examples/bluetooth/react-native/README.md
- Command line
-
hf download hf://Anirudh1950/MentraOS/examples/bluetooth/react-native/README.md
-
curl -L -o README.md https://huggingface.co/Anirudh1950/MentraOS/resolve/main/examples/bluetooth/react-native/README.md
React Native / Expo Example
Expo development-build reference app for the Mentra Bluetooth SDK.
This example installs @mentra/bluetooth-sdk and @mentra/engine. App code imports the SDK through the curated @mentra/engine/bluetooth-sdk entry points, which omit the SDK's debug and devtools-only namespaces. The direct SDK dependency supplies its Expo config plugin and native modules. The example demonstrates the same Device, Camera, Stream, System, and Console flows as the native Android and iOS examples. Its full-page Mentra Live update UI is intentionally app-owned and uses useMentraLiveOta; its page content and actions mirror the Mentra App flow while its visual styling follows this example app. Mentra Engine still owns the complete OTA coordinator underneath it.
Expo Go cannot load the SDK because the package contains native Android and iOS code. Use bunx expo run:ios, bun run android:dev, EAS development builds, or production native builds.
Requirements
- Node.js 20+.
- Xcode 26.2+ for Expo SDK 55 iOS builds.
- Android Studio / Android SDK and Java 17 for Android builds.
- A physical phone for Bluetooth, camera, microphone, direct phone photo, and direct phone WebRTC testing.
- Mentra smart glasses with Bluetooth enabled.
Install
From the MentraOS root:
cd examples
bun install
cd bluetooth/react-native
In MentraOS, this example builds against the SDK source. It is a member of the examples/ Bun workspace
(examples/package.json), which links @mentra/*
(workspace:*) to the SDK source in mobile/modules and cloud-v2/packages
and keeps one Expo / React Native version for all the examples. Install from
examples/; installing also runs the linked packages' prepare scripts, which
build them.
The linked packages here are @mentra/bluetooth-sdk, @mentra/engine and
Engine's @mentra/* dependencies.
To type check, also build Engine's declarations, which the example's imports resolve to:
(cd ../../../mobile/modules/engine && bun run build)
bunx tsc --noEmit
Metro and the native builds use the SDK source directly. metro.config.js
watches examples/node_modules, mobile/modules and cloud-v2/packages so Metro can serve those files,
and resolves React, React Native and Expo to the app's own copies.
app.config.js enables the ACS native build plugin when the installed Engine
includes ACS. It uses Engine's exact dependency for Android desugaring and iOS
framework setup; older Engine versions without ACS keep the existing config.
Run On iOS
cd react-native
bun run ios:setup
bunx expo prebuild
bunx expo run:ios
Run on a physical iPhone for Bluetooth testing. Simulators are useful only for UI and compile checks.
Signing With Your Own Apple Developer Team
The committed bundle identifier, com.mentra.bluetoothsdk.example.reactnative, is registered to Mentra's Apple Developer team. Apple App IDs are globally unique, so automatic signing for a physical-device build fails for any other team with errors such as Provisioning Profile "iOS Team Provisioning Profile: *" does not support the Access Wi-Fi Information capability, and the Apple Developer portal refuses to register the identifier. Simulator builds are not affected because they are not signed.
Set MENTRA_IOS_BUNDLE_ID to your own reverse-DNS identifier before generating the native project. app.config.js applies it on top of app.json:
MENTRA_IOS_BUNDLE_ID=com.yourname.mentrasdkrn bunx expo prebuild --clean --platform ios
bunx expo run:ios --device
Xcode then registers the new App ID under your team with the Wi-Fi entitlements the example needs. Leave the variable unset to keep Mentra's identifier for Mentra-owned builds.
The React Native example uses the SDK photo receiver plus local native modules for direct phone receiving:
@mentra/react-native-barcode-scannerscans the latest photo preview for barcodes.@mentra/engine/bluetooth-sdk/photo-receiverstarts a small phone-local photo upload server for direct JPEG uploads.@mentra/react-native-video-stream-receiverstarts the phone-local WebRTC preview receiver.
Only the video stream receiver needs GStreamer. On iOS, bun run ios:setup downloads the GStreamer package from gstreamer.freedesktop.org, verifies the published SHA-256 checksum, and installs it to ~/Library/Developer/GStreamer/iPhone.sdk. Rerun this setup command after a fresh clone or whenever the local GStreamer SDK is missing from the default location.
If your GStreamer SDK is installed somewhere else, set GSTREAMER_ROOT_IOS before prebuild or run:
GSTREAMER_ROOT_IOS=/path/to/iPhone.sdk bunx expo run:ios
Run On Android
cd react-native
bunx expo prebuild
bun run android:dev
Run on a physical Android phone for Bluetooth testing. Some Android devices require both Nearby Devices and Location permission before BLE scan callbacks are delivered.
Development builds do not install glasses updates unless an OTA manifest is
supplied explicitly. Set EXPO_PUBLIC_ASG_OTA_VERSION_URL when you intentionally
need to exercise OTA against a development manifest:
EXPO_PUBLIC_ASG_OTA_VERSION_URL=https://example.com/pinned-version.json bun run android:dev
bun run android:dev starts Metro first, waits for localhost:8081, installs the development build without starting a second bundler, forwards the Android device's localhost:8081 to your computer, and explicitly opens the Expo dev-client URL. This avoids the first-run blank launcher state where you have to manually tap the localhost:8081 session.
Android install scripts (bun run android, bun run android:dev) never target Mentra Live glasses — only a USB-connected phone. If glasses and a phone are both attached, the scripts pick the phone automatically.
If multiple phones are connected, set ANDROID_SERIAL before running:
ANDROID_SERIAL=<phone-serial> bun run android:dev
Do not use expo run:android directly; it may install on whatever device Expo picks (including Mentra Live).
Faster Android installs
bun run android defaults to the fast path:
- Builds
arm64-v8aonly (physical phones). Override withREACT_NATIVE_ARCHITECTURES=...if you need emulators. - Skips the old forced
:mentra-bluetooth-sdk:clean --rerun-tasksGradle pass. UseSDK_CLEAN=1only when you need a hard refresh of the SDK module.
Local on-device STT/TTS via Sherpa-ONNX is not bundled in the published Android SDK (no-op stubs); cloud transcription still works. Built from source in MentraOS, the SDK's Android module uses the Mentra App's dependency set, so the first Gradle configure downloads the ~54MB Sherpa-ONNX AAR.
Day-to-day iteration: prefer bun run android:dev after the first successful install.
Android Foreground Services
This Bluetooth-only host declares connectedDevice for the SDK foreground
service. Its microphone demo receives PCM from the glasses over BLE; it does
not select Android's phone microphone. It does not run location tasks or play
media in the background. withConnectedDeviceForegroundService overrides the
SDK service type and removes Expo's unused location task service. Expo audio
background playback and recording are disabled, and the four unused typed FGS
permissions are blocked in app.json. Ordinary Bluetooth, Wi-Fi, location and
audio permissions are separate and are not removed by this configuration.
The existing iOS audio background mode is preserved explicitly in infoPlist.
The SDK includes Android ForegroundService support for the merged
host manifest at both startup and subsequent type selection. Do not downgrade
the SDK below 3.2.0-dev.200 while using this configuration: older SDKs try to
start undeclared service types. Rebuild the native app after changing these
settings; a JavaScript update cannot change the manifest.
Before release, verify connection/reconnection and permissions on a physical Android phone, including app background/resume, glasses microphone recording, media playback pause on background, photo transfers, and both OTA transports. The retained connected-device service still needs a Google Play declaration and demonstration video.
SDK Plugin Configuration
The example's app.json already includes the Mentra SDK plugin:
[
"@mentra/bluetooth-sdk",
{
"node": true
}
]
The plugins configure the native project so Expo can register the SDK modules. The example uses expo-build-properties to set Android minSdkVersion to 33 and add native library pickFirst rules for libc++_shared.so, libonnxruntime.so, and libonnxruntime4j_jni.so.
@mentra/engine declares @mentra/crust as a peer for its full runtime, but the
@mentra/engine/ota entry does not use Crust. This OTA-only host excludes Crust
from Expo autolinking so it does not package the unrelated navigation and
miniapp-runtime native libraries.
For production Expo apps that need BLE or microphone behavior while iOS is backgrounded or locked, see Background Operation On iOS.
App Walkthrough
The example has five tabs:
- Device: scan for Mentra Live glasses, connect, disconnect, reconnect to the saved/default device, inspect battery, firmware, Wi-Fi, RSSI, and discovered-device state. Connecting Mentra Live opens the custom full-page OTA presentation in
src/otaautomatically; the Software Update action opens the same flow manually. The presentation mirrors the Mentra App's page content and controller actions in the example app's own visual style, keeps intermediate passes on the controller'sfinishingpage, and renders the release transition and accumulated changelogs as styled Markdown in a bounded “What’s new” card only on final success. Hotspot/Wi-Fi transport, APK/MTK/BES sequencing, retries, restarts, and verification remain in Engine. Legacy glasses without hotspot OTA support can return to the System tab for Wi-Fi setup and resume the flow afterward. - Camera: request photo upload to the local demo cloud or directly to this phone, choose automatic or BLE-only photo transfer, record and upload videos to the media webhook, tune manual exposure and ISO, enable Text Capture Mode for glasses-side max-resolution capture and text-region cropping, preview received media, or separately scan standard photo previews for barcodes. Text capture and barcode scanning are mutually exclusive; enabling either turns the other off. Direct phone photo is provided by the SDK, while barcode scanning is implemented in a companion local native module.
- Stream: start RTMP, SRT, or WebRTC streams with SDK-managed keep-alives and preview HLS/WebRTC output. Android and iOS can receive WebRTC directly on the phone through the app-hosted GStreamer WHIP receiver.
- System: scan/connect/forget Wi-Fi, toggle hotspot, change gallery mode, receive microphone PCM, and send RGB LED controls.
- Console: watch button, touch, swipe, BLE, TX, STORE, hotspot, stream, photo, video upload, microphone, and SDK diagnostic events.
Local Media And Streaming Helper
From the Starter Kit root:
python3 local-demo-cloud/server.py
Paste the printed LAN /upload URL into the Camera screen. Paste the printed RTMP, SRT, or WHIP publish URL into the Stream screen. If Docker is not installed or not running, the helper still starts the media webhook and skips streaming with a warning.
You can also prefill the media upload URL when starting a development build:
EXPO_PUBLIC_MENTRA_PHOTO_WEBHOOK_URL=http://<computer-ip>:8787/upload bunx expo run:ios
Do not use localhost in the app. The glasses, phone, and computer must be on a network where the glasses can reach the printed LAN address.
Key Files
src/useBluetoothSdkExample.ts: example-app orchestration for SDK lifecycle, event subscriptions, scan/connect, camera, stream, Wi-Fi, microphone, and LED commands.src/ota/: custom update pages driven only by the publicuseMentraLiveOtacontroller.src/screens/: Device, Camera, Stream, System, and Console screens.src/sdkFormat.ts: shared status/event formatting.app.json: permissions, SDK plugin, and Android native-library packaging rules.app.config.js: appliesMENTRA_IOS_BUNDLE_IDon top ofapp.jsonso third-party teams can sign device builds.metro.config.js: watch folders for the in-repo SDK source and single copies of React, React Native and Expo.modules/mentra-barcode-scanner: local native module used by this example to scan received photo previews for barcodes.modules/mentra-video-stream-receiver: local native module used by this example for Android/iOS direct phone WebRTC preview demos.