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

SPRK+ Support #9

Open
gazialankus opened this issue Feb 3, 2020 · 6 comments
Open

SPRK+ Support #9

gazialankus opened this issue Feb 3, 2020 · 6 comments

Comments

@gazialankus
Copy link

I used to use a SPRK+ just fine with BLE-supporting Sphero python libs. I just realized that Disney crippled it. I really appreciate your new efforts on this.

I'm trying to use this library but this is what I get:

$ python drive_with_heading.py
Traceback (most recent call last):
  File "drive_with_heading.py", line 25, in <module>
    main()
  File "drive_with_heading.py", line 10, in main
    with Sphero(mac_address=mac_address) as sphero:
  File "/home/pi/sprk/lib/python3.7/site-packages/pysphero/core.py", line 210, in __enter__
    self.sphero_core = SpheroCore(self.mac_address)
  File "/home/pi/sprk/lib/python3.7/site-packages/pysphero/core.py", line 84, in __init__
    self.ch_api_v2 = self.get_characteristic(uuid=SpheroCharacteristic.api_v2.value)
  File "/home/pi/sprk/lib/python3.7/site-packages/pysphero/core.py", line 137, in get_characteristic
    return self.peripheral.getCharacteristics(uuid=uuid)[0]
  File "/home/pi/sprk/lib/python3.7/site-packages/bluepy/btle.py", line 508, in getCharacteristics
    rsp = self._getResp('find')
  File "/home/pi/sprk/lib/python3.7/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/home/pi/sprk/lib/python3.7/site-packages/bluepy/btle.py", line 362, in _waitResp
    raise BTLEDisconnectError("Device disconnected", resp)
bluepy.btle.BTLEDisconnectError: Device disconnected

Could you point me to anything that may help me get this to work with SPRK+? I'd love to contribute.

@EnotYoyo
Copy link
Owner

EnotYoyo commented Feb 4, 2020

I want to rewrite this library from bluepy to another bluetooth library. Maybe gatt-python or bleak.
I hope, that all such errors go away after that.

@EnotYoyo
Copy link
Owner

EnotYoyo commented Feb 4, 2020

You can try this branch.

@gazialankus
Copy link
Author

gazialankus commented Feb 4, 2020

The thing is, I have a Linux desktop in which I can use the SPRK+ fine with many sample codes around. The error above is on a Raspberry Pi 4, on which nothing works with SPRK+. I tried to make the bluepy versions the same etc. but it did not help.

I'll try that branch, thank you.

@gazialankus
Copy link
Author

In the Linux machine in which SPRK+ normally works with other libs, I get this error with this lib (same code as above)

Traceback (most recent call last):
  File "drive.py", line 25, in <module>
    main()
  File "drive.py", line 10, in main
    with Sphero(mac_address=mac_address) as sphero:
  File "/home/gazihan/baresphero/pysphero/pyspherovenv/lib/python3.7/site-packages/pysphero/core.py", line 210, in __enter__
    self.sphero_core = SpheroCore(self.mac_address)
  File "/home/gazihan/baresphero/pysphero/pyspherovenv/lib/python3.7/site-packages/pysphero/core.py", line 84, in __init__
    self.ch_api_v2 = self.get_characteristic(uuid=SpheroCharacteristic.api_v2.value)
  File "/home/gazihan/baresphero/pysphero/pyspherovenv/lib/python3.7/site-packages/pysphero/core.py", line 137, in get_characteristic
    return self.peripheral.getCharacteristics(uuid=uuid)[0]
  File "/home/gazihan/baresphero/pysphero/pyspherovenv/lib/python3.7/site-packages/bluepy/btle.py", line 508, in getCharacteristics
    rsp = self._getResp('find')
  File "/home/gazihan/baresphero/pysphero/pyspherovenv/lib/python3.7/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/home/gazihan/baresphero/pysphero/pyspherovenv/lib/python3.7/site-packages/bluepy/btle.py", line 368, in _waitResp
    raise BTLEGattError("Bluetooth command failed", resp)
bluepy.btle.BTLEGattError: Bluetooth command failed (code: 10, error: No attribute found within the given range)

with that gatt branch I get

Traceback (most recent call last):
  File "drive.py", line 4, in <module>
    from pysphero.core import Sphero
  File "/home/gazihan/baresphero/pysphero/pysphero-gatt-python/pysphero/core.py", line 20, in <module>
    class SpheroDevice(Device):
  File "/home/gazihan/baresphero/pysphero/pysphero-gatt-python/pysphero/core.py", line 74, in SpheroDevice
    def write(self, uuid: str, packet: Packet, timeout: float = 2.0, future: Future[Packet] = None) -> None:
TypeError: 'type' object is not subscriptable

though I have BlueZ 5.37, it may be causing issues because gatt suggests >=5.38. I don't want to break this working setup at the moment, so I guess I'll leave it at this for now and focus on trying to find what's different between the Linux desktop and the Raspberry Pi 4...

@EnotYoyo
Copy link
Owner

EnotYoyo commented Feb 5, 2020

In the near future I will try to rewrite to bleak :(

@gazialankus
Copy link
Author

I managed making the RPi 4 work with the regular Sphero BLE codes such as this (clean install raspbian, full upgrade). Before that BlueZ was disconnecting right after connect, now it works.

With this working system I'll try to give another shot at your code and other branch. Just wanted to say that the above error messages are from the "broken" RPi4 installation.

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