omaraflak / Bluetooth-Library

Bluetooth client library for Android.
198 stars 62 forks source link

Error:multiple broadcasts recieved for same device onStartScanning() #14

Closed root-ansh closed 6 years ago

root-ansh commented 6 years ago

don't know if this is a flaw on my app's side or the library side, but here are the logs:


03-11 14:12:31.582 10699-10699/com.example.android.testing_lib E/#####################: btActions called: flags:flagBtOnOff,flagBtStartStopScan 1
03-11 14:12:32.753 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: HC-05

                                                                                        :00:21:13:01:E5:6C:10
03-11 14:12:33.163 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:33.534 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:34.074 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:38.268 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:38.869 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:39.279 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:39.700 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:40.130 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:40.290 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:43.393 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:43.624 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:44.144 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:44.314 10699-10699/com.example.android.testing_lib E/#####################: DeviceFound: Micromax A104:D6:5F:E0:65:82:3B:10
03-11 14:12:47.618 10699-10699/com.example.android.testing_lib E/#####################: onFinish: scan finished

all i have are 2 devices, one is a cellphone and other is an arduino. But it is spawning the logs again and again for the cellphone in the discoverylistener.(i am using a slightly modified version of your library)

root-ansh commented 6 years ago

tried a few more times, its spawning the logs for everything, and not just my cell phone

omaraflak commented 6 years ago

Well, since you're using a "modified version" of the library I'm not sure what is happening... Can you test the Play Store demo app and tell me if everything is okay ?

You can use this kind of code on your Arduino :

#include <SoftwareSerial.h>

// Initializing communication ports
SoftwareSerial mySerial(11, 10); // TX/RX pins

void setup()  {
    Serial.begin(9600);
    mySerial.begin(9600);
}

String getMessage(){
    String msg = "";
    char a;

    while(mySerial.available()) {
        a = mySerial.read();
        msg+=String(a);
    }
    return msg;
}

void loop(){
    // Check if a message has been received
    String msg = getMessage();
    if(msg!=""){
        Serial.println(msg);
    }

    // Send a string when 'm' is sent through the Serial
    if(Serial.available()){
        if(Serial.read()=='m'){
            mySerial.println("HC-06 IS REPLYING :-)");
        }
    }

    delay(10);
}
root-ansh commented 6 years ago

although i have an hc 05 module, i will still look into its code. Can you tell me what ThreadHelper class is doing?

root-ansh commented 6 years ago

and yes,the current playstore's app is also listing my single device multiple times on start scanning .Can it be a problem of the mobile phone am using to run the app?

omaraflak commented 6 years ago

Can you tell me what ThreadHelper class is doing?

It's simply used to run the listener in the UI thread.

and yes,the current playstore's app is also listing my single device multiple times on start scanning .Can it be a problem of the mobile phone am using to run the app?

Can you do the test with the settings app of your phone ? Is it listing the device multiple times ?

root-ansh commented 6 years ago

yess , it seems that it is a device fault . i changed my device which has stopped multiple spawning.