LoginSignup
2
0

More than 1 year has passed since last update.

FreeBSDのBluetoothを試してみました。FreeBSDのBluetoothサポートはnetgraph(ng)というフレームワークの上に構築されています。BluetoothのUSBドングルを刺すといろいろなngのカーネルモジュールがロードされるのがkldstatで確認できます。

Bluetoothの中でもシリアル通信のためのプロファイルのSerial Port Profile(SPP)を確認します。すべてPINなどは使わない設定なので、hcsecdは使ってません。

確認したのは以下の三つのモジュールです。

ESP32

EPS32には以下のプログラムをPlatformIOでビルドして焼いておきます。

test.ino
#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

void setup() {
  SerialBT.begin("ESP32test"); //Bluetooth device name
}

void loop() {
  SerialBT.println("Hello World!");
  delay(1000);
}

Bluetooth USBドングルをつないだFreeBSD/amd64 13Rでスキャンしてみます。CSRの2.xなUSBモジュールを使いました。

% sudo hccontrol -n ubt0hci inquiry
Inquiry result, num_responses=1
Inquiry result #0
    BD_ADDR: 30:ae:a4:12:34:56
    Page Scan Rep. Mode: 0x1
    Page Scan Period Mode: 0x2
    Page Scan Mode: 00
    Class: 02:c1:10
    Clock offset: 0x6a57
Inquiry complete. Status: No error [00]

SPPのデーモンを上げます。

% sudo rfcomm_sppd -a 30:ae:a4:12:34:56 -t
rfcomm_sppd 1877 - - Starting on /dev/pts/1...
/dev/pts/1

距離などの問題で、電波が届かないのか、時々つながらないこともあります。

rfcomm_sppd: Could not obtain RFCOMM channel: Host is down

別のターミナルで、cuしてみます。

% sudo cu -l /dev/pts/1
Connected
Hello World!
Hello World!
Hello World!

PIC32MX自作モジール

以前portしたsmalltoothのモジュールでも確認してみます。このモジュールは文字を受信するとACKの文字列を返します。

スキャンしてみます。

% sudo hccontrol -n ubt0hci inquiry
Inquiry result, num_responses=1
Inquiry result #0
    BD_ADDR: 00:09:dd:12:34:56
    Page Scan Rep. Mode: 0x1
    Page Scan Period Mode: 0x2
    Page Scan Mode: 00
    Class: 18:01:04
    Clock offset: 0x6b3c
Inquiry complete. Status: No error [00]

SPPデーモンを上げます。

% sudo rfcomm_sppd -a 00:09:dd:12:34:56 -t
rfcomm_sppd: Could not obtain RFCOMM channel: Attribute not found

MacOS Xでは接続できるのですが、PIC32MXのSPPの実装が不完全なのだと思われます。

HC-05

HC-05は小さなSPP専用モジュールなのですが、なぜかSPPで接続できません。

% sudo rfcomm_sppd -a 20:15:07:12:34:56 -t
rfcomm_sppd: Could not connect socket: Connection refused

HC-05の設定によるものか、FreeBSDのバグかもしれません。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0