22
A Report On UI Software Development for BLE smart sensors Submitted by Akanksha Kumari 13IT203, NITK IV Sem B.Tech (IT) in fulfillment for the summer research internship In Wireless Sensor Technology (Indo-US CBERD Project) At May-July 2015

Intern_Report

Embed Size (px)

Citation preview

Page 1: Intern_Report

A Report On

UI Software Development for BLE

smart sensors

Submitted by

Akanksha Kumari

13IT203, NITK

IV Sem B.Tech (IT)

in fulfillment for the summer research

internship

In

Wireless Sensor Technology (Indo-US CBERD Project)

At

May-July 2015

Page 2: Intern_Report

CERTIFICATE

This is to certify that the internship project entitled “UI Software Development for BLE

smart sensors”has been presented by Akanksha Kumari, a student of second year B.Tech

(I.T), Department of Information Technology, National Institute of Technology Karnataka,

Surathkal, during the summer break of the academic year 2014 – 2015.

Place:

Date: (Signature of the Examiner)

Page 3: Intern_Report

ABSTRACT

Bluetooth low energy (Bluetooth LE, BLE, marketed as Bluetooth Smart) is a wireless

personal area network technology designed and marketed by the Bluetooth Special Interest

Group aimed at novel applications in the healthcare, fitness, beacons, security, and home

entertainment industries. Compared to Classic Bluetooth, Bluetooth Smart is intended to

provide considerably reduced power consumption and cost while maintaining a similar

communication range.

Due to this very reason, these sensors are widely used in the eco-friendly buildings around the

world. To operate the appliances around the building, we have to find a way to connect any

gadget with the BLE sensors. This project involves a detailed study of the BLE protocol and

applying that knowledge in connecting an Android smartphone with Android SDK version

greater than or equal to 18. After the connection, values from the BLE MotionSensorActuator

are read and written into, from the smartphone, and that operates the surrounding devices.

At the end of this project, a basic UI for a universal remote has been attempted by using

Android.

Android Studio was used as the development platform throughout the project.

Page 4: Intern_Report

TABLE OF CONTENTS

1 Introduction 7-8

1.1 Connecting the Internet of Things 7

1.2 Developing with Bluetooth Smart 7,8

2

Relevance and Context

9

2.1 Why Bluetooth Smart 9

2.2 BLE in the present scenario 9

3

Technical Discussion

10-19

3.1 Topology and Properties 10

3.2 BLE device roles 10

3.3 Profiles and Services 10,11

3.4 GATT Based Profile 11,12

3.5 Services and Characteristics 13

3.5.1 Service 13

3.5.2 Characteristics 13

3.6 Android SDK used for implementing BLE 13-18

3.6.1 Scanning the devices 13-14

3.6.2 Connecting to the device 14-15

3.6.3 After Connecting 15-16

3.6.4 Function for reading and writing characteristics (values are read/written) 16- 18

3.7 User Interface Design- UNIVERSAL REMOTE 18

3.8 Initial Drawbacks and Improvements 19

Page 5: Intern_Report

4 Future Trends and Ongoing Research 20

4.1 Future of Mobile payments 20

4.2 Arguments for BLE mobile payments 20

5 Conclusion 21

6 References 22

Page 6: Intern_Report

LIST OF FIGURES

The following figures are used in this report:-

Figure 1&2:- GATT Profiles Page-11, 12

Figure 3:- Application Screenshot (Device Scan) Page-14

Figure 4:- Application Screenshot (Device Connecting) Page-15

Figure 5:- Application Screenshot (Device after connecting) Page-16

Figure 6&7:- Application Screenshot (Device writing/reading respectively) Page-17

Figure 8:- BLE chip before writing Page-17

Figure 9:- BLE chip being written on by the app Page-18

Figure 10:- UI for the Universal Remote Page-18

Page 7: Intern_Report

7

1 INTRODUCTION

Bluetooth Smart(also called Bluetooth Low Energy) is the intelligent, power-friendly version of

Bluetooth wireless technology. While the power-efficiency of Bluetooth Smart makes it perfect

for devices needing to run off a tiny battery for long periods, the magic of Bluetooth Smart is its

ability to work with an application on the smartphone or tablet you already own. Bluetooth

Smart makes it easy for developers and OEMs to create solutions that will work with the billions

of Bluetooth enabled products already in the market today. Learn more about the technology

behind Bluetooth Smart.

1.1 CONNECTING THE INTERNET OF THINGS

First talked about more than 15 years ago, the Internet of Things (IoT) theorized objects and

people would connect wirelessly. Classic Bluetooth provided the means for device

communication and manufacturers built hub devices like PCs, smartphones, cars and tablets to

take advantage of these connections. Now, because of Bluetooth Smart, the world is exploding

with an incredible array of devices connecting to these hubs. A projected 30 billion devices will

enter into the IoT ecosystem by 2020 according to ABI Research. Analyst firms all over the

world recognize Bluetooth Smart as a key enabler in the Internet of Things.

For consumers, it comes down to the Internet of Your Things. You wake up and go for a run

with a heart rate monitor that speaks directly to your smart watch. You brush your teeth with a

sensor toothbrush while listening to music through your showerhead. You keep your back

straight and protect your computer with sensors at your desk. You watch your kids play

basketball with a "smart" ball and shoes. You unlock your doors, turn on the lights and run your

TV with your smartphone. These wirelessly connected devices are making your life better and

less hectic while allowing you to benefit from the convenience, empowerment and freedom of

Bluetooth Smart technology

1.2 DEVELOPING WITH BLUETOOTH SMART

Bluetooth Smart is an application-friendly technology supported by every major operating

system. The technology costs less and offers flexible development architecture for creating

applications to bring everyday objects like heart-rate monitors, toothbrushes, and shoes into the

connected world and have them communicate with applications that reside on the Bluetooth

Smart compatible smartphones, tablets, or similar devices those consumers already own. This

means Bluetooth Smart developers are limited only by their imagination.

Bluetooth technology gained an early foothold in several industries like consumer electronics,

PC peripherals and automotive. With the advent of Bluetooth Smart, many sports and fitness

companies rushed to integrate the new technology because of its power efficiency and ability to

connect to smartphone apps—it was the perfect fit for a wide range of devices from heart-rate

Page 8: Intern_Report

8

monitors to cycling computers. Now Bluetooth Smart technology is powering many verticals

from wireless medical devices and home automation to retail and wearable. ABI Research

projects Bluetooth technology will experience the highest growth in these markets in the next

five years.

Page 9: Intern_Report

9

2 RELEVANCE AND CONTEXT

2.1 WHY BLUETOOTH SMART?

The ‘LE’ part is the key. The ‘B’ part (Classic Bluetooth) suffered as the medium of mobile

virus on early 2000, that’s why Apple has restricted Bluetooth API until iOS 5 SDK was

released together with first Bluetooth LE enabled iPhone 4s. A big shift took place in 2012,

when phones started to include dual-mode chips supporting the newest Bluetooth technology

and classic Bluetooth technology.

In BLE, there is no necessity for pairing process in order to receive the data. An iPhone does

not need to be paired with a Philips Hue light bulb to know whether the smart bulb is On and

vice versa. An iBeacon device such as Cubeacon can be powered with a single coin battery for

years because it does not pair with your smartphone. Instead, it will broadcast an information

then captured by your iPhone or Android device.

Bluetooth Smart is developer-friendly, inexpensive and offers flexible development

architecture. All major operating systems natively support Bluetooth Smart making it easy for

developers to create apps that link with everyday objects like heart-rate monitors, toothbrushes,

and even shoes. With Bluetooth Smart, developers are only limited by their imaginations.

2.2 BLE IN THE PRESENT SCENARIO

Building heating, ventilation, and air conditioning (HVAC) systems are considered to be the

main target for energy reduction due to their significant contribution to commercial buildings’

energy consumption. Ultra low power communication mechanisms are essential for present

Internet of Things deployments. Bluetooth Low Energy (BLE) is one promising candidate for

such deployments. When compared to ZigBee, BLE is indeed very energy efficient in terms of

number of bytes transferred per Joule spent. In addition, IPv6 communication energy overhead

remains reasonable. There are a few specific limitations with current stack implementations and

removing those limitations could improve energy utility significantly.

Page 10: Intern_Report

10

3 TECHNICAL DISCUSSIONS

3.1 TOPOLOGY AND PROPERTIES

Wireless Personal Area network with star topology.

Master-slave arrangement.

A slave can be connected to one master.

BLE has a shortened package format or overhead: throughput is lower for BLE than BT

or Wi-Fi.

Communication between two connected devices occurs during connection events.

3.2 BLE DEVICE ROLES

Peripheral, E.g. heart rate sensor

Advertiser that is connectable (slave).

Broadcaster, E.g. temperature sensor

Advertiser that is non-connectable.

Central, E.g. Smartphones

Scans for advertisements and initiates connections(master).

Observer, E.g. temperature display

Scans for advertisements but cannot initiate connections.

3.3 PROFILES AND SERVICES

A profile defines and describes the use of services necessary to implement a given

application.

Bluetooth profiles are definitions of possible applications and specify general

behaviours that Bluetooth enabled devices use to communicate with other Bluetooth

devices. There is a wide range of Bluetooth profiles describing many different types of

applications or use cases for devices. By following the guidance provided by the

Bluetooth specification, developers can create applications to work with other Bluetooth

devices.

At a minimum, each Bluetooth profile contains information on the following topics:

1. Dependencies on other profiles

2. Suggested user interface formats

3. Specific parts of the Bluetooth protocol stack used by the profile. To perform its

Page 11: Intern_Report

11

task, each profile uses particular options and parameters at each layer of the stack and

this may include, if appropriate, an outline of the required service record.

BLE uses the GATT based profile.

Bluetooth SIG adopted examples:

Heart Rate Profile (HRS, DIS)

Proximity profile (link loss service, immediate alert service)

Find-Me profile (immediate alert service)

Proprietary profile (user specific).

GATT profile(general attributes profile)

Specifies the structure in which data is stored and exchanged.

Services have data, which is exposed using characteristics.

Client wants to use this data.

3.4 GATT BASED PROFILE

Generic Attribute Profile (GATT) is built on top of the Attribute Protocol (ATT) and

establishes common operations and a framework for the data transported and stored by

the Attribute Protocol. GATT defines two roles: Server and Client. The GATT roles are

not necessarily tied to specific GAP roles and may be specified by higher layer profiles.

GATT and ATT are not transport specific and can be used in both BR/EDR and LE.

However, GATT and ATT are mandatory to implement in LE since it is used for

discovering services.

The GATT server stores the data transported over the Attribute Protocol and accepts

Attribute Protocol requests, commands and confirmations from the GATT client. The

GATT server sends responses to requests and when configured, sends indication and

notifications asynchronously to the GATT client when specified events occur on the

GATT server. GATT also specifies the format of data contained on the GATT server.

Attributes, as transported by the Attribute Protocol, are formatted as services and

characteristics. Services may contain a collection of characteristics. Characteristics

Figure 1

Page 12: Intern_Report

12

contain a single value and any number of descriptors describing the characteristic value.

With the defined structure of services, characteristics and characteristic descriptors a

GATT client that is not specific to a profile can still traverse the GATT server and

display characteristic values to the user. The characteristic descriptors can be used to

display descriptions of the characteristic values that may make the value understandable

by the user.

3.4.1 GATT-based Profile Hierarchy

The GATT Profile specifies the structure in which profile data is exchanged. This

structure defines basic elements such as services and characteristics, used in a profile.

The top level of the hierarchy is a profile. A profile is composed of one or more services

necessary to fulfil a use case. A service is composed of characteristics or references to

other services. Each characteristic contains a value and may contain optional information

about the value. The service and characteristic and the components of the characteristic

(i.e., value and descriptors) contain the profile data and are all stored in attributes on the

server.

Figure 2

Page 13: Intern_Report

13

3.5 SERVICES AND CHARACTERISTICS

