Skip to content

Commit 627246d

Browse files
committed
Import
0 parents  commit 627246d

4 files changed

Lines changed: 238 additions & 0 deletions

File tree

Makefile.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
# install these files
4+
dist_python_DATA += bme280/bme280.chart.py
5+
dist_pythonconfig_DATA += bme280/bme280.conf
6+
7+
# do not install these files, but include them in the distribution
8+
dist_noinst_DATA += bme280/README.md bme280/Makefile.inc

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!--
2+
title: "BME280 sensor monitoring with netdata"
3+
custom_edit_url: https://github.com/netdata/netdata/edit/master/collectors/python.d.plugin/bme280/README.md
4+
sidebar_label: "BME280"
5+
-->
6+
7+
# BME280 sensor monitoring with netdata
8+
9+
Displays a graph of the temperature, humidity, and pressure from a BME280 sensor.
10+
11+
## Requirements
12+
- Adafruit Circuit Python BME280 library
13+
- Adafruit BME280 I2C Sensor (Product ID: 2652)
14+
- Python 3 (Adafruit libraries are not Python 2.x compatible)
15+
16+
17+
It produces the following charts:
18+
1. **Temperature**
19+
2. **Humidity**
20+
3. **Pressure**
21+
22+
## Configuration
23+
24+
Allow the `netdata` user to access the I2C interface.
25+
26+
```bash
27+
sudo usermod -a -G i2c netdata
28+
```
29+
30+
Edit the `python.d/bme280.conf` configuration file using `edit-config` from the Netdata [config
31+
directory](/docs/configure/nodes.md), which is typically at `/etc/netdata`.
32+
33+
```bash
34+
cd /etc/netdata # Replace this path with your Netdata config directory, if different
35+
sudo ./edit-config python.d/bme280.conf
36+
```
37+
38+
Raspberry Pi Instructions:
39+
40+
Hardware install:
41+
Connect the BME280 to the Raspberry Pi I2C pins
42+
43+
Raspberry Pi 3B/4 Pins:
44+
45+
- Board 3.3V (pin 1) to sensor VIN (pin 1)
46+
- Board SDA (pin 3) to sensor SDA (pin 2)
47+
- Board GND (pin 6) to sensor GND (pin 3)
48+
- Board SCL (pin 5) to sensor SCL (pin 4)
49+
50+
You may also need to add two I2C pullup resistors if your board does not already have them. The Raspberry Pi
51+
does have internal pullup resistors but it doesn't hurt to add them anyway. You can use 2.2K - 10K but we will
52+
just use 10K. The resistors go from VDD to SCL and SDA each.
53+
54+
Software install:
55+
- `sudo pip3 install adafruit-circuitpython-bme280`
56+
- `sudo usermod -a -G i2c netdata`
57+
- edit `/etc/netdata/netdata.conf`
58+
- find `[plugin:python.d]`
59+
- add `command options = -ppython3`
60+
- save the file.
61+
- restart the netdata service.
62+
- check the dashboard.

