BluetoothSerial
BluetoothSerial copied to clipboard
Connections from one Android device to Another
I know this was intended to connect with Arduino but it seems like connecting between a pair of android or ios devices could work too. Is this already the case? I fiddled with the examples for a while (using a nexus 7 and galaxy s4) but could not establish a connection.
The examples don't appear to have code to receive a connection in the javascript. Is that only in the arduino logic?
The code to receive a connection on Android not implemented in the plugin.
This Android code in the plugin is based on sample in the Android SDK. They have a good example of Android to Android chat. See if you can get something working and send pull request.
Hello,
Is communication between android devices planning on being implemented ? I ask because I need that functionality and don't want to delve into hacking this great plugin unless it's absolutely necessary of course.
@fido0101 Android to Android would be nice to have, but I don't think I'll have it implemented soon. If you get something working submit a patch or at least a link to your code.
@don Hi, is there some news for this? it may be very nice :)
@ctreton No news on this. I'm concentrating on BLE lately. I plan to allow multiple connections in the BLE plugin I'm working on.
More info on how this could be implemented https://github.com/don/BluetoothSerial/issues/78#issuecomment-54847883
I've managed to connect Android devices using Phonegap 2.7, with some modifications to the Java source code. I think there was an error in the code, some lines were turned into a comment, I had to "uncomment" them. Now I'm experimenting with Phonegap 4.0 but couldn't install the plugin yet (using cordova plugin add).
@tomvanenckevort has a forked version that might work https://github.com/tomvanenckevort/BluetoothSerial
This version does not work for me.
- I downloaded the project
- copied the Chat example in a separate place
- cordova plugin add com.megster.cordova.bluetoothserial
- cordova platform add android
- cordova build - > and run
but again I see the same issue. when I try to connect my nexus 4 to my nexus 5 or vice versa. it instantly says disconnected. Was anyone successful in connecting 2 android devices with https://github.com/tomvanenckevort/BluetoothSerial ?
I have updated the Java and JavaScript files, these are working just fine. :-) Please feel free to use them! Regards, Bence
2015-02-19 18:49 GMT+01:00 tanzeelrana [email protected]:
This version does not work for me.
- I downloaded the project
- copied the Chat example in a separate place
- cordova plugin add com.megster.cordova.bluetoothserial
- cordova platform add android
- cordova build - > and run
but again I see the same issue. when I try to connect my nexus 4 to my nexus 5 or vice versa. it instantly says disconnected. Was anyone successful in connecting 2 android devices with https://github.com/tomvanenckevort/BluetoothSerial ?
— Reply to this email directly or view it on GitHub https://github.com/don/BluetoothSerial/issues/50#issuecomment-75100418.
Download updated files from here (instructions and final .APK of my test app included): http://benkesmith.com/android/bt_serial/Bluetooth_Serial.zip
Download the full Android Studio project from here: http://benkesmith.com/android/bt_serial/btserial_project.zip
thanks !! @ragcsalo I am going to try this out .....
https://github.com/tomvanenckevort/BluetoothSerial
have you tried this app? my last comment was regarding this link above. I tried this and it was not connecting 2 android devices
No, haven't tried that one. This one I updated myself, and have been using it to connect Samsung devices for 8 months now... :-)
@don Under limitations it says
Limitations
The phone must initiate the Bluetooth connection iOS Bluetooth Low Energy requires iPhone 4S, iPhone5, iPod 5, or iPad3+ Will not connect Android to Android* Will not connect iOS to iOS*
does that need to be changed ?
With my modified source files you CAN connect Android to Android. I don't know how to create a forked version, but will try it someday. :-)
@ragcsalo with your updated files the app is forever on discovering devices or it just normally takes long time to discover devices ?
Are you sure those are the only files that need to be updated ?
I don't discover devices, I just display a dropdown list of paired devices, select one and connect. On the second device I also have to select and connect the first device.... and then can send and receive data. Shall I make a sample file?
If you can zip the project that works for you and share I will try to find the differences in code and figure out what is causing this problem.
I'll upload the project ZIP tomorrow. :-)
Thanks :+1:
@ragcsalo did you upload the project ?
Sorry for the delay. I have updated the source files from Hungarian to English... :-)
Download the full Android Studio project from here: http://benkesmith.com/android/bt_serial/btserial_project.zip
- pair the 2 Android devices over Bluetooth first
- install BluetoothSerial.apk on both devices
- after starting the app, select other device from dropdown list (on both devices)
- click on "Connect BT remote" on both devices
- after connected, you can send messages over Bluetooth :)
Hi,
I know this is 5 months old since last activity, but I am trying to send data between 2 Android devices (Nexus 7 and Moto X 2nd Gen) I Can get them to connect and stay connected using the .connect() and isConnected() functions.
But when I use the Write() function, I get a success callback that the string was sent, but neither read() or Subscribe is receiving the data. Really not sure what else to try, code is very messy as I have been trying all different things, but I have pasted it below for any advise. I just want to send a string from one device to another the same as you would a chat app, although this isn't a chat app.
//Hosting the game
$scope.isHost = null;
//Watching the game
$scope.isGuest = null;
var Delimiter = '\n';
var DeviceAddress;
var isTurnedOn
var isEnabled;
var isConnected;
var sender;
var reciver;
//Check is Bluetooth is turned on
$scope.btEnabled = function () {
$cordovaBluetoothSerial.isEnabled().then(
function () {
isEnabled = "Bluetooth is enabled";
},
function () {
btEnabled = "Bluetooth is NOT enabled";
}
)
return isTurnedOn;
};
//Check if device is connected
var s = ""
$scope.connectionStatus = function () {
setTimeout(function () {
$cordovaBluetoothSerial.isConnected().then(
function (info) {
console.log("BT Connected");
s = "Bluetooth is connected";
isConnected = true;
},
function () {
console.log("BT *not* connected");
s = "Bluetooth is not connected";
isConnected = false;
});
}, 5000);
return "is "+s;
};
//List of BT devices
$scope.btList = {}
$scope.btDiscover = function () {
$cordovaBluetoothSerial.list().then(
function (devices) {
$scope.btList = devices;
$scope.showBTlist = true;
},
function (err) {
console.log(err);
$scope.showBTlist = false;
}
)
};
function subScribe() {
$cordovaBluetoothSerial.subscribe('\n',
function (data) {
console.log(data);
$scope.subscribData = "Sub Data = " + data;
});
}
$scope.btConnect = function (item) {
//Determin devce
if (item.address) {
//Adress Android and WP
DeviceAddress = item.address;
}
else if (item.uuid) {
// UUID used by iOS
DeviceAddress = item.uuid;
}
if (isConnected != true) {
sender = true;
$cordovaBluetoothSerial.connect(DeviceAddress).then(
function (success) {
console.log('Connected');
$scope.connectedTo = item.name;
// subScribe();
//stayConnected();
},
function (err) {
console.log('Connection failed');
$scope.connectedTo = item.name + err;
}
)
}
else {
console.log("Subscribe");
reciver = true;
subScribe();
}
};
$scope.sendMessage = function (message) {
//$cordovaBluetoothSerial.write('\n' + message);
$cordovaBluetoothSerial.write('\n' + message).then(
function (success) {
console.log("Message Sent")
},
function (failure) {
console.log("Message Sent" + failure)
}
)
}
Can you please help me ?I have tried this bluetooth serial plugin.But i can't able to connect the two android device.Please suggest ,what I need to change in code.I am new to cordova
@don actually support android-to-android ? ios-to-ios ? android-to-ios ?
@BurakDev there is no support for that, but you can just take a look at the bluetooth chat example in the official android docs for android to android communication.
I already uploaded my code, I made Android to Android connection with a modified version of Don's bluetooth serial plugin. 2015. dec. 9. 0:11 ezt írta ("Andreas Teufel" [email protected]):
@BurakDev https://github.com/BurakDev there is no support for that, but you can just take a look at the bluetooth chat example in the official android docs for android to android communication.
— Reply to this email directly or view it on GitHub https://github.com/don/BluetoothSerial/issues/50#issuecomment-163051293.
@ragcsalo the link to the zip file does not work anymore
@BurakDev There's a fork that should support Android to Android https://github.com/don/BluetoothSerial/issues/50#issuecomment-66405396
The original code for Android was based on the Android chat example that @ateufel mentioned. I think people enabled the RFCOMM listening to make this work.
Maybe someone can issue a pull request based on @tomvanenckevort or @ragcsalo's changes?
For iOS to iOS, you'll need one of the iOS devices to be running a Bluetooth Low Energy service that looks like one of the supported UART services. (Nordic/Adafruit, RedBearLab, BlueGiga, Laird)
For Android to iOS or iOS to Android, you'd need Bluetooth Low Energy, since iOS doesn't (easily) support Bluetooth Classic. You can use another one of my plugins https://github.com/don/cordova-plugin-ble-central to connect to Bluetooth low energy services. You'd need to create the service with native code for now. (I have cordova-plugin-ble-peripheral planned, but not implemented).
Uhh... I accidentaly deleted the ZIP file... I'll upload it again soon!!!