3.5.1 Service

A service is a collection of data and associated behaviors to accomplish a particular

function or feature of a device or portions of a device. A service may reference other

primary or secondary services and/or a set of characteristics that make up the service.

There are two types of services: primary and secondary. A primary service provides the

primary functionality of a device. A secondary service provides auxiliary functionality

of a device and is referenced from at least one primary service on the device.

To maintain backward compatibility with earlier clients, later revisions of a service

definition can only add new referenced services or optional characteristics. Later

revisions of a service definition are also forbidden from changing behaviors from

previous revision of the service definition. Services may be used in one or more profiles

to fulfill a particular use case

3.5.2 Characteristics

A characteristic is a value used in a service along with properties and configuration

information about how the value is accessed and information about how the value is

displayed or represented. A characteristic definition contains a characteristic declaration,

characteristic properties, and a value. It may also contain descriptors that describe the

value or permit configuration of the server with respect to the characteristic value.

3.6 ANDROID SDK USED FOR IMPLEMENTING BLE

As defined by Android for 18 level API and above

3.6.1 Scanning the devices

Functions involved are startLeScan(ScanCallBack) and stopLeScan(ScanCallBack).

The ScanCallBack is defined as:

private BluetoothAdapter.LeScanCallback mLeScanCallback =

new BluetoothAdapter.LeScanCallback() {

@Override

public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord)

{

Log.i(TAG,"Scan device rssi is " + rssi);

runOnUiThread(new Runnable() {

@Override

Page 14: Intern_Report

14

public void run() {

mLeDeviceListAdapter.addDevice(device);

mLeDeviceListAdapter.notifyDataSetChanged();

}

});

}

};

After this, displaying is done by the List View.

.

3.6.2 Connecting to the device

Function call

mBluetoothGatt.connect();

Callback when connecting

