목표Bluez : 서비스/gatt 서버 예를 광고 하시겠습니까?
저는 리눅스를 실행하는 간단한 장치를 개발 중입니다. 그것은 가능한 BLE이며, 현재 bluez 5.8을 사용하고 있습니다.
iPhone을 사용하여이 장치에서 작업을 실행하고 싶습니다. 이미 작동 무엇
는 :
- 나는 아이폰 장치 "를 참조하십시오"할 수 있습니다.
- iPhone도 장치에 연결됩니다.
I 설정 리눅스에서이 같은 블루투스 장치 (this question 덕분에) :
이# activate bluetooth
hciconfig hci0 up
# set advertise data: "hello world"
hcitool -i hci0 cmd 0x08 0x0008 48 45 4c 4c 4f 57 4f 52 4c 44
# start advertising as connectable
hciconfig hci0 leadv 0
아이폰 OS 코드는 간단하다 :
- (int) scanForPeripherals
{
if (self->centralManager.state != CBCentralManagerStatePoweredOn) {
return -1;
}
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[self.centralManager scanForPeripheralsWithServices:nil options:options];
return 0;
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state == CBCentralManagerStatePoweredOn) {
NSLog(@"Starting scan");
[self scanForPeripherals];
}
}
- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"didDiscoverPeripheral");
/*
* Retain the peripheral to avoid the error:
* CoreBluetooth[WARNING]: state = connecting> is being dealloc'ed while connecting
*/
self.activePeripheral = peripheral;
[centralManager connectPeripheral:peripheral options:nil];
}
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
NSLog(@"Connected to peripheral");
/* discover all services */
[peripheral discoverServices:nil];
}
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
NSLog(@"Discovered services");
for (CBService *service in peripheral.services) {
NSLog(@"Discovered service %@", service);
}
}
아이폰에이 코드를 실행, I 이 로그를 얻으십시오 :
2013-12-19 12:53:22.609 Test2[18518:60b] Starting scan
2013-12-19 12:53:29.945 Test2[18518:60b] didDiscoverPeripheral
2013-12-19 12:53:31.230 Test2[18518:60b] Connected to peripheral
아이폰은 잘 연결되지만 어떤 서비스도 보지 못한다.
내가
- 을 잃었 내가 간단한 BLE 서비스을 광고해야하지만 나는 bluez에서이 작업을 수행하는 방법에 대한 문서를 찾을 수 없습니다.
- 내가 광고 할 서비스에 대한 읽기/쓰기 특성을 받기 위해서는 서버가 필요하다고 생각합니다. bluez에서 plugins/gatt-example.c 파일을 보았지만 사용할 방법은 전혀 모른다. 문서가 없다.
내가이 질문을 보았다 '고 미리 말씀 아마해야? Creating a gatt server,하지만 답변 (예를 들어 너무 많은 의문을 제기 여기서 bluez에 대한 GATT API를 인 GATT 데이터베이스를 설정하는 방법을 읽기에 등록하는 방법/이벤트를 기록)
편집 : 명령을 내가 사용하는 일부 데이터를 광고하기 위해 BLE 장치를-설정하지만, 아이폰 OS는 연결이 가을 받아 들였다는 것을보고합니다. bluez의 어떤 부분이 들어오는 연결을 허용합니까?
맞아요, GATT 서버가 필요합니다. 실행 한 명령은 광고 패킷을 브로드 캐스트하기 위해 하드웨어를 설정했지만 연결 대상은 시작하지 않습니다. 불행히도 나는 아직 GATT 서버를 설치하는 방법을 알아 내지 못해서 내가 당신을 도울 수 없다 ... –
@TimTisdall 나는이 명령이 서버를 설정하지 않는다는 것을 안다. 그리고 이것은 누가 블루투스 연결을 수락합니까? 이 질문을 분명하게하기 위해 내 게시물을 편집했습니다. –
내 생각 엔 커널에 연결을 설정하는 것이 있지만 추측에 불과합니다. –