Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ina219 i2c_bus_num - unknown field #318

Open
renedis opened this issue Jun 23, 2023 · 3 comments
Open

ina219 i2c_bus_num - unknown field #318

renedis opened this issue Jun 23, 2023 · 3 comments

Comments

@renedis
Copy link
Contributor

renedis commented Jun 23, 2023

I have a ina219 sensor on i2c available on bus 10 with address 0x43. I can confirm it works with a default python script.

But with mqtt-io it doesnt.

Code:

root@RD-CLUST00:/srv# python3 -m mqtt_io config.yaml
2023-06-23 14:01:30 mqtt_io.__main__ [ERROR] MqttIo crashed!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/__main__.py", line 107, in main
    mqtt_gpio.run()
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/server.py", line 1242, in run
    self._init_sensor_modules()
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/server.py", line 255, in _init_sensor_modules
    self.sensor_modules[sens_config["name"]] = _init_module(
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/server.py", line 122, in _init_module
    module_config = validate_and_normalise_config(module_config, module_schema)
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/config/__init__.py", line 105, in validate_and_normalise_config
    raise ConfigValidationFailed(
mqtt_io.exceptions.ConfigValidationFailed: Config did not validate:
i2c_bus_num:
- unknown field

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/__main__.py", line 115, in <module>
    main()
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/__main__.py", line 107, in main
    mqtt_gpio.run()
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/server.py", line 1242, in run
    self._init_sensor_modules()
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/server.py", line 255, in _init_sensor_modules
    self.sensor_modules[sens_config["name"]] = _init_module(
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/server.py", line 122, in _init_module
    module_config = validate_and_normalise_config(module_config, module_schema)
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/config/__init__.py", line 105, in validate_and_normalise_config
    raise ConfigValidationFailed(
mqtt_io.exceptions.ConfigValidationFailed: Config did not validate:
i2c_bus_num:
- unknown field

yaml:

mqtt:
  host: X
  port: x
  user: "X"
  password: "X"
  topic_prefix: pimqttgpio/mydevice

sensor_modules:
  # An LM75 sensor attached to the I2C bus
  - name: ina219_sensor
    module: ina219
    i2c_bus_num: 10
    chip_addr: 0x43

sensor_inputs:
  # The configuration of the specific sensor value to use (LM75 only has temperature)
  - name: power
    module: ina219_sensor

What did I do wrong?

@ondras12345
Copy link

Your config contains an extra key i2c_bus_num. You have probably copied it from LM75 config, but it is invalid for ina219.
Valid configuration for ina219 must match this schema:

CONFIG_SCHEMA: CerberusSchemaType = {
"chip_addr": dict(type="integer", required=True),
"shunt_ohms": dict(type="float", required=False, empty=False, default=100),
"max_amps": dict(type="float", required=False, empty=False),
"voltage_range": dict(
type="integer", required=False, empty=False, allowed=[16, 32], default=32
),
"gain": dict(
type="string",
required=False,
empty=False,
coerce=lambda x: str(x).upper(),
default="AUTO",
allowed=["AUTO", "1_40MV", "2_80MV", "4_160MV", "8_320MV"],
),
"low_power": dict(type="boolean", required=False, default=False),
}

@renedis
Copy link
Contributor Author

renedis commented Jun 23, 2023

Makes sense.. But this way it doesn't allow you to set the i2c bus number.

the Python3 script works now.. but sadly, it still does not read any values. But that's an other issue I guess.
I've already changed the script to add "i2c_bus_num" and will make a pull-request.

@mschlenstedt
Copy link
Contributor

I added a pull request to include i2c_bus_num. It's in the develop repo now: 2bb2f94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants