niedziela, 3 lipca 2016

Android - how to communicate with PC using serial port over bluetooth

One time I needed to simulate a device which communicates with PC over bluetooth. I thought that I can use my smartphone with Android because this is faster way than creating new device using microcontroler and bluetooth module. I needed only my phone, Android Studio and a USB cable. I used code from Bluetooth Android Guide.
The most important line is:
 tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
Name parameter can be any value, but in the UUID you should pass correct value if you want to use serial port. This value is:

Where base UUID is "00000000-0000-1000-8000-00805F9B34FB" and 0x1101 is the UUID of "SerialPort" service class. You can check service classes here.
After uploading application to the device and running application, you have to pair your phone with a PC. Sometimes COM port (on Windows) is binded just after pairing, but often you must do it manually. To do this you have to open bluetooth settings.

Then go to the "COM Ports" tab and click "Add". Select outgoing type and also your device from listbox. You should also see your application name below.

Click OK and you should get your COM port number.

1 komentarz:

  1. My husband and I have been having lots of problems living together, he never gives me attention or makes me happy because he has fallen in love with another woman outside our marriage. I tried my best to make sure that my husband leaves this woman but the more I talk to him about it the more he makes me feel sad and unhappy, My marriage started leading to divorce because he no longer gives me attention. I wanted to forget him but i love him and didn't want to lose him. We have been married for years and he is all I could call a true best friend and best in all, the man that handles my problems perfectly, the man that makes sacrifices for ,my happiness. I wanted him back in my life badly and I was so confused. My Friends told me to buy books about relationships, so I went online for relationship books while I came across a spell caster called Dr Emu. I read testimonies and reviews about him so I contacted him immediately, explained my problems to him. Same day , he casted a spell for me and assured me for 2 days that my husband will return to me and to my greatest surprise the third day my husband came knocking on my door and begged for forgiveness. I am so happy that my love is back again and not only that, we are about to get married again, he proposed. I wouldn't stop talking about him. Contact him today if you need his help via email: and you will see that your problem will be solved without any delay. Website: