kenjdavidson / react-native-bluetooth-classic

⚛ Bluetooth classic Android(Bluetooth)/IOS(ExternalAccessory) module for serial communication
https://kenjdavidson.github.io/react-native-bluetooth-classic
MIT License
247 stars 93 forks source link

it not conneting / pairing to the device #288

Closed KartikDevarde2601 closed 8 months ago

KartikDevarde2601 commented 8 months ago

Mobile Device Environment Provide a list of operating systems on which this issue is relevant.

Application Environment Provide information about your development environment:

Describe the bug on press i call the pairdevice function with string address but i not getting anything ...

`import React from 'react'; import {View, Text, StyleSheet, TouchableOpacity} from 'react-native'; import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'; import {faMicrochip} from '@fortawesome/free-solid-svg-icons/faMicrochip'; import {faHeadset} from '@fortawesome/free-solid-svg-icons/faHeadset'; import {useState} from 'react';

import RNBluetoothClassic, { BluetoothDevice, } from 'react-native-bluetooth-classic';

const RenderItem = ({item}) => { const connectToDevice = async address => { try { console.log('Connecting to device', address); let stringAddress = address.toString();

  const device = await RNBluetoothClassic.pairDevice({
    address: stringAddress,
  });
  console.log('Connected to device', device);
  // Handle successful connection
} catch (error) {
  console.error(error);
}

};

return ( <TouchableOpacity onPress={() => connectToDevice(item.address)}>

{item.deviceClass.majorClass === 1024 ? ( ) : ( )} {item.name ? item.name : item.id} {item.address}
</TouchableOpacity>

); };

export default RenderItem; ` LOGS

LOG Running "BluetoothClassic" with {"rootTag":31} LOG true LOG phone Bluetooth is ON/OFF: true LOG Connecting to device 98:D3:71:F6:C2:68 LOG Connecting to device 98:D3:71:F6:C2:68 LOG Connecting to device 98:D3:71:F6:C2:68

KartikDevarde2601 commented 8 months ago

sorry my bad i connetting wrong way async function conectar() { try { const device = await RNBluetoothClassic.connectToDevice(DEVICE_ID); console.log('Conexión exitosa!'); setConnectedDevice(device.id); console.log('connectedDevice: ', connectedDevice); console.log('address: ', device.id); await RNBluetoothClassic.writeToDevice(DEVICE_ID, '1'); } catch (error) { console.error('Error al conectar:', error); // Handle error accordingly } } this correct code