wellue-ble 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wellue_ble-0.1.0/LICENSE +201 -0
- wellue_ble-0.1.0/PKG-INFO +185 -0
- wellue_ble-0.1.0/README.md +161 -0
- wellue_ble-0.1.0/pyproject.toml +57 -0
- wellue_ble-0.1.0/setup.cfg +4 -0
- wellue_ble-0.1.0/src/wellue_ble/__init__.py +26 -0
- wellue_ble-0.1.0/src/wellue_ble/__main__.py +193 -0
- wellue_ble-0.1.0/src/wellue_ble/const.py +77 -0
- wellue_ble-0.1.0/src/wellue_ble/device.py +274 -0
- wellue_ble-0.1.0/src/wellue_ble/exceptions.py +26 -0
- wellue_ble-0.1.0/src/wellue_ble/models.py +251 -0
- wellue_ble-0.1.0/src/wellue_ble/protocol.py +189 -0
- wellue_ble-0.1.0/src/wellue_ble/py.typed +0 -0
- wellue_ble-0.1.0/src/wellue_ble.egg-info/PKG-INFO +185 -0
- wellue_ble-0.1.0/src/wellue_ble.egg-info/SOURCES.txt +16 -0
- wellue_ble-0.1.0/src/wellue_ble.egg-info/dependency_links.txt +1 -0
- wellue_ble-0.1.0/src/wellue_ble.egg-info/requires.txt +5 -0
- wellue_ble-0.1.0/src/wellue_ble.egg-info/top_level.txt +1 -0
wellue_ble-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wellue-ble
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Talk to Wellue Checkme O2 pulse oximeters over Bluetooth Low Energy
|
|
5
|
+
Author: Dylan Sallee
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Source, https://github.com/DylanSallee/wellue-ble
|
|
8
|
+
Keywords: ble,bluetooth,wellue,checkme,pulse-oximeter,home-assistant
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Topic :: Home Automation
|
|
16
|
+
Requires-Python: >=3.13
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: bleak>=0.22
|
|
20
|
+
Requires-Dist: bleak-retry-connector>=3.5
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# wellue-ble
|
|
26
|
+
|
|
27
|
+
A Python library for reading live data from **Wellue Checkme O2** wrist pulse
|
|
28
|
+
oximeters (the Checkme O2 Max and Checkme O2 Ultra) over Bluetooth Low Energy.
|
|
29
|
+
|
|
30
|
+
It was written to power a Home Assistant integration, but it doesn't depend on
|
|
31
|
+
Home Assistant. You can use it from any Python program, or try it directly from
|
|
32
|
+
the command line.
|
|
33
|
+
|
|
34
|
+
> **Not a medical device.** This is an unofficial hobby project that isn't
|
|
35
|
+
> affiliated with Wellue or Viatom. Don't rely on it for medical decisions or
|
|
36
|
+
> alarms.
|
|
37
|
+
|
|
38
|
+
## What it can do
|
|
39
|
+
|
|
40
|
+
| Data | Field | Notes |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| Blood oxygen (SpO2) | `oxygen_saturation_percent` | `None` when there's no valid reading |
|
|
43
|
+
| Heart rate | `heart_rate_bpm` | `None` when there's no valid reading |
|
|
44
|
+
| Perfusion index | `perfusion_index_percent` | Same scale as the official app, e.g. `2.3` |
|
|
45
|
+
| Motion | `motion` | Unitless; a higher number means more movement |
|
|
46
|
+
| Battery level | `battery_level_percent` | |
|
|
47
|
+
| Charging state | `charging_state`, `is_charging` | Not charging / charging / fully charged |
|
|
48
|
+
| Finger present | `finger_detected` | Ignored while the device is charging (see below) |
|
|
49
|
+
| Device information | `DeviceInfo` | Serial number, model, firmware, hardware, bootloader, protocol and file format versions, branch code, region |
|
|
50
|
+
| Current settings | `DeviceInfo` | SpO2 and heart rate alert settings, buzzer volume, vibration intensity, screen mode. **Read only** for now |
|
|
51
|
+
|
|
52
|
+
Planned: changing settings (alert thresholds, vibration, volume, screen mode,
|
|
53
|
+
storage interval).
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
The library isn't published on PyPI yet. To use it, install it from a copy of
|
|
58
|
+
this repository (see [Development](#development)).
|
|
59
|
+
|
|
60
|
+
Python 3.13 or newer is required.
|
|
61
|
+
|
|
62
|
+
## Trying it from the command line
|
|
63
|
+
|
|
64
|
+
Close the ViHealth app first, or turn off Bluetooth on your phone. The device
|
|
65
|
+
only accepts **one connection at a time**.
|
|
66
|
+
|
|
67
|
+
```console
|
|
68
|
+
python -m wellue_ble scan # find nearby devices and their addresses
|
|
69
|
+
python -m wellue_ble info ADDRESS # print device info and current settings
|
|
70
|
+
python -m wellue_ble monitor ADDRESS # print a live reading every second
|
|
71
|
+
python -m wellue_ble --debug monitor ADDRESS # same, plus every raw packet
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
On Linux and Windows, `ADDRESS` is the Bluetooth MAC address
|
|
75
|
+
(`AA:BB:CC:DD:EE:FF`). macOS hides MAC addresses, so `scan` shows a UUID
|
|
76
|
+
there. Use that UUID instead.
|
|
77
|
+
|
|
78
|
+
Example `monitor` output:
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
SpO2 97% HR 72 bpm PI 2.3% motion 0 battery 85% charging NOT_CHARGING finger yes
|
|
82
|
+
SpO2 -- HR -- PI -- motion -- battery 85% charging NOT_CHARGING finger no
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Using it from Python
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import asyncio
|
|
89
|
+
from bleak import BleakScanner
|
|
90
|
+
from wellue_ble import WellueCheckmeO2
|
|
91
|
+
|
|
92
|
+
async def main():
|
|
93
|
+
ble_device = await BleakScanner.find_device_by_address("AA:BB:CC:DD:EE:FF")
|
|
94
|
+
device = WellueCheckmeO2(ble_device)
|
|
95
|
+
|
|
96
|
+
info = await device.get_device_info()
|
|
97
|
+
print(info.serial_number, info.firmware_version)
|
|
98
|
+
|
|
99
|
+
reading = await device.read_sensors() # connects automatically if needed
|
|
100
|
+
print(reading.oxygen_saturation_percent, reading.heart_rate_bpm)
|
|
101
|
+
|
|
102
|
+
await device.disconnect() # frees the device for the official app
|
|
103
|
+
|
|
104
|
+
asyncio.run(main())
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The connection stays open between calls, so calling `read_sensors()` once a
|
|
108
|
+
second keeps one connection open rather than reconnecting every time. If the
|
|
109
|
+
connection drops, the next call reconnects. Every error the library raises on
|
|
110
|
+
purpose is a subclass of `WellueError`.
|
|
111
|
+
|
|
112
|
+
## How it works
|
|
113
|
+
|
|
114
|
+
The Checkme O2 uses a proprietary protocol on top of BLE. The device never
|
|
115
|
+
sends data by itself. Every value has to be requested:
|
|
116
|
+
|
|
117
|
+
1. **Connect** and subscribe to the device's *notify* characteristic, which is
|
|
118
|
+
where its answers arrive.
|
|
119
|
+
2. **Write a request packet** to the device's *write* characteristic.
|
|
120
|
+
3. **Collect the answer.** A long answer is split across several BLE
|
|
121
|
+
notifications. The library joins them back together, checks the checksum
|
|
122
|
+
and decodes the contents.
|
|
123
|
+
|
|
124
|
+
Every packet, in both directions, has the same layout:
|
|
125
|
+
|
|
126
|
+
```text
|
|
127
|
+
marker command ~command block (2) length (2) payload (length bytes) CRC-8
|
|
128
|
+
0xAA request
|
|
129
|
+
0x55 response
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The library uses two commands so far:
|
|
133
|
+
|
|
134
|
+
| Command | Code | Answer |
|
|
135
|
+
| --- | --- | --- |
|
|
136
|
+
| Get device info | `0x14` | JSON text (~264 bytes) with identity and settings |
|
|
137
|
+
| Read sensors | `0x17` | 13 bytes: SpO2, heart rate, battery, charging, motion, perfusion index, finger flag |
|
|
138
|
+
|
|
139
|
+
Other details:
|
|
140
|
+
|
|
141
|
+
- **Invalid readings.** With no finger on the sensor, the device sends
|
|
142
|
+
placeholder values such as 127 or 255. A reading counts as valid only when a
|
|
143
|
+
finger is detected, SpO2 is between 50 and 100 %, and heart rate is between
|
|
144
|
+
30 and 250 bpm. If any check fails, all four health values are `None`.
|
|
145
|
+
- **Charging.** While the device sits in its charger, it sometimes reports a
|
|
146
|
+
finger even when there isn't one. The library ignores the finger flag while
|
|
147
|
+
the device is charging.
|
|
148
|
+
|
|
149
|
+
### Code layout
|
|
150
|
+
|
|
151
|
+
The code is split so that only one file touches Bluetooth. Everything else is
|
|
152
|
+
plain byte handling that you can explore in a Python shell without a device.
|
|
153
|
+
|
|
154
|
+
| File | What it does |
|
|
155
|
+
| --- | --- |
|
|
156
|
+
| [`const.py`](src/wellue_ble/const.py) | Names for the fixed values: UUIDs, command codes, timeouts |
|
|
157
|
+
| [`protocol.py`](src/wellue_ble/protocol.py) | Building request packets, checksums, joining response chunks |
|
|
158
|
+
| [`models.py`](src/wellue_ble/models.py) | Turning response payloads into `SensorReading` and `DeviceInfo` |
|
|
159
|
+
| [`device.py`](src/wellue_ble/device.py) | The `WellueCheckmeO2` class: connecting, sending commands, waiting for answers |
|
|
160
|
+
| [`exceptions.py`](src/wellue_ble/exceptions.py) | The errors the library can raise |
|
|
161
|
+
| [`__main__.py`](src/wellue_ble/__main__.py) | The command line tool |
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
```console
|
|
166
|
+
python -m venv .venv # create an isolated Python environment
|
|
167
|
+
source .venv/bin/activate # use it in this terminal
|
|
168
|
+
python -m pip install -e ".[dev]" # install this library (editable) plus dev tools
|
|
169
|
+
python -m ruff check . # check the code for mistakes
|
|
170
|
+
python -m ruff format . # tidy the code's formatting
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
"Editable" means changes to the files in `src/` take effect immediately, with
|
|
174
|
+
no reinstall needed.
|
|
175
|
+
|
|
176
|
+
## Acknowledgements
|
|
177
|
+
|
|
178
|
+
The protocol was worked out with the help of these open source projects:
|
|
179
|
+
[o2r](https://github.com/shadowmoon-waltz/o2r) and
|
|
180
|
+
[viatom-ble](https://github.com/ecostech/viatom-ble). They were used as
|
|
181
|
+
reference only, and no code was copied from them.
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
Apache License 2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# wellue-ble
|
|
2
|
+
|
|
3
|
+
A Python library for reading live data from **Wellue Checkme O2** wrist pulse
|
|
4
|
+
oximeters (the Checkme O2 Max and Checkme O2 Ultra) over Bluetooth Low Energy.
|
|
5
|
+
|
|
6
|
+
It was written to power a Home Assistant integration, but it doesn't depend on
|
|
7
|
+
Home Assistant. You can use it from any Python program, or try it directly from
|
|
8
|
+
the command line.
|
|
9
|
+
|
|
10
|
+
> **Not a medical device.** This is an unofficial hobby project that isn't
|
|
11
|
+
> affiliated with Wellue or Viatom. Don't rely on it for medical decisions or
|
|
12
|
+
> alarms.
|
|
13
|
+
|
|
14
|
+
## What it can do
|
|
15
|
+
|
|
16
|
+
| Data | Field | Notes |
|
|
17
|
+
| --- | --- | --- |
|
|
18
|
+
| Blood oxygen (SpO2) | `oxygen_saturation_percent` | `None` when there's no valid reading |
|
|
19
|
+
| Heart rate | `heart_rate_bpm` | `None` when there's no valid reading |
|
|
20
|
+
| Perfusion index | `perfusion_index_percent` | Same scale as the official app, e.g. `2.3` |
|
|
21
|
+
| Motion | `motion` | Unitless; a higher number means more movement |
|
|
22
|
+
| Battery level | `battery_level_percent` | |
|
|
23
|
+
| Charging state | `charging_state`, `is_charging` | Not charging / charging / fully charged |
|
|
24
|
+
| Finger present | `finger_detected` | Ignored while the device is charging (see below) |
|
|
25
|
+
| Device information | `DeviceInfo` | Serial number, model, firmware, hardware, bootloader, protocol and file format versions, branch code, region |
|
|
26
|
+
| Current settings | `DeviceInfo` | SpO2 and heart rate alert settings, buzzer volume, vibration intensity, screen mode. **Read only** for now |
|
|
27
|
+
|
|
28
|
+
Planned: changing settings (alert thresholds, vibration, volume, screen mode,
|
|
29
|
+
storage interval).
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
The library isn't published on PyPI yet. To use it, install it from a copy of
|
|
34
|
+
this repository (see [Development](#development)).
|
|
35
|
+
|
|
36
|
+
Python 3.13 or newer is required.
|
|
37
|
+
|
|
38
|
+
## Trying it from the command line
|
|
39
|
+
|
|
40
|
+
Close the ViHealth app first, or turn off Bluetooth on your phone. The device
|
|
41
|
+
only accepts **one connection at a time**.
|
|
42
|
+
|
|
43
|
+
```console
|
|
44
|
+
python -m wellue_ble scan # find nearby devices and their addresses
|
|
45
|
+
python -m wellue_ble info ADDRESS # print device info and current settings
|
|
46
|
+
python -m wellue_ble monitor ADDRESS # print a live reading every second
|
|
47
|
+
python -m wellue_ble --debug monitor ADDRESS # same, plus every raw packet
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
On Linux and Windows, `ADDRESS` is the Bluetooth MAC address
|
|
51
|
+
(`AA:BB:CC:DD:EE:FF`). macOS hides MAC addresses, so `scan` shows a UUID
|
|
52
|
+
there. Use that UUID instead.
|
|
53
|
+
|
|
54
|
+
Example `monitor` output:
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
SpO2 97% HR 72 bpm PI 2.3% motion 0 battery 85% charging NOT_CHARGING finger yes
|
|
58
|
+
SpO2 -- HR -- PI -- motion -- battery 85% charging NOT_CHARGING finger no
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Using it from Python
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import asyncio
|
|
65
|
+
from bleak import BleakScanner
|
|
66
|
+
from wellue_ble import WellueCheckmeO2
|
|
67
|
+
|
|
68
|
+
async def main():
|
|
69
|
+
ble_device = await BleakScanner.find_device_by_address("AA:BB:CC:DD:EE:FF")
|
|
70
|
+
device = WellueCheckmeO2(ble_device)
|
|
71
|
+
|
|
72
|
+
info = await device.get_device_info()
|
|
73
|
+
print(info.serial_number, info.firmware_version)
|
|
74
|
+
|
|
75
|
+
reading = await device.read_sensors() # connects automatically if needed
|
|
76
|
+
print(reading.oxygen_saturation_percent, reading.heart_rate_bpm)
|
|
77
|
+
|
|
78
|
+
await device.disconnect() # frees the device for the official app
|
|
79
|
+
|
|
80
|
+
asyncio.run(main())
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The connection stays open between calls, so calling `read_sensors()` once a
|
|
84
|
+
second keeps one connection open rather than reconnecting every time. If the
|
|
85
|
+
connection drops, the next call reconnects. Every error the library raises on
|
|
86
|
+
purpose is a subclass of `WellueError`.
|
|
87
|
+
|
|
88
|
+
## How it works
|
|
89
|
+
|
|
90
|
+
The Checkme O2 uses a proprietary protocol on top of BLE. The device never
|
|
91
|
+
sends data by itself. Every value has to be requested:
|
|
92
|
+
|
|
93
|
+
1. **Connect** and subscribe to the device's *notify* characteristic, which is
|
|
94
|
+
where its answers arrive.
|
|
95
|
+
2. **Write a request packet** to the device's *write* characteristic.
|
|
96
|
+
3. **Collect the answer.** A long answer is split across several BLE
|
|
97
|
+
notifications. The library joins them back together, checks the checksum
|
|
98
|
+
and decodes the contents.
|
|
99
|
+
|
|
100
|
+
Every packet, in both directions, has the same layout:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
marker command ~command block (2) length (2) payload (length bytes) CRC-8
|
|
104
|
+
0xAA request
|
|
105
|
+
0x55 response
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The library uses two commands so far:
|
|
109
|
+
|
|
110
|
+
| Command | Code | Answer |
|
|
111
|
+
| --- | --- | --- |
|
|
112
|
+
| Get device info | `0x14` | JSON text (~264 bytes) with identity and settings |
|
|
113
|
+
| Read sensors | `0x17` | 13 bytes: SpO2, heart rate, battery, charging, motion, perfusion index, finger flag |
|
|
114
|
+
|
|
115
|
+
Other details:
|
|
116
|
+
|
|
117
|
+
- **Invalid readings.** With no finger on the sensor, the device sends
|
|
118
|
+
placeholder values such as 127 or 255. A reading counts as valid only when a
|
|
119
|
+
finger is detected, SpO2 is between 50 and 100 %, and heart rate is between
|
|
120
|
+
30 and 250 bpm. If any check fails, all four health values are `None`.
|
|
121
|
+
- **Charging.** While the device sits in its charger, it sometimes reports a
|
|
122
|
+
finger even when there isn't one. The library ignores the finger flag while
|
|
123
|
+
the device is charging.
|
|
124
|
+
|
|
125
|
+
### Code layout
|
|
126
|
+
|
|
127
|
+
The code is split so that only one file touches Bluetooth. Everything else is
|
|
128
|
+
plain byte handling that you can explore in a Python shell without a device.
|
|
129
|
+
|
|
130
|
+
| File | What it does |
|
|
131
|
+
| --- | --- |
|
|
132
|
+
| [`const.py`](src/wellue_ble/const.py) | Names for the fixed values: UUIDs, command codes, timeouts |
|
|
133
|
+
| [`protocol.py`](src/wellue_ble/protocol.py) | Building request packets, checksums, joining response chunks |
|
|
134
|
+
| [`models.py`](src/wellue_ble/models.py) | Turning response payloads into `SensorReading` and `DeviceInfo` |
|
|
135
|
+
| [`device.py`](src/wellue_ble/device.py) | The `WellueCheckmeO2` class: connecting, sending commands, waiting for answers |
|
|
136
|
+
| [`exceptions.py`](src/wellue_ble/exceptions.py) | The errors the library can raise |
|
|
137
|
+
| [`__main__.py`](src/wellue_ble/__main__.py) | The command line tool |
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
|
|
141
|
+
```console
|
|
142
|
+
python -m venv .venv # create an isolated Python environment
|
|
143
|
+
source .venv/bin/activate # use it in this terminal
|
|
144
|
+
python -m pip install -e ".[dev]" # install this library (editable) plus dev tools
|
|
145
|
+
python -m ruff check . # check the code for mistakes
|
|
146
|
+
python -m ruff format . # tidy the code's formatting
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
"Editable" means changes to the files in `src/` take effect immediately, with
|
|
150
|
+
no reinstall needed.
|
|
151
|
+
|
|
152
|
+
## Acknowledgements
|
|
153
|
+
|
|
154
|
+
The protocol was worked out with the help of these open source projects:
|
|
155
|
+
[o2r](https://github.com/shadowmoon-waltz/o2r) and
|
|
156
|
+
[viatom-ble](https://github.com/ecostech/viatom-ble). They were used as
|
|
157
|
+
reference only, and no code was copied from them.
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
Apache License 2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# This file describes the project to Python's packaging tools: its name,
|
|
2
|
+
# version, which Python versions it supports, and what it depends on.
|
|
3
|
+
# "pip install ." reads it to build and install the library.
|
|
4
|
+
|
|
5
|
+
[build-system]
|
|
6
|
+
requires = ["setuptools>=77"]
|
|
7
|
+
build-backend = "setuptools.build_meta"
|
|
8
|
+
|
|
9
|
+
[project]
|
|
10
|
+
name = "wellue-ble"
|
|
11
|
+
version = "0.1.0"
|
|
12
|
+
description = "Talk to Wellue Checkme O2 pulse oximeters over Bluetooth Low Energy"
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
# Home Assistant requires Python 3.13 or newer, so we do too.
|
|
15
|
+
requires-python = ">=3.13"
|
|
16
|
+
license = "Apache-2.0"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
18
|
+
authors = [{ name = "Dylan Sallee" }]
|
|
19
|
+
keywords = ["ble", "bluetooth", "wellue", "checkme", "pulse-oximeter", "home-assistant"]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Development Status :: 3 - Alpha",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
|
+
"Topic :: Home Automation",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
# The cross-platform Bluetooth Low Energy library.
|
|
31
|
+
"bleak>=0.22",
|
|
32
|
+
# Reliable connecting/retrying; expected by Home Assistant's bluetooth stack.
|
|
33
|
+
"bleak-retry-connector>=3.5",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.optional-dependencies]
|
|
37
|
+
# Extra tools for working on the library itself: pip install -e ".[dev]"
|
|
38
|
+
dev = [
|
|
39
|
+
"ruff>=0.6",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Source = "https://github.com/DylanSallee/wellue-ble"
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.packages.find]
|
|
46
|
+
where = ["src"]
|
|
47
|
+
|
|
48
|
+
[tool.setuptools.package-data]
|
|
49
|
+
wellue_ble = ["py.typed"]
|
|
50
|
+
|
|
51
|
+
# Ruff is the linter: it checks the code for mistakes and consistent style.
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
line-length = 100
|
|
54
|
+
target-version = "py313"
|
|
55
|
+
|
|
56
|
+
[tool.ruff.lint]
|
|
57
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Talk to Wellue Checkme O2 pulse oximeters over Bluetooth Low Energy.
|
|
2
|
+
|
|
3
|
+
Everything a user of the library normally needs can be imported from here::
|
|
4
|
+
|
|
5
|
+
from wellue_ble import WellueCheckmeO2, SensorReading
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .device import WellueCheckmeO2
|
|
9
|
+
from .exceptions import (
|
|
10
|
+
WellueConnectionError,
|
|
11
|
+
WellueError,
|
|
12
|
+
WellueProtocolError,
|
|
13
|
+
WellueResponseTimeoutError,
|
|
14
|
+
)
|
|
15
|
+
from .models import ChargingState, DeviceInfo, SensorReading
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"ChargingState",
|
|
19
|
+
"DeviceInfo",
|
|
20
|
+
"SensorReading",
|
|
21
|
+
"WellueCheckmeO2",
|
|
22
|
+
"WellueConnectionError",
|
|
23
|
+
"WellueError",
|
|
24
|
+
"WellueProtocolError",
|
|
25
|
+
"WellueResponseTimeoutError",
|
|
26
|
+
]
|