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

New sensor MPU6050 #421

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

Conversation

petr-stupka
Copy link

@petr-stupka petr-stupka commented Feb 5, 2025

This pull request includes significant updates to the sensor configuration and implementation, particularly for the MPU-6050 sensor, as well as improvements to the handling of sensor data in the server module. The changes enhance the flexibility and functionality of the sensor system.

Sensor Configuration and Implementation:

  • mqtt_io/config/config.schema.yml: Updated the sensor_inputs configuration to allow floating-point values for the interval and reduced the minimum value to 0.1 seconds.
  • mqtt_io/modules/sensor/mpu6050.py: Added a new implementation for the MPU-6050 Gyroscope/Accelerometer sensor, including configuration schema, initialization, and data reading methods.

Server Module Enhancements:

  • mqtt_io/server.py: Added JSON import to support new functionality.
  • mqtt_io/server.py: Modified publish_sensor_callback to convert sensor values to JSON strings if they are dictionaries.
  • mqtt_io/server.py: Updated get_sensor_value to skip rounding if the sensor value is a dictionary.

Sensor config:

sensor_modules:

  - name: mpu6050
    module: mpu6050
    chip_addr: 0x69

sensor_inputs:

  - name: gyro
    module: mpu6050
    interval: 0.1

Sensor output:

2025-02-05 09:31:34 mqtt_io.server [INFO] Read sensor 'gyro' value of {'gyro_x': -280, 'gyro_y': 102, 'gyro_z': 94, 'angle_x': 2.9907613976619283, 'angle_y': -2.934957982527787}
2025-02-05 09:31:34 mqtt_io.server [INFO] Read sensor 'gyro' value of {'gyro_x': -307, 'gyro_y': 110, 'gyro_z': 89, 'angle_x': 3.2418049788882777, 'angle_y': -2.5581444189852265}
2025-02-05 09:31:34 mqtt_io.server [INFO] Read sensor 'gyro' value of {'gyro_x': -287, 'gyro_y': 111, 'gyro_z': 74, 'angle_x': 3.1441911935503275, 'angle_y': -2.6698174414062046}
2025-02-05 09:31:34 mqtt_io.server [INFO] Read sensor 'gyro' value of {'gyro_x': -299, 'gyro_y': 98, 'gyro_z': 99, 'angle_x': 3.032610238196618, 'angle_y': -2.7116896376607555}
2025-02-05 09:31:34 mqtt_io.server [INFO] Read sensor 'gyro' value of {'gyro_x': -273, 'gyro_y': 136, 'gyro_z': 105, 'angle_x': 3.032610238196618, 'angle_y': -2.61398341444651}
2025-02-05 09:31:34 mqtt_io.server [INFO] Read sensor 'gyro' value of {'gyro_x': -287, 'gyro_y': 126, 'gyro_z': 113, 'angle_x': 2.8512424422652436, 'angle_y': -2.76751471624175}
2025-02-05 09:31:35 mqtt_io.server [INFO] Read sensor 'gyro' value of {'gyro_x': -296, 'gyro_y': 129, 'gyro_z': 114, 'angle_x': 3.0186609823291506, 'angle_y': -3.0744558402579947}

@petr-stupka petr-stupka mentioned this pull request Feb 5, 2025

from json import dumps
from typing import cast
import smbus
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the smbus module should be moved to the setup_modul method and in the REQUIREMENTS, so it is only required, when this module is really used. (see e.g. lm75 sensor)

Copy link
Collaborator

@BenjiU BenjiU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix comment in mpu6050.py

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

Successfully merging this pull request may close these issues.

2 participants