I am making an Android app to receive data from Arduino(NRF24L01).
Arduino(NRF24L01) can send data only with Bluetooth device name.
So I get the value by putting the analog value in the BLEname.
Like this YouTube video.
https://youtu.be/F9yMTdcd33w?t=240
However, the Android application does not come back with the information of a device once it is already connected.
ex)
BLE Device name : "A=i" //(i=analog.value;)
first BLE SCAN -> find -> BLE Device name : "A=12"
I change i,(i=14;)
Second BLE SCAN -> find -> BLE Device name : "A=12"
why????????? i want "A=14"!!
Therefore, I would like to create an application that will continue to scan and retrieve device name information.
Is there any example I can refer to?
P.S I am sorry that I have not translated the translator and the context is not smooth.
You can refer this example for BLE scanning and connection or you can use customize as you want.
BleConnect
Related
I am developing an android app that fetches temperature from a bluetooth thermometer. I followed the instructions on the google developer page.
https://developer.android.com/guide/topics/connectivity/bluetooth-le.html
I could scan the devices and get connected to the thermometer. I am exactly using the same code from the following github.
https://github.com/googlesamples/android-BluetoothLeGatt/
Instead of using the the heart rate service and associated characteristics. I am using temperature service and the characteristic. I have changed these value on the following page that I downloaded from github
android-BluetoothLeGatt/Application/src/main/java/com/example/android/bluetoothlegatt/SampleGattAttributes.java
I using the following bluetooth thermometer.
http://www.cooper-atkins.com/Products/Blue2/
This is the API document I got from COOPER-ATKINS.
https://drive.google.com/open?id=1eq93Qc6uy0Vv9KompukLuIUnJK4B-e-0
In page 6 I have highlighted the service uuids and characteristic uuids I have replaced in the github code.
I could read the temperature data but only once. If the temperature changes I could not see the temperature value is refreshed in app automatically. I have to hit the temperature list button to get the recent value. Could anyone suggest what I am missing or doing wrong.
Please let me know if you need more info.
The characteristics you highlighted have both read and indicate property.
Reading the characteristic (Calling BluetoothGatt.readCharacteristic in Android) only obtains the value at that instant by definition.
You have to enable the indication to get every update of the value.
You can find how to enable a notification (not indication) on this SO thread. You can substitute the constant value to enable indication.
This question already has an answer here:
Android : Get "device name" on android tv
(1 answer)
Closed 4 years ago.
I wanna get android device name (i.e. the "name" that user can change through settings and that you can find under "Settings > About device > Device name").
Other developers recommend to get this name through bluetooth.
But on my device (Samsung Galaxy S4) this name is only updated when I enable bluetooth, so if I change the name when bluetooth is disabled : the new name won't be displayed until I enable bluetooth.
I'm wondering if there is a way to get the updated device name without enabling bluetooth?
I can think of a workaround like :
enabling bluetooth
get name
disable bluetooth
but I was wondering if a more elegant solution exists.
The device name you are talking about is also known as the bluetooth friendly name and therefore reading it through the bluetooth API is perfectly valid.
Be aware that if your app is running on a non-bluetooth device : this name don't exists.
If you read carefully the doc of the bluetooth API you will see for the setName(...) method:
... If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.
In other words: this behavior is not particular to your device, but it works as specified.
Your workaround is AFAIK the only way the get the updated name when name was changed while bluetooth was disabled (and unfortunately it has serious drawbacks : enabling/disabling BT is costly).
Please also note that you must wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.
I'm trying to develop an Android Wear app that can identify songs with Gracenote's GNSDK. I'm building upon their sample app.
I'm having trouble with the Wifi on the wearable device. The sample app is working in terms of a song identification attempt but misses an internet connection. (Although other apps work perfectly.)
So what happens: When the watch is in Wifi and not connected to the phone via bluetooth but solely via Wifi it works. Now connecting the phone to the watch via bluetooth the watch is supposed to connect to Wifi through the phone. And now a connection is no longer available. So identifying through the phone's internet is not working. Does anybody have a clue what can be the reason and how to troubleshoot?
If not:
Is there a way to, instead of making a full album identification via GnMic, grab only the fingerprint from the GnMusicIDStream object? And if so, how? The idea behind it is to listen to a song via GnMic on the wearable device, grab only the fingerprint and then send it to the mobile device. There, identify the song by doing an identification based on the fingerprint and send the result back on the watch.
Hope one of you has an idea how to solve the problem! Many thanks in advance! Any help is appreciated!
Best,
dmkscr
Due to limitations with accessing the internet directly from a Wear device, you must pass either raw audio bytes or a fingerprint to the handheld device via the DataItem or MessageApi. (See https://developer.android.com/training/wearables/data-layer/index.html for information on these Wear APIs.) Then, on the device you can produce a fingerprint and/or submit a MusicID query. You then need to again use the DataItem or MessageApi to pass result data back to the Wear device for display.
With either approach (passing audio bytes or a fingerprint to the handheld), you need to work with the GnMusicId class instead of GnMusicIdStream. The reason is that GnMusicIdStream automates multiple steps of workflow (capture audio, produce a fingerprint, perform a MusicID query based on the fingerprint), and doesn¹t provide hooks for performing them separately. GnMusicId is a lower level class that gives you more fine-grained control of this process.
If you choose to pass the audio data to the handheld, you can get the audio bytes on the Wear device using GnMic.getData(). Pass the audio data bytes to the handheld via DataItem or MessageApi. Then, on the handheld,
use the following methods of GnMusicId to produce a fingerprint and perform a MusicID query:
fingerprintBegin(GnFingerprintType fpType, long audioSampleRate, long audioSampleSize, long audioChannels)
fingerprintWrite(byte[] audioData, long audioDataSize)
fingerprintEnd()
fingerprintDataGet()
findAlbums(java.lang.String fingerprintData, GnFingerprintType fpType)
Optionally, if you choose to generate the fingerprint on the Wear device, do the following
Call GnMusicId.fingerprintFromSource(IGnAudioSource audioSource, GnFingerprintType fpType) to generate the fingerprint, using an instance of GnMic as the IGnAudioSource.
Get the fingerprint data via GnMusicId.fingerprintDataGet()
Pass the fingerprint data to the handheld via DataItem or MessageApi
On the handheld, call GnMusicId.findAlbums(java.lang.String fingerprintData, GnFingerprintType fpType)
I a trying to understand and modify the BLE sample von Android.com, now I can discover my sample BLE Device (HTC Fetch) and now I want to understand all that GATT and BLE stuff.
What are Characteristics and what are Profile and what are Serivces and what do they mean in the Bluetooth Low Energy World? I used HTC Dev and found a Service and a Characteristics UUID.
https://www.htcdev.com/devcenter/opensense-sdk/bluetooth-smart/htc-fetch/
But I guess what I need is the Find Me Profile, cause for the first steps I only want to get the Find Me react to a Button click.
https://developer.bluetooth.org/gatt/profiles/Pages/ProfileViewer.aspx?u=org.bluetooth.profile.find_me.xml
How to implement this in my App?
When I understand everything I try Power and Proximity (reading RSSI and compare with defined range).
Can some one help me understanding Bluetooth LE?
Here's a related post
How to use the profile of PROXIMITY PROFILE,IMMEDIATE ALERT SERVICE and Find Me Profile in android 4.3 BLE?
Basically you can approximate a proximity level using tx+power - rssi or distance roughly with
d = (rssi-A)/-20 (where A = rssi at one meter) or simply use rssi mapping out ranges to display You could also initially base it on just the connection range and skip rssi.
As for the FindMe, simply write the low or high alert values to make it sound when you press a button in your app. For pressing a button on the device use the UUIDs shown in the documentation.
sample code for that device is forthcoming
Can anyone give me an idea on how to read the values from the OBD II Bluetooth adapter in an android application.
I want to start with scanning for the bluetooth devices from my android application, then after bluetooth device is found, how would I interact with it and get the values from it?
You should start by reading this http://developer.android.com/guide/topics/wireless/bluetooth.html
it contains step by step procedure .
add required permissions,
make a bt adapter,
then find paired/unpaired devices
I used the BluetoothChat Application and was able to get some basic communications, I am not moving into data logging. You can use this application to have a sort of instant messenger conversation with your ECM.
What particular dongle are you using?
Do you know what protocols are in use within your vehicle?
Download the BluetoothChat sample application -
They will have already handled the intricacies of the connection for you, you will have to change the UUID in order to connect with your device - 00001101-0000-1000-8000-00805F9B34FB
Read up on your particular dongle, some require the return character to be sentat the end of every command "\r"
This should get you started!
Once you have made the Bluetooth connection using the android bluetooth api, use the transport to send and receive data via the Bluetooth channel.
This is new developer resource document:
https://developer.android.com/guide/topics/connectivity/bluetooth.html
The general workflow of the application functionality should go like this:
1) connect to the OBDII adapter through Bluetooth;
2) initialize OBDII adapter with AT commands;
3) continuously get data from the vehicle through issuing the corresponding PID codes.
This article also may be helpful.
http://blog.lemberg.co.uk/how-guide-obdii-reader-app-development