BME280 telemetry data #748
Replies: 11 comments 10 replies
-
My aim is to use the sensor (or better the BME680) via the Raspberry (currently with MeshChat). |
Beta Was this translation helpful? Give feedback.
-
Currently, Sideband can only pull telemetry data from something that's directly connected to the host. Here's an example plugin for doing that: https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/telemetry.py That being said, all that's needed for sensors connected to the RNode to be taken into account is simply to add the necessary sensor driver to the firmware, and a shim that sends that data to Sideband over whatever connection is used between the Sdieband host and the RNode. It's not really a big hassle, it just isn't implemented yet. |
Beta Was this translation helpful? Give feedback.
-
This is beyond my skills and knowledge. I then wait a bit until it is implemented in RNode. |
Beta Was this translation helpful? Give feedback.
-
Here's a skeleton example to implement a BME280 telemetry plugin: # This is a BME280 telemetry plugin
# example that you can build upon to
# implement your own telemetry plugins.
import RNS
class BME280Plugin(SidebandTelemetryPlugin):
plugin_name = "telemetry_bme280"
def start(self):
# Do any initialisation work here
RNS.log("BME280 telemetry plugin starting...")
# And finally call start on superclass
super().start()
def stop(self):
# Do any teardown work here
pass
# And finally call stop on superclass
super().stop()
def update_telemetry(self, telemeter):
if telemeter != None:
# Create temperature sensor
telemeter.synthesize("temperature")
telemeter.sensors["temperature"].data = {"c": 23.6}
# Create humidity sensor
telemeter.synthesize("humidity")
telemeter.sensors["humidity"].data = {"percent_relative": 52.1}
# Create humidity sensor
telemeter.synthesize("pressure")
telemeter.sensors["pressure"].data = {"mbar": 1011.2}
# Finally, tell Sideband what class in this
# file is the actual plugin class.
plugin_class = BME280Plugin Currently it just sets the values statically, but it will get you something like this: You will just need to add some way of setting the values from the actual BME280 instead of the example values. You can read from I2C devices directly in Python by using the |
Beta Was this translation helpful? Give feedback.
-
Making two scripts into one 😆
|
Beta Was this translation helpful? Give feedback.
-
Thanks. Today it was the first time I've worked with Python, and it was almost entirely trial and error. And a little logic.
should be placed directely behind
? |
Beta Was this translation helpful? Give feedback.
-
Although I don't know if that's correct now, that's how the plugin works ¯\__(ツ)__/¯
|
Beta Was this translation helpful? Give feedback.
-
Here's an updated version with a bit better init/teardown and error handling added: # This plugin provides temperature, humidity
# and pressure data via a BME280 sensor
# connected over I2C. The plugin requires
# the "smbus2" and "RPi.bme280" modules to
# be available on your system. These can be
# installed with:
#
# pip install smbus2 RPi.bme280
import os
import RNS
from importlib.util import find_spec
class BME280Plugin(SidebandTelemetryPlugin):
plugin_name = "telemetry_bme280"
I2C_ADDRESS = 0x76
I2C_BUS = 1
def start(self):
RNS.log("BME280 telemetry plugin starting...")
if find_spec("smbus2"): import smbus2
else: raise OSError(f"No smbus2 module available, cannot start BME280 telemetry plugin")
if find_spec("bme280"): import bme280
else: raise OSError(f"No bme280 module available, cannot start BME280 telemetry plugin")
self.sensor_connected = False
try:
self.bme280 = bme280
self.address = self.I2C_ADDRESS
self.bus = smbus2.SMBus(self.I2C_BUS)
self.calibration = self.bme280.load_calibration_params(self.bus, self.address)
self.sensor_connected = True
except Exception as e:
RNS.log(f"Could not connect to I2C device while starting BME280 telemetry plugin", RNS.LOG_ERROR)
RNS.log(f"The contained exception was: {e}", RNS.LOG_ERROR)
super().start()
def stop(self):
self.bus.close()
super().stop()
def update_telemetry(self, telemeter):
if telemeter != None:
if self.sensor_connected:
try:
sample = self.bme280.sample(self.bus, self.address, self.calibration); ts = telemeter.sensors
telemeter.synthesize("temperature"); ts["temperature"].data = {"c": round(sample.temperature,1)}
telemeter.synthesize("humidity"); ts["humidity"].data = {"percent_relative": round(sample.humidity,1)}
telemeter.synthesize("pressure"); ts["pressure"].data = {"mbar": round(sample.pressure,1)}
except Exception as e:
RNS.log("An error occurred while updating BME280 sensor data", RNS.LOG_ERROR)
RNS.log(f"The contained exception was: {e}", RNS.LOG_ERROR)
plugin_class = BME280Plugin I didn't actually try running this yet on a Pi, so there might be something wrong, but feel free to try it out! |
Beta Was this translation helpful? Give feedback.
-
Good morning Mark. |
Beta Was this translation helpful? Give feedback.
-
By the way:
However, I couldn't manage to turn the "c" into a "°C". |
Beta Was this translation helpful? Give feedback.
-
I tried to use the telemetry data from a BME280 connected to the Heletec V3. Unfortunately, it appears that only the smartphone's sensors are taken into account. Or did I configure something incorrectly somewhere?
Beta Was this translation helpful? Give feedback.
All reactions