KI4JGT
KI4JGT

Reputation: 480

Python - AF_BLUETOOTH

Is there currently any documentation for AF_BLUETOOTH in python? Every time I try to find any, the only think I run into is a blog discussing remote controlled cars. There are virtually no examples I can find on Google and the py wiki doesn't go into detail on how to use it either.

Upvotes: 1

Views: 2765

Answers (1)

KI4JGT
KI4JGT

Reputation: 480

There appears to be several small blog entries on this topic but not a complete bluetooth library for it. I've scratched together my own based on this information: http://blog.kevindoran.co/bluetooth-programming-with-python-3/ and capturing the output of hcitool for the functions which seem to be missing. For example, using this function:

import subprocess

def scan():
    a = subprocess.Popen(["hcitool", "scan"], stdout = subprocess.PIPE).communicate()[0].split()[2:]
    if a == []:
        return "ERROR"
    else:
        return a

Allows you to scan for nearby bluetooth devices and deposits them into a list of [DeviceMac, DeviceName, DeviceMac, DeviceName] format. I will be updating this and distributing it with a P2P bluetooth communications program I've deving soon.

Upvotes: 2

Related Questions