gpt4 book ai didi

python - 我应该如何使用这个十六进制数据向设备发送 ble 命令?

转载 作者:行者123 更新时间:2023-12-01 06:35:51 25 4
gpt4 key购买 nike

我有这个 ble 继电器板的中文手册,其中似乎指出为了激活继电器 #1,发送的命令是:

C5 04 作为前缀12345678 为密码部分AA作为后缀

如何从 python 脚本发送此内容?我过去用过这个:

p = btle.Peripheral("bb:00:00:15:27:19")
s = p.getServiceByUUID("0000ffe0-0000-1000-8000-00805f9b34fb") #ffe0
c = s.getCharacteristics()[0]
c.write("e")
p.disconnect()

对于不同的板。我知道 bluepy 代码很好,它只是我需要更改的命令。

我粘贴了从手册翻译的图像: enter image description here

尝试此代码后:

  password = '12345678'
response = c.write('\xC5\x04' + password + '\xAA', withResponse=True)

我收到此错误:

Traceback (most recent call last):
File "1on.py", line 54, in <module>
letsgobaby()
File "1on.py", line 46, in letsgobaby
response = c.write('\xC5\x04' + password + '\xAA', withResponse=True)
File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 168, in write
return self.peripheral.writeCharacteristic(self.valHandle, val, withResponse)
File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 520, in writeCharacteristic
return self._getResp('wr')
File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 376, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 331, in _waitResp
raise BTLEException(BTLEException.DISCONNECTED, "Device disconnected")
bluepy.btle.BTLEException: Device disconnected

最佳答案

我可以建议将您的输出更改为:

password = '12345678'            # Or whatever it may have changed to
c.write('\xC5\x04' + password + '\xAA')

这样它将根据该文档发送适当的值。

关于python - 我应该如何使用这个十六进制数据向设备发送 ble 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59673057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com