Skip to content
Snippets Groups Projects
Commit 6ecfe0e7 authored by 최정민's avatar 최정민
Browse files

Toying around with bluetooth

parent 8d19f281
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
"""PyBluez simple example inquiry.py
Performs a simple device inquiry followed by a remote name request of each
discovered device
Author: Albert Huang <albert@csail.mit.edu>
$Id: inquiry.py 401 2006-05-05 19:07:48Z albert $
"""
import bluetooth
print("Performing inquiry...")
nearby_devices = bluetooth.discover_devices(duration=8, lookup_names=True,
flush_cache=True, lookup_class=False)
print("Found {} devices".format(len(nearby_devices)))
for addr, name in nearby_devices:
try:
print(" {} - {}".format(addr, name))
except UnicodeEncodeError:
print(" {} - {}".format(addr, name.encode("utf-8", "replace")))
#!/usr/bin/env python3
"""PyBluez simple example rfcomm-client.py
Simple demonstration of a client application that uses RFCOMM sockets intended
for use with rfcomm-server.
Author: Albert Huang <albert@csail.mit.edu>
$Id: rfcomm-client.py 424 2006-08-24 03:35:54Z albert $
"""
import sys
import bluetooth
addr = input("Input Device Address: ")
# search for the SampleServer service
uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"
service_matches = bluetooth.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 \"{}\" on {}".format(name, host))
# Create the client socket
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((host, port))
print("Connected. Type something...")
while True:
data = input()
if not data:
break
sock.send(data)
sock.close()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment