Skip to content
Advertisement

How should I use this hexadecimal data to send ble command to device?

I have a chinese manual for this ble relay board which seems to state that in order to activate relay #1 the command sent is:

C5 04 as a prefix 12345678 for the password part AA as a suffix

How do I send this from a python script? I used this in the past:

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()

for a different board. I know the bluepy code is fine, its just the command that I need to change.

I pasted the image translated from the manual: enter image description here

After trying this code:

  password = '12345678'
  response = c.write('xC5x04' + password + 'xAA', withResponse=True)

I get this error:

Traceback (most recent call last):
  File "1on.py", line 54, in <module>
    letsgobaby()
  File "1on.py", line 46, in letsgobaby
    response = c.write('xC5x04' + 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

Advertisement

Answer

I can suggest to change your output to something like:

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

This way it’ll send over the appropriate values according to that documentation.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement