Table of Contents

The following are instructions for connecting a Bluetooth device for serial communication using BlueZ 5.31. (adapted from https://gist.github.com/0/c73e2557d875446b9603)

Prerequisites

The following packages are required:

Pair

 power on
 agent on
 scan on
 ... wait ...
 scan off
 pair <dev>

You should now have `/dev/rfcomm0`.

Unpair

 remove <dev>
 power off

Troubleshooting

Check `rfkill list` to make sure that the Bluetooth device is not blocked.

Accessing from Folk

The folk user needs to be able to open the serial port - make sure the folk user is a member of the dialout group.

Folk program to read from the serial port (in this case a n M5StickC running the following program: https://github.com/naninunenoy/AxisOrange):

Start process {

    Wish $::thisProcess shares statements like \
      [list /someone/ claims the m5stickC has quaternion /q/]

    set serial [open /dev/rfcomm0 r+]
    chan configure $serial -mode "115200,n,8,1"
    chan configure $serial -blocking 0 -buffering none -translation binary

    while {1} {
        set data [read $serial]             ;# read ALL incoming bytes
        set size [string length $data]      ;# number of received byte, may be 0
        if { $size } {
            #puts "received $size bytes: $data"
            # parse header
            binary scan $data {su su iu f3 f3 f4} dataId dataLen t a g q
            #puts "$dataId $dataLen $t $a $g $q"
            Retract $::thisProcess claims the m5stickC has quaternion /q/
            Assert $::thisProcess claims the m5stickC has quaternion $q
        } else {
           #puts "<no data>"
        }
        Step
    }
}