sds011

package
v0.0.0-...-3ddcd38 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sds011 implements a library to read the protocol of SDS011, an air quality sensor than can work with Raspberry Pi.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Point

type Point struct {
	PM25      float64
	PM10      float64
	Timestamp time.Time
}

A Point represents a single reading from the sensor.

func (*Point) String

func (point *Point) String() string

type Sensor

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

Sensor represents an SDS011 sensor.

func New

func New(portPath string) (*Sensor, error)

New returns a sensor that will read data from serial port for which the path was provided. It is the responsibility of the caller to close the sensor.

func NewSensor

func NewSensor(rwc io.ReadWriteCloser) *Sensor

NewSensor returns a sensor that will read its data from the provided read-write-closer.

func (*Sensor) Awake

func (sensor *Sensor) Awake() error

Awake awakes the sensor if it is in sleep mode.

func (*Sensor) Close

func (sensor *Sensor) Close()

Close closes the underlying serial port.

func (*Sensor) Cycle

func (sensor *Sensor) Cycle() (uint8, error)

Cycle returns the current cycle length in minutes. If it's 0 it means that cycle is not set, and the sensor is streaming data continuously.

func (*Sensor) DeviceID

func (sensor *Sensor) DeviceID() (string, error)

DeviceID returns the sensor's device ID.

func (*Sensor) Firmware

func (sensor *Sensor) Firmware() (string, error)

Firmware returns the firmware version (a yy-mm-dd date).

func (*Sensor) Get

func (sensor *Sensor) Get() (point *Point, err error)

Get will read one measurement. It will block until data is available. It only makes sense to call read if the sensor is in active mode.

func (*Sensor) IsAwake

func (sensor *Sensor) IsAwake() (bool, error)

IsAwake returns true if the sensor is awake.

func (*Sensor) MakeActive

func (sensor *Sensor) MakeActive() error

MakeActive makes the sensor actively report its measurements.

func (*Sensor) MakePassive

func (sensor *Sensor) MakePassive() error

MakePassive stop the sensor from actively reporting its measurements. You will need to send a Query command.

func (*Sensor) Query

func (sensor *Sensor) Query() (*Point, error)

Query returns one reading.

func (*Sensor) ReportMode

func (sensor *Sensor) ReportMode() (bool, error)

ReportMode returns true if the device is in active mode, false if in query mode.

func (*Sensor) SetCycle

func (sensor *Sensor) SetCycle(value uint8) error

SetCycle sets the cycle length. The value is the cycle's length in minutes, accepting values from 1 to 30. If you pass it 0 it will disable cycle work, and the sensor will just stream data.

func (*Sensor) Sleep

func (sensor *Sensor) Sleep() error

Sleep puts the sensor to sleep.

Jump to

Keyboard shortcuts

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