开发者

Bluetooth programming in python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 6 years ago.

开发者_开发知识库 Improve this question

Are there any nice Python libraries for Bluetooth programming? I tried PyBluez, but Eclipse doesn't recognize the module Bluetooth. Can anyone suggest tutorials for Python and Bluetooth?


PyBluez now supports Python 3, so it may work for you now.

Python 3.3 and above has inbuilt support for Bluetooth though sockets. While there is native support, many features of PyBluez are not available in native Python 3 sockets. For example, you cannot use inquiry scans or SDP.

I created a tutorial describing the differences between using PyBluez vs. Python 3 sockets for a simple Bluetooth application.


I am currently experimenting with scapy in python. I have worked out how to send a packet via srbt1 command and i am currently fuzzing the protocol.

packet = fuzz(L2CAP_Hdr('1111111111111111111111111111111'))
srbt1("20:21:A5:82:44:01",packet,0)

Explanation

  • srbt1 << sends the BT packet.
  • "20:21:A5:82:44:01" << defines the device you want to connect to
  • packet << defines the payload
  • 0 << defines my BT card.

I hope this helps someone out.


I have not tried it personally, but I hope to try this cross platform bluetooth python api: Lightblue


Since you mention your nokia phone, you might like this book: http://www.mobilepythonbook.org/

The examples page (which i cant link directly for some reason) contains an example for using PySerial over bluetooth.


I've recently used Pybluez with good results, you can find the git here. https://github.com/karulis/pybluez

And you can find a neat and helpful tutorial here a neat tutorial here. https://people.csail.mit.edu/albert/bluez-intro/c212.html

If you are using Windows, you'll need to have Visual C++, more details on the git page.


If the interactive mode of gatttool (part of Bluez) works for you then Pygatt is a nice wrapper around this tool. Well maintained. Uses pexpect to interact with gatttool. Also wraps "hcitool lescan" to scan for Bluetooth devices. Basic usage example:

import pygatt.backend
adapter = pygatt.backends.GATTToolBackend()
adapter.start()
device = adapter.connect('xx:xx:xx:xx:xx:xx', 5, 'random')
device.char_write_handle(0x23,[0x20, 0x21])
device.subscribe('00008a22-0000-1000-8000-00805f9b34fb',callback = mycallback, indication=True)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