Skip to content

Instantly share code, notes, and snippets.

@derpeter
Created March 29, 2021 09:26
Show Gist options
  • Save derpeter/7027588dd90a3f9228b66ca0c4c9d07d to your computer and use it in GitHub Desktop.
Save derpeter/7027588dd90a3f9228b66ca0c4c9d07d to your computer and use it in GitHub Desktop.
BME280 telegraf exec plugin
#!/usr/bin/env python3
import time
try:
from smbus2 import SMBus
except ImportError:
from smbus import SMBus
from bme280 import BME280
# Initialise the BME280
bus = SMBus(0)
bme280 = BME280(i2c_dev=bus)
temperature = bme280.get_temperature()
pressure = bme280.get_pressure()
humidity = bme280.get_humidity()
print('BME280,sensor=bme280 celsius={:05.2f},hPa={:05.2f},humidity={:02.2f}'.format(temperature, pressure, humidity))
@derpeter
Copy link
Author

derpeter commented Mar 29, 2021

Uses https://github.com/pimoroni/bme280-python/ and smbus2 to read values from an BME280 sensor and prints out influx line format.
you might wan't to add

chgrp telegraf /dev/i2c-0

to e.g. rc.local

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