private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {

@Override

public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {

Log.i(TAG,"onConnectionStateChange status = " + status + ", newState = " +

newState);

if (newState == BluetoothProfile.STATE_CONNECTED) {

if (mBLEServiceCb != null) {

mBLEServiceCb.notifyConnectedGATT();

}

Log.i(TAG,"Connected to GATT server.");

// Attempts to discover services after successful connection.

Log.i(TAG,"Attempting to start service discovery:" +

mBluetoothGatt.discoverServices());

Figure 3

Page 15: Intern_Report

15

startReadRssi();

} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {

if (mBLEServiceCb != null) {

mBLEServiceCb.notifyDisconnectedGATT();

}

stopReadRssi();

Log.i(TAG,"Disconnected from GATT server.");

}

}

3.6.3 After connecting

public void onServicesDiscovered(BluetoothGatt gatt, int status) {

Log.i(TAG,"onServicesDiscovered status = " + status);

if (status == BluetoothGatt.GATT_SUCCESS) {

if (mBLEServiceCb != null) {

mBLEServiceCb.displayGATTServices();

}

} else {

Log.i(TAG,"onServicesDiscovered received: " + status);

}

Figure 4

Page 16: Intern_Report

16

}

public void onCharacteristicRead(BluetoothGatt gatt,

BluetoothGattCharacteristic characteristic,

int status) {

Log.i(TAG,"onCharacteristicRead status: " + status);

if (status == BluetoothGatt.GATT_SUCCESS) {

displayCharacteristic(characteristic);

}

}

3.6.4 Function for reading and writing characteristics (values are read/written)

public void readCharacteristic(BluetoothGattCharacteristic characteristic) {

if (mBluetoothAdapter == null || mBluetoothGatt == null) {

Log.i(TAG,"BluetoothAdapter not initialized");

return;

}

mBluetoothGatt.readCharacteristic(characteristic);

}

public void writeCharacteristic(BluetoothGattCharacteristic characteristic) {

if (mBluetoothAdapter == null || mBluetoothGatt == null) {

Figure 5

Page 17: Intern_Report

17

Log.i(TAG,"BluetoothAdapter not initialized");

return;

}

mBluetoothGatt.writeCharacteristic(characteristic);

}

Not writing anything in the BLE chip.

Figure 6

Figure 7

Figure 8

Page 18: Intern_Report

18

3.7 USER INTERFACE DESIGN- UNIVERSAL REMOTE

Writing data into the BLE chip.

Figure 9

Figure 10

Page 19: Intern_Report

19

3.8 INITIAL DRAWBACKS AND IMPROVEMENTS

Android 4.3: Biggest drawback was that scanning regularly prevented standby(high

battery consumption)

Improvement to scan in the background, but bombardment of

advertisements still prevent standby.

API allows us to specify filters

Set filters on specific parts of the packet.

Wake up from standby only when the packet matches the type of packet

specified.

3.4.1 Improvements

Scan and advertisement customization

Low latency

Balanced

Low Power

Peripheral mode

An android device can act as a BLE peripheral. It can broadcast

advertisement packets and form data connections with other BLE device.

Since the space for advertisement packets is limited, Android allows

multiple apps to advertise concurrently, allowing each app its own packet

Page 20: Intern_Report

20

4 FUTURE TRENDS AND ONGOING RESEARCH

4.1 FUTURE OF MOBILE PAYMENTS

One thing we can notice in the fast-moving mobile payment space is the constant struggle for

accuracy. In this case, we cannot exclusively refer to location-based accuracy (though we will

get to that momentarily) as much as the struggle over the literal meaning of words.

Case in point: iBeacon. When word began spreading about Apple's iBeacon last fall, many

observers proclaimed the technology would supplant Near Field Communications as a mobile

payment medium. But that's apples-and-oranges.

The iBeacon (and PayPal's Beacon, which rolled out about the same time) are not, of

themselves, a technology. They are but an extension of Bluetooth Low Energy, which has been

around for almost a decade.

BLE and NFC each have several use cases, but they're not the same sort of use cases. We can

think of it this way: Cellular communications provide wireless coverage with a footprint

measured in miles; WiFi's footprint is measured in yards; BLE's is measured in feet; and NFC's

in centimeters.

A BLE beacon is great for passively enabling a retailer's mobile app to deliver promotions,

coupons or offers direct to the consumer's smartphone when the consumer is in the general

vicinity. NFC can't do that. But if you want to research a specific Nikon SLR, for example, you

can scan an NFC-enabled shelf tag next to it and study to your heart's content. BLE can't deliver

that much location granularity.

4.2 ARGUMENTS FOR BLE MOBILE PAYMENTS

Bluetooth Low Energy is the future of mobile payments and mobile marketing, merchants will

need to be very cautious about their approach to avoid creeping out consumers, as customers

are already bombarded by irrelevant offers and a vast number of other communication types.

The best way for merchants to accommodate this is by leveraging big data such as the retailer’s

CRM database and inventory management system, which will enable a merchant to analyze

past spend patterns to make targeted offers based on product availability or inventory in a real-

time manner. Although a more complex approach, this is the best way to drive incremental

sales.

Page 21: Intern_Report

21

5 CONCLUSION

In this report, a full-fledged UI for a BLE MotionSensorActuator is developed using the

Android SDK. The BLE protocol is studied in detail and thus its functionalities and uses in the

current scenario is evaluated. BLE uses the GATT profile. So, the study of the GATT profile

gave the sense of understanding of the internal working of BLE and it helped in connecting the

BLE sensor to the smartphone and reading/writing values in the sensor to control it.

Also, UI design for a universal remote was done in Android.

It’s a new world out there with exciting product innovations coming about, some of which

will work, while others fail. However, one thing remains certain in that there are a lot of

reasons to be excited about the potential associated with BLE-powered beacon technology. The

next several years should yield some interesting experiences for marketing analysts, merchants,

mobile wallet providers and consumers alike.

Page 22: Intern_Report

22

REFERENCES

[1] Bluetooth SIG

[2] Android developers’ forum

[3] www.anrdoid.com/developers

[4]Wikipedia

[5]”Occupancy Detection via iBeacon on Android Devices for Smart Building Management”- A. Corna,

L.Fontana, A. A. Nacci and D. Sciuto Politecnico di Milano