cubicpm1003

package module
v0.0.0-...-5713c15 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: MIT Imports: 11 Imported by: 0

README

go-sensors/cubicpm1003

Go library for interacting with the Cubic PM1003 particulate matter sensor for measuring indoor air quality.

Quickstart

Take a look at rpi-sensor-exporter for an example implementation that makes use of this sensor (and others).

Sensor Details

The Cubic PM1003 particulate matter sensor is primarily used for measuring indoor air quality, per vendor specifications. This go-sensors implementation makes use of the sensor's UART-based protocol for obtaining PM2.5 measurements on a 1-second interval.

Building

This software doesn't have any compiled assets.

Code of Conduct

We are committed to fostering an open and welcoming environment. Please read our code of conduct before participating in or contributing to this project.

Contributing

We welcome contributions and collaboration on this project. Please read our contributor's guide to understand how best to work with us.

License and Authors

Daniel James logo Daniel James

license GitHub contributors

This software is made available by Daniel James under the MIT license.

Documentation

Index

Constants

View Source
const (
	DefaultMeasurementInterval = 1 * time.Second
	DefaultReconnectTimeout    = 5 * time.Second
)
View Source
const (
	PM2_5UpperBoundSize = 2500 * units.Nanometer
)

Variables

View Source
var (
	// Command to write to the sensor to invoke its measurement routine
	ReadMeasurementCommand = []byte{0x11, 0x02, 0x0B, 0x01, 0xE1}
	// Header of a valid measurement
	ReadingHeader = []byte{0x16, 0x11, 0x0B}
)

Functions

func GetDefaultSerialPortConfig

func GetDefaultSerialPortConfig() *serial.SerialPortConfig

GetDefaultSerialPortConfig gets the manufacturer-specified defaults for connecting to the sensor

Types

type Option

type Option struct {
	// contains filtered or unexported fields
}

Option is a configured option that may be applied to a Sensor

func WithMeasurementInterval

func WithMeasurementInterval(interval time.Duration) *Option

WithMeasurementInterval specifies the duration to wait between reading measurements

func WithReconnectTimeout

func WithReconnectTimeout(timeout time.Duration) *Option

WithReconnectTimeout specifies the duration to wait before reconnecting after a recoverable error

func WithRecoverableErrorHandler

func WithRecoverableErrorHandler(f ShouldTerminate) *Option

WithRecoverableErrorHandler registers a function that will be called when a recoverable error occurs

type Sensor

type Sensor struct {
	// contains filtered or unexported fields
}

Sensor represents a configured Cubic PM1003 particulate matter sensor

func NewSensor

func NewSensor(portFactory coreio.PortFactory, options ...*Option) *Sensor

NewSensor creates a Sensor with optional configuration

func (*Sensor) ConcentrationSpecs

func (*Sensor) ConcentrationSpecs() []*pm.ConcentrationSpec

ConcentrationSpecs returns a collection of specified measurement ranges supported by the sensor

func (*Sensor) Concentrations

func (s *Sensor) Concentrations() <-chan *pm.Concentration

Concentrations returns a channel of PM concentration readings as they become available from the sensor

func (*Sensor) MeasurementInterval

func (s *Sensor) MeasurementInterval() time.Duration

MeasurementInterval is the duration to wait between reading measurements

func (*Sensor) ReconnectTimeout

func (s *Sensor) ReconnectTimeout() time.Duration

ReconnectTimeout is the duration to wait before reconnecting after a recoverable error

func (*Sensor) RecoverableErrorHandler

func (s *Sensor) RecoverableErrorHandler() ShouldTerminate

RecoverableErrorHandler a function that will be called when a recoverable error occurs

func (*Sensor) Run

func (s *Sensor) Run(ctx context.Context) error

Run begins reading from the sensor and blocks until either an error occurs or the context is completed

type ShouldTerminate

type ShouldTerminate func(error) bool

ShouldTerminate is a function that returns a result indicating whether the Sensor should terminate after a recoverable error

Jump to

Keyboard shortcuts

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