I'm working on an Android application and I have to make a Bluetooth serial communication between an Android device and a Computer with Ubuntu OS. I don't know what to do and how to connect them. I'm looking for good references and someone who can help me.
I made a button which navigates to the Bluetooth settings of our Android device. I don't know what else I should do.
Pair the devices. This has nothing to do with any software, so it has to be done via the phone settings
Once paired, look at 'Bluetooth Chat' example by Google. It has drop in code for connecting two devices. A serial connection is done via Serial Port Profile that is established over RFCOMM. The UUID for SPP is well known, again, you'll find it in the Bluetooth Chat example.
Related
I am a little confused on how to build this android app. Here's how it should work. I have a list of paired bluetooth devices. Lets say paired devices are:
1. A bluetooth head set.
2. A mobile phone.
And my app should automatically connect only to my headset when ever it comes in range.
Thats the basic functionality. I have been doing some research on bluetooth technology and its implementation. I came across the bluetooth chat application, when I started using the application I realized that both phones should have the app on it in order to connect and exchange messages. I tried connecting to my headset but it doesnt connect. And also when I removed the bluetooth chat app from one of my device and tried to connect it from a device which had bluetooth chat app, the devices couldnt connect.
If you have already worked on bluetooth this might look very simple. But how can I connect to a bluetooth device from my app when ever its in range even if the other device doesnt have my app.
Thanks.
This will be a 2 sections answer:
-To connect to a Bluetooth Headset, check my answer on here
-To Always connect to that device, you can save device address to memory then create a service with BroadCastReciever that listens for Bluetooth Connectivity. and check which device gets connected and compare it address to the one save in memory once its finds it connected call ibth.connect(device). ibth is inside the above link.
I'm trying to figure out how to connect two Android powered devices,
namely a smartphone (Android 4.1.2) and an android developer
board (Android 4.0.4) with apps running on each, via USB and get them
to communicate with each other.
Right now the developer board is running as the host and the phone as
an accessory. The hosts app is searching for connected devices and is
able to identify the phone as a device, but the app running on the
phone isn't able to find the host.
I've searched the web for quite a while now (!!) but I didn't come
up with anything helpful yet that solved my problem.
For my project it is crucial that I use an USB connection, so please
don't propose that I use bluetooth, WiFi, or anything else...
Regards
USB is host initiated, so it's not surprising that this is not working. Your device that is functioning as the USB device should respond to requests initiated from the USB host. You will probably have to create some sort of vendor specific protocol around this. I don't know what you are trying to do with this connection, but if the device needs to know things on the host you will need to bake this in to your protocol definition and send that information directly to the device.
What you could try doing is using both devices as a host and connecting a USB to UART bridge device between them, then you can transmit data generically in any direction by using the serial connection (through USBManager if the USB protocol is available, or some Android Java Serial class if it is not), plus you don't have to worry about the host-device connection. This would look something like this:
[Android 4.1.2 Device]<--USB Connection-->[USB to UART Bridge]<--Serial Connection-->[USB to UART Bridge]<--USB Connection-->[Android 4.0.4 Device].
Use OTG Cable to interact with your board and phone. Its easily available in the market.
Using Arduino I can get the sensor values logged into the serial monitor over the USB cable...
Is there any way that I can read these values directly on an android tablet by connecting a usb convertor(So that I can tramnsmitt it via GPRS to a server Db)...Please give my some solid directions...
You can do it wired if you use a FT232 or CP2102 converter. Here are a couple apps on the Google Play store that act as a serial monitor.
USB Serial Terminal
Slick USB Serial Terminal
One thing to note is that wired USB communication with Android is not very common, so you may run into some problems depending on the phone you are using. If you want a more guaranteed solution, look into an Arduino Bluetooth module that supports SPP - Serial Port Profile. You can connect the Arduino's RX/TX pins to the Bluetooth module, and have it communicate with the Android device over a wireless Bluetooth serial connection.
Also, here is a similar question on SO, however the answer may have outdated information regarding using the wired solution.
How to make Android and Arduino communicate without a wireless module
I a trying to connect my Nexus One with Android version 2.2.1 with my pc and use a terminal program such as windows terminal or hyper terminal to communicate. To do this I believe I need to set up an outgoing serial com port. I have paired the devices. When I go on my PC to Bluetooth -> settings -> "add com port" the android device does not display.
What am I missing?
Does android 2.2.1 support spp? The documentation says it does.
Do I need to root the android to add spp?
Has anyone succeeded in this?
My final goal is to write an android app that communicates with an old school bluetooth device that requires com ports? Getting the android to communicate with the pc is an interim step.
I have tried everything I can think of in my android app to connect to my pc and android device but have not been successful. My android app is essentially the same as Serial over Bluetooth submitted by xCaffeniated but with fewer comments. Any suggestions?
Try beginning with the BluetoothChat sample application. You will then have to alter the UUID used to the generic SPP UUID,
00001101-0000-1000-8000-00805F9B34FB
From this point you pretty much have everything you need.
I have had issues pairing in the BluetoothChat program. So I was required to pair to my computer using the settings menu and then entering the BluetoothChat Program. In BTChat go to the menu and hit connect to a device, choose your computer. I can only speak for windows XP SP3 which is what I'm using. At this point on my machine I receive a task bar pop up asking me if I would like to allow my device to connect as a serial port. I allow it to. Now your phone is associated as the serial port profile on the computer, which you can associate with a specific com port.
Based on bluetooth spec,
http://www.bluetooth.com/SiteCollectionDocuments/SPP_SPEC_V12.pdf,
2.3 User Requirement, "... Any legacy application may be run on either device, using the virtual serial port as if there were a real serial cable connecting the two devices (with RS232 control signalling)." In 4.3 Remote Port Negotiation, "...There is a requirement to do so if the API to the RFCOMM adaptation layer exposes to those settings (e.g. baud rate, parity)... RFCOMM as such will not artificially limit the throughput based on baud rate settings,..."
In my opinion, since Android (2.2) offers no APIs to set up and open a serial port, they may not be necessary as long as you can discover the remote BT device and make a connection to it. I have tried it and it seems working with:
...
sock = device.createRfcommSocketToServiceRecord(myUUID);
sock.connect();
...
where final UUID myUUID= UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); You may need to take care of Bluetooth Permission and Setup in your application as described in
http://developer.android.com/guide/topics/wireless/bluetooth.html
There might be some issues with the connect() call, i.e. Service is not available or connect is refused, which could be resolved by making sure:
The remote BT device be discovered, and
It must be set to use PIN code (for instance 0000), and
It must be paired successfully with your Android device
These steps must be completed prior to running your application (which has connect call).
Hope this help.
George
There is definitely some funny business regarding how the AT set is implemented on the AOS. The problem is that it is hard to know if you're actually talking directly to Modem or through several abstraction layers (more likely). For a best up-to-date review of the AT Commands available on the AOS platform, plus HW, please see the post:
"How to talk to the Modem with AT commands"
http://forum.xda-developers.com/showthread.php?t=1471241
I am trying to use Bluetooth SPP to communicate over it. In some Android phones, SPP profile is not activated. I faced the problem in the application that SPP was not activated and so the connection could not be established over bluetooth and when I started another app that is 3g hotspot which I think activates SPP and I was able to connect over bluetooth in my app.
So, how can we actually activate SPP profile of bluetooth in Android devices? And does all the android devices has SPP profile?
In developer.android.com BluetoothSocket:
The most common type of Bluetooth
socket is RFCOMM, which is the type
supported by the Android APIs. RFCOMM
is a connection-oriented, streaming
transport over Bluetooth. It is also
known as the Serial Port Profile
(SPP).
This might answer your question ..
https://source.android.com/devices/bluetooth/services
SPP (or ability to use Java API's to establish RFCOMM channels) is available from Android (2.0/2.1) release (Eclair) onwards
On the Android phone you will probably need to run an application that initiates the service over SPP.
**
public BluetoothServerSocket
listenUsingRfcommWithServiceRecord
(String name, UUID uuid)
** API can be used to create a service with specified UUID to listen,
Doing this should make this service visible to other devices which can then connect to it.
I just called Samsung help regarding bluetooth SPP on an S8+ phone. They tell me wait for Android Oreo as it isn't available till then. My previous Sony Xperia used Ntrip Client to talk to an external Geneq GPS to receive corrected coordinates and worked really well. Seems we went backwards somewhere?
Ntrip client on the phone collects an internet data stream of GPS corrections every five seconds and sends these to the GPS. The GPS uses the corrections and sends back adjusted coordinates to the phone to use in any application.
I would appreciate someone brighter than me pointing out a quick fix I just load and run to bring back this functionality.