Python 如何使用此十六进制数据向设备发送ble命令?
我有一本关于ble继电器板的中文手册,其中似乎说明,为了激活继电器#1,发送的命令是: C504作为前缀 密码部分为12345678 AA作为后缀 如何从python脚本发送此消息?我过去用过这个:Python 如何使用此十六进制数据向设备发送ble命令?,python,Python,我有一本关于ble继电器板的中文手册,其中似乎说明,为了激活继电器#1,发送的命令是: C504作为前缀 密码部分为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 = 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代码很好,它只是我需要更改的命令
我粘贴了从手册翻译过来的图像:
尝试此代码后:
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
回溯(最近一次呼叫最后一次):
文件“1on.py”,第54行,在
letsgobaby()
letsgobaby中第46行的文件“1on.py”
response=c.write('\xC5\x04'+password+'\xAA',withResponse=True)
文件“/usr/local/lib/python2.7/dist packages/bluepy/btle.py”,第168行,写入
返回self.peripheral.writeCharacteristic(self.valHandle,val,withResponse)
文件“/usr/local/lib/python2.7/dist packages/bluepy/btle.py”,第520行,writeCharacteristic
返回自我。_getResp('wr'))
文件“/usr/local/lib/python2.7/dist-packages/bluepy/btle.py”,第376行,在
resp=self.\u waitResp(wantType+['ntfy','ind'],超时)
文件“/usr/local/lib/python2.7/dist packages/bluepy/btle.py”,第331行,in_waitResp
引发BTLEException(BTLEException.DISCONNECTED,“设备断开”)
bluepy.btle.BTLEException:设备已断开连接
我可以建议您将输出更改为:
password = '12345678' # Or whatever it may have changed to
c.write('\xC5\x04' + password + '\xAA')
通过这种方式,它将根据该文档发送适当的值。这是bluepy吗?是的,它是ian harvey/bluepyOk。它没有激活中继,我作为最后一个呼叫得到了它……实际上在OPOh中发布了它,等等,我得到了!我删除了withResponse=True,只留下c.write命令,它就可以工作了!谢谢