BluetoothSerial icon indicating copy to clipboard operation
BluetoothSerial copied to clipboard

Multiple connections

Open ge-lem opened this issue 8 years ago • 14 comments

Just create context in order to allow multiple connections. It keeps full backward compatibility with the original version.

ge-lem avatar Mar 10 '16 20:03 ge-lem

Is there any example that can POC multi connection? I've already try too many times, still not working now.

hypery11 avatar Apr 12 '16 12:04 hypery11

It's only working on Android.

Here is the small ionic project I created to test it. https://github.com/Shikoruma/blueserialtest

I hope it will help you.

ge-lem avatar Apr 12 '16 13:04 ge-lem

@Shikoruma WOW~ Hey dude, you are pretty fast, I am not sure that ionic could porting to cordova directly,

my goal is to create 2 serial port connection over bluetooth, this is my testing code snippet

In my case, when I start the second connection, the first connection will be colsed.

Thanks .

hypery11 avatar Apr 12 '16 13:04 hypery11

Ionic plugin are in fact cordova plugin.

From your code snippet I don't see were the error is comming from. Are you sure you're giving two different addresses ?

I cant test your code with just the js file

ge-lem avatar Apr 12 '16 14:04 ge-lem

Oops, belowing are my whole cordova project file. bluetooth-serial-test.zip

Thanks a again. I'm very appreciate for your help.

hypery11 avatar Apr 12 '16 14:04 hypery11

Ok I found my mistake.

isConnected take also a macAdress because you want to test a particular connection. I forgot to change de Readme for this function, I update it. So change your bluetoothSerial.isConnected(disconnect, connect); to bluetoothSerial.isConnected(disconnect, connect,app.macAddress2);

I also forget to test if the given address is actualy in the context map. I also fixed it, so update my plugin and it should work now.

Thank you for pointing that issue.

ge-lem avatar Apr 12 '16 15:04 ge-lem

Hi, Shikoruma I'm @hypery11 's co-worker, We have problem on a SPP Client Project (It work's now) But I have a question

when I use function openPort in your example there has 4 arg -> delimeter , success call back , fail call back , macAddress so , I write

app = { ... openPort: function() {

app.display("Connected to: " + app.macAddress);

connectButton.innerHTML = "Disconnect";

bluetoothSerial.subscribe('\n', 
    function (data) {
        app.clear();
        app.display(data);

    },app.showError,app.macAddress);

},

openPort2: function() {

app.display("Connected to: " + app.macAddress2);

connectButton.innerHTML = "Disconnect";

bluetoothSerial.subscribe('\n', 
    function (data) {
        app.clear();
        app.display(data);

    },app.showError2,app.macAddress2);

}, ... }

this code is no work for me, when I connect the first device, It works , but when I connect the second device, the first will lost connect ...

BUT !!!

When we change to this code

app = { ... openPort: function() {

app.display("Connected to: " + app.macAddress);

connectButton.innerHTML = "Disconnect";

bluetoothSerial.subscribe('\n', 
    function (data) {
        app.clear();
        app.display(data);

    },app.macAddress)//different here!! ;

},

openPort2: function() {

app.display("Connected to: " + app.macAddress2);

connectButton.innerHTML = "Disconnect";

bluetoothSerial.subscribe('\n', 
    function (data) {
        app.clear();
        app.display(data);

    },app.macAddress2) //different here;

}, ... }

Strangely, It works @@".... But, I can not find any problem in your java source and javascript lib (it's actually 4 args...)

Anyway, thanks for your help @w@/

Xeriou avatar Apr 15 '16 09:04 Xeriou

Thank you for the PR - there are a couple of merge conflicts. Appreciate you making this PR! <3

Try this plugin https://github.com/bugnano/cordova-plugin-networking-bluetooth

lovelyelfpop avatar Apr 12 '20 11:04 lovelyelfpop

Try this plugin bugnano/cordova-plugin-networking-bluetooth

@lovelyelfpop Does that support multiple clients connect to a host?

filipef101 avatar Apr 14 '20 17:04 filipef101

@filipef101 Doesn't that depend on the host?

lovelyelfpop avatar Apr 15 '20 05:04 lovelyelfpop

@bittelc I think this looks good. What do you think @dominiquejb

braedongough avatar Sep 04 '20 14:09 braedongough

Ya, looks fine to me @braedongough , let's send it through.

bittelc avatar Dec 23 '22 16:12 bittelc