HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2018/05/01

Raspberry Piの Bluetoothで Windows 10と OBEXファイル転送を試してみる Raspberry Piの Bluetoothで Windows 10と OBEXファイル転送を試してみる

(Windows 10対応の Bluetoothファイル転送アプリ Bluetooth OBEX File Transferの動作確認)

Tags: [Raspberry Pi], [電子工作]




●ラズパイ3の Bluetoothで OBEXファイル転送を試してみる!

 Bluetooth OBEX File Transferと言う超絶便利な Windowsアプリを作成したので、ラズパイの Bluetoothでも OBEXファイル転送を試してみました。


2018/03/31
Bluetooth OBEX File Transfer Windows 10対応のファイル転送(送受信) アプリ
Bluetooth OBEX File Transfer Windows 10対応のファイル転送(送受信) アプリ

  BtObexFileTransfer、Bluetooth経由でのファイルの送信、受信を簡単に行なう事ができます


● Raspberry Piで Bluetooth OBEX File Transfer

 まずは hciconfigで Bluetoothデバイスの hci0を確認する。
pi@raspberrypi:~ $ hciconfig
hci0:   Type: Primary  Bus: UART
        BD Address: B8:27:00:11:22:33  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING PSCAN ISCAN
        RX bytes:1745 acl:15 sco:0 events:103 errors:0
        TX bytes:8845 acl:15 sco:0 commands:87 errors:0
 BD Addressが Raspberry Piの Bluetoothデバイスの BDアドレス。
 (LANで言う所の MACアドレスに相当し、世界で一つだけのシリアル番号。)

 hciconfigコマンドは、自分の Bluetoothデバイスのデバイス名を変更したり、周囲に有る他の Bluetoothデバイスの存在を確認したりができます。


●自分の Bluetoothデバイスのデバイス名を変更

pi@raspberrypi:~ $ sudo hciconfig hci0 name ラズパイの名前
・自分の Bluetoothデバイスのデバイス名を変更
自分の Bluetoothデバイスのデバイス名を変更



 sudoが無いと怒られます。
pi@raspberrypi:~ $ hciconfig hci0 name ラズパイの名前
Can't change local name on hci0: Operation not permitted (1)

 名前を「ラズパイです!」にした場合。
pi@raspberrypi:~ $ sudo hciconfig hci0 name ラズパイです!
・自分の Bluetoothデバイスのデバイス名を変更
自分の Bluetoothデバイスのデバイス名を変更




●自分の Bluetoothデバイスを発見可能にする

 発見可能状態にする。
pi@raspberrypi:~ $ sudo hciconfig hci0 piscan
・自分の Bluetoothデバイスを発見可能にする
自分の Bluetoothデバイスを発見可能にする


・自分の Bluetoothデバイスを発見可能にする
自分の Bluetoothデバイスを発見可能にする



 発見可能状態を停止する。
pi@raspberrypi:~ $ sudo hciconfig hci0 noscan

 sudoが無いと怒られます。
pi@raspberrypi:~ $ hciconfig hci0 piscan
Can't set scan mode on hci0: Operation not permitted (1)


●周囲に有る他の「発見可能状態」の Bluetoothデバイスの存在を確認

pi@raspberrypi:~ $ hcitool -i hci0 scan
Scanning ...
        11:22:33:44:55:66       Windows10PC
        AA:BB:CC:DD:EE:FF       iPhoneX


●周囲に有る他の Bluetoothデバイスの存在を確認(ペアリング不要)

 ペアリング不要で周辺に存在するかを確認できます。
 ※これを応用すれば「ボスが来た!」「ママが来た!」等のアプリを作れます。

 00:11:22:33:44:55は存在を確認したいBluetooth機器の BDアドレス。
pi@raspberrypi:~ $ hcitool name 00:11:22:33:44:55
HogeHogeName
 近くに BDアドレス 00:11:22:33:44:55の「HogeHogeName」の Bluetooth機器が在る場合は「HogeHogeName」を表示します。
 存在しない場合は表示しません。


● hcitoolコマンドのコマンド一覧

pi@raspberrypi:~ $ hcitool
hcitool - HCI Tool ver 5.43
Usage:
        hcitool [options] <command> [command parameters]
Options:
        --help  Display help
        -i dev  HCI device
Commands:
        dev     Display local devices
        inq     Inquire remote devices
        scan    Scan for remote devices
        name    Get name from remote device
        info    Get information from remote device
        spinq   Start periodic inquiry
        epinq   Exit periodic inquiry
        cmd     Submit arbitrary HCI commands
        con     Display active connections
        cc      Create connection to remote device
        dc      Disconnect from remote device
        sr      Switch master/slave role
        cpt     Change connection packet type
        rssi    Display connection RSSI
        lq      Display link quality
        tpl     Display transmit power level
        afh     Display AFH channel map
        lp      Set/display link policy settings
        lst     Set/display link supervision timeout
        auth    Request authentication
        enc     Set connection encryption
        key     Change connection link key
        clkoff  Read clock offset
        clock   Read local or remote clock
        lescan  Start LE scan
        leinfo  Get LE remote information
        lewladd Add device to LE White List
        lewlrm  Remove device from LE White List
        lewlsz  Read size of LE White List
        lewlclr Clear LE White List
        lerladd Add device to LE Resolving List
        lerlrm  Remove device from LE Resolving List
        lerlclr Clear LE Resolving List
        lerlsz  Read size of LE Resolving List
        lerlon  Enable LE Address Resolution
        lerloff Disable LE Address Resolution
        lecc    Create a LE Connection
        ledc    Disconnect a LE Connection
        lecup   LE Connection Update

For more information on the usage of each command use:
        hcitool <command> --help


●本題の Raspberry Piで Bluetooth OBEXでファイル転送

 obexftp - Bt OBEXファイル送信ツール(OBEXの FTP方式)
 obexpushd - Bt OBEXファイル受信ツール
 を apt-getでインストールします。

sudo apt-get update
sudo apt-get -y install obexftp obexpushd


● ラズパイの Bluetoothの OBEXでファイル受信 obexpushd

 ラズパイの Bluetoothの OBEXでファイル受信は成功しました。

 obexpushdで OBEXの Push Daemonを動かします。

ObexPushD
 An OBEX Push/FTP server implementation
 Obexpushd can be used to receive files with OBEX protocol over Bluetooth, IrDA (infrared) or network connection. This program should work with many mobile devices like PDAs and mobile phones.

pi@raspberrypi:~ $ cd
# /home/pi
pi@raspberrypi:~ $ mkdir ./obex_files
# /home/pi/obex_files

pi@raspberrypi:~ $ sudo service bluetooth stop
pi@raspberrypi:~ $ sudo bluetoothd --compat &
pi@raspberrypi:~ $ sudo hciconfig hci0 up
pi@raspberrypi:~ $ sudo hciconfig hci0 piscan

pi@raspberrypi:~ $ sudo obexpushd -B -n -o /home/pi/obex_files
obexpushd 0.11.2 Copyright (C) 2006-2010 Hendrik Sattler
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
Listening on bluetooth/[00:00:00:00:00:00]:9
Creating file "/home/pi/obex_files/Settings.txt"
Creating file "/home/pi/obex_files/基本情報.pdf"
 ファイルを受信すると /home/pi/obex_files/に受信ファイルを保存します。
・ラズパイの Bluetoothの OBEXでファイル受信 obexpushd
ラズパイの Bluetoothの OBEXでファイル受信 obexpushd
 Windowsからラズパイにファイルを送信。

 obexpushdで最後に &を付けて常駐モードで動かすとかもできます。
sudo obexpushd -B -n -o /home/pi/obex_files &

 こんなエラーが出る事も
pi@raspberrypi:~ $ sudo obexpushd -B -n -o /home/pi/obex_files
obexpushd 0.11.2 Copyright (C) 2006-2010 Hendrik Sattler
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
Listening on bluetooth/[00:00:00:00:00:00]:9
SDP session setup failed, disabling bluetooth
net_init() failed

pi@raspberrypi:~ $ sudo obexpushd -B -n -o /home/pi/push_files
obexpushd 0.11.2 Copyright (C) 2006-2010 Hendrik Sattler
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
BtOBEX_ServerRegister: Address already in use
net_init() failed


● obexpushdコマンドのヘルプ
pi@raspberrypi:~ $ sudo obexpushd -h
obexpushd 0.11.2 Copyright (C) 2006-2010 Hendrik Sattler
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.

Usage: obexpushd [<interfaces>] [<options>]

Interfaces:
 -B[<channel>]  listen to bluetooth connections (default: channel 9)
 -I[<app>]      listen to IrDA connections (app example: IrXfer)
 -N[<port>]     listen to IPv4/v6 network connections (default: port 650)
 -G<device>     listen on an USB gadget device file
 -S             handle one connection via stdin/stdout

Options:
 -n             do not detach from terminal
 -d             enable debug messages (implies -n)
 -p <file>      write pid to file when getting detached
 -A             use transport layer specific access rules if available
 -a <file>      authenticate against credentials from file (EXPERIMENTAL)
 -o <directory> change base directory
 -s <file>      define script/program for input/output
 -t <protocol>  add a protocol (OPP, FTP)
 -h             this help message
 -v             show version

See manual page obexpushd(1) for details.


● ラズパイの Bluetoothの OBEXでファイル送信 obexftp

obexftp(1) - Linux man page
 Description
 obexftp is used to access files on mobile equipment, i.e. cell phones. With obexftpd you can transfer files between any computers using IrDA, Bluetooth and TCP/IP .

obexftp -b 00:11:22:33:44:55 -p send_test.txt

 00:11:22:33:44:55は送信先の Bluetooth機器の BDアドレス
 send_test.txtは OBEX転送で送信したいファイル


●送信先の機器が OBEXの FTPプロトコルに対応していない場合

pi@raspberrypi:~ $ obexftp -b 00:11:22:33:44:55 -p send_test.txt
Browsing 00:11:22:33:44:55 ...
Connecting...failed: connect
unknown error on connect
Still trying to connect
Connecting...failed: connect
unknown error on connect
Still trying to connect
Connecting...failed: connect
unknown error on connect
Still trying to connect
 ※送信先の機器が OBEXの FTPプロトコルに対応している必要が有ります。


● obexftpでラズパイの Bluetoothの OBEXでファイル送信の成功例

 送信先を Android携帯にして、「ESファイルエクスプローラ」の「ネットワーク」で「Bluetooth」を選択して Android携帯側で ObexFTPを動かした状態にする。
pi@raspberrypi:~ $ obexftp -b AA:BB:CC:DD:EE:FF -p send_test.txt
Browsing AA:BB:CC:DD:EE:FF ...
Connecting..\done
Sending "send_test.txt".../done
Disconnecting..-done
 ※送信先の機器が OBEXの FTPプロトコルに対応している必要が有ります。


