EnotYoyo / pysphero

Unofficial Sphero V2 api for bluetooth low energy toys
MIT License
42 stars 15 forks source link

Unable to detect my Sphero Bolt; toy not found exception #7

Closed stevo399 closed 4 years ago

stevo399 commented 4 years ago

I am running PySphero on an Ubuntu 18.04 LTS installation in VMware, on Python 3.6. When running examples/find_toy.py, I cannot find my sphero bolt; after a second it just gives a toy not found error. I know it's not my hardware as using the Sphero EDU app in windows on the same machine I can connect to it without error. is there something I need to do aside from installing bluepy and pysphero to get it working? Bolt was the one toy this was tested and found to work on I believe.

EnotYoyo commented 4 years ago

Can you connect to sphero using mac address? This example.

EnotYoyo commented 4 years ago

Did you enable bluetooth sharing?

stevo399 commented 4 years ago

Bluetooth sharing is enabled on the vm, still same result. The example tries to connect to a device with the mac address "aa:bb:cc:dd:ee:ff" by default. Was I supposed to change this? I did not, and just tried running the example, and bluepy returned a connection error. Thanks for your help so far, hoping to get this figured out!

EnotYoyo commented 4 years ago

Um... You should execute python with root privilege for using bluepy. I tried execute example without root and I got PySpheroNotFoundError. Try to run example with root privilege.

stevo399 commented 4 years ago

sudo python3 examples/find_toy.py and sudo python3 examples/wake.py The result is the same. Do I need to pair the device in any way to my machine before running this code?

EnotYoyo commented 4 years ago

Ok. Let's check the bluepy and bluetooth. Please, run this code and send output:

from bluepy.btle import Scanner, DefaultDelegate

class ScanDelegate(DefaultDelegate):
    def __init__(self):
        DefaultDelegate.__init__(self)

    def handleDiscovery(self, dev, isNewDev, isNewData):
        if isNewDev:
            print("Discovered device", dev.addr)
        elif isNewData:
            print("Received new data from", dev.addr)

scanner = Scanner().withDelegate(ScanDelegate())
devices = scanner.scan(10.0)

for dev in devices:
    print("Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi))
    for (adtype, desc, value) in dev.getScanData():
        print("  %s = %s" % (desc, value))

This is copy-paste from bluepy docs.

stevo399 commented 4 years ago

Well, I think we may have found the problem.

After running sudo python3 blue_test.py:

Traceback (most recent call last): File "blue_test.py", line 13, in devices = scanner.scan(10.0) File "/home/stevo399/.local/lib/python3.6/site-packages/bluepy/btle.py", line 852, in scan self.start(passive=passive) File "/home/stevo399/.local/lib/python3.6/site-packages/bluepy/btle.py", line 790, in start self._mgmtCmd("le on") File "/home/stevo399/.local/lib/python3.6/site-packages/bluepy/btle.py", line 312, in _mgmtCmd raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp) bluepy.btle.BTLEManagementError: Failed to execute management command 'le on' (code: 12, error: Not Supported)

EnotYoyo commented 4 years ago

See this issue. Maybe it help you.

stevo399 commented 4 years ago

I think it was a hardware issue more than anything. This package works with the pi3, which I got and tested it on this week. I'm guessing it was an issue with my computer's hardware or the vm.

gazialankus commented 4 years ago

This should help with this issue: https://github.com/IanHarvey/bluepy/issues/218#issuecomment-350680433

In my venv, the bluepy-helper executable is here: sudo setcap 'cap_net_raw,cap_net_admin+eip' venv/lib/python3.7/site-packages/bluepy/bluepy-helper

zzrs123 commented 2 years ago

I am running PySphero on an Ubuntu 20.04 LTS with Python 3.8.10 Maybe I 'm not good at programming on Ubuntu. I don't know how to connect my sphero bolt, because I can't find my device in my bluetooth list(gui on upper right corner). Maybe I don't know how to start pysphero? Here is my oprations:

install the vscode
try run code core.py、wake.py, but it doesn't work.
Traceback (most recent call last):
File "/home/zzrs123/Pysphero/pysphero/examples_lmq/wake.py", line 22, in
main()
File "/home/zzrs123/Pysphero/pysphero/examples_lmq/wake.py", line 10, in main
with Sphero(mac_address=mac_address) as sphero:
File "/home/zzrs123/.local/lib/python3.8/site-packages/pysphero/core.py", line 49, in enter
self._ble_adapter = self._ble_adapter_cls(self.mac_address)
File "/home/zzrs123/.local/lib/python3.8/site-packages/pysphero/bluetooth/gatt_adapter.py", line 39, in init
ch_force_band = self._find_characteristic(SpheroCharacteristic.force_band.value)
File "/home/zzrs123/.local/lib/python3.8/site-packages/pysphero/bluetooth/gatt_adapter.py", line 56, in _find_characteristic
raise PySpheroRuntimeError(f"Characteristic {characteristic} not found")
pysphero.exceptions.PySpheroRuntimeError: Characteristic 00020005-574f-4f20-5370-6865726f2121 not found