munim-bluetooth 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +400 -139
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,22 +1,90 @@
1
- # munim-bluetooth
2
-
3
- A comprehensive React Native library for all your Bluetooth Low Energy (BLE) needs, supporting both peripheral and central roles. Built with React Native's Nitro modules architecture for high performance.
4
-
5
- [![Version](https://img.shields.io/npm/v/munim-bluetooth.svg)](https://www.npmjs.com/package/munim-bluetooth)
6
- [![Downloads](https://img.shields.io/npm/dm/munim-bluetooth.svg)](https://www.npmjs.com/package/munim-bluetooth)
7
- [![License](https://img.shields.io/npm/l/munim-bluetooth.svg)](https://github.com/munimtechnologies/munim-bluetooth/LICENSE)
8
-
9
- ## Features
10
-
11
- ### Peripheral Mode (BLE Advertising & GATT Server)
1
+ <!-- Banner Image -->
2
+
3
+ <p align="center">
4
+ <a href="https://github.com/munimtechnologies/munim-bluetooth">
5
+ <img alt="Munim Technologies Bluetooth" height="128" src="./.github/resources/banner.png?v=3">
6
+ <h1 align="center">munim-bluetooth</h1>
7
+ </a>
8
+ </p>
9
+
10
+ <p align="center">
11
+ <a aria-label="Package version" href="https://www.npmjs.com/package/munim-bluetooth" target="_blank">
12
+ <img alt="Package version" src="https://img.shields.io/npm/v/munim-bluetooth.svg?style=flat-square&label=Version&labelColor=000000&color=0066CC" />
13
+ </a>
14
+ <a aria-label="Package is free to use" href="https://github.com/munimtechnologies/munim-bluetooth/blob/main/LICENSE" target="_blank">
15
+ <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-success.svg?style=flat-square&color=33CC12" target="_blank" />
16
+ </a>
17
+ <a aria-label="package downloads" href="https://www.npmtrends.com/munim-bluetooth" target="_blank">
18
+ <img alt="Downloads" src="https://img.shields.io/npm/dm/munim-bluetooth.svg?style=flat-square&labelColor=gray&color=33CC12&label=Downloads" />
19
+ </a>
20
+ <a aria-label="total package downloads" href="https://www.npmjs.com/package/munim-bluetooth" target="_blank">
21
+ <img alt="Total Downloads" src="https://img.shields.io/npm/dt/munim-bluetooth.svg?style=flat-square&labelColor=gray&color=0066CC&label=Total%20Downloads" />
22
+ </a>
23
+ </p>
24
+
25
+ <p align="center">
26
+ <a aria-label="try with expo" href="https://docs.expo.dev/"><b>Works with Expo</b></a>
27
+ &ensp;•&ensp;
28
+ <a aria-label="documentation" href="https://github.com/munimtechnologies/munim-bluetooth#readme">Read the Documentation</a>
29
+ &ensp;•&ensp;
30
+ <a aria-label="report issues" href="https://github.com/munimtechnologies/munim-bluetooth/issues">Report Issues</a>
31
+ </p>
32
+
33
+ <h6 align="center">Follow Munim Technologies</h6>
34
+ <p align="center">
35
+ <a aria-label="Follow Munim Technologies on GitHub" href="https://github.com/munimtechnologies" target="_blank">
36
+ <img alt="Munim Technologies on GitHub" src="https://img.shields.io/badge/GitHub-222222?style=for-the-badge&logo=github&logoColor=white" target="_blank" />
37
+ </a>&nbsp;
38
+ <a aria-label="Follow Munim Technologies on LinkedIn" href="https://linkedin.com/in/sheehanmunim" target="_blank">
39
+ <img alt="Munim Technologies on LinkedIn" src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white" target="_blank" />
40
+ </a>&nbsp;
41
+ <a aria-label="Visit Munim Technologies Website" href="https://munimtech.com" target="_blank">
42
+ <img alt="Munim Technologies Website" src="https://img.shields.io/badge/Website-0066CC?style=for-the-badge&logo=globe&logoColor=white" target="_blank" />
43
+ </a>
44
+ </p>
45
+
46
+ ## Introduction
47
+
48
+ **munim-bluetooth** is a comprehensive React Native library for all your Bluetooth Low Energy (BLE) needs, supporting both peripheral and central roles. This library allows your React Native app to act as a BLE peripheral (advertising services and characteristics) or as a BLE central (scanning, connecting, and communicating with devices).
49
+
50
+ **Fully compatible with Expo!** Works seamlessly with both Expo managed and bare workflows.
51
+
52
+ **Built with React Native's Nitro modules architecture** for high performance and reliability.
53
+
54
+ **Note**: This library focuses on reliability and platform compatibility. It supports the core BLE features that work consistently across both Android and iOS platforms.
55
+
56
+ ## Table of contents
57
+
58
+ - [📚 Documentation](#-documentation)
59
+ - [🚀 Features](#-features)
60
+ - [📦 Installation](#-installation)
61
+ - [⚡ Quick Start](#-quick-start)
62
+ - [🔧 API Reference](#-api-reference)
63
+ - [📖 Usage Examples](#-usage-examples)
64
+ - [🔍 Troubleshooting](#-troubleshooting)
65
+ - [👏 Contributing](#-contributing)
66
+ - [📄 License](#-license)
67
+
68
+ ## 📚 Documentation
69
+
70
+ <p>Learn about building BLE apps <a aria-label="documentation" href="https://github.com/munimtechnologies/munim-bluetooth#readme">in our documentation!</a></p>
71
+
72
+ - [Getting Started](#-installation)
73
+ - [API Reference](#-api-reference)
74
+ - [Usage Examples](#-usage-examples)
75
+ - [Troubleshooting](#-troubleshooting)
76
+
77
+ ## 🚀 Features
78
+
79
+ ### Peripheral Mode
12
80
 
13
81
  - 🔵 **BLE Peripheral Mode**: Transform your React Native app into a BLE peripheral device
14
82
  - 📡 **Service Advertising**: Advertise custom GATT services with multiple characteristics
15
83
  - 🔄 **Real-time Communication**: Support for read, write, and notify operations
16
- - ✅ **Platform-Supported BLE Advertising**: Support for core BLE advertising data types
84
+ - ✅ **Platform-Supported BLE Advertising**: Support for core BLE advertising data types that work reliably on both platforms
17
85
  - 🔧 **Dynamic Updates**: Update advertising data while advertising is active
18
86
 
19
- ### Central Mode (BLE Scanning & GATT Client)
87
+ ### Central Mode
20
88
 
21
89
  - 🔍 **Device Scanning**: Scan for BLE devices with filtering options
22
90
  - 🔗 **Device Connection**: Connect and disconnect from BLE devices
@@ -29,22 +97,27 @@ A comprehensive React Native library for all your Bluetooth Low Energy (BLE) nee
29
97
  - 📱 **Cross-platform**: Works on both iOS and Android
30
98
  - 🎯 **TypeScript Support**: Full TypeScript definitions included
31
99
  - ⚡ **High Performance**: Built with React Native's Nitro modules architecture
100
+ - 🚀 **Expo Compatible**: Works seamlessly with Expo managed and bare workflows
32
101
  - 🔐 **Permission Handling**: Built-in permission request helpers
33
102
 
34
- ## Requirements
103
+ ## 📦 Installation
35
104
 
36
- - React Native v0.76.0 or higher
37
- - Node 18.0.0 or higher
105
+ ### React Native CLI
38
106
 
39
- > [!IMPORTANT]
40
- > To Support `Nitro Modules` you need to install React Native version v0.78.0 or higher.
107
+ ```bash
108
+ npm install munim-bluetooth react-native-nitro-modules
109
+ # or
110
+ yarn add munim-bluetooth react-native-nitro-modules
111
+ ```
41
112
 
42
- ## Installation
113
+ ### Expo
43
114
 
44
115
  ```bash
45
- npm install munim-bluetooth react-native-nitro-modules
116
+ npx expo install munim-bluetooth react-native-nitro-modules
46
117
  ```
47
118
 
119
+ > **Note**: This library requires Expo SDK 50+ and works with both managed and bare workflows. To support Nitro modules, you need React Native version v0.78.0 or higher.
120
+
48
121
  ### iOS Setup
49
122
 
50
123
  For iOS, the library is automatically linked. However, you need to add the following to your `Info.plist`:
@@ -73,7 +146,7 @@ For iOS, the library is automatically linked. However, you need to add the follo
73
146
 
74
147
  ### Android Setup
75
148
 
76
- The required permissions are automatically included in the library's `AndroidManifest.xml`. However, for Android 12+ (API 31+), you may need to add the following to your app's `AndroidManifest.xml`:
149
+ For Android, add the following permissions to your `AndroidManifest.xml`:
77
150
 
78
151
  ```xml
79
152
  <uses-permission android:name="android.permission.BLUETOOTH" />
@@ -85,32 +158,41 @@ The required permissions are automatically included in the library's `AndroidMan
85
158
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
86
159
  ```
87
160
 
88
- For Android 12+, you also need to specify that these permissions are not used for device discovery:
161
+ **For Expo projects**, add these permissions to your `app.json`:
89
162
 
90
- ```xml
91
- <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
163
+ ```json
164
+ {
165
+ "expo": {
166
+ "android": {
167
+ "permissions": [
168
+ "android.permission.BLUETOOTH",
169
+ "android.permission.BLUETOOTH_ADMIN",
170
+ "android.permission.BLUETOOTH_ADVERTISE",
171
+ "android.permission.BLUETOOTH_SCAN",
172
+ "android.permission.BLUETOOTH_CONNECT",
173
+ "android.permission.ACCESS_FINE_LOCATION",
174
+ "android.permission.ACCESS_COARSE_LOCATION"
175
+ ]
176
+ }
177
+ }
178
+ }
92
179
  ```
93
180
 
94
- ## Quick Start
181
+ ## Quick Start
95
182
 
96
- ### Peripheral Mode Example
183
+ ### Basic Usage - Peripheral Mode
97
184
 
98
185
  ```typescript
99
186
  import { startAdvertising, stopAdvertising, setServices } from 'munim-bluetooth'
100
187
 
101
- // Start advertising
188
+ // Start advertising with basic options
102
189
  startAdvertising({
103
190
  serviceUUIDs: ['180D', '180F'],
104
191
  localName: 'My Device',
105
- advertisingData: {
106
- flags: 0x06,
107
- completeLocalName: 'My Smart Device',
108
- txPowerLevel: -12,
109
- manufacturerData: '0102030405',
110
- },
192
+ manufacturerData: '0102030405',
111
193
  })
112
194
 
113
- // Set up GATT services
195
+ // Set GATT services
114
196
  setServices([
115
197
  {
116
198
  uuid: '180D',
@@ -128,7 +210,7 @@ setServices([
128
210
  stopAdvertising()
129
211
  ```
130
212
 
131
- ### Central Mode Example
213
+ ### Basic Usage - Central Mode
132
214
 
133
215
  ```typescript
134
216
  import {
@@ -147,10 +229,7 @@ startScan({
147
229
  scanMode: 'balanced',
148
230
  })
149
231
 
150
- // Listen for discovered devices
151
- // (Event handling would be implemented here)
152
-
153
- // Connect to a device
232
+ // Connect to a device (deviceId from deviceFound event)
154
233
  await connect('device-id-here')
155
234
 
156
235
  // Discover services
@@ -163,7 +242,74 @@ const value = await readCharacteristic('device-id-here', '180D', '2A37')
163
242
  subscribeToCharacteristic('device-id-here', '180D', '2A37')
164
243
  ```
165
244
 
166
- ## API Reference
245
+ ### Advanced Usage with Supported Advertising Data Types
246
+
247
+ ```typescript
248
+ import {
249
+ startAdvertising,
250
+ updateAdvertisingData,
251
+ getAdvertisingData,
252
+ type AdvertisingDataTypes,
253
+ } from 'munim-bluetooth'
254
+
255
+ // Platform-supported advertising data configuration
256
+ const advertisingData: AdvertisingDataTypes = {
257
+ // 0x01 - Flags (LE General Discoverable Mode, BR/EDR Not Supported)
258
+ flags: 0x06,
259
+
260
+ // 0x02-0x07 - Service UUIDs (fully supported)
261
+ completeServiceUUIDs16: ['180D', '180F'],
262
+ incompleteServiceUUIDs128: ['0000180D-0000-1000-8000-00805F9B34FB'],
263
+
264
+ // 0x08-0x09 - Local Name (fully supported)
265
+ completeLocalName: 'My Smart Device',
266
+ shortenedLocalName: 'SmartDev',
267
+
268
+ // 0x0A - Tx Power Level (fully supported)
269
+ txPowerLevel: -12,
270
+
271
+ // 0x14-0x15 - Service Solicitation (fully supported)
272
+ serviceSolicitationUUIDs16: ['180D'],
273
+ serviceSolicitationUUIDs128: ['0000180D-0000-1000-8000-00805F9B34FB'],
274
+
275
+ // 0x16, 0x20, 0x21 - Service Data (fully supported)
276
+ serviceData16: [
277
+ { uuid: '180D', data: '0102030405' },
278
+ { uuid: '180F', data: '060708090A' },
279
+ ],
280
+ serviceData32: [
281
+ { uuid: '0000180D-0000-1000-8000-00805F9B34FB', data: '0B0C0D0E0F' },
282
+ ],
283
+
284
+ // 0x19 - Appearance (partial support)
285
+ appearance: 0x03c0, // Generic Watch
286
+
287
+ // 0x1F - Service Solicitation (32-bit) (fully supported)
288
+ serviceSolicitationUUIDs32: ['0000180D'],
289
+
290
+ // 0xFF - Manufacturer Specific Data (fully supported)
291
+ manufacturerData: '4C000215FDA50693A4E24FB1AFCFC6EB0764782500010001C5',
292
+ }
293
+
294
+ // Start advertising with supported data
295
+ startAdvertising({
296
+ serviceUUIDs: ['180D', '180F'],
297
+ advertisingData: advertisingData,
298
+ })
299
+
300
+ // Update advertising data dynamically
301
+ updateAdvertisingData({
302
+ flags: 0x04,
303
+ completeLocalName: 'Updated Device Name',
304
+ txPowerLevel: -8,
305
+ })
306
+
307
+ // Get current advertising data
308
+ const currentData = await getAdvertisingData()
309
+ console.log('Current advertising data:', currentData)
310
+ ```
311
+
312
+ ## 🔧 API Reference
167
313
 
168
314
  ### Peripheral Functions
169
315
 
@@ -203,7 +349,7 @@ Sets GATT services and characteristics.
203
349
 
204
350
  **Parameters:**
205
351
 
206
- - `services` (GATTService[]): Array of service objects
352
+ - `services` (array): Array of service objects
207
353
 
208
354
  ### Central Functions
209
355
 
@@ -225,7 +371,7 @@ Starts scanning for BLE devices.
225
371
 
226
372
  **Parameters:**
227
373
 
228
- - `options?` (ScanOptions):
374
+ - `options?` (object):
229
375
  - `serviceUUIDs?` (string[]): Filter by service UUIDs
230
376
  - `allowDuplicates?` (boolean): Allow duplicate scan results
231
377
  - `scanMode?` ('lowPower' | 'balanced' | 'lowLatency'): Scan mode
@@ -324,91 +470,80 @@ Reads RSSI (signal strength) for a connected device.
324
470
 
325
471
  **Returns:** Promise<number>
326
472
 
327
- ### Event Management
328
-
329
- #### `addListener(eventName)`
330
-
331
- Adds an event listener.
332
-
333
- **Parameters:**
334
-
335
- - `eventName` (string): The name of the event to listen for
473
+ ### Types
336
474
 
337
- **Event Types:**
338
-
339
- - `deviceFound`: Emitted when a BLE device is discovered during scanning
340
- - `deviceConnected`: Emitted when a device is successfully connected
341
- - `deviceDisconnected`: Emitted when a device is disconnected
342
- - `servicesDiscovered`: Emitted when services are discovered for a device
343
- - `characteristicsDiscovered`: Emitted when characteristics are discovered
344
- - `characteristicValueChanged`: Emitted when a characteristic value changes
345
- - `writeSuccess`: Emitted when a write operation succeeds
346
- - `writeError`: Emitted when a write operation fails
347
- - `rssiUpdated`: Emitted when RSSI is updated
348
-
349
- #### `removeListeners(count)`
350
-
351
- Removes event listeners.
352
-
353
- **Parameters:**
354
-
355
- - `count` (number): Number of listeners to remove
356
-
357
- ## Types
358
-
359
- ### `AdvertisingDataTypes`
475
+ #### `AdvertisingDataTypes`
360
476
 
361
477
  Platform-supported interface for BLE advertising data types:
362
478
 
363
479
  ```typescript
364
480
  interface AdvertisingDataTypes {
481
+ // 0x01 - Flags (partial support)
365
482
  flags?: number
483
+
484
+ // 0x02-0x07 - Service UUIDs (fully supported)
366
485
  incompleteServiceUUIDs16?: string[]
367
486
  completeServiceUUIDs16?: string[]
368
487
  incompleteServiceUUIDs32?: string[]
369
488
  completeServiceUUIDs32?: string[]
370
489
  incompleteServiceUUIDs128?: string[]
371
490
  completeServiceUUIDs128?: string[]
491
+
492
+ // 0x08-0x09 - Local Name (fully supported)
372
493
  shortenedLocalName?: string
373
494
  completeLocalName?: string
495
+
496
+ // 0x0A - Tx Power Level (fully supported)
374
497
  txPowerLevel?: number
498
+
499
+ // 0x14-0x15 - Service Solicitation (fully supported)
375
500
  serviceSolicitationUUIDs16?: string[]
376
501
  serviceSolicitationUUIDs128?: string[]
377
- serviceSolicitationUUIDs32?: string[]
378
- serviceData16?: Array<{ uuid: string; data: string }>
379
- serviceData32?: Array<{ uuid: string; data: string }>
380
- serviceData128?: Array<{ uuid: string; data: string }>
381
- appearance?: number
382
- manufacturerData?: string
383
- }
384
- ```
385
-
386
- ### `GATTService`
387
502
 
388
- ```typescript
389
- interface GATTService {
390
- uuid: string
391
- characteristics: Array<{
503
+ // 0x16, 0x20, 0x21 - Service Data (fully supported)
504
+ serviceData16?: Array<{
392
505
  uuid: string
393
- properties: string[]
394
- value?: string
506
+ data: string
507
+ }>
508
+ serviceData32?: Array<{
509
+ uuid: string
510
+ data: string
511
+ }>
512
+ serviceData128?: Array<{
513
+ uuid: string
514
+ data: string
395
515
  }>
396
- }
397
- ```
398
516
 
399
- ### `ScanOptions`
517
+ // 0x19 - Appearance (partial support)
518
+ appearance?: number
400
519
 
401
- ```typescript
402
- interface ScanOptions {
403
- serviceUUIDs?: string[]
404
- allowDuplicates?: boolean
405
- scanMode?: 'lowPower' | 'balanced' | 'lowLatency'
520
+ // 0x1F - Service Solicitation (32-bit) (fully supported)
521
+ serviceSolicitationUUIDs32?: string[]
522
+
523
+ // 0xFF - Manufacturer Specific Data (fully supported)
524
+ manufacturerData?: string
406
525
  }
407
526
  ```
408
527
 
409
- ## Usage Examples
528
+ ## Supported BLE Advertising Data Types
529
+
530
+ | Hex | Type Name | Description | Support Level | Example |
531
+ | ---------------- | ----------------------------- | ------------------------------- | ------------- | ------------------------------------------------- |
532
+ | 0x01 | Flags | Basic device capabilities | Partial | `flags: 0x06` |
533
+ | 0x02-0x07 | Service UUIDs | Service UUIDs offered | Full | `completeServiceUUIDs16: ['180D']` |
534
+ | 0x08-0x09 | Local Name | Device name | Full | `completeLocalName: 'My Device'` |
535
+ | 0x0A | Tx Power Level | Transmit power in dBm | Full | `txPowerLevel: -12` |
536
+ | 0x14-0x15 | Service Solicitation | Services being sought | Full | `serviceSolicitationUUIDs16: ['180D']` |
537
+ | 0x16, 0x20, 0x21 | Service Data | Data associated with services | Full | `serviceData16: [{uuid: '180D', data: '010203'}]` |
538
+ | 0x19 | Appearance | Appearance category | Partial | `appearance: 0x03C0` |
539
+ | 0x1F | Service Solicitation (32-bit) | 32-bit services being solicited | Full | `serviceSolicitationUUIDs32: ['0000180D']` |
540
+ | 0xFF | Manufacturer Specific Data | Vendor-defined data | Full | `manufacturerData: '4748494A4B4C4D4E'` |
541
+
542
+ **Note**: This library focuses on reliability and platform compatibility. Advanced BLE features like mesh networking, LE Audio, indoor positioning, etc., are not supported due to platform limitations.
543
+
544
+ ## 📖 Usage Examples
410
545
 
411
- ### Health Device (Peripheral)
546
+ ### Health Device Example
412
547
 
413
548
  ```typescript
414
549
  import { startAdvertising, setServices } from 'munim-bluetooth'
@@ -417,11 +552,11 @@ import { startAdvertising, setServices } from 'munim-bluetooth'
417
552
  startAdvertising({
418
553
  serviceUUIDs: ['180D', '180F'], // Heart Rate, Battery Service
419
554
  advertisingData: {
420
- flags: 0x06,
555
+ flags: 0x06, // LE General Discoverable Mode, BR/EDR Not Supported
421
556
  completeLocalName: 'Health Monitor',
422
557
  appearance: 0x03c0, // Generic Watch
423
558
  txPowerLevel: -8,
424
- manufacturerData: '0102030405',
559
+ manufacturerData: '0102030405', // Custom health data
425
560
  serviceData16: [
426
561
  { uuid: '180D', data: '6400' }, // Heart rate: 100 bpm
427
562
  { uuid: '180F', data: '64' }, // Battery: 100%
@@ -441,12 +576,112 @@ setServices([
441
576
  },
442
577
  ],
443
578
  },
579
+ {
580
+ uuid: '180F', // Battery Service
581
+ characteristics: [
582
+ {
583
+ uuid: '2A19', // Battery Level
584
+ properties: ['read', 'notify'],
585
+ value: '64', // 100%
586
+ },
587
+ ],
588
+ },
444
589
  ])
445
590
  ```
446
591
 
447
- ### Device Scanner (Central)
592
+ ### Smart Home Device Example
448
593
 
449
594
  ```typescript
595
+ import { startAdvertising, updateAdvertisingData } from 'munim-bluetooth'
596
+
597
+ // Smart home device
598
+ startAdvertising({
599
+ serviceUUIDs: ['1812', '180F'], // HID, Battery Service
600
+ advertisingData: {
601
+ flags: 0x04, // LE General Discoverable Mode
602
+ completeLocalName: 'Smart Light Bulb',
603
+ appearance: 0x03c1, // Generic Light Fixture
604
+ manufacturerData: '0102030405', // Custom light data
605
+ serviceData16: [
606
+ { uuid: '1812', data: '01' }, // HID: Keyboard
607
+ { uuid: '180F', data: '64' }, // Battery: 100%
608
+ ],
609
+ },
610
+ })
611
+
612
+ // Update advertising data when light state changes
613
+ updateAdvertisingData({
614
+ manufacturerData: '0102030406', // Updated light data
615
+ serviceData16: [
616
+ { uuid: '1812', data: '02' }, // HID: Mouse
617
+ { uuid: '180F', data: '50' }, // Battery: 80%
618
+ ],
619
+ })
620
+ ```
621
+
622
+ ### Basic Peripheral Setup
623
+
624
+ ```js
625
+ import React, { useEffect } from 'react'
626
+ import {
627
+ startAdvertising,
628
+ stopAdvertising,
629
+ setServices,
630
+ addListener,
631
+ removeListeners,
632
+ } from 'munim-bluetooth'
633
+
634
+ const MyPeripheral = () => {
635
+ useEffect(() => {
636
+ // Configure services
637
+ setServices([
638
+ {
639
+ uuid: '1800', // Generic Access Service
640
+ characteristics: [
641
+ {
642
+ uuid: '2a00', // Device Name
643
+ properties: ['read'],
644
+ value: 'MyDevice',
645
+ },
646
+ {
647
+ uuid: '2a01', // Appearance
648
+ properties: ['read'],
649
+ value: '0x03C0', // Generic Computer
650
+ },
651
+ ],
652
+ },
653
+ {
654
+ uuid: '1801', // Generic Attribute Service
655
+ characteristics: [
656
+ {
657
+ uuid: '2a05', // Service Changed
658
+ properties: ['indicate'],
659
+ },
660
+ ],
661
+ },
662
+ ])
663
+
664
+ // Start advertising
665
+ startAdvertising({
666
+ serviceUUIDs: ['1800', '1801'],
667
+ localName: 'MyReactNativePeripheral',
668
+ })
669
+
670
+ // Cleanup on unmount
671
+ return () => {
672
+ stopAdvertising()
673
+ removeListeners('connectionStateChanged')
674
+ }
675
+ }, [])
676
+
677
+ return <Text>Peripheral is running...</Text>
678
+ }
679
+ ```
680
+
681
+ ### Device Scanner Example
682
+
683
+ ```js
684
+ import React, { useState, useEffect } from 'react'
450
685
  import {
451
686
  startScan,
452
687
  stopScan,
@@ -457,36 +692,60 @@ import {
457
692
  addListener,
458
693
  } from 'munim-bluetooth'
459
694
 
460
- // Start scanning
461
- startScan({
462
- serviceUUIDs: ['180D'], // Filter by Heart Rate service
463
- allowDuplicates: false,
464
- scanMode: 'balanced',
465
- })
695
+ const DeviceScanner = () => {
696
+ const [devices, setDevices] = useState([])
697
+ const [connectedDevice, setConnectedDevice] = useState(null)
698
+
699
+ useEffect(() => {
700
+ // Start scanning
701
+ startScan({
702
+ serviceUUIDs: ['180D'], // Filter by Heart Rate service
703
+ allowDuplicates: false,
704
+ scanMode: 'balanced',
705
+ })
706
+
707
+ // Listen for discovered devices
708
+ addListener('deviceFound')
709
+ // Handle deviceFound events to update devices state
710
+
711
+ // Cleanup
712
+ return () => {
713
+ stopScan()
714
+ if (connectedDevice) {
715
+ disconnect(connectedDevice)
716
+ }
717
+ }
718
+ }, [])
466
719
 
467
- // Listen for discovered devices
468
- addListener('deviceFound')
469
- // Handle deviceFound events to get device information
720
+ const handleConnect = async (deviceId) => {
721
+ await connect(deviceId)
722
+ setConnectedDevice(deviceId)
470
723
 
471
- // Connect to a device
472
- const deviceId = '...' // From deviceFound event
473
- await connect(deviceId)
724
+ // Discover services
725
+ const services = await discoverServices(deviceId)
726
+ console.log('Services:', services)
474
727
 
475
- // Discover services
476
- const services = await discoverServices(deviceId)
728
+ // Read a characteristic
729
+ const value = await readCharacteristic(deviceId, '180D', '2A37')
730
+ console.log('Heart Rate:', value)
477
731
 
478
- // Read a characteristic
479
- const heartRate = await readCharacteristic(deviceId, '180D', '2A37')
732
+ // Subscribe to notifications
733
+ subscribeToCharacteristic(deviceId, '180D', '2A37')
480
734
 
481
- // Subscribe to notifications
482
- subscribeToCharacteristic(deviceId, '180D', '2A37')
735
+ // Listen for value changes
736
+ addListener('characteristicValueChanged')
737
+ }
483
738
 
484
- // Listen for value changes
485
- addListener('characteristicValueChanged')
486
- // Handle characteristicValueChanged events
739
+ return (
740
+ <View>
741
+ <Text>Found {devices.length} devices</Text>
742
+ {/* Render device list */}
743
+ </View>
744
+ )
745
+ }
487
746
  ```
488
747
 
489
- ## Troubleshooting
748
+ ## 🔍 Troubleshooting
490
749
 
491
750
  ### Common Issues
492
751
 
@@ -496,27 +755,29 @@ addListener('characteristicValueChanged')
496
755
  4. **Scanning Not Working**: On Android 6.0+, ensure location permissions are granted
497
756
  5. **Connection Fails**: Verify the device is in range and advertising
498
757
 
499
- ### Platform-Specific Notes
758
+ ### Expo-Specific Issues
500
759
 
501
- **iOS:**
760
+ 1. **Development Build Required**: This library requires a development build in Expo. Use `npx expo run:ios` or `npx expo run:android`
761
+ 2. **Permissions Not Working**: Make sure you've added the permissions to your `app.json` as shown in the setup section
762
+ 3. **Build Errors**: Ensure you're using Expo SDK 50+ and have the latest Expo CLI
763
+ 4. **Nitro Modules**: Make sure you have `react-native-nitro-modules` installed and configured
502
764
 
503
- - All features work natively through Core Bluetooth
504
- - Permission prompts appear automatically when needed
765
+ ### Debug Mode
505
766
 
506
- **Android:**
767
+ Enable debug logging by setting the following environment variable:
507
768
 
508
- - Android 12+ requires additional permission flags
509
- - Location permissions are required for BLE scanning
510
- - Some features may behave differently on different Android versions
769
+ ```bash
770
+ export REACT_NATIVE_BLUETOOTH_DEBUG=1
771
+ ```
511
772
 
512
- ## Contributing
773
+ ## 👏 Contributing
513
774
 
514
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
775
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on how to submit pull requests, report issues, and contribute to the project.
515
776
 
516
- ## Credits
777
+ ## 📄 License
517
778
 
518
- Bootstrapped with [create-nitro-module](https://github.com/patrickkabwe/create-nitro-module).
779
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
519
780
 
520
- ## License
781
+ ---
521
782
 
522
- MIT
783
+ <img alt="Star the Munim Technologies repo on GitHub to support the project" src="https://user-images.githubusercontent.com/9664363/185428788-d762fd5d-97b3-4f59-8db7-f72405be9677.gif" width="50%">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "munim-bluetooth",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "munim-bluetooth is a react native package for all your Bluetooth, BLE, and BLE pheripheral needs",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",