0

I am trying to develop an Android application in which I want to communicate with thermometer using bluetooth. Right now I am already able to pair my phone with the device and I know that the device is acting as a slave, waiting for incoming request from phone in order to send measured data to the phone. Even though I have a communication protocol, I am facing difficulties following it so I am looking for help here:)

public void write(byte[] bytes) {
        String text = new String(bytes, Charset.defaultCharset());
        Log.d(TAG, "write: Writing to outputstream: " + text);
        try {
            mmOutStream.write(bytes);
        } catch (IOException e) {
            Log.e(TAG, "write: Error writing to output stream. " + e.getMessage());
        }
    }

Here you can see snippet of method in which I am trying to write the data to OutputStream mmOutStream. And now lets get to the question, I dont really know what I should put as an argument when I am calling this method. These are necessary images of communication protocol:

Frame structure

Command and its description

I would be really grateful if you can help me read and understand this communication protocol and direct me in order to be able to send valid data to the device - what should byte[] bytes variable contains.

Community
  • 1
  • 1
  • Have you checked [this](https://stackoverflow.com/questions/3936023/printing-runtime-exec-outputstream-to-console) thread regarding stream logging? Might be helpful. – alfalfa Jan 16 '19 at 21:25
  • First of all thanks for your response and the edit as well. I guess that I partly already know what should byte[] bytes contains except the last byte. I think it should be like this: byte[] bytes = {81, 38, 0, 0, 0, 0, -93, ???};. I dont get what do they mean by "ie. Check sum means the summation from byte 1 to byte 7 with 8-bit length" in communication protocol - Frame structure screen. – user7185507 Jan 16 '19 at 21:53

0 Answers0