Obtain RSSI from bluetooth adapter Raspberry3 - bluetooth

I need to know how I can obtain de REAL RSSI from a non-connected bluetooth device with my RPi3.
I know there is a program named bluetoothctl which I don't know how it works, I can't find anything about how it works bluetootctl. But when I used it, I can obtain ALL the REAL RSSI of ALL the bluetooth devices, only with a scanning. (scan on)
I do this.
1) bluetoothctl
2) scan on
(you will obtain something like this: "Device XX:XX:XX:XX:XX:XX RSSI: -48" )
It's so simple, but, the problem, it's that I need to work with this data, I am not able to get this data to process later. So I need some code, in c++(better) to do this.
I know hcitool, but you have to be connected and they not give you data until you are at a distance. I can't understand how it works bluetoothctl
I try to do a redirect of the output to a log but...I am not able to do that..because when you put on temrinal bluetoothctl it happens this:
pi#raspberrypi:~ $ bluetoothctl
[NEW] Controller B8:27:EB:90:E8:79 raspberrypi [default]
[bluetooth]#
now, you can use all the commands of bluetoothctl
Thanks ;)

Look at source as kaylum said.
You will find in doc folder hci and dbus documentation.
You can also take the bluetoothctl source (available in the folder client) and make a wrapper around it to your needs. It uses the dbus library helper developed in gdbus folder.

you can see the rssi value using hcidump [-a] command but make sure to keep Bluetooth on in background , so u can just start scanning like you usually do in Bluetoothctl and then Scan on ,leave that in background and on a new command line use the hcidump command This might help you.See this also : http://www.linuxcommand.org/man_pages/hcidump8.html

You can use the following, from the command line
sudo btmon |grep RSSI &
sudo hcitool scan
Or if you want to use python you can use the inquiry with rssi example found in the pybluez module.
Another option would be to use the DeviceDiscoverer skeleton class found in this example and then adjust to your own needs. The device discovered function is passed the rssi which can be stored and manipulated to suit.

Related

How to set default audio output on Raspberry Pi to hdmi?

if I execute:
speaker-test -D plughw:1,0 -t wav , sound gets played over the hdmi cable, as it is supposed to.
But if I type speaker-test -t wav , no sound gets played over the hdmi cable, so I guess the issue is the default output device.
Here is a list of what I've already tried:
change the output device in the top left corner on the Desktop
execute amixer cset numid=3 2 in the console
uncomment those 2 lines in the config:
hdmi_drive=2
hdmi_force_hotplug=1
change to those 2 lines in the alsa.conf file:
defaults.ctl.card 1
defaults.pcm.card 1 (also tried with 2 instead of 1)
My goal is to later play sound over a browser, but chrome seems to only be able to output sound over the default audio output device, so I guess I somehow need to change it.
I am a noob, so please tell if me if you need more informations and how to get them.
If anyone has some hits on how to solve this issue, I'd be really grateful
had the same problem (PI 4, Bullseye).
what helped was:
sudo raspi-config
1. System options
S2. Audio
Select HDMI Option (In my case it was HDMI 2, because default output was on HDMI 1)
After that default output worked. Everything else (changing config.txt or alsa.conf) wasn't necessary in my case.
reference: Raspberry Pi Configuration
At the time I tried to get into the configuratioms via
sudo raspi-config
as #reallyATypo suggested, but it seemed to be broken somehow. Even navigating into it on the desktop environment didn't work...
Since there were those weird things going on with the os and there wasn't much data on the RasPi anyways, I decided to set up an entirely new os on the same SD card. On there the default configurations seemed to be already correct and there also was no problem anymore with the os.
Thank you all for answering :)
Idk if that is the right thing to do, but I'm gonna set my answer as a workig one in order to close the issue

How to make Linux ignore a keyboard while keeping it available for my program to read?

