Documentation
¶
Index ¶
- Constants
- Variables
- type Bus
- type Measurement
- type SGP30Sensor
- func (s *SGP30Sensor) GetBaseline() (Measurement, error)
- func (s *SGP30Sensor) GetFeatureSet() (uint16, error)
- func (s *SGP30Sensor) GetSerial() (uint64, error)
- func (s *SGP30Sensor) InitAirQuality() (err error)
- func (s *SGP30Sensor) Measure() (Measurement, error)
- func (s *SGP30Sensor) SetBaseline(ECO2 uint16, TVOC uint16) error
- func (s *SGP30Sensor) SetHumidity(absHumidity uint16) error
- func (s *SGP30Sensor) Start() error
- func (s *SGP30Sensor) Stop()
- func (s *SGP30Sensor) WithBaseline(bl Measurement) *SGP30Sensor
- func (s *SGP30Sensor) WithHumidity(hm uint16) *SGP30Sensor
Constants ¶
Variables ¶
var ValidFeaturesets = []uint16{0x0020, 0x0022}
ValidFeaturesets are the supported featuresets of the SGP30.
Functions ¶
This section is empty.
Types ¶
type Measurement ¶
Measurement encapsulates air quality readings from the sensor.
type SGP30Sensor ¶
type SGP30Sensor struct {
// contains filtered or unexported fields
}
SGP30Sensor provides methods to interact with the sensor.
func (*SGP30Sensor) GetBaseline ¶
func (s *SGP30Sensor) GetBaseline() (Measurement, error)
GetBaseline returns a measurement representing the baseline readings. > For best performance and faster startup times, the current baseline needs to be persistently stored before power off and set again accordingly after boot up. > Approximately in the first 60min of operation after init the call will fail unless a previous baseline was restored.
func (*SGP30Sensor) GetFeatureSet ¶
func (s *SGP30Sensor) GetFeatureSet() (uint16, error)
GetFeatureSet returns the featureset value directly from the sensor.
func (*SGP30Sensor) GetSerial ¶
func (s *SGP30Sensor) GetSerial() (uint64, error)
GetSerial returns the ID value directly from the sensor.
func (*SGP30Sensor) InitAirQuality ¶
func (s *SGP30Sensor) InitAirQuality() (err error)
InitAirQuality prepares the sensor for taking measurements. > Call init to initialize or re-initialize the indoor air quality algorithm. > Call init to reset all SGP baselines. The initialization takes up to around 15 seconds, during which measurements will not change.
func (*SGP30Sensor) Measure ¶
func (s *SGP30Sensor) Measure() (Measurement, error)
Measure returns air quality measurements, using the most recently sampled value if available. Otherwise, directly measures from the sensor.
func (*SGP30Sensor) SetBaseline ¶
func (s *SGP30Sensor) SetBaseline(ECO2 uint16, TVOC uint16) error
SetBaseline sets the baseline values of the sensor > The baseline value must be exactly as returned by get_baseline and should only be set if it’s less than one week old.
func (*SGP30Sensor) SetHumidity ¶
func (s *SGP30Sensor) SetHumidity(absHumidity uint16) error
SetHumidity configures the humidity compensation. Set to zero to disable. > Call set_humidity to a value greater than 0 and smaller than 256000 mg/m3 to enable the humidity compensation feature, or write 0 to disable it. > The absolute humidity in g/m3 can be retrieved by measuring the relative humidity and temperature and converting the value to absolute humidity > With AH in g/m3, RH in 0-100%, and t in °C > Note: the value in g/m3 has to be multiplied by 1000 to convert to mg/m3 and any remaining decimal places have to be rounded and removed since the interface does not support floating point numbers. > Note: The humidity compensation is disabled by setting the value to 0.
func (*SGP30Sensor) Start ¶
func (s *SGP30Sensor) Start() error
Start intialises the sensor according to the manufacturer documentation, including reseting the baseline compensation algorithm and polling at the recommended 1 second interval.
For the first 15s the sensor is in an initialization phase during which measurements return fixed values of 400 ppm CO2eq and 0 ppb TVOC.
Use `.New().WithHumidity()` and `.WithBaseline()` to set compensation values immediately after init.
> If no stored baseline is available after initializing the baseline algorithm, the sensor has to run for 12 hours until the baseline can be stored. > This will ensure an optimal behavior for preceding startups. Reading out the baseline prior should be avoided unless a valid baseline is restored first. > Once the baseline is properly initialized or restored, the current baseline value should be stored approximately once per hour. > While the sensor is off, baseline values are valid for a maximum of seven days.
func (*SGP30Sensor) Stop ¶
func (s *SGP30Sensor) Stop()
Stop ends sampling. Restarting sampling requires re-initialisation of the baseline compensation, so you probably don't want to do this.
func (*SGP30Sensor) WithBaseline ¶
func (s *SGP30Sensor) WithBaseline(bl Measurement) *SGP30Sensor
WithBaseline restores the baseline to a previous known value in the init proccess. Calling this after `Start()` will have no effect until the next time `Start()` is called. Call `GetBseline()` every hour after an initial 12 hour calibration phase to obtain the value. > After a power-up or soft reset, the baseline of the baseline correction algorithm can be restored by sending first an > “Init_air_quality” command followed by a “Set_baseline” command
func (*SGP30Sensor) WithHumidity ¶
func (s *SGP30Sensor) WithHumidity(hm uint16) *SGP30Sensor
WithHumidity sets the humidity compensation value in the init proccess. Calling this after `Start()` will have no effect until the next time `Start()` is called. > Call set_humidity to a value greater than 0 and smaller than 256000 mg/m3 to enable the humidity compensation feature, or write 0 to disable it. Changes in humidity can be provided using the `.SetHumidity()` method during sampling.