반응형

Raspberry Pi 3와 Arduino 101 간에 BLE 통신 테스트를 진행했습니다.


최종 수정 - 2017. 8. 2.




1. 우선 다음 포스팅에 소개한 대로 Arduino 101에 LED 예제를 업로드 해야 합니다.


Arduino 101의 Bluetooth Low Energy(BLE) 예제를 안드로이드 폰과 테스트

http://webnautes.tistory.com/901




2. 라즈베리파이3에 내장된 블루투스 디바이스를 확인합니다.


pi@raspberrypi:~ $ hcitool dev
Devices:
       hci0    B8:27:EB:DA:FA:66




3. Arduino 101를 검색합니다.


pi@raspberrypi:~ $ sudo hcitool -i hci0 lescan
LE Scan ...
98:4F:EE:0F:4E:1E LED
09:EA:46:D3:03:D0 (unknown)
^Cpi@raspberrypi:~ $



첫번째 줄에 있는 LED라고 적힌 것이 Arduino 101입니다.

따라서  Arduino 101에 내장된 블루투스 디바이스의 주소는 98:4F:EE:0F:4E:1E입니다.

주소를 확인했으니 Ctrl+C를 눌러 블루투스 디바이스 검색을 중지합니다.




4. gatttool을 사용하여 Arduino 101의 블루투스 장치에 연결합니다.


pi@raspberrypi:~ $ sudo gatttool -i hci0 -b 98:4F:EE:0F:4E:1E -I
[98:4F:EE:0F:4E:1E][LE]> connect
Attempting to connect to 98:4F:EE:0F:4E:1E
Connection successful
[98:4F:EE:0F:4E:1E][LE]>




5. 이제 Arduino 101에서 제공하는 블루투스 서비스 목록을 불러옵니다.

마지막 줄에 있는 항목이 LED를 제어하기 위한 서비스입니다.


[98:4F:EE:0F:4E:1E][LE]> char-desc
handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x0006, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0007, uuid: 00002a04-0000-1000-8000-00805f9b34fb
handle: 0x0008, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0009, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x000a, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x000b, uuid: 19b10001-e8f2-537e-4f6c-d104768a1214
[98:4F:EE:0F:4E:1E][LE]>




6. 이제 확인한 서비스의 핸들을 가지고 LED를 제어해봅니다.

첫번째 줄을 실행시키면 LED가 켜지고,  두번째 줄을 실행시키면 LED가 꺼지게 됩니다.


[98:4F:EE:0F:4E:1E][LE]> char-write-req b 01
[98:4F:EE:0F:4E:1E][LE]> char-write-req b 00






참고

http://joost.damad.be/2013/08/experiments-with-bluetooth-low-energy.html


https://github.com/pcborenstein/bluezDoc/wiki/hcitool-and-gatttool-example






문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts