Bluetooth server with Python 3.3 -
python 3.3 came native support bluetooth sockets. unfortunately, it's not documented yet (there 1 mention of in documentation).
googling there a blog post implementing client, couldn't find creating server.
more specifically, how set user-friendly name , advertise service.
so, like
import socket serversocket = socket.socket(socket.af_bluetooth, socket.sock_stream, socket.btproto_rfcomm) serversocket.settimeout(1) serversocket.bind(("", 1)) serversocket.listen(1) something.advertise_service(something something)
any ideas?
bad news: python doesn't appear support want out of box. (at least not in socketmodule.c).
most of python/bluetooth users i've seen use pybluez
although hasn't been updated since 2009.
good news: went through source (for linux connections), , found relevant bits advertising services. of code copy-pasted python 2.2 version of socketmodule.c
.
pybluez
define additional functionality socket
object implement bluetooth goodies. doesn't low-level, , instead depends on bluez
that. can tell, takes python objects , creates data structures expected bluez
, calls that. if don't want to/can't use pybluez
, you'll have somehow implement missing functionality. think may able c-types. relevant parts advertising service in btmodule.c, lines 2562-2642.
there python-3 branch in source pybluez
, although don't know if works or not.
if decide use pybluez
, example taken their source
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 ], )
as google code closing, code can found on github here.
Comments
Post a Comment