aranet4

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: BSD-3-Clause Imports: 13 Imported by: 4

README

aranet4

Build status GoDoc

aranet4 is a Bluez-based driver for the Aranet4 air quality monitor.

Installation

aranet4-ls
$> go install sbinet.org/x/aranet4/cmd/aranet4-ls
$> aranet4-ls
CO2:         547 ppm
temperature: 19.85°C
pressure:    980.5 hPa
humidity:    29%
quality:     green
battery:     96%
interval:    5m0s
time-stamp:  2022-01-20 15:48:28 UTC

$> aranet4-ls -ts -o out.csv
CO2:         547 ppm
temperature: 19.85°C
pressure:    980.5 hPa
humidity:    29%
quality:     green
battery:     96%
interval:    5m0s
time-stamp:  2022-01-20 15:48:28 UTC

$> head out.csv
id;timestamp (UTC);temperature (°C);humidity (%);pressure (hPa);CO2 (ppm)
0;2022-01-18 13:53:28;20.30;38;982.3;667
1;2022-01-18 13:58:28;21.30;36;982.3;836
2;2022-01-18 14:03:28;21.20;36;982.2;763
3;2022-01-18 14:08:28;21.10;35;982.2;825
4;2022-01-18 14:13:28;21.05;35;982.2;807
5;2022-01-18 14:18:28;21.00;34;982.3;765
6;2022-01-18 14:23:28;20.95;34;982.2;928
7;2022-01-18 14:28:28;20.90;34;982.2;911
8;2022-01-18 14:33:28;20.85;34;982.2;861
aranet4-srv

aranet4-srv is a simple HTTP server that plots the full history of data samples one can retrieve from an aranet4 sensor.

img

This Go-based driver is heavily inspired from Anrijs/Aranet4-Python. Thanks a bunch.

Development & mailing list

Development of aranet4 happens on SourceHut.

Discussions can take place over there:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoData indicates a missing data point.
	// This may happen during sensor calibration.
	ErrNoData = errors.New("aranet4: no data")

	// ErrDupDevice is returned by DB.AddDevice when a device with
	// the provided id is already stored in the database.
	ErrDupDevice = errors.New("aranet4: duplicate device")
)

Functions

This section is empty.

Types

type DB added in v0.11.0

type DB interface {
	io.Closer

	// PutData puts the provided data for the device id into the underlying store
	PutData(id string, vs []Data) error

	// Data iterates over data for the device id and the requested time interval [beg, end)
	Data(id string, beg, end time.Time) iter.Seq2[Data, error]

	// Last returns the last data point for the provided device id
	Last(id string) (Data, error)

	// AddDevice declares a new device id
	AddDevice(id string) error

	// Devices returns the device ids list
	Devices() ([]string, error)
}

DB is the interface to manage aranet4 data.

type Data

type Data struct {
	H, P, T float64
	CO2     int
	Battery int
	Quality Quality

	Interval time.Duration
	Time     time.Time
}

Data holds measured data samples provided by Aranet4.

func (Data) Before added in v0.11.0

func (data Data) Before(o Data) bool

func (Data) BinarySize added in v0.11.0

func (Data) BinarySize() int

BinarySize returns the number of bytes needed to hold the binary data for a single Data element.

func (Data) Marshal added in v0.11.0

func (data Data) Marshal(p []byte) error

func (Data) String

func (data Data) String() string

func (*Data) Unmarshal added in v0.11.0

func (data *Data) Unmarshal(p []byte) error

type Device

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

func New

func New(ctx context.Context, addr string) (*Device, error)

func (*Device) Close

func (dev *Device) Close() error

func (*Device) Interval

func (dev *Device) Interval() (time.Duration, error)

func (*Device) Name

func (dev *Device) Name() string

func (*Device) NumData

func (dev *Device) NumData() (int, error)

func (*Device) Read

func (dev *Device) Read() (Data, error)

func (*Device) ReadAll

func (dev *Device) ReadAll() ([]Data, error)

func (*Device) Since

func (dev *Device) Since() (time.Duration, error)

func (*Device) Version

func (dev *Device) Version() (string, error)

type Quality

type Quality int

Quality gives a general assessment of air quality (green/yellow/red).

  • green: [ 0 - 1000) ppm
  • yellow: [1000 - 1400) ppm
  • red: [1400 - ...) ppm

func QualityFrom added in v0.11.0

func QualityFrom(co2 int) Quality

QualityFrom creates a quality value from a CO2 value.

func (Quality) String

func (st Quality) String() string

type Samples added in v0.11.0

type Samples []Data

Samples implements sort.Interface for Data, sorting in increasing timestamps.

func (Samples) Len added in v0.11.0

func (vs Samples) Len() int

func (Samples) Less added in v0.11.0

func (vs Samples) Less(i, j int) bool

func (Samples) Swap added in v0.11.0

func (vs Samples) Swap(i, j int)

Directories

Path Synopsis
Package arasrv provides tools to gather and present aranet4 data over HTTP.
Package arasrv provides tools to gather and present aranet4 data over HTTP.
cmd
aranet4-daq
Command aranet4-daq retrieves data from an Aranet4 device and uploads it to an HTTP server.
Command aranet4-daq retrieves data from an Aranet4 device and uploads it to an HTTP server.
internal
arabolt
Package arabolt provides an implementation of an aranet4 database, backed by bbolt.
Package arabolt provides an implementation of an aranet4 database, backed by bbolt.
arasqlite
Package arasqlite provides an implementation of an aranet4 database, backed by SQlite3.
Package arasqlite provides an implementation of an aranet4 database, backed by SQlite3.

Jump to

Keyboard shortcuts

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