rusel1989 / react-native-bluetooth-serial Goto Github PK
View Code? Open in Web Editor NEWPort of https://github.com/don/BluetoothSerial for react native
Port of https://github.com/don/BluetoothSerial for react native
BluetoothSerial.removeListener('eventname',callback) does not enter into the callback function.
Can anyone find the cause?
Always no devices found on iOS
Promise.all([
Bluetooth.isEnabled(),
Bluetooth.isConnected(),
Bluetooth.list()
])
.then((values) => {
console.log(values)
})
Output: true, false, []
React Native 0.31, iOS 9.3
Does This tool serve to send archives for impression in a thermal printer?
I'm trying to write image but they all didn't work. Here's the code
var byteArray = Base64.decodeString(base64String);
for (var i = 0 ; i < byteArray.length; i++){
this.write(new Buffer(byteArray[i].toString(2)))
}
this.write(byteArray.buffer)
var byteArray = Base64.decodeArrayBuffer(base64String);
console.log(byteArray)
this.write(byteArray)
When I press "Reload" or the application reloads due to Live Reload being enabled, the onDestroy method of the module is not called. Because of that, the sockets (and streams) are no correctly disposed.
When the reload is finished, I can no longer open a bluetooth socket. It requires me to disable and enable bluetooth, or to restart the application.
Is there ant callback or method I could implement that would correctly dispose these sockets when I reload my application?
Hi there. Great library.
Curious if there's a way to get the currently connected device name and id from the library or do I have to store it myself after successfully connecting.
Right now connected()
just returns true
or false
but I'm thinking it would be great if it returned the device object if it's connected or return false
if it's not. This way you could still do a conditional like if (RNBS.connected()) { ... }
but it would also allow you to display the currently connected Bluetooth device, etc.
Let me know what you think.
Thanks!
How to send files via Bluetooth
Hi guys,
I'm follow the provider example.
I'm able to:
but when i try to connect to a device through
connect (device) {
this.setState({ connecting: true })
BluetoothSerial.connect(device.id)
.then((res) => {
Toast.showLongBottom(`Connected to device ${device.name}`)
this.setState({ device, connected: true, connecting: false })
})
.catch((err) => Toast.showLongBottom(err))
}
That always enter in the catch err.
I saw that the follow error appear in log section:
java.io.IOException: read failed, socket might closed or timeout, read ret: -1
I am testing this by connecting the app to mobile devices, but in the future i need to access to a obdII device.
after i pair the device, the error ocurrs, but in the bluetooth settings of the phone, the phone appear paired.
any idea?
Thanks in advance.
I try to install BluetoothSerialExample on my device. But it always show:
"
Failed to build DependencyGraph: @providesModule naming collision:
Duplicate module name: deprecated
Paths: G:/AndroidDemo/react-native-bluetooth-serial/BluetoothSerialExample\node_modules/react-native/local-cli/server/middleware/heapCapture/bundle.js collides with G:/AndroidDemo/react-native-bluetooth-serial/BluetoothSerialExample\node_modules/react-native/Libraries/Renderer/src/shared/utils/deprecated.js
This error is caused by a @providesModule declaration with the same name across two different files.
"
How can i deal it?
Could you please publish a new version to NPM? The addition of removeListener
is very important to me, and is now in the readme, but the NPM version is 3 months, old.
Thanks!!
I think there should be the way to abort the connection after some timeout. I'm now using this solution from JakeChampion/fetch#175 to wrap the connect()
function, but it will be nice, if there was a way to abort the connection attempt after specified period of time. Or at least abort it directly like Bluetooth.abort()
- that could be used in solution above. At this moment there isn't any.
Following the install procedures, I've got the following error at runtime :
(node:14363) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'message' of undefined
Any idea what's going wrong ?
....node_modules\react-native-bluetooth-serial\android\src\main\java\com\rusel\RCTBluetoothSerial\RCTBluetoothSe
rialModule.java Use or covered the outdated API.
Note: for more information, please use - Xlint: deprecation recompiling.
then in the RED-box,"pairDevice not a function"
Should I change the '.node_modules\react-native-bluetooth-serial\android\src\main\java\com\rusel\RCTBluetoothSerial\RCTBluetoothSe
rialModule.java' import pairDevice function?
My example does not run, after run-ios i get a crash:
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist
What are the chances of getting external accessories build in for the iOS implementation?
Hi I am trying to integrate react-native-bluetooth-serial into my react-native app.I followed the documentation and completed these 3 steps:-
1)Install package via npm: npm i -S react-native-bluetooth-serial
2)Link libraries with: rnpm link or react-native link for React Native >= 0.27
3)For android you also need to put following code to AndroidManifest.xml
After this I ran react-native run-android and the app started failing with the following error:-
1 error
:react-native-bluetooth-serial:compileReleaseJavaWithJavac FAILED
Please revert as soon as possible.
Thank you.
First just wanted to say thank you so much to the contributors working on this.
I am using the BluetoothSerialExample you have provided.
I am using this bluetooth module: https://www.adafruit.com/product/1697
with the "EchoDemo" found here: https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/software-uart-service
I am running the example app on a Sony Xperia Z3v running android 5.1.1.
I have the app running on the phone, and am able to discover the bluetooth connected to my Arduino. However everytime I try to connect I am getting a message on the app Pairing rejected by UART
on the serial monitor through the arduino IDE, I am seeing this:
It connects for a short bit and then goes back to advertising. I am unsure of what could be causing this, and I tried to look through your code to understand what could be causing this, but to no avail.
Am I missing something on the arduino sketch end or is there something more that I should be doing inside the example sketch?
Thanks for any help, and again love the library. I hope to be able to help in anyway I can once I get the example working.
Not sure if this is a bug or I am doing something wrong. Basically I am unable to connect with an already paired device.
I have code like this:
return BluetoothSerial.isConnected().then(isConnected => {
if (isConnected) {
return true;
}
return BluetoothSerial.connect(lmu.address).then(response => {
return response;
});
});
The first time this code runs connect
is called, and the (Android) phone prompts me to accept the pairing. I accept. Connect succeeds. I am able to write
and read
. All is well.
Upon subsequent passed through this code, isConnected
is true. I can still write
and read
. Again, all is well.
Then I close and restart the app. After that when this code runs, I get an error on connect
: "Error: Unable to connect to device"
Then I on the phone go to Settings > Bluetooth and Unpair from the device. Now when this code runs connect
succeeds again.
I tried skipping connect
if the device is already paired and just proceed to write
. I did not expect that to work, and it does not.
Tested on both of my Galaxy S3 (v5.1) and Galaxy Note 5 (v7.0).
The app in my Note 5 won't be able to discover devices.
I'm getting the same error as issue #6.
TypeError: Cannot set property 'on' of undefined
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:138348:19
at loadModuleImplementation (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:127:1)
at guardedLoadModule (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:70:8)
at _require (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:54:1)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:136436:33
at loadModuleImplementation (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:127:1)
at guardedLoadModule (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:70:8)
at _require (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:54:1)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:94598:28
at loadModuleImplementation (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:127:1)
Initially, I was missing necessary code in MainApplication.java
. After I added it, I continue to get the same error.
I'm on [email protected]
. Could that be the problem? Ideas?
Using React-native 0.29 on Android 4.4.2.
I'm seeing an exception on Android when attempting to enable Bluetooth. This doesn't result in an error from the promise. The exception is:
E/BluetoothAdapter( 2176): Bluetooth binder is null
E/RequestPermissionActivity( 2176): Error: there's a problem starting Bluetooth
The permissions are set-up in the manifest as follows:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
anyone can help me ?
Hello,
With the working example, I cannot discover Adafruit Bluefruit LE UART Friend.
It seems that TX and RX are exchanged if I refer to the following documentation :
https://learn.adafruit.com/introducing-the-adafruit-bluefruit-le-uart-friend/uart-service
TX must be on 0x0002
and RX on 0x0003
So I edited ../ios/RCTBluetoothSerial/BLEDefines.h
correspondingly
but it doesn't seems to work either.
I'm working on Android, it this the right file to edit ?
Did I miss something else ?
Do I need to compile java files or something like that so the changes are taking into account ?
Sincerly
Will this library connect an Android phone and an RFCOMM server?
I need to read from a barcode scanner without using an input field. Is there a listener I can use?
We are running a BLE server running debian & bluez 5.43. Other android apps such as bluepixel's BLE Scanner can find and connect to the device. However the device is not visible in paired or unpaired devices via this example app.
The docs state:
Reading and writing
In Android after you connect to peripheral write and read methods should work for most of devices out of the box. On ios with BLE it is little bit complicated, you need to know correct serice and characteristics UUIDs. Currently supported and preconfigured services are Red Bear lab, Adafruit BLE, Bluegiga, Laird Virtual Serial Port and Rongta. If you know about some services that you think should be supported send PR.
How do I configure the example app to connect to BLE peripherals?
Will this be added soon?
Can you release a new version? You fixed a lot of bugs and improved new features since the last version was released. A couple of issues will be also closed by doing that.
Good job with this library!
I used this library to connect to iOS device from Android and it worked well! However when I am trying to connect to a Bluetooth 2.1+EDR audio receiver, it doesnt connect.
Below is the Logcat for the same -
06-22 12:10:31.563 10360 14004 D BluetoothSerial: connect to: 11:09:33:36:6A:FE
06-22 12:10:31.564 10360 15618 E BluetoothSerial: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
06-22 12:10:31.564 10360 15618 D BluetoothSerial: Sending event: error
06-22 12:10:31.564 10360 15618 I BluetoothSerial: Trying fallback...
06-22 12:10:31.565 5627 5726 E bt_btif_sock_rfcomm: btsock_rfc_signaled socket signaled for read while disconnected, slot: 6, channel: -1
06-22 12:10:31.565 10360 14004 D BluetoothSerial: setState() connecting -> connecting
06-22 12:10:31.568 10360 15618 W BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
06-22 12:10:31.570 10360 15660 D BluetoothSerial: BEGIN mConnectThread
06-22 12:10:31.571 5627 5722 W bt_l2cap: L2CA_ErtmConnectReq() PSM: 0x0003 BDA: 648af40616b2 p_ertm_info: 0x00000000 allowed:0x0 preferred:0
06-22 12:10:31.571 10360 15660 D BluetoothSerial: Connecting to socket...
06-22 12:10:31.572 5627 5722 E bt_btif : bte_scan_filt_param_cfg_evt, 1
06-22 12:10:31.574 10360 15660 W BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
06-22 12:10:31.575 5627 5726 E bt_btif_sock_rfcomm: find_rfc_slot_by_id unable to find RFCOMM slot id: 8
06-22 12:10:31.575 10360 15660 E BluetoothSerial: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
06-22 12:10:31.575 10360 15660 D BluetoothSerial: Sending event: error
06-22 12:10:31.576 10360 15660 I BluetoothSerial: Trying fallback...
06-22 12:10:31.578 10360 15660 W BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
06-22 12:10:31.579 5627 5722 W bt_l2cap: L2CA_ErtmConnectReq() PSM: 0x0003 BDA: 110933366afe p_ertm_info: 0x00000000 allowed:0x0 preferred:0
06-22 12:10:31.579 5627 5722 W bt_l2cap: L2CAP - st: CLOSED evt: 21
06-22 12:10:31.579 5627 5722 W bt_l2cap: L2CAP - st: CLOSED evt: 7
06-22 12:10:31.607 5627 5666 W bt_hci_packet_fragmenter: reassemble_and_dispatch complete l2cap packet received:l2cap full length 12 and hci length 20.
06-22 12:10:31.607 5627 5722 W bt_l2cap: L2CAP - st: W4_L2CAP_CON_RSP evt: 13
06-22 12:10:31.607 5627 5722 W bt_rfcomm: PORT_StartCnf failed result:2
06-22 12:10:31.608 5627 5726 E bt_btif_sock_rfcomm: find_rfc_slot_by_id unable to find RFCOMM slot id: 9
06-22 12:10:31.608 10360 15660 E BluetoothSerial: Couldn't establish a Bluetooth connection.
06-22 12:10:31.608 10360 15660 D BluetoothSerial: Sending event: error
06-22 12:10:31.611 10360 15660 D BluetoothSerial: Sending event: connectionFailed
06-22 12:10:31.611 10360 15660 D BluetoothSerial: stop
06-22 12:10:31.611 10360 15660 D BluetoothSerial: setState() connecting -> none
06-22 12:10:33.974 5627 5722 W bt_l2cap: L2CAP - st: CLOSED evt: 1
06-22 12:10:33.974 5627 5722 W bt_sdp : SDP - Rcvd conn cnf with error: 0x4 CID 0x45
06-22 12:10:33.974 5627 5722 E bt_btif_sock_rfcomm: find_rfc_slot_by_id unable to find RFCOMM slot id: 6
06-22 12:10:33.974 5627 5722 W bt_l2cap: L2CAP - st: CLOSED evt: 1
06-22 12:10:33.975 5627 5722 W bt_rfcomm: PORT_StartCnf failed result:4
06-22 12:10:33.975 5627 5726 E bt_btif_sock_rfcomm: find_rfc_slot_by_id unable to find RFCOMM slot id: 7
06-22 12:10:33.975 10360 15618 E BluetoothSerial: Couldn't establish a Bluetooth connection.
06-22 12:10:33.976 10360 15618 D BluetoothSerial: Sending event: error
06-22 12:10:33.986 10360 15618 D BluetoothSerial: Sending event: connectionFailed
I am not sure but does it have to do something with A2DP profile? We cannot stream audio with this?
I must have missed an essential part for this module. Whenever discoverUnpairDevices is called it returns an empty list. No error messages or warnings are thrown. I used the following code.
import BluetoothSerial from 'react-native-bluetooth-serial'
BluetoothSerial.enable()
.then((res) => console.log(res))
.catch((err) => console.log(err.message))
BluetoothSerial.discoverUnpairedDevices()
.then((unpairedDevices) => {
console.log(unpairedDevices)
})
.catch((err) => console.log(err.message))
Any way to subscribe to read events from the connected device?
I want to connect to a Bluetooth Classic SPP device ( not an Arduino device ).
Use Case1:
Use Case2:
Is there an API event or something that can be used to asynchronously handle data reception from the Bluetooth device?
Thanks for sharing your work. Any advice is appreciated.
ERROR watch /node_modules/react-native-bluetooth-serial/android/build/intermediates/res/merged/androidTest/debug/drawable-xhdpi-v4 ENOSPC
this my react version
"react": "15.4.2",
"react-native": "0.42.0"
I run this example in IOS, but it appears the following error, I can't solve it, do you know why?
undefined is not an object(evaluating'BluetoothSerial.on=function(eventName,handler){
deviceEventEmitter.addListener(eventName,handler);
}')
Can you add a fix to avoid exception inside an Android Emulator that doesn't have a bluetooth? Like add some checks if bluetoothAdapter is null inside RCTBluetoothSerialModule?
Thanks
I'm looking for a solution to connect to an Arduino running Firmata using a bluetooth serial port module, such as the JY-MCU. It appears this project would work for this, but I'm having trouble understanding how to make that work.
Using Johnny-five, you can pass a node-serialport
instance, but i'm not sure if this offers a drop-in replacement. I've seen other projects like https://github.com/jacobrosenthal/react-native-ble and https://github.com/elin-moco/ble-serialport that also look promising, but they are only for BLE and not full-fledged Bluetooth, which I think I need for the hardware module.
I have a PoC connecting to the the device from my Mac, but am struggling to find how to accomplish the same from React-Native (since /dev/*
isn't a concept there).
I'm running on android, and the following code seems to cause the app to crash without any react-native error output. I assume that's because it crashes in native code.
What seems to happen is the app successfully enables bluetooth (i.e. it is enabled when I go check in the device settings), but the app dies when it calls BluetoothSerial.connect(...)
.
var enabled = await BluetoothSerial.isEnabled(); // resolves to false
if (!enabled) {
try {
enabled = await BluetoothSerial.enable();
// enabled is true here
}
catch (error) {
console.log(error);
}
}
try {
await BluetoothSerial.connect(device); // crash without error
}
catch (error) {
console.log(error);
}
When I import (after install) :
import BluetoothSerial from 'react-native-bluetooth-serial'
I get the following error on the device :
ExceptionsManager.js:61Cannot set property 'on' of undefined
When I try to connect device,there will be occurred 'expected dynamic type string, but had type object'.
Tried to run BluetoothSerialExample and i am unable to scan unpaired devices
BluetoothSerial.discoverUnpairedDevices()
.then((unpairedDevices) => {
console.log("discoverUnpaired",unpairedDevices); // Returns empty array
const devices = this.state.devices
const deviceIds = devices.map((d) => d.id)
unpairedDevices.forEach((device) => {
if (deviceIds.indexOf(device.id) < 0) {
devices.push(device)
}
})
this.setState({ devices, discovering: false })
})
react-native version : 0.32.0
mobile os : android
Hi,
I've cloned the example which works fine. Then I've tryed to connect my Android device to both Android and iOS devices after pairing them. Oddly, i've only been able to connect my Android phone to an iPhone but not to another Android device even though they are all paired.
Has anyone encountered that ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.