RFCOMM sem emparelhamento usando PyBluez no Debian?
Eu estou tentando criar um processo de servidor RFCOMM com Python que pode ser usado sem a necessidade de emparelhamento. Inicialmente, peguei os dois scripts de exemplo da documentação do PyBluez:
Servidor:
# file: rfcomm-server.py
# auth: Albert Huang <[email protected]>
# desc: simple demonstration of a server application that uses RFCOMM sockets
#
# $Id: rfcomm-server.py 518 2007-08-10 07:20:07Z albert $
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 for connection on RFCOMM channel %d" % port
client_sock, client_info = server_sock.accept()
print "Accepted connection from ", 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"
Cliente:
# file: rfcomm-client.py
# auth: Albert Huang <[email protected]>
# desc: simple demonstration of a client application that uses RFCOMM sockets
# intended for use with rfcomm-server
#
# $Id: rfcomm-client.py 424 2006-08-24 03:35:54Z albert $
from bluetooth import *
import sys
addr = None
if len(sys.argv) < 2:
print "no device specified. Searching all nearby bluetooth devices for"
print "the SampleServer service"
else:
addr = sys.argv[1]
print "Searching for SampleServer on %s" % addr
# search for the SampleServer service
uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"
service_matches = find_service( uuid = uuid, address = addr )
if len(service_matches) == 0:
print "couldn't find the SampleServer service =("
sys.exit(0)
first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]
print "connecting to \"%s\" on %s" % (name, host)
# Create the client socket
sock=BluetoothSocket( RFCOMM )
sock.connect((host, port))
print "connected. type stuff"
while True:
data = raw_input()
if len(data) == 0: break
sock.send(data)
sock.close()
Quando eu corri o script do servidor no Windows, tudo funcionou exatamente como eu esperava - nenhum emparelhamento era necessário. Nesta fase, tudo parecia muito promissor.
No entanto, eu preciso do processo do servidor para rodar sob o Debian Squeeze. Quando eu testo no Debian, a conexão do cliente é recusada. No syslog, há mensagens do bluetoothd para uma solicitação de chave de link com falha e uma solicitação de PIN.
Versão informação:
PyBluez 0,18Python 2.6Bluez 4,66Hardware Bluetooth v2.0 em ambas as extremidades da conexãoEsta discussão Parece sugerir que, se eu puder ajustar o nível de segurança no soquete do servidor, o emparelhamento será desativado e tudo funcionará conforme o esperado. Não é evidente para mim como fazer isso com o PyBluez, ou mesmo se é possível.
Eu experimentei chamadas para setsockopt () usando várias constantes BT_SECURITY *, assim como pegando o último PyBluez e chamando setl2capsecurity (), mas não consegui fazer nenhum progresso.
Isso será possível com o PyBluez?