Skip to content

Backend Interface

The Sensor class supports multiple Modbus backends, allowing you to choose which Modbus library to use for communication. Simply pass a backend tag when creating a sensor.

Using a Backend

Default Backend

By default, sensors use the minimalmodbus backend:

from atmospyre.sensors.implementations.gmp252 import GMP252, CO2

# Uses minimalmodbus backend by default
sensor = GMP252(port='/dev/ttyUSB0', slave_address=1)
result = sensor.read([CO2])

Specifying a Backend

To use a different backend, pass a backend_tag parameter:

from atmospyre.sensors.implementations.gmp252 import GMP252, CO2
from atmospyre.sensors.backends.minimalmodbus import MinimalmodbusBackendTag

# Explicitly use minimalmodbus
sensor = GMP252(
    port='/dev/ttyUSB0',
    slave_address=1,
    backend_tag=MinimalmodbusBackendTag()
)
# Automatically dispatched to the correct backend
result = sensor.read([CO2])

Built-in backends

Implemented backends for modbus communication

View All Implemented Sensors