에디슨에서 SensorTag에 연결하기 위해서는 먼저 블루투스 기능을 활성화 시켜줘야 한다. (TI SensorTag에 대한 소개는 이전 포스트 참조)
# rfkill unblock bluetooth
# hciconfig hci0 up
# rfkill list
0: phy0: wlan
Soft blocked: no
Hard blocked: no
1: brcmfmac-wifi: wlan
Soft blocked: no
Hard blocked: no
2: bcm43xx Bluetooth: bluetooth
Soft blocked: no
Hard blocked: no
3: hci0: bluetooth
Soft blocked: no
Hard blocked: no
#
위와 같이 출력되면 블루투스를 사용할 수 있게 된 것이다. 다음은 주변의 SensorTag를 검색한다. 검색을 하기 전에 SensorTag 왼쪽 옆면에 있는 pairing 버튼을 눌러준다. 그러면 녹색 LED가 빠르게 점멸할것이다. (빨간색 실리콘 케이스를 씌워놓으면 LED 점멸은 보이지 않음)
# hcitool lescan
LE Scan ...
D0:39:72:D3:4A:AF (unknown)
D0:39:72:D3:4A:AF Bean
EC:C3:09:E2:18:A4 (unknown)
BC:6A:29:C3:54:33 (unknown)
BC:6A:29:C3:54:33 SensorTag
^C#
# hcitool lecc BC:6A:29:C3:54:33
Connection handle 64
위에서 형광색으로 된 부분은 검색에서 발견한 SensorTag의 MAC address(여기서는 BC:6A:29:C3:54:33)를 넣어주면 된다. 이제 gatttool을 사용해 직접 명령을 주고받아 본다. (에디슨에 디폴트로는 gatttool은 설치되어 있지 않다. 설치하는 방법은 '에디슨에 gatttool 설치' 참조)
# gatttool -b BC:6A:29:C3:54:33 --interactive
[BC:6A:29:C3:54:33][LE]> connect
Attempting to connect to BC:6A:29:C3:54:33
Connection successful
[BC:6A:29:C3:54:33][LE]> char-read-hnd 0x25
Characteristic value/descriptor: 00 00 00 00
[BC:6A:29:C3:54:33][LE]> char-write-cmd 0x29 01
[BC:6A:29:C3:54:33][LE]> char-read-hnd 0x25
Characteristic value/descriptor: 52 ff d8 0b
핸들 0x25는 온도 센서값을 의미한다. 처음 읽을때는 00이었지만 센서를 활성화(0x29에 1을 써줌)시킨 후에 다시 읽어보면 현재 센서 값이 읽혀진다. 핸들에 대한 자세한 정보는 http://processors.wiki.ti.com/index.php/SensorTag_User_Guide#Gatt_Server 를 참조하면 된다.
[BC:6A:29:C3:54:33][LE]> char-write-cmd 0x26 0100
Notification handle = 0x0025 value: 42 ff d8 0b
Notification handle = 0x0025 value: 42 ff d8 0b
Notification handle = 0x0025 value: 40 ff d8 0b
Notification handle = 0x0025 value: 3f ff d8 0b
Notification handle = 0x0025 value: 41 ff d8 0b
Notification handle = 0x0025 value: 3c ff d8 0b
Notification handle = 0x0025 value: 3b ff d8 0b
Notification handle = 0x0025 value: 42 ff dc 0b
Notification handle = 0x0025 value: 39 ff dc 0b
Notification handle = 0x0025 value: 3e ff dc 0b
[BC:6A:29:C3:54:33][LE]> char-write-cmd 0x26 0000
[BC:6A:29:C3:54:33][LE]>
온도센서 값을 지속적으로 읽고 싶으면 0x26에 0100을 써 주면 위와 같이 지속적으로 센서값이 리포트된다. 리포팅을 끝내려면 0x26에 0000을 써 주면 된다.
푸쉬버튼 입력 같은 경우는 버튼의 상태를 지속적으로 폴링하는건 매우 비효율적이기 때문에 버튼이 눌린걸 notify 하도록 설정할 수 있다. 아래와 같이 request하면 푸쉬버튼의 상태가 바뀔때 마다 상태값이 통보된다.
[BC:6A:29:C3:54:33][LE]> char-write-req 0x67 80
Characteristic value was written successfully
[BC:6A:29:C3:54:33][LE]> char-write-req 0x60 0100
Characteristic value was written successfully
Notification handle = 0x005f value: 02
Notification handle = 0x005f value: 00
Notification handle = 0x005f value: 01
Notification handle = 0x005f value: 00
[BC:6A:29:C3:54:33][LE]>
왼쪽 버튼이 bit1, 오른쪽 버튼이 bit0이므로 위에서는 먼저 왼쪽 버튼을 눌렀다 뗀 후, 오른쪽 버튼을 눌렀다 뗀 것이다. 버튼이 둘 다 눌리면 03이 통보된다.
이런식으로 SensorTag를 에디슨에 연결해 다양한 동작을 할 수 있다. 여러개의 SensorTag를 집안 곳곳에 설치해 놓고 에디슨에서 센서값들을 읽어들어 IoT 모니터링 시스템을 구축하는등의 다양한 응용이 가능하다.
2015년 3월 11일 수요일
2015년 3월 10일 화요일
에디슨에 gatttool 설치 (Install gatttool in Intel Edison)
에디슨에서 BLE를 테스트 해 보기 위해 인터넷을 검색해 보면 대부분의 예제에서 gatttool을 사용하고 있지만 에디슨에는 gatttool이 설치되어 있지 않다. opkg로 bluez를 설치해도 gatttool은 들어있지 않다.
설치하기 위해서는 bluez5 소스코드를 다운받아 설치해 주면 된다.
# wget --no-check-certificate https://www.kernel.org/pub/linux/bluetooth/bluez-5.24.tar.xz
다운받은 소스코드는 xz 로 압축되어 있기 때문에 압축을 풀기 위해서는 xz utility가 있어야 한다.
# opkg install xz
이제 압축을 풀어준다.
# xz -d bluez-5.24.tar.xz
# tar xvf bluez-5.24.tar
# cd bluez-5.24
Configure 후 빌드한다. (configure 할 때 --disable-systemd 와 --disable-udev 옵션을 넣어줘야 함)
# ./configure --disable-systemd --disable-udev
...
# make
...
# make install
...
#
빌드가 끝나면 gatttool을 복사해 주면 된다.
# cp attrib/gatttool /usr/bin
#
설치하기 위해서는 bluez5 소스코드를 다운받아 설치해 주면 된다.
# wget --no-check-certificate https://www.kernel.org/pub/linux/bluetooth/bluez-5.24.tar.xz
다운받은 소스코드는 xz 로 압축되어 있기 때문에 압축을 풀기 위해서는 xz utility가 있어야 한다.
# opkg install xz
이제 압축을 풀어준다.
# xz -d bluez-5.24.tar.xz
# tar xvf bluez-5.24.tar
# cd bluez-5.24
Configure 후 빌드한다. (configure 할 때 --disable-systemd 와 --disable-udev 옵션을 넣어줘야 함)
# ./configure --disable-systemd --disable-udev
...
# make
...
# make install
...
#
빌드가 끝나면 gatttool을 복사해 주면 된다.
# cp attrib/gatttool /usr/bin
#
Labels:
손에 잡히는 IoT,
인텔 IoT,
BLE,
Bluetooth 4.0,
bluez,
gatttool,
hciconfig,
hcitool,
Intel IoT,
IoT,
linux bluetooth
피드 구독하기:
글 (Atom)

