Netdata Community

BME680 digital i2c temp sensor support

Tried to post this at github but got directed here… I modified the AM2320 sensor python module to fit the Bosch BME680 sensor for i2c com. on a RPi. It works fine but I could not get out two decimal readings in the charts. If someone could give a pointer to as get those decimals in the charts and perhaps later post this at github. NOTE: If first i2c module on a RPi you need to add netdata user to i2c group:

apt install i2c-tools
adduser netdata i2c.

https://shop.pimoroni.com/products/bme680-breakout

# _*_ coding: utf-8 _*_
# Description: BME680 netdata module
# Author: lennong
# SPDX-License-Identifier: GPL-3.0-or-Later

try:
    import board
    import adafruit_bme680

    HAS_BME680 = True
except ImportError:
    HAS_BME680 = False

from bases.FrameworkServices.SimpleService import SimpleService

ORDER = [
    'temperature',
    'humidity',
    'pressure',
]

CHARTS = {
    'temperature': {
        'options': [None, 'Air Temperature', 'celsius', 'temperature', 'bme680.temperature', 'line'],
        'lines': [
            ['temperature']
        ]
    },
    'humidity': {
        'options': [None, 'Relative Humidity', '%RH', 'humidity', 'bme680.humidity', 'line'],
        'lines': [
            ['humidity']
        ]
    },
    'pressure': {
        'options': [None, 'Barometric Pressure', 'hPa', 'pressure', 'bme680.pressure', 'line'],
        'lines': [
            ['pressure']
        ]
    }
}


class Service(SimpleService):
    def __init__(self, configuration=None, name=None):
        SimpleService.__init__(self, configuration=configuration, name=name)
        self.order = ORDER
        self.definitions = CHARTS
        self.am = None

    def check(self):
        if not HAS_BME680:
            self.error("Could not find the adafruit-circuitpython-bme680 package.")
            return False

        try:
            i2c = board.I2C()
            self.am = adafruit_bme680.Adafruit_BME680_I2C(i2c,address=0x76)
        except ValueError as error:
            self.error("error on creating I2C shared bus : {0}".format(error))
            return False

        return True

    def get_data(self):
        try:
            return {
                'temperature': self.am.temperature,
                'humidity': self.am.humidity,
                'pressure': self.am.pressure,
            }

        except (OSError, RuntimeError) as error:
            self.error(error)
            return None

Updated the module for spelling errors and added more descriptive labels.

Hi, @Lennong. Thanks for sharing this!

It works fine but I could not get out two decimal readings in the charts.

If you want to push fractional values, multiply this value by 1000 and set the dimension divider to 1000.

For instance, let’s assume ‘temperature’ is float

    'temperature': {
        'options': [None, 'Air Temperature', 'celsius', 'temperature', 'bme680.temperature', 'line'],
        'lines': [
            ['temperature', 1, 1000]
        ]
    },

  ...

    def get_data(self):
        try:
            return {
                'temperature': self.am.temperature * 1000,
                'humidity': self.am.humidity,
                'pressure': self.am.pressure,
            }
  

Very nice! Thank You!