bme280.chart.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# _*_ coding: utf-8 _*_
2+
# Description: BME280 netdata module
3+
# Author: LucAce
4+
# SPDX-License-Identifier: GPL-3.0-or-Later
5+
6+
try:
7+
import board
8+
import busio
9+
from adafruit_bme280 import basic as adafruit_bme280
10+
11+
HAS_BME280 = True
12+
except ImportError:
13+
HAS_BME280 = False
14+
15+
from bases.FrameworkServices.SimpleService import SimpleService
16+
17+
# Default module values (can be overridden per job in `config`)
18+
update_every = 5
19+
20+
# Default precision value
21+
precision_scaling = 100
22+
23+
ORDER = [
24+
'temperature',
25+
'humidity',
26+
'pressure',
27+
'altitude'
28+
]
29+
30+
CHARTS = {
31+
'temperature': {
32+
'options': [None, 'Temperature', 'celsius', 'temperature', 'bme280.temperature', 'line'],
33+
'lines': [
34+
['temperature', 'temperature', 'absolute', 1, precision_scaling]
35+
]
36+
},
37+
'humidity': {
38+
'options': [None, 'Relative Humidity', 'percent', 'humidity', 'bme280.humidity', 'line'],
39+
'lines': [
40+
['humidity', 'humidity', 'absolute', 1, precision_scaling]
41+
]
42+
},
43+
'pressure': {
44+
'options': [None, 'Barometric Pressure', 'hPa', 'pressure', 'bme280.pressure', 'line'],
45+
'lines': [
46+
['pressure', 'pressure', 'absolute', 1, precision_scaling]
47+
]
48+
},
49+
'altitude': {
50+
'options': [None, 'Altitude', 'meters', 'altitude', 'bme280.altitude', 'line'],
51+
'lines': [
52+
['altitude', 'altitude', 'absolute', 1, precision_scaling]
53+
]
54+
}
55+
}
56+
57+
58+
class Service(SimpleService):
59+
def __init__(self, configuration=None, name=None):
60+
SimpleService.__init__(self, configuration=configuration, name=name)
61+
self.order = ORDER
62+
self.definitions = CHARTS
63+
self.i2c_address = int(self.configuration.get('i2c_address', '0x77'))
64+
self.sea_level_pressure = float(self.configuration.get('sea_level_pressure', '1013.25'))
65+
self.bme = None
66+
67+
def check(self):
68+
if not HAS_BME280:
69+
self.error("Could not find the Adafruit_CircuitPython_BME280 package.")
70+
return False
71+
72+
try:
73+
i2c = busio.I2C(board.SCL, board.SDA)
74+
self.bme = adafruit_bme280.Adafruit_BME280_I2C(i2c, self.i2c_address)
75+
self.bme.sea_level_pressure = self.sea_level_pressure
76+
77+
except ValueError as error:
78+
self.error("Error on creating I2C shared bus: {0}".format(error))
79+
return False
80+
81+
return True
82+
83+
def get_data(self):
84+
try:
85+
return {
86+
'temperature': int(self.bme.temperature * precision_scaling),
87+
'humidity': int(self.bme.relative_humidity * precision_scaling),
88+
'pressure': int(self.bme.pressure * precision_scaling),
89+
'altitude': int(self.bme.altitude * precision_scaling)
90+
}
91+
92+
except (OSError, RuntimeError) as error:
93+
self.error(error)
94+
return None

bme280.conf

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# netdata python.d.plugin configuration for bme280 temperature/humidity/pressure/altitude sensor
2+
#
3+
# This file is in YaML format. Generally the format is:
4+
#
5+
# name: value
6+
#
7+
# There are 2 sections:
8+
# - global variables
9+
# - one or more JOBS
10+
#
11+
# JOBS allow you to collect values from multiple sources.
12+
# Each source will have its own set of charts.
13+
#
14+
# JOB parameters have to be indented (using spaces only, example below).
15+
16+
# ----------------------------------------------------------------------
17+
# Global Variables
18+
# These variables set the defaults for all JOBs, however each JOB
19+
# may define its own, overriding the defaults.
20+
21+
# update_every sets the default data collection frequency.
22+
# If unset, the python.d.plugin default is used.
23+
# update_every: 5
24+
25+
# priority controls the order of charts at the netdata dashboard.
26+
# Lower numbers move the charts towards the top of the page.
27+
# If unset, the default for python.d.plugin is used.
28+
# priority: 60000
29+
30+
# penalty indicates whether to apply penalty to update_every in case of failures.
31+
# Penalty will increase every 5 failed updates in a row. Maximum penalty is 10 minutes.
32+
# penalty: yes
33+
34+
# autodetection_retry sets the job re-check interval in seconds.
35+
# The job is not deleted if check fails.
36+
# Attempts to start the job are made once every autodetection_retry.
37+
# This feature is disabled by default.
38+
# autodetection_retry: 0
39+
40+
# ----------------------------------------------------------------------
41+
# JOBS (data collection sources)
42+
#
43+
# The default JOBS share the same *name*. JOBS with the same name
44+
# are mutually exclusive. Only one of them will be allowed running at
45+
# any time. This allows autodetection to try several alternatives and
46+
# pick the one that works.
47+
#
48+
# Any number of jobs is supported.
49+
#
50+
# All python.d.plugin JOBS (for all its modules) support a set of
51+
# predefined parameters. These are:
52+
#
53+
# job_name:
54+
# name: myname # the JOB's name as it will appear at the
55+
# # dashboard (by default is the job_name)
56+
# # JOBs sharing a name are mutually exclusive
57+
# update_every: 1 # the JOB's data collection frequency
58+
# priority: 60000 # the JOB's order on the dashboard
59+
# penalty: yes # the JOB's penalty
60+
# autodetection_retry: 0 # the JOB's re-check interval in seconds
61+
#
62+
# Additionally to the above, example also supports the following:
63+
#
64+
# - none
65+
#
66+
# ----------------------------------------------------------------------
67+
# AUTO-DETECTION JOBS
68+
# only one of them will run (they have the same name)
69+
#
70+
# Set a custom I2C Address
71+
# i2c_address: 0x77
72+
#
73+
# Set a custom Sea Level Pressure (hPA)
74+
# sea_level_pressure: 1013.25

0 commit comments

Comments
 (0)