kai-morich / SimpleBluetoothTerminal

Android terminal app for Bluetooth classic devices using SPP profile
MIT License
447 stars 166 forks source link

Issues while waking up from background with 1.47 and logging is ON #38

Open igor-m opened 7 months ago

igor-m commented 7 months ago

With 1.47 while logging is on and when the phone is waken up, the app shows following anomaly:

  1. it takes sometimes a minute (or more) the app starts to show incoming data in the terminal (ie new data coming in every 4 seconds)
  2. terminal shows the old data logged before getting sleep (or it shows black screen), it writes sometimes a message that BT is not connected and whether I want to close or wait, the connection and logging icons show "connected" and "logging on", during the waiting I can see a small "DB9 rs232" icon in the android status bar (the small DB9 icon disappears in the moment the terminal starts to show incoming data again)
  3. when waiting enough time it starts to show incoming data in the terminal again
  4. the data logged during the sleep are not lost, that means the BT connection has not been lost and it logged the data during the sleeping properly.

I haven't seen such weird behavior with the previous version, when the phone got awake I saw data coming into the terminal immediately.

kai-morich commented 7 months ago

there are no changes in logging/resume behavior from 1.46 to 1.47 the Android SDK version has been changed from 32 to 33. Is your phone on Android 13 and now background activities are prioritized slightly different?

igor-m commented 7 months ago

My phone is Android 7 exclusively used for logging data (via BT). No sim card inside. I did not change anything just upgraded to the 1.47 version. I've just installed it on an another phone (Andr 7) and will compare (it is an S6, there is an issue with the font - instead of a standard green terminal font I get a font which shows only white contours of the characters - like the characters are hollow).

igor-m commented 7 months ago

I cleaned up, restarted couple of times the phone (the Honor Android 7), removed and reinstalled the v1.47 SBT and started to log. My observation is as follows:

  1. it started such the resume from sleep was quick
  2. the longer I logged (about 3kB per minute, my .csv files are typically 2-6MB large at the end) the longer it took to resume
  3. I let the logging over night, after aprox 18hours the first resume took 36 seconds, after perhaps 2 minutes I tried again and the resume showed black screen (only the Android status bar visible), I got several times the info with "BT is not responding, do you want Wait or Close", while still waiting it then showed the frozen terminal not responding (with the connectivity and logging icons indicators missing), and after a several seconds the SBT crashed and closed.
  4. The logged data file is there, 2.54MB large, and it seems to be complete (I've been using my own unix epoch time stamps in each logged data record, 15 records per minute, the last record indicates aprox the time when it crashed).

With previous versions (using your SBT for pretty long time) I had not seen such a behavior. Next I will try with the Samsung the overnight logging and I will report.

PS: I've been using "unlimited" buffer size..

igor-m commented 7 months ago

Hi, I tried with S6 for 8 hours and I it seems it worked fine (except the weird font).

I tried again with Honor (I set all apps except SBT to be stopped while the phone is with display off), it ran for 24hours. The behavior was the same - the resume took 10-20secs, during that I saw the terminal with last data before going sleep (not responding), the small DB9 connector icon (I never ever seen that icon in the Android top status bar in the previous versions) appears perhaps indicating it tries to connect, sometimes a popup with whether I want close or wait, at the end the resume took aprox 30secs, I stopped the logging, the file has been saved properly, after three minutes I resumed again and I got black SBT screen and it crashed or what. I checked the saved data and all data are there (3.6MB).

My current understanding is the latest version has got some changes with the BT handling during the resuming, the phone during the resuming thinks the connection is lost but it is not, internally it works ok and receives the data during the "sleep" and "resume" (I call here the "sleep" when the display is off, I have to tap the display such it resumes).

Would be great if I could try with the previous version again..

kai-morich commented 7 months ago

you can get previous versions e.g. here

igor-m commented 7 months ago

I am going to try with 1.42 upwards, I will report..

igor-m commented 7 months ago

I've tried with Honor and v1.37, 1.42, 1.47 and while logging is ON with buffer size set to "Unlimited" I saw the above issue with long wake up from background/sleep etc.

With buffer set to 10kB it wakes up almost immediately during logging. Perhaps I have been mistaken by the "Buffer size" setting, thinking for larger data volumes logged it requires a larger buffer to be safe.

The usage as the "terminal only" (with logging OFF) perhaps requires the larger buffers (where it stores the last XXX kB of data which may be saved by the user then), but when in the "logging mode ON" the large or unlimited buffer size causes issues as described above, and the buffering is not required, imho, as the data are saved continuously. At least this is my understanding how the stuff works today.

Thus the issue comes from handling the larger amount of data in the buffer (when the buffer size is set to "unlimited" or to a larger size - I've tried with 10k only) and while logging is ON.

kai-morich commented 7 months ago

Larger buffer only affects on screen scrollable history. The buffer is not required for logging.

The performance impact of screen redraw is known and already optimized. As mitigation the buffer size is relatively small by default.