Is there anyone who knows how I can get bluetooth rssi and link quality values in bluez without any file and data transfered ?
I am using bluez in linux to make some bluetooth program.
but I got a question about bluetooth rssi and lq..
although I don't trasmit or receive any file or data, I can get rssi ,lq value in linux
using hci_read_rssi,hci_read_lq..
just through pairing and connection between two bluetooth devices
my program is to transmit files at an odroid board based on linux to an android mobile phone
and check rssi and lq value at The odroid board
actually It is possible I can get those values..
but I don't know how i can get rssi, lq eventhough Odroid board just sends a file
please let me know if there is anyone who knows about that.
You can read the following link but to summarize you don't have to use pybluez:
install bluetooth by:
sudo apt-get install --no-install-recommends bluetooth
You don't have to use pybluez, you can use the following to obtain rssi by the device mac address:
#!/bin/bash
echo "testing rssi /n"> logs1
while (true)
do
hcitool rssi [MAC Address]>> logs1
date +%S
date +%S>> logs1
sleep 0.25
done
if you son't know the mac you can use:
hcitool scan
Related
I made an Android app to communicate with an ELM327 OBD-II dongle via bluetooth.
When I test the app with a bluetooth serial terminal (CoolTerm / macOS) the app is receiving and sending data without an issue.
Using my app to transfer commands to the ELM will result in broken and splitted answers.
Output:
DataReceivedHandler: 9V
DataReceivedHandler: 9V>
DataReceivedHandler: 11.
DataReceivedHandler: 9V>
The example above should show the result of the AT RV command which queries the battery's voltage of the vehicle (I sent the command multiple times).
Expected (good) result should look like this: >11.9V
Before I send the first command to query OBD values the ELM is initialized by these AT-commands:
AT D
AT Z
AT E0
AT L0
AT S0
AT H0
AT SP 0
If you have any idea how to get clear answers from the ELM, please let me know.
Thanks in advance!
Found the solution..
The terminal program was sending \n and the ELM sends \r for the termination of the statement.
I am new to android studios and I have the task to develop an app which transfers data from an app (Acceleration sensor data - i have created this app already which shows the data) to matlab (on the pc).
I don't really know how I should do this. I've experimented a bit with bluetooth apps, but I don't have a clue how to connect to Matlab.
I would be greatful for your help.
Thanks in advance,
Annika
Unfortunately I can not speak to the android side of things, but MatLab can connect to generic devices with the UART interface, which is fairly low level.
The process with some microprocessors that I am using is to connect the device to the PC, and then note the Outgoing com port.
(In windows 10, these can be found in Bluetooth settings -> More Bluetooth options)
Then you can use
s = serial('COM<what you found in settings>');
s.Baudrate=115200;
s.InputBufferSize = 100;
fopen(s{i});
serials = instrfindall;
to open an connection. The critical command is serial, the other parameters depend on your device/ configuration. Sometimes there can be issues, in which case one options is to build a loop that tries again until it works.
You then collect the data sent via UART via
flushinput(serials);
temp = fscanf(serials,'%s');
and then split the string. If data is sent continuously, you wrap this into a while loop.
After you are done, you can clean up via
fclose(s{i});
delete(instrfind)
instrreset
It should be noted, that establishing a connection takes longer, the more enabled COM ports there are. So it might be worth disabling all those you don't need.
For more specific things matlab can do, check out What Is the MATLAB Serial Port Interface
I developed an android app that sends data (text, binary, hex..etc) using bluetooth communication. I want to test my app, what methods are there?
Is there a method on mac to receive what is sent ?
There is an app called LightBlue on the Mac (and iOS) App Stores which is very useful when developing with BLE. It allows you to scan, see advertisement data (iOS version only), connect, list services and characteristics, subscribe to a notify / indicate characteristic and read or write a characteristic's value.
For classic Bluetooth, if using SPP you will need a serial terminal. First you need to connect to your device from the Bluetooth System Preferences. This will create a device file in /dev, its name follows the pattern /dev/cu.<DEVICE_NAME>-SPPDev where DEVICE_NAME is the advertised Local Name. This is a character device that you can use with any program that can read(2) and write(2) to a file. For instance the simplest way with default tools, if your device file is /dev/cu.XXXX, is to run cat /dev/cu.XXXX in one terminal window (or cat /dev/cu.XXXX | hexdump -C for hex output), then in another terminal window run echo -n "my command" > /dev/cu.XXXX. Then in the first terminal window you will see the response from your device. For hex input you can use the -e switch and backslash escapes, for instance to send 0x01 0x02, you would run echo -ne "\x01\x02" > /dev/cu.XXXX.
There are programs that are specialized in this sort of communication, called serial terminals. These also let you change the serial port configuration, although the one selected by osx is generally good. I personally use cutecom for this. In cutecom, you need to input the device file name (/dev/cu.XXXX) in the "Device" text field, then configure the desired serial port parameters. To use those that osx selected, just uncheck the "Apply settings when opening" checkbox. Then click on "Open device". You can then input text or hex and see output as text or hex also. If you get gibberish on the output that means that the serial port parameters are not good. If you don't know the right parameters for your device you can experiment, but a typical configuration would be Baud rate : 115200; Data bits : 8; Stop bits : 1; Parity : None, and no handshake.
I try to send AT commands from my computer (ubuntu 13.04) to my phone (Android 5.1) via bluetooth. I want to read the SMS.
I retrieve the MAC address of my phone with :
hcitool scan
I browse all available services on the device with :
sdptool browse XX:XX:XX:XX:XX:XX
I get the good RFCOMM channel for SMS/MMS service and now I'm trying to send the AT command.
I tried with pySerial with a bound and connected rfcomm to my phone but no response :
import serial
phone = serial.Serial('/dev/rfcomm0', 115200, timeout=2)
phone.write(b'AT\r')
data = phone.readall()
print data
I tried the same code on a USB serial port and I have a response :
import serial
phone = serial.Serial('/dev/ttyACM0', 115200, timeout=2)
phone.write(b'AT\r')
data = phone.readall()
print data
# *EMRDY: 1
# AT
# OK
I tried with pyBluez but same problem, no response of my AT command :
import bluetooth
client_sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
client_sock.connect(('XX:XX:XX:XX:XX:XX', 4))
client_sock.send(b'AT\r')
data = client_sock.recv(1024)
print "received [%s]" % data
And I finally tried with native python sockets, but no response :
import socket
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
s.connect(('XX:XX:XX:XX:XX:XX',4))
s.send(b'AT\r')
data = s.recv(1024)
s.close()
print('Received', repr(data))
Note: The phone displays a prompt window to accept that my computer accesses my sms. Of course I accepted.
Can anyone tell me what is wrong and what I can try?
Well, for starter it is better to check first that you have a two-way communication between your Host computer and your Phone on bluetooth, like you said, it did work with USB, then there should be no reason it does not with bluetooth unless you didn't yet established a good communication, so I think it is better to try first that you have good communication by just sending and replying with the same string (kinda hand-shaking protocol) and make sure that you know what your python code is actually sending, may be unseen extra characters using bluetooth that you don't pay attention to, which makes your AT command unrecognizable by your phone.
I'm trying to achieve this goal: I have a bluetooth device connected to my android phone. Given this device can vibrate, is it possible to send a vibrate command to the device?
I have researched the bluetooth apis and the vibrate api on android developers' site but nothing clearly answers my question.
In bluetooth HFP (Handsfree) spec, there is no command (AT Command) to send vibrate to the peer device. As per the technical specification of bracelet "Vibration prompt for incoming phone" , once an AT command is send from phone to bracelet indicating a incoming call, bracelet generates vibration locally, phone does not ask/request to vibrate.
If you want peer device to vibrate,may be you have to use your own defined commands (AT command), with command recognized by the peer device.
I'm very glad to update this thread that I was able to programmatically vibrate the BT bracelet and in the right way using AT commands. So my application is based on Bluetooth Chat application in the Android samples. Here are the steps I followed:
connect the device to the phone
device follows BT Hands-Free profile specification. That requires "handshaking" by means of AT commands.
So I mimic this exchange of commands (with hard coded responses to bracelet's commands)
Once handshake is complete, I send AT command based on BT Hands-Free profile specification to RING and +CLIP:
On receiving the last set of response from application, the bracelet vibrates.
It seems simple, but without knowledge of BT Hands-Free profile specification, and sample AT commands this was nearly impossible.
#bt_user: Thanks for your pointer, that put me on the right track of R&D.
I was fiddeling with exaclty the same problem. After days of trial and error, I finally got it to work. I think it depends on the speed at wich you answer the HF's commands, as well as on the correct line-endings ([13][10]"COMMAND"[13][10]).
Here is my DroidScript which works. It's not cleaned up, but it works.
https://gist.github.com/t-oster/68a568ac4c4e133f67ac
The exact sequence, which works for my bracelet is:
CR is ASCII Code 13 and LF is ASCII Code 10
> AT+BRSF=0<cr>
< <cr><lf>+BRSF:0<cr><lf>
< <cr><lf>OK<cr><lf>
> AT+CIND=?<cr>
< <cr><lf>+CIND: ("service",(0,1)),("call",(0,1))<cr><lf>
< <cr><lf>OK<cr><lf>
> AT+CIND?<cr>
< <cr><lf>+CIND: 1,0<cr><lf>
< <cr><lf>OK<cr><lf>
> AT+CMER=3,0,0,1<cr>
> <cr><lf>OK<cr><lf>
from then on I can just send
<cr><lf>RING<cr><lf>
to make it vibrate.
i have developed a java android version
using parts from Thomas Oster and an example i found online
https://gist.github.com/shimondoodkin/a582d910045ab06ab68c