Open
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Member
|
Very cool! We will have to take a detailed look at it. Currently all of our devs are super busy with other projects, so it will unfortunately take a few days until we review this PR and can give you feedback. But we will schedule someone! Edit: Meta-Question: Did you schedule the Copilot review or is that something that automatically happened? I don't mind if you scheduled it, but if it is something that was done automatically i find it a bit rude and would rather turn it off by default. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add MicroPython bindings generator for Tinkerforge devices. This enables using Bricks and Bricklets from MicroPython environments (ESP32, Raspberry Pi Pico, etc.) via TCP/IP.
Design Decisions
Synchronous/polling architecture (like PHP, unlike Python)
MicroPython doesn't support the
threadingmodule on most boards. Instead of Python's multi-threaded approach (background receive thread, callback queue thread, disconnect probe thread), the MicroPython bindings use explicit callback dispatching viaipcon.dispatch_callbacks(seconds), following the same pattern as the PHP bindings. The user controls when callbacks are processed — either in an infinite loop (dispatch_callbacks(-1)) or polled periodically.Flat module structure (no package hierarchy)
MicroPython boards have limited filesystems and no pip/setuptools. All bindings are flat
.pyfiles meant to be copied directly to the board (via mpremote, Thonny, ampy, etc.). There is no__init__.py, nosetup.py, and no namespace package. Imports use the flat form:from ip_connection import IPConnectionrather than Python'sfrom tinkerforge.ip_connection import IPConnection.No auto-reconnect
Auto-reconnect in the Python bindings relies on a background thread to detect disconnections and re-establish the connection. Without threading, this isn't possible, so
set_auto_reconnect()is not provided. Users must handle reconnection explicitly.Simplified examples
if __name__ == "__main__":guard — MicroPython scripts are executed directlyinput("Press key to exit")— embedded systems typically don't have interactive stdinipcon.dispatch_callbacks(-1); non-callback examples end withtime.sleep(1)#!/usr/bin/env micropythonNo threading-related locks
The Python bindings use
stream_lockfor high-level streaming functions. Since MicroPython is single-threaded, these locks are omitted from generated bindings.Minimal testing
The tester runs
py_compile.compile()for syntax validation only (no pylint). MicroPython environments don't typically have linting tools available.Device validity check in callback dispatch
Matches PHP's pattern:
_dispatch_pending_callbacks()callscheck_validity()before dispatching each callback, silently skipping callbacks for devices that have been replaced or don't match.What's Included
ip_connection.py— full protocol implementation (connect, enumerate, authenticate, callback dispatch, streaming)generate_micropython_bindings.py— generates device binding filesgenerate_micropython_doc.py— generates RST API documentation (EN/DE)generate_micropython_examples.py— generates example scriptsgenerate_micropython_stubs.py— generate stubs for IDE supportgenerate_micropython_zip.py— packages bindings for distributionmicropython_common.py— language-specific Device/Packet/Element subclassestest_micropython_bindings.py— syntax validation testerexample_enumerate.py,example_authenticate.py— IP Connection examplesVerification
Manual tests
I did test it with an ESP32-WROOM board via Wifi (connecting to a master with Wifi Extension).
I just made a small play application that can be started on the ESP32 by importing it.
Unfortunately i have not all the bricklets and bricks, that i can test it. 😉
config.py
test_rotary_oled.py
I also made a PR for the
docrepo.Best regards
René