Friday, February 7, 2014

[Help] Bluetooth single-chip Bluetooth module communicate with Android


            
By now connect method has been connected with the MCU on the Bluetooth module, and the output achieved through the socket input stream. Under-bit machine (SCM) regulations, android phone must crew sent down 'A' character, the next crew if the receiver got 'A' character, then it returns 'D' character, and automatically start the blood pressure measuring instrument, constantly send back the relevant measurement data to the android phone.

I am sending this character 'A' to the next bit machine:
 
String target_address = 00:15:83:12:17:86 / / Address
lower machine Bluetooth moduleString uuid = "00001101-0000-1000-8000-00805F9B34FB";
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter ();
BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice (target_address);
BluetoothSocket clientSocket;
OutputStream os = null;
InputStream is = null;

new Thread (new Runnable () {
@ Override
public void run ()
{
try
{
clientSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord (UUID.fromString (uuid));
clientSocket.connect ();
is = clientSocket.getInputStream ();
os = clientSocket.getOutputStream ();
}
catch (IOException e) {e.printStackTrace ();}
}
.}) Start ();

/ / Read the contents from the next crew
new Thread (new Runnable () {
@ Override
public void run ()
{
try
{
while (true)
{
byte [] buffer = new byte [1024];
int bytes = 0;
/ / Read from the InputStream
if ((bytes = is.read (buffer))> 0) {
byte [] buf_data = new byte [bytes];
for (int i = 0; i buf_data [i] = buffer [i];
Log.i ("read from MCU:", buf_data [i] + "");}
}
}
}
catch (IOException e) {e.printStackTrace ();}
}
.}) Start ();


try {
byte msg = 65;
os.write (msg);
os.flush ();
} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}


But tried many times without success, the character does not receive the next bit machine returns 'D'

This is the next bit machine communication protocol, I do not know if you want to send data according to this, seeking expert advice, grateful!

Serial communication protocol
1. Conventions
The phone is called the PC side, the sphygmomanometer square collectively lower machine.
Data formats are hexadecimal code.
2. Communication process described
Communications using PC is ready, the next crew sent.
Each run, the host computer for each lower machine handshake commands are sent, the next crew
Receive the correct loopback handshake success. PC from which to determine the status of the next crew (whether linked
Machine).
The communication data frame format
1) start character: Start a byte identifies once sent to FFH.
2) Data Frame ID: Record number of data frames, length 2 bytes.
3) waveform data: 2 bytes.
4) voltage signal data: 2 bytes.
5) terminator 0AH.
Data frame length is 8 bytes. Using a set of data sent three times, no parity.
4 handshake command 0x0A, 0x0D:
PC to send 0X0A, the next crew to return 0X0D that receives a handshake successful.
5 38400 baud rate selection; sampling rate 100Hz.



Reply:
Seek expert advice grateful!
Reply:
Learning, waiting for an expert to solve
Reply:
Learn to wait
Reply:
A top daily, until the master so far! !
Reply:
The exception proposed landlord stickers out.

From your code, the two threads are initialized and receiving data, and no order, so when the received data stream object may not initialized.

Also uncertain is already paired.

Proposal also look bluetoothchat example.
Reply:
Now experiencing the same problem, and hope to help a landlord Ha, I QQ: 349216360 .. grateful ah
Reply:
According to statement, the PC sends a command to the peripheral, peripherals return D, open at the same peripherals, are not you send commands peripherals not received in the past? Because logically speaking, as long as the instruction to send the phone, peripherals received, it will turn on the machine, you are sent instructions not receive a reply, and the machine does not turn on, and that there may be peripheral and did not receive instructions, your connection is not successful.
In addition, if there are multiple matching the peripheral peripherals, then better to use peripherals to match the ID or Bluetooth address, to ensure the uniqueness of the connection.
If only a peripheral connection to the case, with the name of peripherals on it.

Reply:
Landlord, this does not solve the problem, you can share code,
Reply:
Landlord, hello
Ask, you pair the phone with a Bluetooth is automatic right? How to avoid the pairing dialog pops up?
Thank you!
Reply:
reference to the 9th floor zhanshanyou reply:
landlord, hello
Ask, you pair the phone with a Bluetooth is automatic right? How to avoid the pairing dialog pops up?
Thank you!


The village does not prompt the question, because the single-chip Bluetooth module can not operate, it's this pairing process is automatic
Reply:
Are built Bluetooth socket, single-chip Bluetooth I can not connect, been stuck here, can scan to, but not connected, I think it should be a problem of single-chip Bluetooth module, which does not open the service side of the socket, I do not know whether I said correct, please advise

No comments:

Post a Comment