bme280

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2025 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package bme280 provides a driver for the BME280 temperature, humidity, and pressure sensor using I2C communication.

Index

Constants

View Source
const (
	DefaultI2CBus     = "/dev/i2c-1"
	DefaultI2CAddress = 0x77
)

Variables

View Source
var (
	ErrInitFailed    = errors.New("failed to initialize BME280")
	ErrReadFailed    = errors.New("failed to read from BME280")
	ErrMarshalFailed = errors.New("failed to marshal BME280 data")
)

Functions

func ConvertCtoF

func ConvertCtoF(celsius float64) float64

ConvertCtoF converts Celsius to Fahrenheit

Types

type BME280

type BME280 struct {
	devices.Device[*bme280.Response]
	MockReader func() (*bme280.Response, error) // Function to mock reading data
	// contains filtered or unexported fields
}

BME280 represents an I2C temperature, humidity and pressure sensor. It defaults to address 0x77 and implements the device.Device interface.

func New

func New(id, bus string, addr int) *BME280

Create a new BME280 at the give bus and address. Defaults are typically /dev/i2c-1 address 0x99

func (*BME280) Close

func (b *BME280) Close() error

func (*BME280) Get

func (b *BME280) Get() (resp *bme280.Response, err error)

Read one Response from the sensor. If this device is being mocked we will make up some random floating point numbers between 0 and 100.

func (*BME280) ID

func (b *BME280) ID() string

func (*BME280) MockRead

func (b *BME280) MockRead() (*bme280.Response, error)

func (*BME280) Open

func (b *BME280) Open() error

Init opens the i2c bus at the specified address and gets the device ready for reading

func (*BME280) Set

func (b *BME280) Set(v *bme280.Response) error

func (*BME280) String

func (b *BME280) String() string

func (*BME280) Type

func (b *BME280) Type() devices.Type

type BME280Config

type BME280Config struct {
	Mode       bme280.Mode
	Filter     bme280.Filter
	Standby    bme280.StandByTime
	Oversample struct {
		Pressure    bme280.Oversampling
		Temperature bme280.Oversampling
		Humidity    bme280.Oversampling
	}
}

BME280Config holds the configuration for the BME280 sensor

func DefaultConfig

func DefaultConfig() BME280Config

DefaultConfig returns the default configuration

type Env

type Env struct {
	Temperature string `json:"temperature"`
	Humidity    string `json:"humidity"`
	Pressure    string `json:"pressure"`
}

type Response

type Response bme280.Response

Response returns values read from the sensor containing all three values for temperature, humidity and pressure

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL