Giter VIP home page Giter VIP logo

Comments (19)

userx14 avatar userx14 commented on August 17, 2024 1

Hi Robert,

If I remember correctely, you could use bluetoothctl on the terminal, but you need to do this simulteneously to running the python script with something like a terminal multiplexer.

The Camebridge Silicon Stick will work on linux, but NOT on Windows. ATS2851 sounds fine for both OS.
Windows 11 is sadly not so good for testing, see: #23 (comment)

Regards,
Benjamin

from omblepy.

userx14 avatar userx14 commented on August 17, 2024

Hi Robert,

this is most likely something wrong with the bluetooth library or on os level with the bluetooth connection and pairing.
I assume this is a linux machine? Do you get a pairing confirmation dialog in your os bluetooth dialog?

From my testing only very specific sets of bluez, bluetooth adapters and linux kernel versions did work.
What bluetooth adapter are you using?

If you have the possibility please test with win10 to rule out the operating system as the cause,
as that was the most reproducible setup unfortunately.
The windows 10 live boot images did also work in my testing.

Best
Benjamin

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

Hi @userx14

I am using Debian 12, I am using ssh console, for this you need a graphical mode ?
I use usb bluetooth 5.3 on ATS2851 chipset (supported natively by Debian 12). It works fine for me when syncing Xiaomi scales.
Unfortunately I do not have Windows 10 I have Windows 11, but the solution wants to use with Linux.

PS. I also tested on BT 4.0 (Cambridge Silicon Radio) and the same problem.

BR,
Robert

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

@userx14

Unfortunately, it doesn't want to pair:

^Croot@adm:~# bluetoothctl pair 28:FF:B2:32:E0:19
Attempting to pair with 28:FF:B2:32:E0:19
Failed to pair: org.bluez.Error.AuthenticationFailed

Which version of bluez are you using ?

root@adm:~# dpkg --status bluez | grep '^Version:'
Version: 5.66-1+deb12u1
root@adm:~#

Is it possible to read data without pairing ?

BR,
Robert

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

@userx14

BT 4.0 works better than BT 5.3, at least with bluetoothctl:

