[英]How should I use this hexadecimal data to send ble command to device?
我有這個 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 代碼很好,它只是我需要更改的命令。
嘗試此代碼后:
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')
這樣,它將根據該文檔發送適當的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.