Periodically select data from a Bluetooth stream

I am using the bluetooth chat example to stream data from an external sensor. this works great and I get all the data. What I need to do next is a sample of the received data at set time periods (for example, every 10 ms).

Can anyone advise what to use for this and how to interact with the bluetooth stream?

+4
source share
2 answers

Basically, you can achieve this by periodically requesting data using the AlarmManager . check the link below for an example:

Android: how to periodically send location to server

+1
source

If your bluetooth stream can try at 10 milliseconds, you can use it directly. Otherwise, you will need a new thread operating at a frequency of 10 ms. Assuming the accuracy of the data transfer speed is not high enough, therefore, Thread.sleep () when sending the stream will be sufficient, and some cross-thread communication will be required - there are clearly defined templates for this task. Only one of them: http://javaprogramming.language-tutorial.com/2012/09/interthread-communication-java.html

Thus, in the general case, you have a data transmission thread with a sleeping value of 10 milliseconds, the bluetooth stream sends everything that has to this send stream, through the template above. The transmitted data is stored in the buffer of the same queue, and the sending stream receives them one by one with a sleep () between attempts to send.

0
source

Source: https://habr.com/ru/post/1488028/


All Articles