BB.Sensor.INA219 (bb_sensor_ina219 v0.2.2)

Copy Markdown View Source

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).

Read failures crash the process — going silent on the topic would hide a dead sensor from the supervisor and from downstream consumers. The supervisor restarts the process per its restart strategy; if the device is genuinely gone (e.g. a USB-attached bus disappeared), init/1 will fail to reacquire and the restart intensity limit propagates the failure up the tree.