Filter results by

Build an Android app with BLE and ARTIK Cloud

This post updates our previous article to use the ARTIK Cloud endpoint and Java/Android SDK V2.

Today we’re developing an Android app that illustrates how well ARTIK Cloud and Bluetooth low energy (BLE) work together to get device data.

It’s a simple process. We are attempting to get our Android app to locate nearby BLE devices, collect their data and then send it directly to ARTIK Cloud.

Introduction

Many health and fitness sensors today use Bluetooth low energy (BLE) technologies. With this in mind, I want to develop an Android application that scans and connects to nearby BLE devices. The app collects relevant measurements from them, and sends this data to ARTIK Cloud.

Once in ARTIK Cloud, the data is useful in many ways. For example, my app and similar apps can retrieve data. ARTIK Cloud is a data exchange broker, which gives developers the opportunity to use the data from diverse devices in a variety of ways.

Our goal is to collect data from a BLE device and send it to ARTIK Cloud. Then it can be viewed in near-real-time in My ARTIK Cloud.

Each data point is sent to ARTIK Cloud on the behalf of the Heart Rate Tracker device that you created (or selected) in the “ARTIK Cloud Devices” screen.

The ARTIK Cloud device ID is also shown in the device detail screen.

Different devices will provide different data points, and you can pick any of them to test. My focus for this prototype is only heart rate, so if you pick a different type, the app will stop receiving heart rate and show an “N/A” in the “Data” and “ARTIK Cloud device ID” fields.

Click “BLE Disconnection” to stop the connection between AKCnBLE and the BLE device.

Now use the back arrow on the top-left to navigate back to the “BLE Device Scan” screen.

Again, use the back arrow on the top-left to navigate back to the “ARTIK Cloud Devices” screen.

Click “logout” to logout from ARTIK Cloud.

While the app is collecting heart rate data, you can log into My ARTIK Cloud to view the data in near-real-time. Below is an animated screenshot.

Installation and setup

Once you build the app you are going to need to install it. I’ll walk you through the process with my own account.

I log into the Developer Dashboard to register my Android application on ARTIK Cloud. To properly test my application, I have two separate Samsung accounts with different email addresses:

My official developer account. This is the account I use to log into the Developer Dashboard and register my application.

A simulated user account. This is the account that I used in the above demo to log into ARTIK Cloud on phone and to log into My ARTIK Cloud.

I follow these instructions to create an application. For this Android app, I select the following:

For the last functionality above, I use the code of the Android sample application BluetoothLeGatt. There is no need to discuss its implementation here. After you read Android’s documentation on Bluetooth Low Energy, you should be able to understand the implementation related to BLE in this app.

You can easily change the code to collect measurements other than Heart Rate Measurement from BLE devices.

The following code from SampleGattAttributes.java identifies the heart rate measurement. You could do the same for other measurements by consulting Bluetooth Characteristics.

Set up a WebSocket device channel

To stream sensor data to ARTIK Cloud in real-time, you need to establish a WebSocket device channel.

Method connectDeviceChannelWebSocket() in ArtikCloudSession opens the WebSocket, then sends a message to ARTIK Cloud to register the device, and finally gets callbacks on various events like onMessage and onClose.

Conclusion

Development of the app that interfaces with nearby BLE connections is also simple, thanks to the native SDK. Along with ARTIK Cloud, such a third-party app provides a service that is highly relevant to individual users, because it brings together their data from different types of data sources.

Yes! Connect me with Samsung IoT partners to hear more about their products and services. *

* By checking either box, you may receive notifications by phone, email, text, and/or other electronic means from Samsung Semiconductor, Inc. and its affiliates. If you choose to receive partner notifications, we may forward your contact information to ourpartners. You may unsubscribe from these services at any time by clicking on the unsubscribe link in our communications or by submitting a request here. Please see our Privacy Policy and Terms of Use for more information about how your data is stored and used.