본문 바로가기
실전 임베디드

bluetooth raspberry pi에서 HC-06으로 연결하기. 페어링 까지만. 실전 임베디드 2016. 2. 11. 16:44

by BABEL-II 2019. 9. 22.

1. 코드 수정

2. 페어링

3. 수정된 rfcommclient 실행.

4. 페어링 제거

 

# bluez-test-device remove xx:xx:xx:xx:xx:xx

 

1. 코드 수정

 

사용자가 없는데 PIN 코드를 입력할 수 없으므로.

bluez-simple-agent를 수정하자.

 

아래 import는 기본이시고

import os
 

root@raspberrypi:/home/pi# whereis bluez-simple-agent
bluez-simple-agent: /usr/bin/bluez-simple-agent /usr/bin/X11/bluez-simple-agent /usr/share/man/man1/bluez-simple-agent.1.gz
root@raspberrypi:/home/pi# vi /usr/bin/bluez-simple-agent

 

def RequestPinCode(self, device):
                print "RequestPinCode (%s)" % (device)
                return raw_input("Enter PIN Code: ")

 def RequestPinCode(self, device):
                pin_code = os.getenv('PIN_CODE', "unknown")
                print pin_code
                if(pin_code == "unknown"):
                        print "RequestPinCode (%s)" % (device)
                        return raw_input("Enter PIN Code: ")
                else:
                        return pin_code
 

 

 

2. 페어링 - 우리 말로 짝짓기 -> 한자어로 교미 -> 영어로 i가e가 되는 six. -- ???

 

The pairing can be done by running the following command:


sudo bluez-simple-agent hci# xx:xx:xx:xx:xx:xx

 
The # is the number of your device (probably be 0 if you have only one bluetooth dongle connected) and xx:xx:xx:xx:xx:xx is the address of the serial Bluetooth module. After a few seconds, the program should ask you for the pin code of the Bluetooth module. By default, the pin for this module is 1234, and this password could be modified in AT mode.