I am building some kind of kiosk system and I bought this USB DIY keyboard for it: https://www.amazon.com/gp/product/B07QPXQQ7L
This allows me to have a lot of buttons and they behave like keyboard keys.
I'm writing a program (Perl) that will take the input from that keyboard and do things based on that.
The problem is that I need to have the rest of the system (both X and the TTYs) ignore that keyboard so that it won't type random things in the terminal or in the window manager. In other words, the system should disregard it but the device itself must still be available in /dev/input/...
I don't need a real keyboard to control the machine because I connect via VNC and SSH.
Bonus points if you know how to read from a /dev/input/... keyboard and end up with letters typed just like with STDIN in a terminal.
Thanks!
I found the solution here where someone wanted the exact same thing in the case of a barcode reader:
https://serverfault.com/questions/385260/bind-usb-keyboard-exclusively-to-specific-application/976557#976557
SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="yyyy", RUN+="/bin/sh -c 'echo remove > /sys$env{DEVPATH}/uevent'"
ACTION=="add", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="yyyy", SYMLINK+="diykeyboard"
And then replace xxxx and yyyy by the Vendor and Product ID as found in lsusb. So in my case 1c4f and 0002:
Bus 001 Device 003: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
The udevadm control --reload thing didn't do it for me, I had to reboot.
Then in theory the data typed on the keyboard should be available at /dev/diykeyboard (the SYMLINK variable).
Now in my case unfortunately there are multiple events that match this vendor+product, and to match the right one I needed to add DEVPATH=="*:1.0/*", KERNEL=="event*" in the second line where it creates the SYMLINK. And then surprise it did not create the link in /dev so I had to do something dirty, create a link myself with ln:
SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="1c4f", ATTRS{idProduct}=="0002", RUN+="/bin/sh -c 'echo remove > /sys$env{DEVPATH}/uevent'"
SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="1c4f", ATTRS{idProduct}=="0002", DEVPATH=="*:1.0/*", KERNEL=="event*", RUN+="/bin/sh -c 'ln -sf /dev/input/$kernel /diykeyboard'"
(don't create the link in /tmp since udev happens before the mounting of /tmp at boot)
From there I can read from /diykeyboard (which usually points to /dev/input/event0) either with evtest which shows the keys typed, or directly with my program and then decoding the scancodes.

Can't send AT commands to Bluetooth module with UART interface

I want to change the pairing code of a device. It's a chinese clone of a MiniELM327 adapter with a Bluetooth interface. If I power it up through its OBD2 connector supplying 12V, the whole device is on. Through the Bluetooth Serial Port I can communicate with the ELM327 chip and send AT Commands, receiving correct answers.
But that is not what I want to do. I want to change the pairing code of the bluetooth interface itself.
The module is a RG-BT10-10 from Redgoo based on a Beken BK3211 chip. I have the datasheet and the command set (not sure if it's the right one). Unfortunately it is all in chinese and the customer support is in chinese too (they use automatic translators).
www . redgoo.com.cn/product/20131106105822750.pdf
www . redgoo.com.cn/product/20131130122844243.pdf
www . belon.cn/Uploadfiles/psd/BK3211datasheetv1.2.pdf
I tried to contact the manufacturer and they said that I have to send the following commands:
AT+EN1 (enter command mode)
AT+PIN****
AT+EN0 (exit command mode)
and then reset the module.
I bought a ftdi-based USB-to-UART converter at denkovi.com
www . denkovi.com/usb-to-uart-ftdi-serial-interface-adaptor
Then I wired the pins on the USB-to-UART with the corresponding contacts on the RG-BT10-10 (Tx and Rx are switched of course).
According to the datasheets, the parameters are:
Baud Rate: 38400
Parity: None
Data bits: 8
Stop bit: 1
And the AT commands should be terminated with \r\n that is CR+LF if I'm not mistaken.
No information on flow control. The RTS pin on the board is not even soldered, meaning that it's not used during device normal operation.
From here on, I'm lost. I tried with several programs (Hyperterminal, Putty, Tera Term etc.) to send the AT command which should yield an "OK" but no response has ever arrived.
To be clear, if I fiddle with the wires (like grounding and releasing RTS or turning the RG-BT10-10 on and off) I sometimes get some chars so the flow of data from the module to the computer physically works.
Is there some basic theory I'm missing? I can't get enough information from the manufacturer (language barriers...). And I believe that I have all the hardware that I need, so I just have to understand how to set it correctly :)
Thank you very much for your help!
I had exactly your problem. No response to AT from PuTTY or HyperTerminal at 9600 Baud (which is correct/default for the SPP-CA).
All I would see is:
+READY
+PAIRABLE
when powering up.
I then tried the Serial Monitor that comes with the Arduino IDE, www .arduino.cc/download_handler.php?f=/arduino-1.6.7-windows.exe. Changed line endings to "Both NL & CR" and at 9600 Baud, it came to life:
AT
OK
AT+VERSION
+VERSION=+BOLUTEK Firmware V2.2, Bluetooth V2.1
I hope this helps someone.
You can also use Putty to send
Ctrl+M : Carriage Return(“\r”)
Ctrl+J : Line Feed(“\n”)
This worked for me in getting a response:
AT [CTRL-J]
OK

How to use iwlist to scan hidden ssid?

Should I configure some wireless settings (use commands on linux) so that "iwlist wlan0 scan" can list hidden APs if they exist? Or iwlist always reports hidden APs?
(I don't want to use wpa_supplicant to do AP scanning.)
Commenting on a pretty old post but just came across this question and I don't believe iwlist scans for hidden APs. Remember the AP name is not broadcasted at all so there is no way for iwlist to magically find the name.
Instead, you have to pass the name of the AP during your scan. I.e you have to actively probe for that hidden network.
So your command should look something like this:
iwlist <my_wireless_interface> scan essid <my_fancy_essid>
Although I don't know how to scan for multiple hidden essids in a single scan, this should detect a single hidden SSID.
I have to mention this -- Hidden SSID does NOT add security at all.
I think iwlist will show hidden non broadcasted SSIDs as well.
But to be sure you can test that by hiding your AP's SSID and test it (best way to be sure).
iwlist <you_interface_name> scanning essid <your_hiddden_ssid>
will do the trick
otherwise iwlist shows hidden ssids with empty ESSID
e.g.: ESSID:""
than you have to match by the Address-Field, which holds the MAC
of the Station/Router.

How to control/check gpio states with shell commands (at91sam9260 board)

I need to write a script that controls and checks the gpio states.
I have been trying for a while to find a way to do it, but I didn't succeed.
Here is for the details :
I use an at91sam9260 board with a Linux kernel 2.6.27 embedded in it.
I see the /dev/gpio device
I tried some commands like cat /dev/gpio OR echo 1> /dev/gpio but it did not give me any result ( except an error message for the first command)
I also tried to create /dev/gpio0 .. to /dev/gpio31 (with the makedev command before recompiling the CRAMFS filesystem, but I did not get more results.
Does someone know how to check these gpio states and set/clear some of them ?
More generally, Is there an easy way to find out the proper shell commands for a particular device just by looking at the driver source files ?
If your kernel has sysfs support you can access and control the gpio pins through the interface in /sys/class/gpio. See the sysfs section of the kernel document in Documentation/gpio.txt.
I have used at91sam9260. You can set/unset the gpio pins using sysfs interface.
for ex. go to: cd /sys/class/gpio and then "echo 2 > export" and then set the directions of gpio pins to input(in)/output(out) by "echo in > direction" and then you can read the value from "value" file by "cat value"
Check /sys/kernel/debug/pinctrl/ directory for verbose GPIO info.

Resources