python - 'BluetoothSocket' is not defined -
i trying set bluetooth server on raspberry pi using python. have error 'bluetoothsocket' not defined, however, followed sample code on bluez repository.
however, have installed required libraries.
from bluetooth import * server_sock=bluetoothsocket( rfcomm ) server_sock.bind(("",port_any)) server_sock.listen(1) port = server_sock.getsockname()[1] uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee" advertise_service( server_sock, "sampleserver", service_id = uuid, service_classes = [ uuid, serial_port_class ], profiles = [ serial_port_profile ], # protocols = [ obex_uuid ] ) print("waiting connection on rfcomm channel %d" % port) client_sock, client_info = server_sock.accept() print("accepted connection ", client_info) try: while true: data = client_sock.recv(1024) if len(data) == 0: break print("received [%s]" % data) except ioerror: pass print("disconnected") client_sock.close() server_sock.close() print("all done")
this version:
pi@tolotrapi:~ $ sudo apt-get install python-bluez reading package lists... done building dependency tree reading state information... done python-bluez newest version. 0 upgraded, 0 newly installed, 0 remove , 161 not upgraded. pi@tolotrapi:~ $ sudo apt-get install bluez reading package lists... done building dependency tree reading state information... done bluez newest version. 0 upgraded, 0 newly installed, 0 remove , 161 not upgraded. pi@tolotrapi:~ $ python --version python 2.7.9
what doing wrong?
Comments
Post a Comment