How matth-x/microocpp works
Main Components
• Library Core: The “src” directory contains the core of MicroOcpp. This is where all the modules such as Configuration management, Connection handling, Context, Models, and Operations reside.
• Operation Modules: Under “src/MicroOcpp/Operations” you have the individual OCPP operations (Authorize, BootNotification, RemoteStartTransaction, etc.). Each operation is encapsulated as its own file.
• Model & Services: The “src/MicroOcpp/Model” folder implements various services and functionalities (Authorization, Boot, Availability, Diagnostics, Metering, SmartCharging, Certificates, etc.) that represent the business logic of a charging station.
• Dependencies & Adapters: There are adapters like FilesystemAdapter and MbedTLS integration for certificate management. External dependencies include ArduinoJSON, arduinoWebSockets and optionally Mbed-TLS.
• Hardware & Platform Layer: There is a “Platform.cpp/h” indicating that the library abstracts hardware or system-dependent operations.
• Test Suite: The “tests” directory contains unit tests, benchmarks, and integration tests. This indicates strong test coverage and separation of test code.
• Demo/Example Projects: The “examples” folder shows multiple demo integrations (e.g., for ESP-IDF, ESP, and ESP-TLS) which serve as usage references.
Relationships and Interactions
• Data Flow: Start with external events coming from the microcontroller’s hardware (for instance, an RFID read or a charging session event). These events are processed by the Core (e.g., MicroOcpp.cpp) and then routed to the appropriate Operation (e.g., Authorize, BootNotification) based on configuration.
• Configuration Management: The Configuration Container and related modules manage settings and persist them (e.g., flash storage or a file system) before they are used to adjust behavior at runtime.
• Communication: The Connection module is responsible for establishing and maintaining a WebSocket or similar connection with the OCPP backend, sending/receiving messages.
• Cryptography/Certificates: If enabled (using MbedTLS), certificate management verifies the security handshake and manages credentials.
• The operations make calls to the model layer services which encapsulate business logic specific to charging station functionality.
• CI/CD and Documentation: The ".github/workflows" along with documentation directories show supporting infrastructure for testing, continuous integration, and user documentation. While not part of the runtime architecture, they reflect the overall development and deployment lifecycle.
Architectural Patterns and Important Principles
• Modular Design: By separating operations, models, and core utilities into their own subdirectories, the project follows a modular approach.
• Hardware Abstraction Layer: The use of platform-specific adapters (e.g., for filesystem or communication) suggests that the library is designed to keep hardware dependencies nicely isolated.
• Extensibility: The clear separation between core functionality, operations, and models allows integrators to extend or customize behavior.
• Interdependency Management: The CMakeLists, SConscript, and various build configuration files illustrate how cross-platform compilation and dependency integration are managed.
Relevant Technologies and Frameworks
• C/C++ language for the embedded environment.
• Build Systems: CMake, SCons, and PlatformIO are used based on configuration files (platformio.ini, CMakeLists.txt).
• External Libraries: ArduinoJSON for JSON parsing, ArduinoWebSockets for communication, and optionally MbedTLS for secure communications.
• GitHub Workflows: Various CI workflows (documented in .github/workflows) are part of the overall ecosystem to ensure code quality.