Notice
Recent Posts
Recent Comments
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
10-10 22:21
Archives
Today
Total
관리 메뉴

Developer_Neo

[Bluetooth 통신] 라즈베리파이 3B와 노트북간 통신 본문

Extra

[Bluetooth 통신] 라즈베리파이 3B와 노트북간 통신

_Neo_ 2022. 5. 9. 16:51
반응형

1. 블루투스로 진입

sudo bluetoothctl

2. 주변 블루투스 기기를 탐색하는 scan on 명령어를 입력

scan on

3. 원하는 장치를 찾았다면 장치에 페어링 하고 인증을 처리해주는 에이전트를 활성화하고 기본 에이전트로 설정해줍니다.

agent on
default-agent

위의 명령어 입력시 에이전트 활성화 완료

4. 해당 장치(라즈베리파이 아닌거) 맥 주소 입력

pair 98:D3:71:FD:55:C4

 

블루투스 라이브러리 설치

sudo pip3 install PyBluez

 

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=roboholic84&logNo=221563796733 

 

라즈베리파이3B+와 HC-06으로 블루투스 통신해보기

안녕하세요 메카솔루션입니다. 기존에 라즈베리파이와 스마트폰, 아두이노와 스마트폰의 형식으로 블루투스...

blog.naver.com


라즈베리파이를 server로 사용할 것임.

import bluetooth

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )

port = 1
server_sock.bind(("",port))
server_sock.listen(1)

client_sock,address = server_sock.accept()
print "Accepted connection from ",address

data = client_sock.recv(1024)
print "received [%s]" % data

client_sock.close()
server_sock.close()

 

 

노트북을 client로 사용할 것임.

import bluetooth

bd_addr = "라즈베리파이의 맥 주소"

port = 1

sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))

sock.send("hello!!")

sock.close()

https://people.csail.mit.edu/albert/bluez-intro/x232.html

 

Communicating with RFCOMM

Bluetooth programming in Python follows the socket programming model. This is a concept that should be familiar to almost all network programmers, and makes the transition from Internet programming to Bluetooth programming much simpler. Example 3-2 and Ex

people.csail.mit.edu

 

반응형
Comments