Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Distance Sonification
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
최정민
Distance Sonification
Commits
6ecfe0e7
Commit
6ecfe0e7
authored
4 years ago
by
최정민
Browse files
Options
Downloads
Patches
Plain Diff
Toying around with bluetooth
parent
8d19f281
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bluetoothApp.py
+65
-0
65 additions, 0 deletions
bluetoothApp.py
with
65 additions
and
0 deletions
bluetoothApp.py
0 → 100644
+
65
−
0
View file @
6ecfe0e7
#!/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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment