Using Bluetooth FTP Profile Print


Bluetooth is widely used when it is necessary to provide a wireless access to the devices located in short distances. In this application note we will show how to organize a wireless FTP access to the STM32F7 SOM running Linux using a USB Bluetooth adapter. In practical embedded applications such a wireless channel may be used to retrieve data collected by the STM32F7 via the standard FTP protocol. The most obvious use case scenario for this need is a technician visiting an embedded device residing at a remote site in order to retrieve data collected and stored locally by the STM32F7 SOM locally (e.g. the STM32F7 may store data on a JFFS2 partition in the NOR Flash or on a connected USB Flash). Being able to access the STM32F7 over Bluetooth from a notebook or a smartphone, with no need to connect to the STM32F7 with any physical cables, comes in very hand, especially for devices with limited physical access.

Hardware Platform

The hardware platform used in this application note is the Emcraft STM32F7 SOM Starter Kit with a USB Bluetooth adapter plugged into the USB OTG connector on the SOM-BSB-EXT development baseboard. The adapter used by Emcraft to perform the tests documented below was based on the LM506 chip. The generic Linux kernel device driver for the USB transport HCI layer (CONFIG_BT_HCIBTUSB) is used in this configuration so other USB Bluetooth adapters should work as described below too.

Software Platform

Support for the Bluetooth FTP server is implemented by the obexftp package:

The obexftpd daemon is used to implement the FTP server functionality over Bluetooth. The daemon, once started, waits for connections to the specified port from clients. The obexftp utility is used to implement the FTP client functionality over Bluetooth (this allows to connect to FTP servers running on other Bluetooth devices).

The OBEX FTP protocol is used for store and retrieve files. Support for the OBEX protocol is implemented with the openobex package:

The functionality described below is available from the rootfs.uImage project installed by Emcraft to every shipping STM32F7 SOM Starter Kit.

Test Setup

We will use the following terminology below:

  • Target: Emcraft STM32F7 Starter Kit with the LM506 Bluetooth adapter plugged into the USB OTG port over the Mini-A Male - A Female cable.
    The Bluetooth <Target address> in the examples below is 5C:F3:70:70:FA:D5;
  • Host: Any computer with a Bluetooth interface, running Linux with the Bluetooth tools (bluez-utils, openobex, and obexftp) installed.
    The Bluetooth <Host address> in the examples below is C4:D9:87:8C:B2:24.

Bluetooth FTP Server on STM32F7

Power-on the STM32F7 Starter Kit and wait for the Linux to boot on the Target. Run the Bluetooth daemons in the background:

init started: BusyBox v1.17.0 (2016-09-20 14:00:02 +0400)
/ # hcid -n&
/ # sdpd -n&

Plug-in the Bluetooth adapter to the USB OTG interface of the STM32F7 Starter Kit. Observe the messages similar to the following in the Target console:

usb 1-1: new full-speed USB device number 3 using dwc2
hcid[50]: HCI dev 0 registered
Bluetooth: hci0: BCM: chip id 63
Bluetooth: hci0: BCM20702A1 (001.002.014) build 0000
Bluetooth: hci0: BCM20702A1 (001.002.014) build 1338
hcid[50]: HCI dev 0 up
hcid[50]: Starting security manager 0

Get the <Target address> Bluetooth address of the adapter just plugged-in:

/ # cat /sys/class/bluetooth/hci0/address

Create a test file in the root/ directory, which will be exported over FTP from the Target:

/ # dd if=/dev/zero of=/root/ bs=1024 count=1024
1024+0 records in
1024+0 records out
1048576 bytes (1.0MB) copied, 0.177231 seconds, 5.6MB/s

Run the FTP server daemon specifying the Bluetooth port to listen upon, and the exported root directory. In the example below the channel number is 2, an FTP root directory is /root:

/ # obexftpd -c /root -b2 &
Waiting for connection...
/ #

List the names of files exported by the Target over Bluetooth by executing the following command on the Host:

[yur@ubuntu rootfs]$ obexftp -b 5c:f3:70:70:fa:d5 -B 2 -l
Tried to connect for 379ms
Receiving "(null)"...|<?xml version="1.0"?>
<!DOCTYPE folder-listing SYSTEM "obex-folder-listing.dtd">
<folder-listing version="1.0">
<file name="" size="1048576" user-perm="RWD" modified="20000102T011140Z" created="20000102T011140Z" accessed="20000102T011140Z" />

Download the test file from the Target over Bluetooth by executing the following commands on the Host:

[yur@ubuntu rootfs]$ obexftp -b 5c:f3:70:70:fa:d5 -B 2 -g
Tried to connect for 372ms
Receiving ""...-done

[yur@ubuntu rootfs]$ ls -l
-rw-r--r-- 1 yur yur 1048576 2016-09-27 14:19

Upload the test file to the Target over Bluetooth by executing the following commands on the Host:

[yur@ubuntu rootfs]$ dd if=/dev/zero bs=1024 count=2048
[yur@ubuntu rootfs]$ obexftp -b 5c:f3:70:70:fa:d5 -B 2 -p
Tried to connect for 287ms
Sending ""...|done

Validate the uploaded file:

/ # ls -lt /root/
-rw-r--r-- 1 root root 2097152 Jan 2 01:21
-rw-r--r-- 1 root root 1048576 Jan 2 01:11

Bluetooth FTP Client on the STM32F7

The Target may also implement the FTP Client functionality and connect to the FTP servers exported over Bluetooth by other devices. The obexftp utility is integrated into the rootfs project and may be used for this purpose. See the commands executed on the Host above in this application note: similar commands may be run on the Target side if we want it to perform the FTP Client role.