Replies: 1 comment 6 replies
-
Thanks for testing advanced code and sharing your findings with us!
Do you get any kind of exception or does the hub just switch off?
This seems to link to the same program as the first one listed.
There is a way to "freeze" MicroPython code along with the firmware. That way you don't have to write it in C but you still get some of the benefits. I don't think is set up right now but we should be able to do that. If set up, you can basically put your Python libraries in a folder and it gets compiled and built into the firmware as a frozen module. Would this be useful? See also optimizing. I haven't tried any of these things recently, so I'm not sure what is or isn't enabled right now. If you find a useful feature that isn't enabled or configured, it should be possible to enable it, so feel free to open an issue. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
Since we now have micropython module support (awesome!), I have spent a few days extracting the PC-Hub-communication protocol of my hub programs into a separate module. While I was at it I wanted to upgrade it's reliability and efficiency, enabling messages of pure binary streams, using a xor-checksum as well as fail-safe timeouts if the messages somehow get desynced with the receiver buffer.
micropython communication modulle
Example micropython program using the module
Python program with the PC-side protocol and a program to test the above program
This works pretty well, however the resulting module is now quite large ( ~2-3kB on the hub). This seems to produce problems for my more complicated programs, which result in a final size of ~6kB and the cityhub crashes the program in hard to debug ways. I am guessing it is a memory thing, since I don't have the issue on the TechnicHub.
My question here, more than actually understanding the memory-issue, would be what my options are regarding moving this protocol-layer to C code. Is the firmware modular in some way where I could just compile the firmware with every new release and just adding the protocol module? Another option would be a fork of the firmware of course, or, if there is interest, I could try to make it an actual PR to the firmware. What are your thoughts?
Edit: Of course all of this assumes that implementing the module in C would make it noticably more efficient. I am guessing so, but admittedly I am still thinking about CPython-level efficiency while working on Micropython programs, which might not be entirely accurate.
Beta Was this translation helpful? Give feedback.
All reactions