How wirepas/wirepas-mqtt-library works
Project type and purpose
• This is an open-source Python library (wheel) named “wirepas-mqtt-library.”
• Its purpose is to wrap MQTT connectivity and protobuf payload handling for the Wirepas Gateway backend API.
• It provides both synchronous and asynchronous methods to control a full Wirepas network without managing individual gateway connections.
File structure
• Top-level directories:
• .github – CI workflows for packaging and documentation
• docs – Sphinx documentation sources and build scripts
• examples – Python scripts demonstrating library usage
• wirepas_mqtt_library – the actual Python module implementing:
– __about__.py (metadata)
– wirepas_network_interface.py (core interface)
– topic_helper.py (topic naming/management)
– wirepas_otap_helper.py, wirepas_tlv_app_config_helper.py (feature helpers)
– otap_status_storage.py (state persistence)
• Configuration files:
• requirements.txt, setup.py for packaging dependencies
• docs/conf.py for Sphinx
• The structure follows a typical library layout, separating documentation, examples, and source code.
README for additional insights
• Describes a three–threading model:
• Network thread runs all internal MQTT operations
• Worker thread(s) dispatch user callbacks (configurable pool size)
• Calling thread blocks on synchronous calls
• Emphasizes synchronous vs. asynchronous usage patterns
• Notes use of MQTT with protobuf payloads under the hood
a. Components
1. User Application (example scripts or client code)
2. WirepasNetworkInterface (WN I) – the library’s façade
3. MQTT Client Library (e.g., paho-mqtt)
4. MQTT Broker (Wirepas Gateway endpoint)
5. Wirepas Gateway / Network Backend
6. Protobuf Encoder/Decoder inside the library
7. Threading subsystem:
– Network Thread
– Worker Thread Pool
– Calling Thread
8. Helper modules: topic_helper, OTAP helper, TLV app config helper, status storage
b. Relationships / Data flow
• User Application calls WNI methods (sync or async).
• WNI hands off publish/subscribes to the MQTT client on the Network Thread.
• MQTT Broker ↔ WNI via MQTT topics (protobuf payloads).
• Incoming MQTT messages go to the Network Thread → parsed by Protobuf Decoder → dispatched to Worker Thread(s).
• Worker threads execute user callbacks or resolve futures for synchronous calls.
• Helpers manage topic naming, OTAP sequences, TLV config serialization, and store OTAP status.
c. Architectural patterns / principles
• Pub/Sub messaging via MQTT
• Thread-based concurrency to isolate network IO from user callbacks
• Modular helpers for cross-cutting concerns (topics, OTAP, config)
• Dual sync/async API design for flexibility
d. Key technologies
• Python 3.x
• MQTT (via paho-mqtt or similar client)
• Protocol Buffers for payload serialization
• Sphinx for docs
• Threading module for concurrency