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

raspberry pi bluetooth 실전 임베디드 2016. 2. 11. 15:17

by BABEL-II 2019. 9. 22.

Rsapbian Wheezy를 사용합니다.

Jessie는 이런 저런 기능이 잘 안 됩니다.

 

1. 설치
 apt-get install bluetooth bluez-utils blueman
 
 혹시 설치가 안될 때 방법
 sudo apt-get install update
 sudo apt-get install upgrade
 그래도 안될때 방법
 sudo apt-get clean
sudo mv /var/lib/apt/lists /tmp
sudo mkdir -p /var/lib/apt/lists/partial
sudo apt-get clean
sudo apt-get update

 

2. rfcomm 설정
 sudo vi /etc/bluetooth/rfcomm.conf

 #
 # RFCOMM configuration file.
 #

 rfcomm0 {
         # Automatically bind the device at startup
         bind no;

         # Bluetooth address of the device
  # hciconfig 에서 확인한 자기 블루투스 어드레스
         device 00:1A:7D:DA:71:0A;

         # RFCOMM channel for the connection
         channel 1;

         # Description of the connection
         comment "Example Bluetooth device";
 }
3. 시작 프로그램에 쉘 명령 추가
 sudo vi /etc/init/rc.local

 sudo hciconfig hci0 piscan
 sudo sdptool add SP

4. 연결 test
 sudo rfcomm listen hci0
 
 스마트폰으로 블루투스 SPP 연결 테스트

5. 필요라이브러리 설치
 sudo apt-get install libbluetooth-dev

6. rfcommServer.cpp 맥어드레스 수정
 hciconfig 으로 확인한 맥어드레스를 기록
 str2ba("00:1A:7D:DA:71:0A",&loc_addr.rc_bdaddr);

7. make

8. 실행
 ./bt_server

9. wifi 세팅시 파일 권한 변경
sudo chmod a+rw /etc/network/interfaces

라즈베리 파이 에러 대응
1.핸드폰 mac address trust 추가
sudo bluez-test-device trusted 28:CC:01:52:A9:C6 yes
2. 라즈베리파이 블루투스 stack 버그 방지
http://devkyu.tistory.com/345
$sudo vi /etc/bluetooth/main.conf
    #add this line towards the top:
    DisablePlugins = pnat