BLE Communication - Can't collect statistics of sensor use - android

All Running apps receive the sensors data through BLE.
it means that the sensor connects directly to the 3rd app and i can't collect any statistics of sensor use.
Here are my questions:
Do you have an idea for a solution for it? How I can collect statistics?
Can I build an app that receives the data from the sensor and communicates with the running apps through BLE, both my app and running app on the same mobile device?
In simple words, can the running app receives BLE transmission from another app in same device?

It's pretty unclear what your goal really is, but anyway from a technical point of view here is how it works:
In both Android and iOS, multiple apps can be connected to the same peripheral. But if one app issues a GATT request, the response will be delivered to only that app. Both apps can also register for notifications/indications. When a notification/indication is received, it is sent to all apps that are registered for notifications/indications. There is no way for the peripheral to know which app a GATT request comes from since they all appear to be sent from the same client.

Related

BLE Beacon vs Peripheral - Which is better for mobile app background scanning?

I'm a firmware developer, and 2 of my clients both have similar needs: they are developing mobile apps that interface with my hardware and open their respective apps when an advertisement is received in the background.
Client A absolutely needs a peripheral, since GATT writes/reads are done for the core functionality of the device.
Client B can use either, as really the only thing they need are advertisements.
Client A has come back with complaints that their mobile app developers are having issues with peripheral advertisements, and would like to switch to a "connectable beacon" (which in my eyes is just a peripheral with modified advertisement data)
Are there any good resources on which works better with Android/iOS background tasks?
I guess the Client A is expecting to receive the collected data of your peripheral through "asynchronous" callbacks from BluetoothGattCallback class.
From what I could hypothesize, Client A is expecting an onCharacteristicChanged() callback being triggered by a Notification from a previously registered Characteristic, all raised by the BLE device.
Basically, this makes the peripheral data transfer less dependent of the scanning callbacks timming raised by Android itself, and it immediatly receives the data when the device triggers it.

Does Android app needs to perform Central and Peripheral roles at same time to send and receive data over BLE?

Currently, I am developing an app which is communicating with one BLE Hardware which is receiving commands and responding back the command response. To Simulate hardware, We have developed one iOS Simulator app, which is working in Peripheral and responding back on requested command. But Somehow, As and when I try to write to the write characteristics, I got the status = BluetoothGatt .GATT_REQUEST_NOT_SUPPORTED in the onCharacteristicWrite callback. But somehow, I came to know that we need to implement the Central and Peripheral roles into Android app.
But I am still not sure, Do we need to implement Peripheral role as well to send and receive data in multiple packets.
I am developing the app using following nice blog post:
- https://medium.com/#avigezerit/bluetooth-low-energy-on-android-22bc7310387a
- https://android.jlelse.eu/android-bluetooth-low-energy-communication-simplified-d4fc67d3d26e
- https://www.bignerdranch.com/blog/bluetooth-low-energy-on-android-part-2/
And using following repo as learning point of view:
- https://github.com/bignerdranch/android-bluetooth-testbed/tree/a/android-ble-part-3
Thanks in advance!
Typically your phone app is the central and it communicates with a peripheral device over Bluetooth. If you want to send data to the peripheral, you can write a characteristic in the phone app, given writing is enabled for that characteristic. Your central can get data from the peripheral in 2 ways: it can either read a characteristic (if it's enabled) from the peripheral or receive notifications from the peripheral (if it's enabled). So if all you have is a central (phone app) and a peripheral (some kind of Bluetooth device) and you want to send data back and forth, you don't need to have both central and peripheral roles in the phone app. If you have some special stuff going on, it might be different for you, I don't know. I'm talking about a typical setup.
If you want to send commands to the peripheral, you could write those commands to a characteristic. The peripheral could in turn respond with notifications. This is basically the way I develop a Bluetooth solution, but it can be different depending what you want to achieve.
It takes two devices to communicate with each other.
Device A:
It will be Peripheral device which will be advertising the data. i.e.: Beacons, BLE Hardware
Device B:
It will be Central device which will send request for read,write. i.e.: Mobile
Setup for Device A:
If you don't have Peripheral, there is a way to make your android mobile to act like a Peripheral if your device is supporting that advance feature.
So before beginning, you may simply check that by using following app:
https://play.google.com/store/apps/details?id=com.kyriakosalexandrou.bluetoothsupportcheck
To make your device act like Peripheral, you may install following app which simply simulates the GATT and advertising:
https://play.google.com/store/apps/details?id=com.ble.peripheral.sim
Important: Setup service and characteristics based on your requirements, make sure characteristic is write enabled if you want write data on it.

