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

Scan and press fails with firmware v4.7 #13

Closed
kyori19 opened this issue Apr 21, 2020 · 2 comments
Closed

Scan and press fails with firmware v4.7 #13

kyori19 opened this issue Apr 21, 2020 · 2 comments

Comments

@kyori19
Copy link

kyori19 commented Apr 21, 2020

I recently bought a switchbot and tried to control with api and python.
But scanning and controlling the bot don't work.

Steps to reproduce

  • Scan

    from switchbot import Scanner
    s = Scanner()
    m = s.scan() # Push "Pair with Remote" in SwitchBot app

    Error:

    Can't init device hci0: Connection timed out (110)
    ERROR:pygatt.backends.gatttool.gatttool:Unexpected error when scanning: Invalid device: Network is down
    
    Traceback (most recent call last):
      File "/home/pi/.local/share/virtualenvs/switchbot-rpEz6xuZ/lib/python3.7/site-packages/pexpect/spawnbase.py", line 166, in read_nonblocking
        s = os.read(self.child_fd, size)
    OSError: [Errno 5] Input/output error
    

    I can get same error when I use flask api.

  • Press button (Interactive Only)

    b = Bot(mac = "xx:xx:xx:xx:xx:xx", id = 1, name = "Bedroom Light")
    b.press()

    Error:

    Can't init device hci0: Connection timed out (110)
    ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to CF:BF:8B:68:CB:8F after 5.0 seconds.
    ERROR:switchbot:pygatt: failed to connect to ble device
    Traceback (most recent call last):
      File "/home/pi/.local/share/virtualenvs/switchbot-rpEz6xuZ/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 415, in connect
        self.sendline(cmd)
      File "/usr/lib/python3.7/contextlib.py", line 119, in __exit__
        next(self.gen)
      File "/home/pi/.local/share/virtualenvs/switchbot-rpEz6xuZ/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 191, in event
        self.wait(event, timeout)
      File "/home/pi/.local/share/virtualenvs/switchbot-rpEz6xuZ/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 157, in wait
          raise NotificationTimeout()
    pygatt.exceptions.NotificationTimeout: None
    

Environment

  • SwitchBot Bot Firmware v4.7
  • Raspberry Pi 3B+ Raspbian Buster Lite
@nicolas-kuechler
Copy link
Collaborator

@kyori19
Hi, I don't have a bot with firmware 4.7 available but I don't think that this is the problem here.

It looks like the ble library that I use (pygatt) has problems to connect.
This could be because some software packages are not up to date.
I would recommend that you try the following:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install build-essential libssl-dev libffi-dev python-dev
  • remove the Pipefile.lock file and reinstall the environement with pipenv install in the root directory of switchbot
  • sudo reboot reboot your raspberry pi

btw. the scanning requires root privileges (but it would show you a different error).
Here there is a link which describes how to circumvent this:
https://www.raspberrypi.org/forums/viewtopic.php?t=151858

Let me know if this fixed your problem.

@kyori19
Copy link
Author

kyori19 commented Apr 21, 2020

@nicolas-kuechler Thanks for your comment.

Reinstall fixed all errors and now works fine.
Scan works without using mobile app.

btw. the scanning requires root privileges (but it would show you a different error).

I fixed that issue by this command.

sudo setcap 'cap_net_raw,cap_net_admin+eip' `which hcitool`

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