与Python 3.3蓝牙服务器 [英] Bluetooth server with Python 3.3

查看:401
本文介绍了与Python 3.3蓝牙服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python的3​​.3附带蓝牙插槽的原生支持。不幸的是,这不是太有据可查的,但(那里只有一个文档)。

Python 3.3 came with native support for bluetooth sockets. Unfortunately, it's not too well documented yet (there is only one mention of it in the documentation).

谷歌搜索它有有关实现客户端的博客文章 ,但我无法找到有关创建服务器的任何东西。

Googling it there is a blog post about implementing a client, but I couldn't find anything about creating a server.

更具体地说,如何设置用户友好的名称和广告服务。

More specifically, how to set the user-friendly name and advertise the service.

所以,像

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)

任何想法?

推荐答案

坏消息的:
蟒蛇似乎并不支持你想要做的开箱即用的东西。 (至少在 socketmodule.c )。

大多数我见过蟒蛇/蓝牙的用户使用 pybluez 虽然它并没有被2009年以来更新

Most of the python/bluetooth users I've seen use pybluez although it hasn't been updated since 2009.

好消息​​的:
我通过自己的源代码(对于Linux连接)去了​​,找到了广告服务的相关位。大部分的code是从Python 2.2版本的 socketmodule.c 基本上是复制粘贴的。

Good news: I went through their source (for Linux connections), and found the relevant bits for advertising services. Most of the code is essentially copy-pasted from the python 2.2 version of socketmodule.c.

pybluez 确实定义为插座对象来实现所有蓝牙好吃一些附加功能。它没有得到太低的水平,而是取决于 的BlueZ 了解这一点。从我所知道的,它主要负责Python对象,并创建由的BlueZ 预期的数据结构,只是调用。
如果你不想/不能使用 pybluez ,你必须以某种方式实现这个缺少的功能。我想,你可以用C-类型来做到这一点。为广告服务的相关部分在 btmodule .C ,系2562年至2642年。

pybluez does define some additional functionality for a socket object to implement all those bluetooth goodies. It doesn't get too low-level, and instead depends on BlueZ for that. From what I can tell, it basically takes python objects and creates the data structures expected by BlueZ and just calls that. If you don't want to/can't use pybluez, you'll have to somehow implement this missing functionality. I think you may be able to do it with c-types. The relevant parts for advertising the service are in btmodule.c, lines 2562-2642.

有是一个Python-3支源的 pybluez ,虽然我不知道,如果它工作或没有。

There is a python-3 branch in the source for pybluez, although I don't know if it works or not.

如果你决定使用 pybluez ,从的其源

If you do decide to use pybluez, an example taken from 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 ], 
                  )

随着谷歌code正在关闭时,code,也可以在github上此处

这篇关于与Python 3.3蓝牙服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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