Android BLE Notification

I'm developing an android application using BLE. I've implemented all the basic operations like discovery, connection, and data transfer.
Now I was looking for BLE notifications, Is it possible to receive notification from BLE device when the application is not running (not even in background).
What I want to implement is the notification similar to GCM/FCM, we receive notifications in our app even though app is not running.
So want to check if similar notification mechanism is supported by BLE devices and Android framework.
I've searched for few hours now but didn't get any proper result.
If anyone can just tell me if it is supported or not?
Now I was looking for BLE notifications, Is is possible to receive notification from BLE device when the application is not running (not even in background).
BLE is just a communication protocol. When someone talks, someone has to listen.
What I want to implement is the notification similar to GCM/FCM, we receive notifications in our app even though app is not running. So want to check if similar notification mechanism is supported by BLE devices and Android framework.
GCM/FCM works because Google Play Services is running on the device listening for messages.
I can imagine two possible cases based on your question:
If by "receive notification" you mean a change in a Bluetooth characteristic - well your app should be running already. Only you know how to talk to the BLE device.
If you want to implement a location aware beacon type behavior with BLE you may be able to leverage the existing Google Nearby feature to achieve the desired effect.
I would say no. You need to have the app running to get Bluetooth callbacks. You should simply set up a Foreground Service in your process and that will keep the app running in the background.
If you want to receive notification event if your app is not running, you should implement Android service that continuously scan for BLE frames and ones it catch some frame that is met some parameters (for example for iBeacon it will be specific Major and Minor values; for Eddystone URL -- some specific URL etc.) -- just send intend to start your application.

How long (milliseconds) does it take to show the services, when device BLE connects to mobile BLE?

An embedded device will send data through BLE. I developed an Android application to receive data, but have the following problem:
When the device connects to mobile BLEit will send data immediately but I am not able to read data, if I give a delay the app starts reading characteristics but will not be collecting data.
So when device BLE connects to mobile BLE how many milliseconds will it take to show the services? So I can match delay and receive data.
Instead of manually setting delays, you can use onConnectionStateChange, and onServicesDiscovered callbacks to execute your code based on the connection stage.

Send a Android BLE GATT Notification

I´m currently developing an BLE application, based on the Gatt sample project provided by Google.
What I want to realize is to send a notification from my Android device(smartphone) to another BLE device(e.g. TI CC2540). There are many discussion about how to receive a notification on the Internet.
However, I can't find out any discussions about sending a notification. So is there any method to sending a notification through Android device? Thank you in advance.
Technically, there is a difference between the Central/Peripheral classification, which belongs to the GAP, and the Client/Server one, which belongs to the GATT. A Central (one that scans and connects) is usually a Client, and the Peripheral (one that advertises) is usually a Server, but not necessarily.
The smartphone is the Central (it can be Peripheral as of Android 5.0 but I doubt that's the case for you), and usually it's the Client because it connects to GATT Servers located on Peripherals such as your sensor (or whatever you are building).
So, if you want to send a Notification from your device you need 2 things:
Create a GATT Server on your smartphone.
Design your Peripheral to execute GATT Client procedures (Discover Characteristics, Read/Write etc).
This may not be necessary, as #istirbu pointed out. If your application is already up-and-running, your smartphone Central is a Client. The equivalent of a Notification at Client-side is the Write Command (without response). So use that.
Notifications are used by the peripheral device to send back information to the client (eg Android device). There is no need to send a notification to the device from GATT perspective, you can perform a write operation on a characteristic. As a result of that write, or any periodic operation, the peripheral device will send back (notify) some info to the client on the same or other characteristic that you have subscribed for.

Categories

Resources