Architecture¶
Py ToloMEO splits a microservice into four layers, each with one job: service, plugin, messaging and task.
The diagram shows a command traveling from the ToloMEO Cloud down to a plugin, and data and events traveling back up.
A service declares its plugin class, messaging strategy and commands in an inner Meta class. The declarations are
collected across the class hierarchy when the class is defined, so a subclass extends a service by declaring, not by
overriding.
Services Orchestrate and Own the Subjects¶
The service (ServiceBase, NATSService) is the orchestrator. It owns the messaging strategy, a command registry, a
plugin registry and a task manager. It:
- Subscribes to
commands.{name}.reqand decodes inbound commands. - Runs a service command if one matches, otherwise routes the command to the plugin named by the payload's
id. - Publishes command replies to
events.params, sensor data toevents.data, and OTA status toevents.infos. - Publishes a heartbeat to
heartbeat.{name}.service.
Plugins push their data: push_reading and push_info call back into the service, which publishes at once. There is
no polling loop.
A service holds one plugin class and many plugin instances, keyed by plugin id. SenML records are built in this layer; the messaging layer never sees SenML.
acquire_plugins Decides Which Plugins Attach¶
setup registers the service's commands, then calls acquire_plugins: the one hook a service overrides to say which
plugins it manages and how it gets them. The common steps live in ServiceBase:
| Method | Description |
|---|---|
acquire_plugins |
Which plugins to obtain, and how. Default: none |
new_plugin |
Instantiate Meta.plugin_class |
wire_plugin |
Bind the plugin's push callbacks. Default: none |
attach_plugin |
Wire, attach, and register — registering only if attach succeeds |
A plugin whose connect failed never enters the registry, so it is never sent commands.
OTAService and SingleSensorService attach their one plugin in acquire_plugins. BLESensorService acquires
later, in start(): BLE discovery is slow and would delay startup.
The plugin base classes are abstract, so SensorService, OTAService and BLESensorService name no default plugin
class. Every deployment declares its own; a missing one raises RuntimeError when the service is created.
Plugins Hold Domain Logic, Not Transport¶
Plugins hold the domain logic and know nothing about the transport. The base classes are SensorPlugin (a sensor),
BLESensorPlugin (a Bluetooth Low Energy sensor) and OTAPlugin (firmware updates). Each plugin:
- Declares its commands, metrics and options in a
Metaclass. Output metrics are prefixed with the plugin id. - Opens and closes its own connection to hardware or external resources.
- Runs its background work on its own task manager and pushes results to the service.
Reusable behavior lives in mixins that the base classes combine with PluginBase; see
Plugin System.
Messaging Is Pure Transport¶
NATSMessageStrategy wraps the nats-py client and is pure transport: it serializes payloads to JSON and publishes
or subscribes on subjects. The service uses it only through the MessageStrategyABC interface.
The strategy is swappable in Meta, but NATSService itself decodes NATS messages and owns the NATS subjects. Another
transport needs both a strategy and a service that implements remote_handler.
Background Work Runs as Named Tasks¶
TaskManager runs background work as named tasks that can be paused, resumed, retried and stopped. Every service and
every plugin owns one. Plugins run their read loops and downloads there; a successful detach stops them. DownloadTask
is the resumable HTTP download that OTAPlugin uses.
Services Reach the ToloMEO Cloud Through the Edge Agent¶
A Py ToloMEO service runs on an edge device. It reaches the ToloMEO Cloud through the ToloMEO Edge agent, a NATS proxy
that runs as the connhex-edge-agent service. ToloMEO Cloud sends commands in, such as an OTA update, and receives data
out, such as sensor readings and OTA status.
See also
- Plugin System — the plugin lifecycle,
Metadeclarations and mixins - NATS Messaging — the subjects and records the messaging layer carries
- Implement a Custom Plugin — write a plugin for the plugin layer

