Skip to main content

Everything about BLE with iOS Part1 (Introduction)

In this article we will learn how to turn your iPhone to behave as peripheral (who has data to send) or central (who receive the data).


What is BLE (Bluetooth Low energy device) ?

Bluetooth LE is a wireless personal area network technology like its previous incarnation, Classic Bluetooth. It can be use to transfer and receiving of the data.

What is difference between Classic and LE ?

BLE has low power consumption and low data transfer rate. BLE can support large number of slaves. On the other hand Classic (3.0) support maximum 7 devices connectivity. Unique feature of BLE is advertising functionality, So other devices can scan, connect and receive data from the advertising BLE device. Other difference is in classic you need to pair the devices first for the communication.

Terms:

Peripheral: It is device which advertise the service. In client-server architecture form we can say peripheral is server which has data to send to client. The basic difference is it broadcast the small data in the form advertise packets. 

Central: It is device which use the information broadcast by the peripheral. To capture the information from the peripheral it need to scan the peripheral and its services.


Proximity UUID: It is 128-bit unique id for one or more peripheral of certain type of service. If central need to connect to specific peripheral (Advertising data) then it must know the proximity UUID for the peripheral. A major value is 16 bit unsigned integer and it can be used to group related peripheral. A minor value is 16 bit unsigned integer and it can be used to differentiate between the group of peripheral. So if number of peripheral has same proximity UUID then we can differentiate between them by minor value. 

Service UUID: A peripheral can advertise multiple service and each service has a unique id which can be represent as service UUID.

Characteristic UUID: A service can have attributes which represent a single logical value known as characteristic. Each characteristic has unique ID.

Where i can use BLE features ? 

So there are numerous example to use BLE advertising function (peripheral) in the current mobile technology. 

1) In retail store it is used as providing the information of particular segment of store when user near to that segment. 

Implementation :

Put peripherals or iBeacons on each segment of store. Like gaming, checkout, electronics etc. Create application which can listen to those iBeacons based on the proximity UUID. So when user in region of particular iBeacons (will receive the advertisement packet) then application will display the information of segment which already feed in the application.

2) In home automation system we can also use the iBeacons. It will be costly and there are some other methods also but for understanding purpose we can take the example.   

Implementation :

Put peripherals or iBeacons on each house of the room.Create application which can listen to those iBeacons based on the proximity UUID. So when user in region of particular iBeacons (will receive the advertisement packet) then application will display the information of segment which already feed in the application.


iOS Implementation:

Device Support: iPhone 4S and later
Operating System: iOS 5 and later
Framework Require: CoreBluetooth, CoreLocation

CoreLocation:

Core Location provide you the API to create a central and monitor a beacon region. you can prepare an application which can monitor a region. So you will get entry and exit callback for the peripheral region.

CoreBluetooth:   

Core Bluetooth provide you API to create iPhone as a peripheral and a region with your define proximity UUID. You need to create a peripheral first and then it has start Advertising method in which you need to provide beacon region with its properties.

By using only Core Bluetooth we can also monitor a peripheral. As discussed above each peripheral can expose services and each service has characteristics. So by using core bluetooth API we can register for particular service and listen to particular characteristics. That part will be explain in third part of the tutorial.

In next part of tutorial we will learn how to prepare a sample application which can monitor a region by using CoreLocation.

Comments

Popular posts from this blog

Asynchronous Request with NSOperationQueue

Today post is about how to run a asynchronous task in NSOperationQueue.  Generally we do not run a Asynchronous task in NSOperationQueue. It is also not recommended for any programmer to do that. This post is only for learning purpose what will happen if we schedule a asynchronous task in a queue and how can we complete that task:). So let us move to the learning: NSOperationQueue: In iOS NSOperationQueue is a class, which provide a way to perform operation concurrently. We also have others way to perform concurrent operation: 1) GCD 2) NSThread 3) pThread NSOperationQueue is a wrapper on GCD, which provides a very convenient way to execute operation concurrently. To create a Queue for Operation you have to simply allocate a object of the class: NSOperationQueue * opertionQueue = [[ NSOperationQueue alloc ] init ]; For this post let suppose you are making a queue to handle all Http request in your application. So i want to create a queue in Handler class

Shake Effect in iOS

Animation Animation always capture the user attention. We can use animation to update things on the screen.  For developer also animations fascinated things to learn and implement. Today we will try shake effect with Various  API. CABasicAnimation: Here we animate view's frame y coordinate from one position to another position. It is simple example of changing the position with respect to time. CABasic Animation is deal with the single keyframe.                                        y(t) = y 0 + t*d(y) You can use CABasic Animation if you have to play with single value. You need to move object from  one position to another without any intermediate steps. CABasicAnimation * shakeAnimation = [CABasicAnimation animationWithKeyPath: @ "position" ]; shakeAnimation . duration = 0.05 ; shakeAnimation . autoreverses = YES; shakeAnimation . repeatCount = 6 ; CGPoint shakeFromPoint = CGPointMake( self . shakeLabel . center . x,

NSThread with Asynchronous Request

NSThread: It is class used in Cocoa framework to create a thread.You have to specify a target and selector to create a new thread in objective c. So the selector or method is main entry point of your thread.  Detail: What happen once the thread execute all the code in the method (Thread main routine)? Thread is terminated after execute all the code in the entry(its main routine) routine. So how we can run an asynchronous request on NSThread ? What is Async request? It is non blocking request which permit the application to do other task side by side as request is in continue. So it enhance parallelism in the application. Now question is how we can prepare a asynchronous request in iOS: - ( void ) startAsyncRequestWithUrl:( NSString *)urlString{     assert (urlString != nil && urlString. length > 0 );     NSURL * url = [[ NSURL alloc ] initWithString :urlString];     NSURLRequest * urlRequest = [[ NSURLRequest alloc ] initWithURL :url cac