● obexftpコマンドのヘルプ
pi@raspberrypi:~ $ obexftp --help
ObexFTP 0.24
Usage: obexftp [ -i | -b <dev> [-B <chan>] | -U <intf> | -t <dev> | -N <host> ]
[-c <dir> ...] [-C <dir> ] [-l [<dir>]]
[-g <file> ...] [-p <files> ...] [-k <files> ...] [-x] [-m <src> <dest> ...]
Transfer files from/to Mobile Equipment.
Copyright (c) 2002-2004 Christian W. Zuckschwerdt

 -i, --irda                  connect using IrDA transport (default)
 -b, --bluetooth [<device>]  use or search a bluetooth device
 [ -B, --channel <number> ]  use this bluetooth channel when connecting
 [ -d, --hci <no/address> ]  use source device with this address or number
 -u, --usb [<intf>]          connect to a usb interface or list interfaces
 -t, --tty <device>          connect to this tty using a custom transport
 -n, --network <host>        connect to this host

 -U, --uuid                  use given uuid (none, FBS, IRMC, S45, SHARP)
 -H, --noconn                suppress connection ids (no conn header)
 -S, --nopath                dont use setpaths (use path as filename)
 -T, --timeout <seconds>     timeout transfer if no accept/reject received

 -c, --chdir <DIR>           chdir
 -C, --mkdir <DIR>           mkdir and chdir
 -l, --list [<FOLDER>]       list current/given folder
 -o, --output <PATH>         specify the target file name
                             get and put always specify the remote name.
 -g, --get <SOURCE>          fetch files
 -G, --getdelete <SOURCE>    fetch and delete (move) files
 -p, --put <SOURCE>          send files
 -k, --delete <SOURCE>       delete files

 -X, --capability            retrieve capability object
 -Y, --probe                 probe and report device characteristics
 -x, --info                  retrieve infos (Siemens)
 -m, --move <SRC> <DEST>     move files (Siemens)

 -v, --verbose               verbose messages
 -V, --version               print version info
 -h, --help, --usage         this help text


● ラズパイの Bluetoothの OBEXでファイル送信 ussp-push

 ussp-pushコマンドを使用したラズパイの Bluetoothの OBEXでファイル送信は成功していません。
 送信先を Windowsパソコンにしても Android携帯にしても駄目でした。

ussp-push
 ussp-push is a OBEX object pusher for Linux, using the BlueZ BlueTooth stack. The original ussp-push implementation required explicit binding to RFCOMM channels before the usage, that made it quite cumbersome to use. I added BlueTooth name resolution, SDP service resolution, and direct access to remote BlueTooth listening channels.

ussp-push
 ussp プッシュは BlueZ !BlueTooth スタックを使用して [/projects/freshmeat_linux/ Linux] 用のブルートゥース OBEX オブジェクトの補助機関車です。OBEX 接続をリッスンして任意のデバイスにファイルを送信することができます。

sudo apt-get -y install ussp-push

 ussp-pushコマンドは送信元のファイルに対して受信側で使用するファイル名を指定できます。


●送信先が存在しない場合の ussp-pushの挙動
pi@raspberrypi:~ $ sudo ussp-push --debug 22:22:22:22:22:22@ ./受信側用のファイル名.txt 受信側用のファイル名.txt
pushing file ./受信側用のファイル名.txt
name=./受信側用のファイル名.txt, size=39782
__obex_connect: client_context_t = 0x27afc0
Unable to find OBEX service in '22:22:22:22:22:22'
cobex_open() failed
Unable to connect to the server
Error


●送信先が受信待機の場合の ussp-pushの挙動(その1)
pi@raspberrypi:~ $ sudo ussp-push --debug 22:22:22:22:22:22@ ./受信側用のファイル名.txt 受信側用のファイル名.txt
pushing file ./受信側用のファイル名.txt
name=./受信側用のファイル名.txt, size=39782
__obex_connect: client_context_t = 0x3b4fc0
        Found "OBEX Object Push" (0x1105)
Found channel 2
Remote OBEX channel: 2
Registered transport
Set user data
Created new objext
Started a new request
^C


●送信先が受信待機の場合の ussp-pushの挙動(その2)
pi@raspberrypi:~ $ sudo ussp-push --debug 11:11:11:11:11:11@ ./受信側用のファイル名.txt 受信側用のファイル名.txt
pushing file ./受信側用のファイル名.txt
name=./受信側用のファイル名.txt, size=39782
__obex_connect: client_context_t = 0x338fc0
        Found "AV Remote Target" (0x110c)
        Found "AV Remote" (0x110e)
        Found "AV Remote Controller" (0x110f)
        Found "Phonebook Access - PSE" (0x112f)
        Found "OBEX Object Push" (0x1105)
Found channel 5
Service search failed: Invalid argument
        Found "OBEX Object Push" (0x1105)
Found channel 5
Service search failed: Invalid argument
        Found "Message Access - MAS" (0x1132)
Remote OBEX channel: 5
Registered transport
Set user data
Created new objext
Started a new request
^C


●送信先が受信待機の場合の ussp-pushの挙動(その3)
pi@raspberrypi:~ $ sudo ussp-push --debug 33:33:33:33:33:33@ ./受信側用のファイル名.txt 受信側用のファイル名.txt
pushing file ./受信側用のファイル名.txt
name=./受信側用のファイル名.txt, size=39782
__obex_connect: client_context_t = 0x1c0afc0
        Found "OBEX Object Push" (0x1105)
Found channel 1
Remote OBEX channel: 1
Registered transport
Set user data
Created new objext
Started a new request
^C


●送信先が受信待機の場合の ussp-pushの挙動(その4)

 送信先を Android携帯にして、「ESファイルエクスプローラ」の「ネットワーク」で「Bluetooth」を選択して Android携帯側で ObexFTPを動かした状態にする。
pi@raspberrypi:~ $ sudo ussp-push --debug 44:44:44:44:44:44@ ./test_hoge.txt test_hoge_name.txt
pushing file ./test_hoge.txt
name=./test_hoge.txt, size=16758
__obex_connect: client_context_t = 0x4df5c8
        Found "AV Remote Target" (0x110c)
        Found "AV Remote" (0x110e)
        Found "AV Remote Controller" (0x110f)
        Found "Message Access - MAS" (0x1132)
        Found "Phonebook Access - PSE" (0x112f)
        Found "OBEX Object Push" (0x1105)
Found channel 7
Service search failed: Invalid argument
        Found "OBEX File Transfer" (0x1106)
Remote OBEX channel: 7
Registered transport
Set user data
Created new objext
Started a new request
^C


● OBEXでファイル送信 ussp-pushの試行錯誤の残骸

ussp-push 11:11:11:11:11:11 ./ラズパイの元のファイル.txt 受信側用のファイル名.txt
sudo rfcomm connect 0 11:11:11:11:11:11 4 &
sudo ussp-push /dev/rfcomm0 ./ラズパイの元のファイル.txt 受信側用のファイル名.txt

sudo ussp-push --debug 11:11:11:11:11:11@12 ./ラズパイの元のファイル.txt 受信側用のファイル名.txt
sudo ussp-push --debug 22:22:22:22:22:22@2 ./ラズパイの元のファイル.txt 受信側用のファイル名.txt

sudo obexpushd -B23 -o /bluetooth -n
sudo ussp-push 33:33:33:33:33:33@23 ./受信側用のファイル名.txt 受信側用のファイル名.txt
sudo ussp-push --dev hci0 --debug 33:33:33:33:33:33@12 ./受信側用のファイル名.txt 受信側用のファイル名.txt

sudo rfcomm connect 0 22:22:22:22:22:22 2 &
sudo ussp-push --debug /dev/rfcomm0 ./ラズパイの元のファイル.txt 受信側用のファイル名.txt


● ussp-pushコマンドのヘルプ
pi@raspberrypi:~ $ ussp-push
ussp-push v0.11

Usage: ussp-push [--dev DEVID] [--timeo TIMEO] [--debug] {DEVICE, BTADDR@[BTCHAN]} LFILE RFILE

        DEVICE          = RFCOMM TTY device file
        TIMEO           = RFCOMM connect timeout in seconds
        BTADDR@[BTCHAN] = BlueTooth address/name and OBEX channel. If the OBEX channel
                          is not specified, and SDP quesry is used to retrieve it
        LFILE           = Local file path
        RFILE           = Remote file name



Tags: [Raspberry Pi], [電子工作]



[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2018 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_bluetooth_obex_ftp_file_transfer/