plantowerpms5003

package module
v0.0.0-...-8dec1e0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 13 Imported by: 0

README

go-sensors/plantowerpms5003

Go library for interacting with the Plantower PMS5003 particulate matter sensor for measuring 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 Plantower PMS5003 particulate matter sensor is used for measuring air quality, per vendor specifications. This go-sensors implementation makes use of the sensor's UART-based protocol for obtaining PM1.0, PM2.5, and PM10.0 measurements on an interval defined by the vendor.

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 (
	PM01_0UpperBoundSize = 1 * units.Micrometer
	PM02_5UpperBoundSize = 2_500 * units.Nanometer
	PM10_0UpperBoundSize = 10 * units.Micrometer
)
View Source
const (
	DefaultReconnectTimeout = 5 * time.Second
)

Variables

View Source
var (
	// Header of a valid measurement
	ReadingHeader = []byte{0x42, 0x4D}
)

Functions

func GetDefaultSerialPortConfig

func GetDefaultSerialPortConfig() *serial.SerialPortConfig

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

Types

type ChecksumError

type ChecksumError struct {
	Bytes            []byte
	ReportedChecksum uint16
	ActualChecksum   uint16
}

func (*ChecksumError) Error

func (ce *ChecksumError) Error() string

type Option

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

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

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 Plantower PMS5003 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) 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