Bluetooth is a mature tecnology used everywhere.
For my experience, it is not an easy tecnology to manage, if you want to simply share something you have to follow many steps.
If you are a developer and you want to simply create a connection and pass data between 2 devices (whatever the devices are), you have to create a lot of code and first of all, learn how this tecnology works.
As a reference platform in this post I will use Android; things can change from a platform to another but the key concept are the same.
Who are you? Be visible!
- visible: any other device around that start a bluetooth search, Inquiry, will find the device.
- not visible: you can see other device around you, but none can see you in a search and establish a connection.
- off: the chip is off.
So the first things you have to do, in a bluetooth server are:
- get a reference to your internal bluetooth chip
- set the chip on
- set chip in visible mode
On Android, whenever you try to make your bluetooth phone on or visible, a system dialog message, automatically advise the user of the action.
The 3rd step is available only for a limited amout of time (you can specify how many seconds)... I think this is just for security and autonomy reason.
What do you offer? A service
Be visible is not enough to establish a connection with another device.
You have to specify the services that you are offering.
It is what you expose to others.
Every phone have some default service created for sharing content like calendar, phonebook etc...
A service is identified by a name and a UUID: http://en.wikipedia.org/wiki/Universally_unique_identifier.
How do we talk? With a profile
A profile is a low level bluetooth protocol that explain which type of message and communication you are trying to establish.
Bluetooth is used in different way so you have different profile specific for a task: there is A2DP for bluetooth audio communication (used by bluetooth earphone), Obex for file transfers, L2Cap for exchange information, RfComm is a sort of serial communication over bluetooth and others profiles.
When you have to make 2 device talk eachother with your own protocol, the options are usually use L2Cap or RfComm and built your protocol on top of them.
I have decided to use RfComm.
Summary for a bluetooth server:
- Turn the bluetooth chip on
- Be visible to others
- Create a Service
- Listen for incoming connection
The android code will be explained and available in the next post on the blog.