Open maxromanovsky opened 1 month ago
Hi @maxromanovsky
the BP786N is also called HEM-7321T.
From what I can find out it should be usable with the HEM-7322T driver.
The error is caused because omblepy does not find the bluetooth characteristic with the UUID
ecbe3980-c9a2-11e1-b1bd-0002a5d5c51b
.
The most reliable way to check if it exist on your omron device, is to use nRF Connect on a phone. I never had bluetooth weirdness using an android phone, the backend seems to be much more stable. When the device is paired, check if the service uuid (ecbe3980...) exists. Most likely it will be there, and this is a linux / bluez issue.
Best, Benjamin
@userx14 thank you for quick reply!
I verified that the service is visible in nRF Connect:
I have tried it again with the external and built-in Bluetooth on RPI Zero 2. I couldn't figure out how to spoof the external Realtek's MAC address, so I reverted to the internal and set MAC address to be the same as my iPhone's (where the app is working). I disabled iPhone's bluetooth just in case (as in, fully in the settings). Still no luck, but the error is different (tried in pairing mode and in normal sync mode). I hope to verify it on Windows later (realistically in few months).
max@rpi02w:~/omblepy-main $ python3 ./omblepy.py -d HEM-7322T -m D0:05:06:80:89:00
2024-07-13 12:19:11,973 - omblepy - INFO - Attempt to import module for device hem-7322t
2024-07-13 12:19:12,120 - omblepy - INFO - Attempt connecting to D0:05:06:80:89:00.
2024-07-13 12:19:14,044 - omblepy - INFO - unpair and disconnect
Traceback (most recent call last):
File "/home/max/omblepy-main/./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/max/omblepy-main/./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 254, in connect
assert_reply(reply)
File "/usr/local/lib/python3.11/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Input/output error
max@rpi02w:~/omblepy-main $ python3 ./omblepy.py -p -d HEM-7322T -m D0:05:06:80:89:00
2024-07-13 12:19:16,467 - omblepy - INFO - Attempt to import module for device hem-7322t
2024-07-13 12:19:16,641 - omblepy - INFO - Attempt connecting to D0:05:06:80:89:00.
2024-07-13 12:19:18,570 - omblepy - INFO - unpair and disconnect
Traceback (most recent call last):
File "/home/max/omblepy-main/./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/max/omblepy-main/./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 254, in connect
assert_reply(reply)
File "/usr/local/lib/python3.11/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Input/output error
@maxromanovsky, thanks for verifying with the nRF app.
So looks like the device has the service, but it is not visible from your linux device.
Do you see a pairing confirmation request on your linux device?
You can use bluetoothctl
and menu gatt/list-attributes
to check the visiblity of the attributes on your test device.
If they are missing there, it is very likely some linux bluetooth weirdness going on.
[org.bluez.Error.Failed] Input/output error
The new error looks like something is going wrong in the bluez linux driver.
I couldn't figure out how to spoof the external Realtek's MAC address, so I reverted to the internal and set MAC address to be the same as my iPhone's (where the app is working).
Omblepy unlike ubpm does not require BT-MAC address spoofing, just leave your mac address as is. When you pair one time with omblepy, it overwrites a pairing key in one bluetooth attribute. This unlocking reading the data from every pc from this point onward, until you pair with your phone again.
I disabled iPhone's bluetooth just in case (as in, fully in the settings).
That's a good step. I had a report where this caused problem, because the omron app tried to autoconnect, interfering with the pairing.
@userx14 sorry for the delayed response.
Here's how it looks like if I launch bluetoothctl
in another terminal and respond yes
to pairing.
I'd appreciate if you could clarify:
bleak
relies on BlueZ, but IDK if that's the OS-level thingie or if there are other implementations.Here's how it looks like if I launch bluetoothctl in another terminal and respond yes to pairing.
Still seems to be the exact same problem.
would that mean that the Omron device now would be paired just to that new device
You can just write pair it again with the mobile app and pull the readings after using omblepy. When you use omblepy in the default mode, it will not modify the "currently unread recods" counter.
Does it make sense to try and test it on Windows instead of Linux?
The Windows 10 bluetooth stack seems to be more reliable for BLE devices like the omron, so yes.
I'm total n00b when it comes to the Bluetooth on Linux, but are there other programming languages that rely on different underlying libraries that could make it work on the same OS version/BT adapter?
So your main goal is to get it working on linux? I think the main problem is, that there is something fundamentally wrong with some versions of the linux bluetooth stack. No mater which tool/library (gatttool / bleak / bluezero) you use on top of the linux bluetooth stack (bluez), will not change anything. But I have not investigated what actually causes the problem of the missing services, maybe it is some mishap in the pairing process, or some bluez versions are just broken. The bluetooth pairing process is a bit complicated with all the possible variations: (https://www.bluetooth.com/blog/bluetooth-pairing-part-1-pairing-feature-exchange/).
Similar question, but regarding the MCUs. I wonder if that can work more reliably on ESP32, for instance. Sorry if that's a dumb question, but I never dug deep into BLE, and always assumed that it "just works", and the only issue with Bluetooth on Linux are missing drivers for some of the chipsets.
Yes the ESP32 would work, I already did some tests in this direction. But so far, I did not develop if further. I could not find a nice way to transfer the data to the pc and give commands to the esp32. Writing the data to a SD card and then having to constantly swapp it between pc and esp seems troublesome.
But now that I think about it, maybe splitting the application between esp32 and pc might be the way to go: The esp32 would implement the omron bluetooth communication, but which addresses are read and written are specified by the pc. Should be relativly simple to do the serial communication with pySerial instead of bleak.
For me omblepy with bleak worked fine on windows 10, my tests for linux were only 10% successful. But win11 seems to break bluetooth compatibility, so I might have to explore the esp32 route sooner or later.
This was very crude test from 2023, just for verifying if basic pairing could be done: ombleESP32.ino.txt
Thank you for the detailed answer.
So your main goal is to get it working on linux?
What I want to achieve ideally, is sync readings to Garmin Connect via omblepy
, but keep syncing the same readings to Omron Connect / Apple Health via native iOS app.
I could not find a nice way to transfer the data to the pc and give commands to the esp32.
Common pattern is to use MQTT for 2-way communication. Another option would be ESPHome with it's connectivity to Home Assistant.
Hi @maxromanovsky, @userx14
As if a working firmware for ESP32 would appear, I can test and implement in my integration as here: https://github.com/RobertWojtowicz/export2garmin/blob/master/manuals/Miscale_ESP32.md
BR, Robert
Find the work in progress esp32 firmware here. In the current state it only supports pairing but not data transmission and has to be operated from the arduino serial monitor.
The first working prototype of the esp32-bridge-firmware is uploaded in the branch. If anyone has time for testing, please report your results. For my HEM-7322 I could successfully read the data.
Thanks, Benjamin
Hi, @userx14
I understand the issues of connection over COM in terms of pairing in the terminal, but will you create a version that sends MQTT data over WiFi ?
In many cases after my experience ESP32 modules have a small internal antenna which results in a small range therefore the gateway must be close to the bluetooth device.
For this reason I use a USB bluetooth with an external antenna so I have coverage throughout my apartment. ESP32 module makes sense when it can be embedded in the device or is very close to it, and the server is far away to be in WiFi range.
BR, Robert
but will you create a version that sends MQTT data over WiFi ?
The issue would be that the full communication would need to be ported to the esp32. I find it much simpler to do the device specific communication and data handling in python, but there is no fundamental reason why it is not doable in c++ on the esp. Currently I do not have enough time to port more functionality to the esp32.
In many cases after my experience ESP32 modules have a small internal antenna which results in a small range therefore the gateway must be close to the bluetooth device.
Some of them have external antenna connectors, which can increase the range like ESP32-WROOM-32UE. I agree that the standard modules are quiet limited in range.
Best, Benjamin
Hi, @userx14
sure I understand, I also have a problem with time ;) If anything, take a look at my code esp32, maybe it will inspire in handling WIFI and MQTT.
BR, Robert
I think BP786N (series 10) has been discontinued by Omron, but it still works well and supported by the Omron Connect app.
I can't find a landing page for it anymore, but the manual is still available: https://omronhealthcare.com/wp-content/uploads/BP786N-IM_EN.pdf
I would be happy to assist with the troubleshooting :)
I have been trying to connect to it using
bluetoothctl
running in another terminal, and when asked interactively[agent] Accept pairing (yes/no):
I answeredyes
bluetoothctl
output:OS Details: