RFCOMM不Debian上的PyBluez配对? [英] RFCOMM without pairing using PyBluez on Debian?

查看:910
本文介绍了RFCOMM不Debian上的PyBluez配对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建与Python一个RFCOMM服务器的过程,可以无需配对使用。最初,我一把抓起PyBluez文档两个示例脚本:

I am trying to create an RFCOMM server process with Python that can be used without the need for pairing. Initially, I grabbed the two example scripts from the PyBluez documentation:

服务器:

# file: rfcomm-server.py

# auth: Albert Huang <albert@csail.mit.edu>
# 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"

客户:

# file: rfcomm-client.py
# auth: Albert Huang <albert@csail.mit.edu>
# 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()

当我跑在Windows上的一切服务器脚本工作,我曾是多么希望 - 没有配对的是必要的。在这个阶段,一切都在寻找非常有前途的。

When I ran the server script on Windows everything worked just how I had hoped - no pairing was necessary. At this stage everything was looking very promising.

不过,我需要服务器进程在Debian挤压运行。当我在Debian测试客户端连接被拒绝。在系统日志有来自bluetoothd消息故障链路密钥请求和PIN请求。

However, I need the server process to run under Debian Squeeze. When I test on Debian the client connection is refused. In the syslog there are messages from bluetoothd for a failed link key request and PIN request.

版本信息:


  • PyBluez 0.18

  • 的Python 2.6

  • 配合bluez 4.66

  • 在连接的两端蓝牙v2.0硬件

这个讨论似乎暗示,如果我可以调整服务器插槽上的安全级别那么配对将被禁用,一切都将只是正常工作。这不是显而易见的我如何与PyBluez为此虽然,或即使它是可能的。

This discussion seems to suggest that if I can adjust the security level on the server socket then pairing will be disabled and everything will just work as expected. It is not apparent to me how to do this with PyBluez though, or even if it is possible.

我与调用使用各种BT_SECURITY *常量,以及抓住最后的PyBluez并调用setl2capsecurity()试验,以setsockopt的(),但一直没能取得任何进展。

I have experimented with calls to setsockopt() using various BT_SECURITY* constants, as well as grabbing the last PyBluez and calling setl2capsecurity() but have not been able to make any progress.

这是将要与PyBluez实现?

Is this going to be achievable with PyBluez?

推荐答案

这竟然是与Debian的一个问题的bluez挤压默认配置。

This turned out to be a problem with the Debian Squeeze bluez default configuration.

如果别人碰到此问题,禁用通过编辑/etc/bluetooth/main.conf的PNAT插件:

If anyone else hits this problem, disable the pnat plugin by editing /etc/bluetooth/main.conf:

DisablePlugins = pnat

然后重新启动bluetoothd。

Then restart bluetoothd.

$ sudo invoke-rc.d bluetooth restart

没有变化需要对PyBluez code。

No changes were required to the PyBluez code.

这篇关于RFCOMM不Debian上的PyBluez配对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