KanoComputing / community-sdk

Scripts, tools and libraries to help you to interact with your Kano Devices in your favourite programming language.
MIT License
31 stars 11 forks source link

python library: get_x functions on PIxel object not working #10

Closed netmanchris closed 5 years ago

netmanchris commented 5 years ago

Environment: macOS Mojave Python version

sys.version
'3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'

Having issues with pixel python code status methods on pixel class object. In the example below you can see that I have an object of <class 'communitysdk.retailpixelkit.RetailPixelKitSerial'> that is in a connected state. I used the connect_to_wifi method to ensure that it was connected and response suggests that it worked as I'm getting a valid IP address for this network.

When I run the .get_wifi_status method on this object. I get the error below. This is consistent with the get_battery function as well.

my_pixel.connect()
my_pixel.is_connected
True
my_pixel.connect_to_wifi("my_network", "my_secret")
{'ssid': 'my_network', 'mac_address': '30AEA40D8858', 'connected': True, 'signal_strenth': -82, 'ip': '10.101.0.142', 'netmask': '255.255.255.0', 'gateway': '10.101.0.1'}
list_connected_devices()
[<communitysdk.retailpixelkit.RetailPixelKitSerial object at 0x10546db38>]
my_pixel.get_wifi_status()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/christopheryoung/PycharmProjects/community-sdk/communitysdk/retailpixelkit.py", line 52, in get_wifi_status
    return self.rpc_request('wifi-status', [])
  File "/Users/christopheryoung/PycharmProjects/community-sdk/communitysdk/rpcclient.py", line 76, in rpc_request
    self.loop.run_until_complete(tasks)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 466, in run_until_complete
    return future.result()
  File "/Users/christopheryoung/PycharmProjects/community-sdk/communitysdk/rpcclient.py", line 53, in wait_for_response
    raise TimeoutError('Request timed out')
TimeoutError: Request timed out

The get_battery_status method also appears to be having issues, but with slightly different output.

my_pixel.get_battery_status()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/christopheryoung/PycharmProjects/community-sdk/communitysdk/retailpixelkit.py", line 49, in get_battery_status
    return self.rpc_request('battery-status', [])
  File "/Users/christopheryoung/PycharmProjects/community-sdk/communitysdk/rpcclient.py", line 76, in rpc_request
    self.loop.run_until_complete(tasks)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 466, in run_until_complete
    return future.result()
  File "/Users/christopheryoung/PycharmProjects/community-sdk/communitysdk/rpcclient.py", line 53, in wait_for_response
    raise TimeoutError('Request timed out')
TimeoutError: Request timed out
Future exception was never retrieved
future: <Future finished exception=SerialException('read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)',)>
Traceback (most recent call last):
  File "/Users/christopheryoung/VENVpyawair/lib/python3.6/site-packages/serial/serialposix.py", line 501, in read
    'device reports readiness to read but returned no data '
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/christopheryoung/PycharmProjects/community-sdk/communitysdk/serialdevice.py", line 45, in poll_data
    msg = self.connection.readline()
  File "/Users/christopheryoung/VENVpyawair/lib/python3.6/site-packages/serial/serialposix.py", line 509, in read
    raise SerialException('read failed: {}'.format(e))
serial.serialutil.SerialException: read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
murilopolese commented 5 years ago

Interesting! I'll have a look on this first thing on Monday!

murilopolese commented 5 years ago

@netmanchris github went a bit crazy yesterday but I did try the code you mentioned above and I wasn't able to reproduce your issue.

One thing I did notice is that whenever the board disconnects the is_connected property won't update. Perhaps that was the problem? Does that make sense?

netmanchris commented 5 years ago

@murilopolese Makes sense! I'll test this out and update with results.

murilopolese commented 5 years ago

Hey, @netmanchris ! Did you have any luck finding out if it was really a connection error or a different bug? I'm keen to add this to the things to fix on next sprint of development!

murilopolese commented 5 years ago

Hey @netmanchris! Did you have any luck finding out if this was a connection problem? Otherwise I'd like to close this issue :)

netmanchris commented 5 years ago

Let's close the issue. Issue seems to have resolved itself. Not sure what I did or didn't do differently.

murilopolese commented 5 years ago

Hey @netmanchris !

Reading again and carefully your logs it seems that was a connection problem.

my_pixel.get_wifi_status()
Traceback (most recent call last):
    ...
    raise TimeoutError('Request timed out')
TimeoutError: Request timed out
my_pixel.get_battery_status()
Traceback (most recent call last):
    ...
    raise SerialException('read failed: {}'.format(e))
serial.serialutil.SerialException: read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)