{"id":13776925,"url":"https://github.com/rusel1989/react-native-bluetooth-serial","last_synced_at":"2025-05-11T10:31:27.871Z","repository":{"id":46458947,"uuid":"56335642","full_name":"rusel1989/react-native-bluetooth-serial","owner":"rusel1989","description":"Port of https://github.com/don/BluetoothSerial for react native","archived":false,"fork":false,"pushed_at":"2024-05-24T18:08:41.000Z","size":199,"stargazers_count":481,"open_issues_count":94,"forks_count":288,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-19T17:13:50.941Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rusel1989.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-15T16:48:29.000Z","updated_at":"2025-03-30T20:32:13.000Z","dependencies_parsed_at":"2024-10-02T04:08:51.773Z","dependency_job_id":"568c243d-a83b-4a2b-9dda-7cbcd05a62a6","html_url":"https://github.com/rusel1989/react-native-bluetooth-serial","commit_stats":{"total_commits":70,"total_committers":7,"mean_commits":10.0,"dds":0.09999999999999998,"last_synced_commit":"09434a0726697902f52ea3a58790fc19f6f14dbe"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusel1989%2Freact-native-bluetooth-serial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusel1989%2Freact-native-bluetooth-serial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusel1989%2Freact-native-bluetooth-serial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusel1989%2Freact-native-bluetooth-serial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rusel1989","download_url":"https://codeload.github.com/rusel1989/react-native-bluetooth-serial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251687138,"owners_count":21627531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:00:35.149Z","updated_at":"2025-05-11T10:31:25.744Z","avatar_url":"https://github.com/rusel1989.png","language":"Objective-C","funding_links":[],"categories":["\u003ca name=\"Network:-Native-Modules\"\u003eNetwork: Native Modules\u003c/a\u003e","Hardware Com"],"sub_categories":["Bluetooth"],"readme":"## React Native Bluetooth Serial\n\nReact Native version of [BluetoothSerial](https://github.com/don/BluetoothSerial) plugin. For both\nandroid and ios\n\n## Compatibility\nOfficialy this library supports React Native \u003e= 0.25, it may run on older versions but no guarantees.\n\n## Installation\n1. Install package via npm: `npm i -S react-native-bluetooth-serial`\n2. Link libraries with: `rnpm link` or `react-native link` for React Native \u003e= 0.27\n3. For android you also need to put following code to `AndroidManifest.xml`\n```\n\u003cuses-permission android:name=\"android.permission.BLUETOOTH\" /\u003e\n\u003cuses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" /\u003e\n```\n\n## Manual installation\n#### iOS\n1. `npm i -S react-native-bluetooth-serial`\n2. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`\n3. Go to `node_modules` ➜ `react-native-bluetooth-serial` and add `RCTBluetoothSerial.xcodeproj`\n4. In XCode, in the project navigator, select your project. Add `libRCTBluetoothSerial.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`\n5. Click `RCTBluetoothSerial.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). In the `Search Paths` section, look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../../react-native/React` and `$(SRCROOT)/../../../React` - mark both as `recursive`.\n5. Run your project (`Cmd+R`)\n\n\n#### Android\n1. `npm i -S react-native-bluetooth-serial`\n2. Open up `android/app/src/main/java/[...]/MainActivity.java` or `MainApplication.java` for React Native \u003e= 0.29\n  - Add `import com.rusel.RCTBluetoothSerial.*;` to the imports at the top of the file\n  - Add `new RCTBluetoothSerialPackage()` to the list returned by the `getPackages()` method\n3. Append the following lines to `android/settings.gradle`:\n    ```\n    include ':react-native-bluetooth-serial'\n    project(':react-native-bluetooth-serial').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-bluetooth-serial/android')\n    ```\n4. Insert the following lines inside the dependencies block in `android/app/build.gradle`:\n    ```\n    compile project(':react-native-bluetooth-serial')\n    ```\n\n## Example\nAs bluetooth is not available in any simulators, if you want to test it with some bluetooth peripherals you have\nto run the example on actual device.\n1. `git clone https://github.com/rusel1989/react-native-bluetooth-serial.git`\n2. `cd react-native-bluetooth-serial/BluetoothSerialExample`\n3. `npm i`\n4. `react-native run-ios/run-android`\n\n# Reading and writing\nIn Android after you connect to peripheral `write` and `read` methods should work for most of devices out of the box.\nOn ios with BLE it is little bit complicated, you need to know correct serice and characteristics UUIDs. Currently\nsupported and preconfigured services are Red Bear lab, Adafruit BLE, Bluegiga, Laird Virtual Serial Port and Rongta. If\nyou know about some services that you think should be supported send PR.\n\nIn near future i will try to improve device discovery on ios and also make services configurable from js.\n\n## API\nAll following methods have been tested on both android and ios devices and return promise.\n\n### [android] enable()\nEnable bluetooth currently in android only.\n\n### [android] disable()\nDisable bluetooth currently in android only.\n\n### isEnabled()\nResolves to boolean value indicating current bluetooth state.\n\n### list()\nResolves to array of available devices, devices are in following format:\n```\n{\n    id: String // MAC address (android) or UUID (ios)\n    name: Sring // Device name\n}\n```\ndoesn't return unpaired devices in android.\n\n### [android] discoverUnpairedDevices()\nResolves to array of unpaired devices on android, device will pair after successful connection. Format is same as list method.\n\n### connect(String id)\nConnect to device by MAC address on android or UUID on ios. Resolves to object with message or rejects with reason of failure.\n\n### disconnect()\nDisconnects from current device should always resolve to true.\n\n### isConnected()\nResolves to true if there is active connection to device or false if not.\n\n### write(Buffer|String data)\nWrite data to connected device, for now buffer is internally converted to Base64 encoded string and decoded to byte array\non native side, beacause react native is currently not capable of passing buffer directly to native methods. Resolves\nto true when write was successful, otherwise rejects with error.\n\n\n## Events\nYou can listen to few event with `BluetoothSerial.on(eventName, callback)`\n\nCurrently provided events are:\n- `bluetoothEnabled` - when user enabled bt\n- `bluetoothDisabled` - when user disabled bt\n- `connectionSuccess` - when app connected to device\n- `connectionLost` - when app lost connection to device (fired with `bluetoothDisabled`)\n\nYou can use `BluetoothSerial.removeListener(eventName, callback)` to stop listening to an event\n\n## TODO\n- Make services configurable on ios\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusel1989%2Freact-native-bluetooth-serial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frusel1989%2Freact-native-bluetooth-serial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusel1989%2Freact-native-bluetooth-serial/lists"}