Android Question [SOLVED] Bluetooth transmition is blocked

Discussion in 'Android Questions' started by TomKluz, Mar 8, 2019.

  1. TomKluz

    TomKluz Member Licensed User

    Hello,
    I would like to continue the adventure with Chat examle redone to pick up data from Arduino remote item.

    Chat example starts to work under condition what it is a first time. Starts well but after several seconds slow down and finally comunication is blocked. I have to wait some minutes to be able to start this example and read data. Sometimes I am getting this foults in log panel:

    Logger connected to: HTC HTC One A9s
    --------- beginning of system
    --------- beginning of main
    ** Activity (main) Create, isFirst = false **
    ** Activity (main) Resume **
    Koniec
    connected: false
    java.io.IOException: read failed, socket might closed or timeout, read ret: -1
    ** Activity (main) Pause, UserClosed = true **
    sending message to waiting queue (serial1_connected)
    ** Activity (main) Create, isFirst = false **
    running waiting messages (1)
    connected: false
    java.io.IOException: read failed, socket might closed or timeout, read ret: -1
    ** Activity (main) Resume **
    Koniec

    In mean time I have lisened to Mr Erel lecture about TCP/IP and have read this at: https://developer.android.com/reference/android/bluetooth/BluetoothServerSocket.
    Is it possible to create something like this ? Or any other solution to unlock a bluetooth comunication.


    Kind regards
    TomKluz
     
    Last edited: Mar 8, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. TomKluz

    TomKluz Member Licensed User

    I have just discovered a documentation of Serial Library. Info about BliuetoothServerSocket was something which I have found during searching for solution.
    My general question is why Chat example (after modification from AsyncStream to AsyncStreamText) is starting, but after several seconds is slowing down and finally stops at all. Maybe where is to many data coming from Arduino ?
    May I ask for your help in this case ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Only you know what your app is doing with the incoming data. We cannot guess it.

    Is AStream_NewText event raised? Are you ending each message with an end of line character?
     
  5. TomKluz

    TomKluz Member Licensed User

    Hello,
    My app is not doing anything special now. Only trying to display a result on a phone and logging. Nothing else. I am sending you code and also 2 txt files containing logs.
    I am ending each line by end of line character . As you see in the log files 6 characters long data are created by the same Arduino procedure. In fact there is also another one creating 3 characters long data and it looks like this:
    Serial.print(character1);
    Serial.print(character2);
    Serial.println(character3);
    Anyway if I try connect Arduino to Bluetooth terminal instaled on my smartfon, data are coming constantly without slowing down or stopping.
    If you remember I have created before (with your help) the same kind of app in B4J and it goes with no problem, now with 2 Arduino devices together (hoping it can go also with 3).
    In case of Android_Ardu, it starts but after several seconds data are freezed (blocked), just not coming.

    Thank you for your suport.
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

  7. TomKluz

    TomKluz Member Licensed User

    I have done it in case of Android_Ardu example and for Arduino_Bluetooth example. I both I have add logs in NewText sub and And add this in astreams_NewData inside AsyncStreamsText (There Message and Buffer Lenght). In both cases apps finally hase stopped (in second case was working longer), however in both cases in both cases
    majority of logs are buffer lenght and logs was slowing lown.
    What do you mean "output" ? is it a display of smartfon ?
     

    Attached Files:

  8. Erel

    Erel Administrator Staff Member Licensed User

    No. I meant the logs output after you added the two Log calls.

    If NewData is not raised then the other device (Arduino in this case) has stopped sending or the Android Bluetooth adapter is broken. Worth testing with a different Android device.
     
  9. TomKluz

    TomKluz Member Licensed User

    Obviously I will try to find another smarfon. It will take some time. On the other hand Bluetooth terminal from Google Play installed on the same phone (HTC) is not freezing. Can work constantly for a long time and never stops itself like as app under B4J. Till I got another phone will try to reduce amount of data coming from Arduino.
    We will see soon.
    What you can say after reading my log files ? Is it any idea coming from tchem ?
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    You made it difficult to understand the logs by not adding the code I asked you to add. So I don't really understand where the logs come from.

    Based on this:
    Code:
    Buffer lenght:   7
    Buffer lenght:   
    1
    Buffer lenght:   
    4
    Buffer lenght:   
    1
    Buffer lenght:   
    7
    Buffer lenght:   
    1
    Buffer lenght:   
    4
    Buffer lenght:   
    1
    Buffer lenght:   
    7
    Buffer lenght:   
    1
    Buffer lenght:   
    4
    Buffer lenght:   
    1
    Buffer lenght:   
    7
    Buffer lenght:   
    1
    Buffer lenght:   
    4
    Buffer lenght:   
    1
    Buffer lenght:   
    7
    I can guess that data keeps coming but without the end of line character. So NewText event is not raised.
     
  11. TomKluz

    TomKluz Member Licensed User

    Why you think that I didn't made your suggestions ? I did. I case Android_Ardu_Log3.txt you have 'NewText' and 'Newdata' lines and in case of Arduino_Bluetooth_LogX.txt files I only have changed NewTex for Message and NewData to Buffer Lenght ( sending Android_Ardu_Log2.txt was a mistake, sorry). Data from Arduino have the end of line character with no doubts.
    Today I have reduced amount of data coming from Arduino and situation was a little better but not enaugh. Finally I have went due your last suggestion to try another Android device and result is great. Both examples Android_Ardu (in fact your Chat example) and your lately sended Arduino_Bluetooth example have started working.
    It means that I had a bad luck with my first phone HTC (Android 6) and this device has probably something wrong with bluetooth adapter. Recently I am trying ZTE (Android 5). I would like to play a little more now with that one and will let you know.
    The only question for now is about this two examples. Each contains a little different tritment of serial comunication establishing. Chat example with serial connect and astream initialize and Arduino_Bluetooth with a new item admin As BluetoothAdmin.
    Which way is better or more safe ?
    Thanks a lot for your attention.
    Kind regards
    TomKluz
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Why upload 4 different log files? You are making it difficult to help you.

    The latest and most recommended example is this one: https://www.b4x.com/android/forum/threads/android-bluetooth-bluetoothadmin-tutorial.14768/#content
     
  13. TomKluz

    TomKluz Member Licensed User

    Thanks for a new example. I will analyse it deaply.
    Would like to ask another Question.
    In my App finally I wish to start comunication with 2 or 3 Arduino devices together without making a choice after dicovering. In B4J I have done it in naiv way, reading from a text file a list of Mac adreses and so on. Is it possible to do it similary in Android case ?
    Sorry for this question, but it is my first experience with Android.
    Does this problem is totaly included in TxtWriter and TxtReader of B4xBasic language manual ? How to read and write a file from SD card for example ?

    TomKluz
     
    Last edited: Mar 14, 2019 at 9:05 AM
  14. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for each of these unrelated questions.
     
  15. TomKluz

    TomKluz Member Licensed User

    Ok.

    I am adding this comments after few days.
    Bluetooth connection is working quite well. Actually I am using 2 Arduino devices paralelly and I hope if I add next one it will be also fine.
    From the Arduino site, I have correct the software to not broadcast constantly. Arduino is lisening and sending a message only if requested. The amount of data 'in the air' is reduced and streaming is not interrupted eaven after long time.

    Thank you for everyone who has help me to solve this initial problem with my first app.

    Kind regards
    TomKluz
     
    Last edited: Mar 18, 2019 at 8:45 AM
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice