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

Invalid handle on all commands #43

Open
dcarrion87 opened this issue Jan 20, 2023 · 8 comments
Open

Invalid handle on all commands #43

dcarrion87 opened this issue Jan 20, 2023 · 8 comments
Assignees
Labels

Comments

@dcarrion87
Copy link

dcarrion87 commented Jan 20, 2023

Running on a Raspberry Pi 4 using the inbuilt BT adapter

I've attempted to use the switchbot_py3.py as well as doing this myself and get the following when sending the handles which it should be sending:

gattlib.GATTException: Characteristic value/descriptor operation failed: Invalid handle

E.g.

python3 switchbot_py3.py -d XX:XX:XX:XX:XX:XX -c on
Connected!
Traceback (most recent call last):
  File "/root/python-host/switchbot_py3.py", line 180, in <module>
    main()
  File "/root/python-host/switchbot_py3.py", line 175, in main
    driver.run_command(opts.command)
  File "/root/python-host/switchbot_py3.py", line 124, in run_command
    return req.write_by_handle(self.handles[command], self.commands[command])
gattlib.GATTException: Characteristic value/descriptor operation failed: Invalid handle

Is there a change to the commands/handles with Switchbot Bot version 5?

@dcarrion87
Copy link
Author

Not sure if this helps at all with troubleshooting:

# gatttool -t random -b XX:XX:XX:XX:XX:XX --characteristics
handle = 0x0002, char properties = 0x20, char value handle = 0x0003, uuid = 00002a05-0000-1000-8000-00805f9b34fb
handle = 0x0006, char properties = 0x02, char value handle = 0x0007, uuid = 00002a00-0000-1000-8000-00805f9b34fb
handle = 0x0008, char properties = 0x02, char value handle = 0x0009, uuid = 00002a01-0000-1000-8000-00805f9b34fb
handle = 0x000a, char properties = 0x02, char value handle = 0x000b, uuid = 00002a04-0000-1000-8000-00805f9b34fb
handle = 0x000c, char properties = 0x02, char value handle = 0x000d, uuid = 00002aa6-0000-1000-8000-00805f9b34fb
handle = 0x000f, char properties = 0x0c, char value handle = 0x0010, uuid = cba20002-224d-11e6-9fb8-0002a5d5c51b
handle = 0x0011, char properties = 0x10, char value handle = 0x0012, uuid = cba20003-224d-11e6-9fb8-0002a5d5c51b
# gatttool -t random -b XX:XX:XX:XX:XX:XX --char-write-req -a 0x0016 -n 570101
Characteristic Write Request failed: Invalid handle

# gatttool -t random -b XX:XX:XX:XX:XX:XX --char-write-req -a 0x0016 -n 570102
Characteristic Write Request failed: Invalid handle

@BroZer8360
Copy link

BroZer8360 commented Jan 20, 2023

Let's write in here @dcarrion87
Did you tried
sudo python2 switchbot.py <mac_adress> Bot Turn On
And what's the error message ?

Edit : <Mac_adress> is to be replaced by the mac adresse of your device, it's shown in the mobile app and is like this format : XX:XX:XX:XX:XX:XX with X from 0 to 9 and from A to F

@dcarrion87
Copy link
Author

dcarrion87 commented Jan 20, 2023

@BroZer8360 I don't have python2 on this system no error message for the switchbot_py2topy3.py converted one but doubt it would show an error as it's just firing the command and not listening for a response. Nothing happening on the bot.

# sudo switchbot_py2topy3.py XX:XX:XX:XX:XX:XX Bot Turn On
Preparing to connect.
Connection successful.
Complete

Not showing mac address for identification reasons.

@dcarrion87
Copy link
Author

I was able to get this working with this project https://github.com/Danielhiversen/pySwitchbot

E.g.:

from switchbot import Switchbot
from bleak import BleakScanner
import asyncio

async def main():
  ble_device = await BleakScanner.find_device_by_address("MAC ADDRESS", timeout=20)
  device = Switchbot(ble_device)
  await device.turn_off()

if __name__ == "__main__":
  asyncio.run(main())

Looks like there's differences in how it handles.

@allegewhd
Copy link

same problem with fireware 6.3. OS is ubuntu 20.04

> gatttool -t random -b switch_bot_with_fireware_6.3_mac  --char-write-req -a 0x0016 -n 570101
Characteristic Write Request failed: Invalid handle

 > gatttool -t random -b switch_bot_with_fireware_4.9_mac  --char-write-req -a 0x0016 -n 570101
Characteristic value was written successfully

@peterneutron
Copy link

@dcarrion87 This is all very strange and almost looks like either the BLE API is abandoned in favour of the Hub or the documentation is totally out of date regarding newer Bots. As it seems newer Bots can't be controlled anymore using just BLE and instead require the App or a Hub. See my issue here OpenWonderLabs/SwitchBotAPI-BLE#25 (comment)

@zedrdave
Copy link

zedrdave commented Jul 3, 2023

Based on replies on that other thread, does this seem to address the problem above?

@mesigned
Copy link

mesigned commented Dec 17, 2023

I ran into the same issue using the switchbot_py3.py file. Interestingly using the switchbot_py2topy3.py file worked for me.
What I noticed was that the command used to e.g. turn on the switchbot looked like this:

> gatttool -t random -b XX:XX:XX:XX:XX:XX --char-write-req -a 0x0013 -n 570101
Characteristic value was written successfully

I spent quite some hours searching for a package that works, hopefully this information is of use to someone.
Switchbot running on firmware version 6.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests