Proper structure of MicroPython package



  • Recently I realized that the MicroPython code which is used to build firmware for our products got too big and hardly readable - almost 2000 LOC. Current structure is very simple - there is single module file which defines main application class. The class is then imported from this module in _main.py, then instantiated and consequently run() method is called. On top of that there are several 3rd party modules located in /lib directory (umqtt, urequests, ...) which are imported as well. All modules are frozen in custom firmware build.

    We would like to re-write the code to become better structured.

    1. The structure should allow flexible building of custom firmware which may be different for each customer with build configuration described in a single file (Python script, JSON, ...)

    2. The package should contain directories for modules with similar functionality - low-level sensor/IC drivers, IoT platform client implementations, etc.

    3. Several attributes and functions should be available for all modules - e.g. current configuration (Python dictionary), logging function, etc.

    What are the best practices when designing and building such MicroPython package?
    What is the best way to share data between modules? E.g. using global statement/namespace, passing object names as arguments, etc.


 

Hello World?

Pylife on Kickstarter - November 2018








Back Us On Kickstarter >

Pycom on Twitter