npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-serialport-bluetooth

v0.4.11

Published

comunicacao serialport e bluetooth para android

Readme

react-native-serialport-bluetooth

react-native-serialport-bluetooth is an open-source library for managing serial port connections over Bluetooth and USB in React Native applications. It provides a simple API for listing devices, requesting permissions, opening connections, sending data, and handling received data.

Features

  • List Devices: Retrieve a list of available Bluetooth and USB devices.
  • Request Permissions: Ensure permissions are granted for accessing devices.
  • Open Connections: Establish connections to devices with customizable settings.
  • Send Data: Transmit data to connected devices in hexadecimal format.
  • Close Connections: Safely terminate connections with devices.
  • Handle Received Data: Respond to data received from connected devices.

Compatible Devices

This library supports USB to serial converter chips:

  • FTDI FT232R, FT232H, FT2232H, FT4232H, FT230X, FT231X, FT234XD
  • Prolific PL2303
  • Silabs CP2102, CP210*
  • Qinheng CH340, CH341A, CH9102

Installation

Install the library using npm or yarn:

npm install react-native-serialport-bluetooth
# or
yarn add react-native-serialport-bluetooth

Link the native modules:

npx react-native link react-native-serialport-bluetooth

API Reference

Device Interface

export interface Device {
  readonly name: string;
  readonly type: 'bluetooth' | 'usb';
  readonly deviceId: number;
  readonly vendorId: number;
  readonly productId: number;
}

Methods

list()

Returns a list of available devices.

list(): Promise<Device[]>;

Example:

const devices = await SerialportBluetooth.list();
console.log(devices);

tryRequestPermission(deviceId: number)

Requests permission to access a specific device.

tryRequestPermission(deviceId: number): Promise<number>;

Example:

const permissionCode = await SerialportBluetooth.tryRequestPermission(123);
if (permissionCode === 1) {
  console.log('Permission granted');
}

hasPermission(deviceId: number)

Checks if the app has permission to access a device.

hasPermission(deviceId: number): Promise<boolean>;

Example:

const hasPermission = await SerialportBluetooth.hasPermission(123);
console.log(`Has permission: ${hasPermission}`);

open()

Opens a connection to a device with the specified parameters.

open(
  deviceId: number,
  baudRate: number,
  dataBits: number,
  stopBits: number,
  parity: number,
  readWaitMillis: number,
  writeWaitMillis: number
): Promise<number>;

Example:

const connectionId = await SerialportBluetooth.open(
  123,
  9600,
  8,
  1,
  0,
  100,
  100
);
console.log(`Connection opened with ID: ${connectionId}`);

send()

Sends data to the connected device in hexadecimal format.

send(deviceId: number, hexStr: string): Promise<null>;

Example:

await SerialportBluetooth.send(123, '4a6f686e');
console.log('Data sent successfully');

close()

Closes the connection to a device.

close(deviceId: number): Promise<null>;

Example:

await SerialportBluetooth.close(123);
console.log('Connection closed');

Event: onReceived

Handles data received from the connected device.

SerialportBluetooth.onReceived((data) => {
  console.log('Data received:', data);
});

Usage Example

import SerialportBluetooth from 'react-native-serialport-bluetooth';

async function connectToDevice() {
  const devices = await SerialportBluetooth.list();
  console.log('Available devices:', devices);

  const device = devices[0]; // Select the first device
  const hasPermission = await SerialportBluetooth.hasPermission(
    device.deviceId
  );

  if (!hasPermission) {
    await SerialportBluetooth.tryRequestPermission(device.deviceId);
  }

  const connectionId = await SerialportBluetooth.open(
    device.deviceId,
    9600, // baudRate
    8, // dataBits
    1, // stopBits
    0, // parity
    100, // readWaitMillis
    100 // writeWaitMillis
  );

  console.log('Connected with ID:', connectionId);

  await SerialportBluetooth.send(device.deviceId, '4a6f686e'); // Send "John" in hex
  SerialportBluetooth.onReceived((data) => {
    console.log('Received data:', data);
  });

  await SerialportBluetooth.close(device.deviceId);
  console.log('Connection closed');
}

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Commit your changes and push the branch.
  4. Open a pull request.

License

react-native-serialport-bluetooth is licensed under the MIT License. See LICENSE for details.