# `BB.Sensor.INA219`
[🔗](https://github.com/beam-bots/bb_sensor_ina219/blob/main/lib/bb/sensor/ina219.ex#L5)

A BB sensor that polls an INA219 voltage / current / power monitor
over I2C and publishes `BB.Message.Sensor.PowerState` messages.

The INA219 is a general-purpose power monitor. Use it to watch a battery,
a motor's draw for stall detection, a logic rail, a solar input, or any
other electrical bus you can run a shunt resistor on.

## Example DSL Usage

    topology do
      link :chassis do
        sensor :main_bus, {BB.Sensor.INA219,
          bus: "i2c-1",
          address: 0x40,
          calibration: :calibrate_32V_2A,
          publish_rate: ~u(10 hertz)
        }
      end
    end

## Options

- `bus` — I2C bus name (e.g. `"i2c-1"`) — required.
- `address` — I2C address (default `0x40`).
- `calibration` — One of `:calibrate_32V_2A` (default), `:calibrate_32V_1A`,
  `:calibrate_16V_400mA`. These match the helper functions on the underlying
  `INA219` library and assume a 0.1Ω shunt resistor (Adafruit breakout).
  Each preset implies a fixed `current_divisor` and `power_divisor`.
- `publish_rate` — How often to read + publish (default `~u(1 hertz)`).

## Published Messages

`BB.Message.Sensor.PowerState` published to `[:sensor | path]` where `path`
is the sensor's position in the topology. Fields are in SI units (Volts,
Amperes, Watts).

A single failed read is logged at warning level and does not crash the
process — the polling loop continues. Persistent failures will manifest as
silence on the topic rather than a crash; future work may add a heartbeat
or self-test message for liveness monitoring.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