[bluetooth]# connect 28:FF:B2:32:E0:19
Attempting to connect to 28:FF:B2:32:E0:19
[CHG] Device 28:FF:B2:32:E0:19 Connected: yes
Connection successful
[NEW] Primary Service (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0100
        00001801-0000-1000-8000-00805f9b34fb
        Generic Attribute Profile
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0100/char0110
        00002a05-0000-1000-8000-00805f9b34fb
        Service Changed
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0100/char0110/desc0112
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Primary Service (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0200
        0000180a-0000-1000-8000-00805f9b34fb
        Device Information
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0200/char0210
        00002a23-0000-1000-8000-00805f9b34fb
        System ID
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0200/char0220
        00002a24-0000-1000-8000-00805f9b34fb
        Model Number String
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0200/char0230
        00002a25-0000-1000-8000-00805f9b34fb
        Serial Number String
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0200/char0240
        00002a26-0000-1000-8000-00805f9b34fb
        Firmware Revision String
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0200/char0250
        00002a27-0000-1000-8000-00805f9b34fb
        Hardware Revision String
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0200/char0260
        00002a28-0000-1000-8000-00805f9b34fb
        Software Revision String
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0200/char0270
        00002a29-0000-1000-8000-00805f9b34fb
        Manufacturer Name String
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0200/char0280
        00002a2a-0000-1000-8000-00805f9b34fb
        IEEE 11073-20601 Regulatory Cert. Data List
[NEW] Primary Service (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300
        ecbe3980-c9a2-11e1-b1bd-0002a5d5c51b
        Vendor specific
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0310
        b305b680-aee7-11e1-a730-0002a5d5c51b
        Vendor specific
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0310/desc0312
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0320
        db5b55e0-aee7-11e1-965e-0002a5d5c51b
        Vendor specific
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0330
        e0b8a060-aee7-11e1-92f4-0002a5d5c51b
        Vendor specific
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0340
        0ae12b00-aee8-11e1-a192-0002a5d5c51b
        Vendor specific
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0350
        10e1ba60-aee8-11e1-89e5-0002a5d5c51b
        Vendor specific
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0360
        49123040-aee8-11e1-a74d-0002a5d5c51b
        Vendor specific
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0360/desc0362
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0370
        4d0bf320-aee8-11e1-a0d9-0002a5d5c51b
        Vendor specific
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0370/desc0372
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0380
        5128ce60-aee8-11e1-b84b-0002a5d5c51b
        Vendor specific
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0380/desc0382
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0390
        560f1420-aee8-11e1-8184-0002a5d5c51b
        Vendor specific
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char0390/desc0392
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char03a0
        8858eb40-aee8-11e1-bb67-0002a5d5c51b
        Vendor specific
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0300/char03a0/desc03a2
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Primary Service (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0400
        0000180f-0000-1000-8000-00805f9b34fb
        Battery Service
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0400/char0410
        00002a19-0000-1000-8000-00805f9b34fb
        Battery Level
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0400/char0410/desc0412
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Primary Service (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0500
        00001805-0000-1000-8000-00805f9b34fb
        Current Time Service
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0500/char0510
        00002a2b-0000-1000-8000-00805f9b34fb
        Current Time
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0500/char0510/desc0512
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Primary Service (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0600
        5df5e817-a945-4f81-89c0-3d4e9759c07c
        Vendor specific
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0600/char0610
        00002a52-0000-1000-8000-00805f9b34fb
        Record Access Control Point
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0600/char0610/desc0612
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0600/char0620
        c195da8a-0e23-4582-acd8-d446c77c45de
        Vendor specific
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0600/char0620/desc0622
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Primary Service (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0700
        0000181c-0000-1000-8000-00805f9b34fb
        User Data
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0700/char0710
        00002a99-0000-1000-8000-00805f9b34fb
        Database Change Increment
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0700/char0710/desc0712
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0700/char0720
        00002a9a-0000-1000-8000-00805f9b34fb
        User Index
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0700/char0730
        00002a9f-0000-1000-8000-00805f9b34fb
        User Control Point
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0700/char0730/desc0732
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0700/char0740
        00002a85-0000-1000-8000-00805f9b34fb
        Date of Birth
[NEW] Primary Service (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0800
        00001810-0000-1000-8000-00805f9b34fb
        Blood Pressure
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0800/char0810
        00002a35-0000-1000-8000-00805f9b34fb
        Blood Pressure Measurement
[NEW] Descriptor (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0800/char0810/desc0812
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0000)
        /org/bluez/hci0/dev_28_FF_B2_32_E0_19/service0800/char0820
        00002a49-0000-1000-8000-00805f9b34fb
        Blood Pressure Feature
[CHG] Device 28:FF:B2:32:E0:19 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device 28:FF:B2:32:E0:19 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device 28:FF:B2:32:E0:19 UUIDs: 00001805-0000-1000-8000-00805f9b34fb
[CHG] Device 28:FF:B2:32:E0:19 UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Device 28:FF:B2:32:E0:19 UUIDs: 0000180f-0000-1000-8000-00805f9b34fb
[CHG] Device 28:FF:B2:32:E0:19 UUIDs: 00001810-0000-1000-8000-00805f9b34fb
[CHG] Device 28:FF:B2:32:E0:19 UUIDs: 0000181c-0000-1000-8000-00805f9b34fb
[CHG] Device 28:FF:B2:32:E0:19 UUIDs: 5df5e817-a945-4f81-89c0-3d4e9759c07c
[CHG] Device 28:FF:B2:32:E0:19 UUIDs: ecbe3980-c9a2-11e1-b1bd-0002a5d5c51b
[CHG] Device 28:FF:B2:32:E0:19 ServicesResolved: yes
[CHG] Device 28:FF:B2:32:E0:19 Name: M7 Intelli IT
[CHG] Device 28:FF:B2:32:E0:19 Alias: M7 Intelli IT
[CHG] Device 28:FF:B2:32:E0:19 Appearance: 0x0381

BR,
Robert

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

Now your script returns this:

root@adm:/home/robert/omblepy# python3 omblepy.py -p -d HEM-7361T --loggerDebug
2024-06-16 12:34:16,154 - omblepy - INFO - Attempt to import module for device hem-7361t
To improve your chance of a successful connection please do the following:
 -remove previous device pairings in your OS's bluetooth dialog
 -enable bluetooth on you omron device and use the specified mode (pairing or normal)
 -do not accept any pairing dialog until you selected your device in the following list

Select your Omron device from the list below...
/home/robert/omblepy/omblepy.py:297: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead
  devices = sorted(devices, key = lambda x: x.rssi, reverse=True)
/home/robert/omblepy/omblepy.py:301: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead
  tableEntries.append([deviceIdx, device.address, device.name, device.rssi])
+----+-------------------+-------------------------------+------+
| ID | MAC               | NAME                          | RSSI |
+----+-------------------+-------------------------------+------+
| 0  | 24:FC:E5:8F:CE:BF | 24-FC-E5-8F-CE-BF             | -66  |
| 1  | 10:0E:68:2C:6A:9F | 10-0E-68-2C-6A-9F             | -70  |
| 2  | A0:92:08:5A:95:A0 | TY                            | -76  |
| 3  | 54:A1:FC:06:4A:6A | 54-A1-FC-06-4A-6A             | -81  |
| 4  | 14:13:0B:44:F5:FC | 14-13-0B-44-F5-FC             | -86  |
| 5  | 28:FF:B2:32:E0:19 | BLEsmart_0000025828FFB232E019 | -90  |
| 6  | 68:27:19:1B:31:83 | D1531102                      | -93  |
+----+-------------------+-------------------------------+------+
Enter ID or just press Enter to rescan.
5
2024-06-16 12:34:42,741 - omblepy - INFO - Attempt connecting to 28:FF:B2:32:E0:19.
2024-06-16 12:35:00,542 - omblepy - INFO - unpair and disconnect
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/bleak/backends/bluezdbus/client.py", line 273, in connect
    await self.get_services(
  File "/usr/local/lib/python3.11/dist-packages/bleak/backends/bluezdbus/client.py", line 661, in get_services
    self.services = await manager.get_services(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/bleak/backends/bluezdbus/manager.py", line 666, in get_services
    await self._wait_for_services_discovery(device_path)
  File "/usr/local/lib/python3.11/dist-packages/bleak/backends/bluezdbus/manager.py", line 783, in _wait_for_services_discovery
    done, _ = await asyncio.wait(
              ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 418, in wait
    return await _wait(fs, timeout, return_when, loop)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 525, in _wait
    await waiter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/robert/omblepy/omblepy.py", line 389, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/robert/omblepy/omblepy.py", line 362, in main
    await bleClient.connect()
  File "/usr/local/lib/python3.11/dist-packages/bleak/__init__.py", line 615, in connect
    return await self._backend.connect(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/bleak/backends/bluezdbus/client.py", line 151, in connect
    async with async_timeout(timeout):
  File "/usr/lib/python3.11/asyncio/timeouts.py", line 98, in __aexit__
    raise TimeoutError
TimeoutError

from omblepy.

userx14 avatar userx14 commented on August 17, 2024

Hi Robert,

Which version of bluez are you using ?

I think it was an old ubuntu version with bluez 5.55.
But that was some time ago, so I don't remember all the details.
For most of my testing I used Win 10.

You could also try ubpm, he uses the QT Bluetooth library.
But ubpm requires cloning the bluetooth mac address from a phone with the omron app,
this should work with your csr stick though.

Is it possible to read data without pairing ?

You need bluetooth pairing to work, in order to read out the data.
Without pairing it returns error codes when you try to write / read to the unlock characteristic.

Now your script returns this: [...]

This still looks like some error in the bluetooth library (_wait_for_services_discovery).

Regards,
Benjamin

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

@userx14 Thanks for your reply,
A little progress, Raspberry PI0W with integrated BT and Debian 12 32-bit (Linux raspberrypi 6.6.31+rpt-rpi-v6).
Pairing works:

pi@raspberrypi:~/omblepy $ python3 omblepy.py -p -d HEM-7361T
2024-06-16 13:49:51,005 - omblepy - INFO - Attempt to import module for device hem-7361t
To improve your chance of a successful connection please do the following:
 -remove previous device pairings in your OS's bluetooth dialog
 -enable bluetooth on you omron device and use the specified mode (pairing or normal)
 -do not accept any pairing dialog until you selected your device in the following list

Select your Omron device from the list below...
/home/pi/omblepy/omblepy.py:297: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead
  devices = sorted(devices, key = lambda x: x.rssi, reverse=True)
/home/pi/omblepy/omblepy.py:301: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead
  tableEntries.append([deviceIdx, device.address, device.name, device.rssi])
+----+-------------------+-------------------------------+------+
| ID | MAC               | NAME                          | RSSI |
+----+-------------------+-------------------------------+------+
| 0  | 0A:F7:B6:36:9B:19 | 0A-F7-B6-36-9B-19             | -43  |
| 1  | 28:FF:B2:32:E0:19 | BLEsmart_0000025828FFB232E019 | -47  |
| 2  | 14:13:0B:44:F5:FC | 14-13-0B-44-F5-FC             | -50  |
| 3  | 24:FC:E5:8F:CE:BF | 24-FC-E5-8F-CE-BF             | -56  |
| 4  | 75:E4:18:07:80:DB | 75-E4-18-07-80-DB             | -75  |
| 5  | 68:27:A8:E5:EF:15 | 68-27-A8-E5-EF-15             | -76  |
| 6  | 6C:6F:2F:F2:49:A3 | 6C-6F-2F-F2-49-A3             | -83  |
| 7  | D5:F0:73:F7:0C:F0 | D5-F0-73-F7-0C-F0             | -84  |
| 8  | 65:B4:EB:9D:FF:87 | 65-B4-EB-9D-FF-87             | -94  |
| 9  | A0:92:08:5A:95:A0 | TY                            | -95  |
| 10 | 38:01:95:9B:80:D1 | 38-01-95-9B-80-D1             | -95  |
| 11 | 7D:33:F0:58:C0:38 | 7D-33-F0-58-C0-38             | -97  |
| 12 | 68:27:19:1B:31:83 | D1531102                      | -97  |
+----+-------------------+-------------------------------+------+
Enter ID or just press Enter to rescan.
1
2024-06-16 13:49:59,737 - omblepy - INFO - Attempt connecting to 28:FF:B2:32:E0:19.
2024-06-16 13:50:04,954 - omblepy - INFO - Paired device successfully with new key bytearray(b'\xde\xad\xbe\xaf\x124\x124\xde\xad\xbe\xaf\x124\x124').
2024-06-16 13:50:04,960 - omblepy - INFO - From now on you can connect ommit the -p flag, even on other PCs with different bluetooth-mac-addresses.
2024-06-16 13:50:05,629 - omblepy - INFO - unpair and disconnect
Traceback (most recent call last):
  File "/home/pi/omblepy/omblepy.py", line 389, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/pi/omblepy/omblepy.py", line 387, in main
    await bleClient.disconnect()
  File "/usr/local/lib/python3.11/dist-packages/bleak/__init__.py", line 624, in disconnect
    return await self._backend.disconnect()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/bleak/backends/bluezdbus/client.py", line 425, in disconnect
    assert self._bus is None
           ^^^^^^^^^^^^^^^^^
AssertionError

Download data works:

pi@raspberrypi:~/omblepy $ python3 omblepy.py -d HEM-7361T --mac 28:FF:B2:32:E0:19
2024-06-16 14:14:59,961 - omblepy - INFO - Attempt to import module for device hem-7361t
2024-06-16 14:15:00,442 - omblepy - INFO - Attempt connecting to 28:FF:B2:32:E0:19.
2024-06-16 14:15:05,845 - omblepy - INFO - communication started
2024-06-16 14:15:06,510 - omblepy - INFO - start reading data, this can take a while, use debug flag to see progress
2024-06-16 14:15:36,948 - omblepy - INFO - communication finished
2024-06-16 14:15:37,058 - omblepy - INFO - writing data to user1.csv
2024-06-16 14:15:37,141 - omblepy - INFO - writing data to user2.csv
2024-06-16 14:15:37,370 - omblepy - INFO - unpair and disconnect
Traceback (most recent call last):
  File "/home/pi/omblepy/omblepy.py", line 389, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/pi/omblepy/omblepy.py", line 387, in main
    await bleClient.disconnect()
  File "/usr/local/lib/python3.11/dist-packages/bleak/__init__.py", line 624, in disconnect
    return await self._backend.disconnect()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/bleak/backends/bluezdbus/client.py", line 425, in disconnect
    assert self._bus is None
           ^^^^^^^^^^^^^^^^^
AssertionError

Now I need to figure out why it doesn't work on x86 virtual machine with BT 4.0 (and 5.3) with Debian 12 64bit, maybe some ideas ?

pi@raspberrypi:~/omblepy $ dpkg --status bluez | grep '^Version:'
Version: 5.66-1+rpt1+deb12u1

BR,
Robert

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

@userx14

I made a clone of the MAC address of the paired BT 4.1 Raspberry PI and changed the MAC to BT 4.0 (other machine) on which the omblepy reading does not work.
Unfortunately this did not help, I would like a simple way from the command line to read the measurement data.

BR,
Robert

from omblepy.

userx14 avatar userx14 commented on August 17, 2024

I'm not really sure what it could be, but it is interesting that you got it working with a pi zero w.
Maybe it is related to the differences in the bluetooth driver of the broadcom chipset,
or it might be some configuration regarding bluetooth le, like encryption or the device supported pairing modes.
Did you try changing them with btmgmt on your other machine?
(setting up encryption: https://unix.stackexchange.com/a/678696)

Maybe you can find a difference when you try to look at the communication with the bluetooth stack:
https://wiki.ubuntu.com/DebuggingBluetooth

Regards
Benjamin

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

HI @userx14

I came to the same thoughts, that it is the fault of BT firmware or drivers. I will continue to fight with BT :)

BR,
Robert

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

Same problem with BT5.0/5.1 on RTL8761B chipset, with btmgt at ombley launch, I even tried to confirm pairing:

[mgmt]# power off
hci0 Set Powered complete, settings: connectable bondable ssp br/edr le secure-conn
[mgmt]# discov on
hci0 Set Discoverable complete, settings: connectable discoverable bondable ssp br/edr le secure-conn
[mgmt]# connectable on
hci0 Set Connectable complete, settings: connectable discoverable bondable ssp br/edr le secure-conn
[mgmt]# pairable on
hci0 Set Bondable complete, settings: connectable discoverable bondable ssp br/edr le secure-conn
[mgmt]# power on
hci0 Set Powered complete, settings: powered connectable discoverable bondable ssp br/edr le secure-conn
hci0 type 6 discovering on
hci0 type 6 discovering off
hci0 type 6 discovering on
hci0 type 6 discovering off
hci0 28:FF:B2:32:E0:19 type LE Public connected eir_len 22
hci0 28:FF:B2:32:E0:19 User Confirm 000000 hint 1
[] Accept pairing with 28:FF:B2:32:E0:19 (yes/no) >>  hci0 28:FF:B2:32:E0:19 auth failed with status 0x05 (Authentication Failed)
[] Accept pairing with 28:FF:B2:32:E0:19 (yes/no) >>  hci0 28:FF:B2:32:E0:19 type LE Public disconnected with reason 2
[] Accept pairing with 28:FF:B2:32:E0:19 (yes/no) >>  yes
User Confirm reply failed. status 0x02 (Not Connected)

BR,
Robert

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

Hi, @userx14

I got a good scan just not sure what else helped :)

Bingo! works with BT4.1 (Cambridge Silicon Radio) i BT5.1 (RTL8761B) - If bluetoothctl console is enabled then everything works, just how to solve it permanently?

It is necessary to remember that the BT of the phone with the app should be turned off because the Omron disappears from the possibility of reading data when the app connects to the Omron.

BR,
Robert

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

Looks like this problem:
hbldh/bleak#1100
hbldh/bleak#1434
hbldh/bleak#758

Workaround does not solve this problem:
#22

Interesting article works correctly bluetoothctl and bt-agent tool:
https://technotes.kynetics.com/2018/pairing_agents_bluez/

There is another problem with BT5.3 - ATS2851 chipset:

hci0 28:FF:B2:32:E0:19 type LE Public connect failed (status 0x01, Unknown Command)

https://forum.manjaro.org/t/bluetooth-sends-5-0-commands-to-4-0-devices-any-way-to-force-compatibility/162940

BR,
Robert

from omblepy.

userx14 avatar userx14 commented on August 17, 2024

Bingo! works with BT4.1 (Cambridge Silicon Radio) i BT5.1 (RTL8761B) - If bluetoothctl console is enabled then everything works, just how to solve it permanently?

Not sure how a permanent fix looks like,
but that is what I meant with terminal multiplexer and bluetoothctl simultaneously, in my previous comment.

It is necessary to remember that the BT of the phone with the app should be turned off because the Omron disappears from the possibility of reading data when the app connects to the Omron.

Probably the omron does not support multiple connections, sounds as expected.

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

@userx14

The workaround for the problem is very simple to script in bash:

#!/bin/bash

coproc bluetoothctl

path=`cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd`

python3 $path/omblepy.py -d HEM-7361T

An additional issue, Omron sends data only 2 times data - after establishing a connection 2 times and then disappears from transmission.

BR,
Robert

from omblepy.

userx14 avatar userx14 commented on August 17, 2024

Hi Robert,

thanks for posting the bash script, I think I should add a note about running bluetoothctl to the readme of this project.

Omron sends data only 2 times data

Does that mean that only two records are sent, or that after the second time reading all the records, the transmission does not work anymore? And what part stops working, the pairing process, the unlocking process or the data readout?

Regards,
Benjamin

from omblepy.

RobertWojtowicz avatar RobertWojtowicz commented on August 17, 2024

This is probably the nature of Omron, when it connects to a paired device, it sends all the data, and then it disconnects and disappears from the search?

This is not cool when you have a paired phone and omblepy, because the phone will establish a connection faster and even when it downloads the data it doesn't have a chance to download through omblepy.

BR,
Robert

from omblepy.

userx14 avatar userx14 commented on August 17, 2024

I think it does poll the omron from time to time so that it can automatically synchronize new data. Can you disable this in the omron app options (auto synchronization)?

To be fair, omron very likely didn't plan for third party readout tools.

Regards,
Benjamin

from omblepy.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.