Skip to content

Conversation

@o-murphy
Copy link
Contributor

This is the work in progress PR that tries to implement bleak-compatible backend for CircuitPython
This PR is relative to #1812 issue

Keynotes

  • For now the only BleakScanner works, BleakClient is not complete.
  • It uses monkeypatching but better approach can be the conditonal imports
  • bleak have a lot of conditional imports that is not DRY (Too much repeating conditional imports #1813), as you can see that creates the need to make many changes to the original code, i can create a separate PR to refactor it

@o-murphy o-murphy force-pushed the circuit branch 2 times, most recently from 106fd8e to e7f1f5a Compare August 20, 2025 21:03
@o-murphy
Copy link
Contributor Author

This can be done if #1815 will be merged

@dlech
Copy link
Collaborator

dlech commented Aug 21, 2025

I know quite a few people disagree with me on this, but I am not a fan of mixing CPython code and MicroPython code. I think MicroPython/CircuitPython code should be written in a highly optimized way that makes sense for embedded systems and CPython code should be easier to use and understand and take advantage of all of the additional libraries that are available.

Writing a MicroPython or CircuitPython library that has the same high-level API is fine if you want to have the same code run on both embedded systems and desktop, but trying to combine the two in a single code base just makes both worse.

@o-murphy
Copy link
Contributor Author

I know quite a few people disagree with me on this, but I am not a fan of mixing CPython code and MicroPython code. I think MicroPython/CircuitPython code should be written in a highly optimized way that makes sense for embedded systems and CPython code should be easier to use and understand and take advantage of all of the additional libraries that are available.

Writing a MicroPython or CircuitPython library that has the same high-level API is fine if you want to have the same code run on both embedded systems and desktop, but trying to combine the two in a single code base just makes both worse.

I understand about highly optimized code, but currently there is no normal high-level solution for CircuitPython.

When I started doing this, the main criterion was to do everything possible not to modify bleak

this PR at a very early stage, in fact I am trying to make the backend compatible, and it is quite possible with almost no modification to bleak. This is possible because the main codebase is already almost completely compatible, except for some annotations and a few modules missing from CircuitPython, which can be easily bypassed or replaced with native alternatives.

I suggest you wait until I finish at least the main part and see the result, I hope it will pleasantly surprise you. For now it is a test ground.

@o-murphy
Copy link
Contributor Author

If it is not approved in the end, and I put a separate optimized fork. But before that, I’ll at least try.

@o-murphy o-murphy force-pushed the circuit branch 7 times, most recently from 9be1b50 to f4e351b Compare August 22, 2025 14:07
@o-murphy
Copy link
Contributor Author

o-murphy commented Aug 22, 2025

@dlech

It is just still sample, the backend realisation is totally dumb now, and there are a lot of patches aplying in runtime. But It is already allows to run bleak on CircuitPython with just 45 lines modified in the original code base.

It's much simplier to make specially optimized fork for micropython/circuitpython, so If you still not agree with approaches like that I will move it all to 3rd party fork (circuitpython-bleak or kinda) and optimize it specially for micropython/circuitpython

Also if you can please change this PR to draft

@o-murphy o-murphy marked this pull request as draft August 23, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants