ph4r05/ph4-walkingpad

Problem running from console on raspberry pi

Closed this issue · 6 comments

Hi thanks for the script it works great through jupyter notebook on my PC.

However, I would like to run this on my raspberry pi with Home Assistant. When I try to run it in terminal I get it to connect to WalkingPad but I'm unable to start it or do anything beyond that. It gives this error:

  ph4-walkingpad-master python3
Python 3.9.5 (default, May 12 2021, 20:44:22) 
[GCC 10.3.1 20210424] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> import coloredlogs
>>> import asyncio 
>>> 
>>> from ph4_walkingpad import pad
>>> from ph4_walkingpad.pad import Scanner, WalkingPad, WalkingPadCurStatus, WalkingPadLastStatus, Controller
>>> from ph4_walkingpad.utils import setup_logging
>>> 
>>> log = setup_logging()
>>> pad.logger = log
>>> #coloredlogs.install(level=logging.INFO)
>>> ctler = Controller()
>>> async def run():
...     await ctler.run('57:4C:4E:1F:6C:12')
... 
>>> asyncio.run(run())
/config/ph4-walkingpad-master/ph4_walkingpad/pad.py:332: FutureWarning: is_connected has been changed to a property. Calling it as an async method will be removed in a future version
  x = await client.is_connected()
Connected: True
[Service] 0000180a-0000-1000-8000-00805f9b34fb: Device Information
        [Characteristic] 00002a25-0000-1000-8000-00805f9b34fb: (Handle: 9) (read) | Name: Serial Number String, Value: b'Serial Number\x00' 
        [Characteristic] 00002a26-0000-1000-8000-00805f9b34fb: (Handle: 11) (read) | Name: Firmware Revision String, Value: b'M30_V187.2.0\x00' 
        [Characteristic] 00002a28-0000-1000-8000-00805f9b34fb: (Handle: 13) (read) | Name: Software Revision String, Value: b'Hardware Revision\x00' 
        [Characteristic] 00002a24-0000-1000-8000-00805f9b34fb: (Handle: 15) (read) | Name: Model Number String, Value: b'WLT8266M\x00' 
        [Characteristic] 00002a29-0000-1000-8000-00805f9b34fb: (Handle: 17) (read) | Name: Manufacturer Name String, Value: b'Software Revision\x00' 
[Service] 0000fe00-0000-1000-8000-00805f9b34fb: Vendor specific
        [Characteristic] 0000fe01-0000-1000-8000-00805f9b34fb: (Handle: 20) (read,notify) | Name: Vendor specific, Value: None 
                [Descriptor] 00002902-0000-1000-8000-00805f9b34fb: (Handle: 22) | Value: b'\x00\x00' 
        [Characteristic] 0000fe02-0000-1000-8000-00805f9b34fb: (Handle: 23) (write-without-response) | Name: Vendor specific, Value: None 
[Service] 00010203-0405-0607-0809-0a0b0c0d1912: Unknown
        [Characteristic] 00010203-0405-0607-0809-0a0b0c0d2b12: (Handle: 26) (read,write-without-response) | Name: Unknown, Value: b'\x00' 
                [Descriptor] 00002901-0000-1000-8000-00805f9b34fb: (Handle: 28) | Value: b'OTA' 
Enabling notification for 0000fe01-0000-1000-8000-00805f9b34fb
Service enumeration done
>>> async def start():
...     await ctler.switch_mode(WalkingPad.MODE_MANUAL)
...     await asyncio.sleep(1.0)
...     await ctler.start_belt()
... 
>>> asyncio.run(start())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "<stdin>", line 2, in start
  File "/config/ph4-walkingpad-master/ph4_walkingpad/pad.py", line 267, in switch_mode
    return await self.send_cmd(cmd)
  File "/config/ph4-walkingpad-master/ph4_walkingpad/pad.py", line 257, in send_cmd
    return await self.send_cmd_raw(cmd)
  File "/config/ph4-walkingpad-master/ph4_walkingpad/pad.py", line 262, in send_cmd_raw
    r = await self.client.write_gatt_char(self.char_fe02, cmd)
  File "/usr/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 787, in write_gatt_char
    reply = await self._bus.call(
  File "/usr/lib/python3.9/site-packages/dbus_next/aio/message_bus.py", line 303, in call
    self._call(msg, reply_handler)
  File "/usr/lib/python3.9/site-packages/dbus_next/message_bus.py", line 588, in _call
    self.send(msg)
  File "/usr/lib/python3.9/site-packages/dbus_next/aio/message_bus.py", line 326, in send
    self._writer.schedule_write(msg, future)
  File "/usr/lib/python3.9/site-packages/dbus_next/aio/message_bus.py", line 85, in schedule_write
    self.loop.add_writer(self.fd, self.write_callback)
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 346, in add_writer
    self._add_writer(fd, callback, *args)
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 295, in _add_writer
    self._check_closed()
  File "/usr/lib/python3.9/asyncio/base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Thanks for the report. I will take a look.

Many thanks,

Maybe it's just something dumb that I'm doing.. I would like to get it working on raspberry so that I can eventually make Home Assistant integration :)

@Yersi88 could you pls try the newest master ed211c676c994092c925ae51adfe268affdd1e97? I could not replicate this on my rasp. Thanks!

@Yersi88 I've released a new version fixing other problems. Pls give it a try. I am closing this issue due to innactivity, if it happens again, pls reopen.

Hello, I finally had time to play with this again. I installed with pip on my raspberry with home assistant and it does work just fine now!

I would like to make custom HA integration, hopefully I will be able to pull it off, should be doable with your pip package :)

Many thanks!

@Yersi88 if you want testers for that, I'd love to help out!