jannopet / LEGO-WeDo-2.0-Python-SDK

Python SDK for LEGO WeDo 2.0
MIT License
35 stars 18 forks source link

Bothersome issues #1

Open Githubmoses opened 6 years ago

Githubmoses commented 6 years ago

First off let me say WOW. Thank you. I am a newbie and attempting to help my daughter connect her wedo2 to her raspberry pi. We are learning python together. We installed your SDK, and were successful at connection the hub to the pi. However, we get this error message and can't figure out what it means. Anybody's thoughts, comments or help would be greatly appreciated.

hub = Smarthub() Traceback (most recent call last): File "", line 1, in File "/home/pi/.local/lib/python2.7/site-packages/wedo2/smarthub.py", line 29, in init device_address = devices[0]['address'] IndexError: list index out of range hub = Smarthub() Traceback (most recent call last): File "", line 1, in File "/home/pi/.local/lib/python2.7/site-packages/wedo2/smarthub.py", line 32, in init self.service_manager = ServiceManager(self.io) File "/home/pi/.local/lib/python2.7/site-packages/wedo2/bluetooth/service_manager.py", line 15, in init self.find_available_services() File "/home/pi/.local/lib/python2.7/site-packages/wedo2/bluetooth/service_manager.py", line 26, in find_available_services self.create_services(self.services_data) File "/home/pi/.local/lib/python2.7/site-packages/wedo2/bluetooth/service_manager.py", line 31, in create_services service = LegoServiceFactory.create(connect_info, self.io) TypeError: unbound method create() must be called with LegoServiceFactory instance as first argument (got ConnectInfo instance instead)

Githubmoses commented 6 years ago

Subsequently attempting without the assignment:

Smarthub.turn_motor(80) Traceback (most recent call last): File "", line 1, in TypeError: unbound method turn_motor() must be called with Smarthub instance as first argument (got int instance instead)

We don't understand how to fix it and please forgive our learning curve and ignorance if this problem is obvious.

jannopet commented 6 years ago

First of all, sorry for not responding in any timely manner, I haven't been checking in on this repository for quite a while. Concerning the error you got, the line IndexError: list index out of range would lead me to believe that during the initialization of the hub, while executing hub = Smarthub(), the Smarthub was not detected by the Bluetooth adapter.

Assuming that the Bluetooth LE is working properly for the Raspberry PI, I think that the error appeared because the Smarthub wasn't "active" i.e. ready for connections. Make sure that you click the green button on top of the Smarthub beforehand and run the python script while the LED light on the Smarthub is blinking, indicating that it's ready for connections. You also said that you were already able to connect the Raspberry PI to the Smarthub, so I'm guessing that this is why the error appeared.

Regarding the second error, you can't really call out the methods in Smarthub class without first creating an instance of the class. For example, hub = Smarthub() creates an instance of the class Smarthub (also while doing so, it creates a connection between the Smarthub and your device), and saves it into a variable called "hub". All the methods in Smarthub class are instance methods, meaning they can only be called with an instance. So instead of Smarthub.turn_motor(80), you could use hub = Smarthub() and hub.turn_motor(80).