Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s.recv(128) gets stuck (line 81) #24

Open
EkanshdeepGupta opened this issue Jun 14, 2020 · 8 comments
Open

s.recv(128) gets stuck (line 81) #24

EkanshdeepGupta opened this issue Jun 14, 2020 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@EkanshdeepGupta
Copy link

Hi,
I have been wanting something like this for a long time, so thank you for making this.

I have a Jabra 65e bluetooth headset. It shows the battery level when I connect to my phone. When I run this script however, for every port other than 3, I get an Errno 111 Connection refused.

However, when I run it with port 3, the script gets stuck. Specifically, the s.recv(128) function does not return in the while loop on line 81.

I don't know anything about low level network interfaces, so can you help me figure out what might be going wrong?

Thanks a lot!

@TheWeirdDev
Copy link
Owner

Hi.
This is a known issue with some devices. I still don't have a solution for it.

@TheWeirdDev TheWeirdDev added the help wanted Extra attention is needed label Jun 15, 2020
@maxwell380
Copy link

Hi!
Thank you so much for this code.
It works fine with a Bluetooth speaker using port .2-9 suffix.
Unfortunately, I encounter the same error as EkansheepGupta when trying to read the battery level of either my iPhone 4S or iPhone 6s without defining a port suffix. When defining any port suffix I get {device} is offline [Errno 104] Connection reset by peer. This happens allthough the iPhone still says that it is connected.

Best regards!

@TheWeirdDev
Copy link
Owner

Hi @maxwell380.
This code only supports Bluetooth accessories and not phones, etc...
Why do you need that anyway? The phone can show its battery level.

@maxwell380
Copy link

Thanks for the quick response, @TheWeirdDev. I am using a Pi4 with Python and would like to indicate the battery level of the iPhone in an UI on the Pi. Similar to what you may have in your car.

@EkanshdeepGupta
Copy link
Author

Hi.
This is a known issue with some devices. I still don't have a solution for it.

Can you explain or point me to some resources so I can understand better what exactly is happening? And is there literally anything I can try that might work at this point?

I tried another bluetooth headset and faced the same issue.

@TheWeirdDev
Copy link
Owner

Can you explain or point me to some resources so I can understand better what exactly is happening? And is there literally anything I can try that might work at this point?

This code simply opens a Bluetooth Socket and expects to receive raw AT commands from the headset (usually the first command that is received is AT+BRSF).

This problem happens to one of my speakers too. I checked the sniffed data from my android phone and it seems like there is some sort of RFCOMM communication before receiving the AT Commands (maybe that's what wee need?).
image

Currently i'm busy with my exams and don't have enough time to research on this.
For now there is nothing you can try except the things i mentioned in the 'readme' file.
Or you can research and figure out what is going on. Every pull request is welcome and appreciated.

@Spurlos
Copy link

Spurlos commented Aug 24, 2020

Getting same behaviour on Sennheiser headphones:

Device 00:16:94:xx:xx:xx (public)
	Name: HD 4.40BT
	Alias: HD 4.40BT
	Class: 0x00240404
	Icon: audio-card
	Paired: yes
	Trusted: yes
	Blocked: no
	Connected: yes
	LegacyPairing: no
	UUID: Headset                   (00001108-0000-1000-8000-00805f9b34fb)
	UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
	UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
	UUID: Advanced Audio Distribu.. (0000110d-0000-1000-8000-00805f9b34fb)
	UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
	UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
	UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
	Modalias: bluetooth:v0A12p0001d0000

Every port responds with following message, although i'm currently using headphones perfectly:

spurlos@spurlos:~/Bluetooth_project$ bluetooth_battery 00:16:94:xx:xx:xx.6
00:16:94:xx:xx:xx is offline [Errno 111] Connection refused

@psydvl
Copy link

psydvl commented Dec 4, 2021

With OnePlus Buds Z on 3 ports got stuck: 3, 7 & 9
Interrupt with Ctrl+C

Traceback (most recent call last):
  File "bluetooth_battery.py", line 167, in <module>
    main()
  File "bluetooth_battery.py", line 164, in main
    print("Battery level for {} is {}".format(device, str(query)))
  File "bluetooth_battery.py", line 94, in __str__
    return "{:.0%}".format(self._perform_query() / 100)
  File "bluetooth_battery.py", line 104, in _perform_query
    for line in sock:
  File "bluetooth_battery.py", line 35, in __next__
    return self._sock.recv(self._chunk_size)
  File "<string>", line 3, in recv
KeyboardInterrupt

When call on 9 also breaks audio play

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants