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

Very unstable and slow connection #13

Open
polyphia opened this issue Dec 6, 2019 · 5 comments
Open

Very unstable and slow connection #13

polyphia opened this issue Dec 6, 2019 · 5 comments

Comments

@polyphia
Copy link

polyphia commented Dec 6, 2019

Hello!

I have recently installed your repo in order to integrate for my home assistant but so far it's been extremely unreliable .

I only have 1 bluetooth lamp (Eglo 11569 g95) and when the commands work it usually takes about 5 seconds ornso to respond .

Often they don't work at all as the script fails to connect , especially if I just ran a command in the last 10 seconds (but not limited to this)

I am running on a rpi3 with ubuntu and using the rpi3 built in bluetooth .

Any clue?

Thanks!

@Leiaz
Copy link
Owner

Leiaz commented Dec 9, 2019

It takes time to connect, not 5 seconds with the light I have, but it is not instantaneous, so you could try to stay connected so you don't have to reconnect after each command.
Also, the disconnect need to have completed before you try to connect again.
After connecting, the commands work, if you try to use them from the python interpreter, in interactive mode ? Your light is a different model, so it could also expect different commands.

@polyphia
Copy link
Author

polyphia commented Dec 9, 2019

Hi, thanks for the reply !

Yea it's around 5 seconds everytime I try to issue a command. How can I keep connected to avoid reconnecting each time ?
About the disconnect, it's weird that sometimes I wait over 10 seconds and it still fails to connect back again . Can't find a logical pattern but the errors on connecting are mostly when I have recently ran another command. Here's the error I get :

oot@raspberrypi:/home/python-awox-mesh-light# python3 turnon.py Traceback (most recent call last): File "turnon.py", line 4, in <module> mylight.connect() File "/home/python-awox-mesh-light/awoxmeshlight/__init__.py", line 116, in connect self.btdevice.connect (self.mac) File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 445, in connect self._connect(addr, addrType, iface) File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 439, in _connect raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)

The commands work fine when it connects but I'm calling the script directly from cmd line , didn't try in interactive mode yet .

This is the only lamp of this format (G95) which I was able to find worldwide with smart features so I'm really hoping I can make it work reliably . The huge delays and constant failures to connect made it pretty much unusable for me so far .

@polyphia
Copy link
Author

polyphia commented Dec 9, 2019

This was done over a period of 30 seconds after successfully turning the light on :

`root@raspberrypi:/home/python-awox-mesh-light# python3 -i turnoff.py
Traceback (most recent call last):
File "turnoff.py", line 4, in
mylight.connect()
File "/home/python-awox-mesh-light/awoxmeshlight/init.py", line 116, in connect
self.btdevice.connect (self.mac)
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 445, in connect
self._connect(addr, addrType, iface)
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral A4:C1:38:46:86:CA, addr type: public

root@raspberrypi:/home/python-awox-mesh-light# python3 -i turnoff.py
Traceback (most recent call last):
File "turnoff.py", line 4, in
mylight.connect()
File "/home/python-awox-mesh-light/awoxmeshlight/init.py", line 116, in connect
self.btdevice.connect (self.mac)
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 445, in connect
self._connect(addr, addrType, iface)
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral A4:C1:38:46:86:CA, addr type: public

root@raspberrypi:/home/python-awox-mesh-light# python3 -i turnoff.py
Traceback (most recent call last):
File "turnoff.py", line 4, in
mylight.connect()
File "/home/python-awox-mesh-light/awoxmeshlight/init.py", line 116, in connect
self.btdevice.connect (self.mac)
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 445, in connect
self._connect(addr, addrType, iface)
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral A4:C1:38:46:86:CA, addr type: public
`
Just now I ran the turnoff command 10 times in a row and all are failing to connect . The turnon and setbrightness command both worked fine !

Here's the turnoff script :

import awoxmeshlight import time mylight = awoxmeshlight.AwoxMeshLight ("A4:C1:38:46:86:CA", "user", "password") mylight.connect() mylight.off()

@polyphia
Copy link
Author

polyphia commented Dec 9, 2019

Sorry for the multiple posts but I have an update :

Adding disconnect command to the end of every script fixed the connecting issues .

Now the only problem left to deal with is the delay which flutuates between 3 and 6 seconds, maybe if I can keep it connected while avoiding the previous connection issues that would sort it out .

@Leiaz
Copy link
Owner

Leiaz commented Dec 9, 2019

Yes, you must disconnect before you can connect again.
I see you ran your script with -i, this should give you a python prompt after running the script. To test the delay when running commands when connected, you could run commands at the python prompt. Run with -i a script that only connects to the light, and then from the python prompt, try sending commands to the light like mylight.off() mylight.on() or others and see if there is a big delay.
Then for staying connected, it depends how you want to control the light. You could, for example, have a process that runs in the background, connects to the light and reads commands from a pipe, and scripts to write to the pipe ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants