0

I'm a little confused on how I would interact with a bluetooth device on my Raspberry Pi 4. I have a four probe cooking thermometer that I'd like to read tempatures from and then make a web interface and save my data points. Before I even begin to read data or choose a language I thought I'd try to pair the device with my pi 4.

I've tried the following

sudo bluetoothctl
discoverable on
pairable on
agent on
default-agent
scan on
pair CD:89:7A:45:32:FB
Attempting to pair with CD:89:7A:45:32:FB
[CHG] Device CD:89:7A:45:32:FB Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed

I can pair the device to my Windows laptop and my Android phone without issue. Neither required a pin or any other authentication.

I did try to "connect" to the device from my Pi with the following results

[bluetooth]# connect CD:89:7A:45:32:FB
Attempting to connect to CD:89:7A:45:32:FB
[CHG] Device CD:89:7A:45:32:FB Connected: yes
Connection successful
[bluetooth]# trust CD:89:7A:45:32:FB
Changing CD:89:7A:45:32:FB trust succeeded
[bluetooth]# pair CD:89:7A:45:32:FB
Attempting to pair with CD:89:7A:45:32:FB
[CHG] Device CD:89:7A:45:32:FB Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device CD:89:7A:45:32:FB Connected: no

After connecting to the device I tried to monitor hci0 with no success

$ sudo rfcomm watch hci0
Can't bind RFCOMM socket: Address already in use

So I guess I have two questions

  1. How do I successfully pair my pi 4 over bluetooth to this device?
  2. After I pair it, is there any quick and dirty ways to read values from it at the terminal to verify it's working?

tyia

Updated with the output of list-atributes

nRF Connect shows this device as a BLE device

Primary Service
        /org/bluez/hci0/dev_CD_89_7A_45_32_FB/service000a
        00001801-0000-1000-8000-00805f9b34fb
        Generic Attribute Profile
Primary Service
        /org/bluez/hci0/dev_CD_89_7A_45_32_FB/service000b
        0000fe59-0000-1000-8000-00805f9b34fb
        Nordic Semiconductor ASA
Characteristic
        /org/bluez/hci0/dev_CD_89_7A_45_32_FB/service000b/char000c
        8ec90003-f315-4f60-9fb8-838830daea50
        Vendor specific
Descriptor
        /org/bluez/hci0/dev_CD_89_7A_45_32_FB/service000b/char000c/desc000e
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
Primary Service
        /org/bluez/hci0/dev_CD_89_7A_45_32_FB/service000f
        1086fff0-3343-4817-8bb2-b32206336ce8
        Vendor specific
Characteristic
        /org/bluez/hci0/dev_CD_89_7A_45_32_FB/service000f/char0010
        1086fff1-3343-4817-8bb2-b32206336ce8
        Vendor specific
Characteristic
        /org/bluez/hci0/dev_CD_89_7A_45_32_FB/service000f/char0012
        1086fff2-3343-4817-8bb2-b32206336ce8
        Vendor specific
Descriptor
        /org/bluez/hci0/dev_CD_89_7A_45_32_FB/service000f/char0012/desc0014
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration

Another edit, I think I'm nearly there:

var deviceGUID = 'CD:89:7A:45:32:FB'
var primaryServiceGUID = '1086fff0-3343-4817-8bb2-b32206336ce8'
var characteristicGUID = '1086fff1-3343-4817-8bb2-b32206336ce8'
async function start() {
        const {createBluetooth} = require('node-ble')
        const {bluetooth, destroy} = createBluetooth()
        const adapter = await bluetooth.defaultAdapter()

        console.log('Connecting')
        const device = await adapter.waitDevice(deviceGUID)
        await device.connect()

        const gattServer = await device.gatt()
        console.log('Services')
        console.log(gattServer.services())

        const service1 = await gattServer.getPrimaryService(primaryServiceGUID)
        console.log(service1)

        const characteristic1 = await service1.getCharacteristic(characteristicGUID)
        const buffer = await characteristic1.readValue()
        console.log('Buffer:')
        console.log(buffer)
}

start()

Another update:

Here is the output I get from readValue()

Buffer:
<Buffer 30 00 30 0a 06 00 00 00 3a 67 c2 a0 9f ff fb b7 4c 04 44 c0>
00
:g ÿû·LDÀ
{"type":"Buffer","data":[48,0,48,10,6,0,0,0,58,103,194,160,159,255,251,183,76,4,68,192]}
*********
00
:g ����LD�
*********
4
  • Does the code with the readValue() work?
    – ukBaz
    Commented Feb 9, 2021 at 20:29
  • Kind of - I get what looks like a byte array in response and when I try to convert it I get giberish. Updating the question now to include the output
    – user316114
    Commented Feb 10, 2021 at 15:50
  • Seems to be working as expected in that you are connecting and communicating with the device characteristics. As it is a custom service, then the binary data to send and received will be manufacturer specific.
    – ukBaz
    Commented Feb 11, 2021 at 9:54
  • That's kind of what I was wondering @ukBaz
    – user316114
    Commented Feb 11, 2021 at 18:15

2 Answers 2

1

There are two types of Bluetooth, classic and BLE. How these two types of Bluetooth work is very different. We need to know which type it is before being able to make recommendations on how to proceed.

As bluetoothctl could connect without error, then I suspect that you don't need to do the pair step. When you connected, did you get a list of Bluetooth services available on the cooking thermometer? You can get this list in bluetoothctl with the commands menu gatt and list-attributes CD:89:7A:45:32:FB. From the list of the UUIDs it might be easier to understand what services are on the device.

rfcomm was one of the 7 tools that were marked as deprecated back in 2017. rfcomm was used to connect to Bluetooth Classic devices. There are other ways of making those connections to Bluetooth Classic devices in the latest versions of BlueZ.

nRF Connect for Mobile is a powerful generic Bluetooth Low Energy (BLE) scanning and exploration tool that can be useful to understand the data on a device before starting programming.

The UUIDs being used are not listed in 16-bit UUID Numbers Document on the Bluetooth.com website. This means the thermometer is using custom services and characteristics so you will have to source that information from elsewhere.

The manufacturer may make the information available or you might be lucky with an internet search. If there is no luck with either of them, then there are various tutorials around about how to discover the messages being sent and received.

2
0

So I cleaned up my script to loop through all services and characteristics then read the values. I'm still getting gibberish for the values but here's what I've come up with so far

var deviceGUID = 'CD:89:7A:45:32:FB';

if(process.argv.length > 2) {
    deviceGUID = process.argv[2];
}

async function start() {
    const {createBluetooth} = require('node-ble');
    const {bluetooth, destroy} = createBluetooth();
    const adapter = await bluetooth.defaultAdapter();

    console.log('Connecting');
    const device = await adapter.waitDevice(deviceGUID);
    await device.connect();

    const gattServer = await device.gatt();

    gattServer.services().then(function(services) {
        services.forEach(function(service, index) {
            gattServer.getPrimaryService(service).then(function(services) {
                var characteristics = services['_characteristics'];

                for(const property in characteristics) {
                    services.getCharacteristic(property).then(function(t) {
                        t.readValue().then(function(data) {
                            console.log('Device         = ' + deviceGUID);
                            console.log('Service        = ' + service);
                            console.log('Characteristic = ' + property);
                            console.log('data           = ' + data);
                        });
                    });
                }
            });
        });
    });

    await device.disconnect();
    destroy();
}

start();

Output:

Connecting
Device         = CD:89:7A:45:32:FB
Service        = 0000fe59-0000-1000-8000-00805f9b34fb
Characteristic = 8ec90003-f315-4f60-9fb8-838830daea50
data           = 
Device         = CD:89:7A:45:32:FB
Service        = 1086fff0-3343-4817-8bb2-b32206336ce8
Characteristic = 1086fff1-3343-4817-8bb2-b32206336ce8
data           = 00
:g ����LD�
Device         = CD:89:7A:45:32:FB
Service        = 1086fff0-3343-4817-8bb2-b32206336ce8
Characteristic = 1086fff2-3343-4817-8bb2-b32206336ce8
data           = 0^�������������@
1
  • This is potentially useful information, but it is not an answer. Please edit your question to add this information, AND delete this "answer". Thanks.
    – Seamus
    Commented Mar 12, 2021 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.