Reputation: 41
I am using the bluetooth chat example to stream data from an external sensor. this works fine and I receive all the data. What I need to do next is sample the received data at set time periods (every 10ms for example).
Can anyone advise on what to use in order to this and how to interact with the bluetooth thread?
Upvotes: 4
Views: 393
Reputation: 49
if your bluetooth thread can sample at 10 milliseconds rate then you can use it directly. Otherwise you will need new thread running at 10 ms frequency. Assuming accuracy of data sending rate is not high enough so Thread.sleep() on sending thread will suffice and some inter-thread communication will be needed - there are well defined templates to do this job. Just one of them: http://javaprogramming.language-tutorial.com/2012/09/interthread-communication-java.html
So in general you have data sending thread with sleep set to 10 millisecond, bluetooth thread sends whatever it has to this sending thread via template above. Data sent are stored in queue alike buffer and sending thread takes them one by one with sleep() between sending attempts.
Upvotes: 0
Reputation: 3695
Well basically you can achieve this by requesting data periodically using AlarmManager
.
check the below link for an example:
Android: How to periodically send location to a server
Upvotes: 1