0

I have this code I want to write the decimal value 1 to a ble device from a python script using bluepy:

#!/usr/bin/env python

import bluepy.btle as btle
print ("outside")

def letsgobaby():
  print ("turning1on")
  p = btle.Peripheral("bb:00:00:15:27:19") #zl-rc04a

  # GET SERVICES
  services=p.getServices()
  for service in services:
     print service

  # NORMAL get to write to ...
  s = p.getServiceByUUID("0000ffe0-0000-1000-8000-00805f9b34fb") #ffe0
  c = s.getCharacteristics()[0]

  #1 is relay1on, 2 is relay1off
  c.write(1)
  p.disconnect()

if __name__ == "__main__":
  letsgobaby()

but I get this error:

pi@raspberrypi:~/Documents/python/failedPythonBLE $ python 1on.py
outside
turning1on
Hallo from Peripheral
discovering services
Hello
Service <uuid=Generic Attribute handleStart=8 handleEnd=11>
Service <uuid=Generic Access handleStart=1 handleEnd=7>
commonName= 0000ffe0-0000-1000-8000-00805f9b34fb
commonName= ffe0
Service <uuid=ffe0 handleStart=12 handleEnd=17>
17
Traceback (most recent call last):
File "1on.py", line 43, in <module>
letsgobaby()
File "1on.py", line 39, in letsgobaby
c.write(1)
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 519, in writeCharacteristic
self._writeCmd("%s %X %s\n" % (cmd, handle, binascii.b2a_hex(val).decode('utf-8')))
TypeError: must be string or buffer, not int
sshashank124
  • 31,495
  • 9
  • 67
  • 76
marciokoko
  • 4,988
  • 8
  • 51
  • 91

0 Answers0