I have an android app that so far connect properly to a arduino jymcu bluetooth module. I was able to make it to write some data and print them in the arduino console when I press a button. What I want to do is to print in the console "Connection lost" as soon as my connection is lost. I was trying to do it in AT, but it won't work as long as you are paired. The second idea that I had was to send data every 30 seconds with the board and the phone should reply. If it doesn't reply it means that the connection was lost. I was not able to do that, because I still haven't figured out how to read data on android that is received from the bluetooth. So far for reading data I've got only :
public void run() {
byte[] buffer = new byte[1024];
int bytes;
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = inStream.read(buffer);
} catch (IOException e) {
break;
}
}
}
I don't know where to put this in my app to use that data somehow.Thank you.
No comments:
Post a Comment