sensor

package
v2.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidColumn = errors.New("invalid column")
	ErrMissingColumn = errors.New("missing mandatory column")
)
View Source
var DefaultColumnMap map[string]string

DefaultColumnMap column mapping where each column has the default name.

View Source
var DefaultColumns = []string{
	"time",
	"mac",
	"name",
	"temperature",
	"humidity",
	"pressure",
	"acceleration_x",
	"acceleration_y",
	"acceleration_z",
	"movement_counter",
	"measurement_number",
	"dew_point",
	"battery_voltage",
	"tx_power",
}

DefaultColumns names of fields contained in a RuuviTag v5 protocol transmission.

Functions

func Float64Pointer

func Float64Pointer(v float64) *float64

Float64Pointer returns a pointer to the given float64.

func IntPointer

func IntPointer(v int) *int

IntPointer returns a pointer to the given int.

func StringPointer

func StringPointer(v string) *string

StringPointer returns a pointer to the given string.

func ValidateColumnMapping

func ValidateColumnMapping(columns map[string]string) error

ValidateColumnMapping validates that a given custom column mapping contains necessary fields to look up RuuviTag data.

func ValidateRequestedColumns

func ValidateRequestedColumns(columns map[string]string, requested []string) error

ValidateRequestedColumns validates that given requested columns conform to given custom column mapping.

The custom column mapping is expected to be validated with ValidateColumnMapping prior to calling this function.

func ZeroFloat64Pointer

func ZeroFloat64Pointer() *float64

ZeroFloat64Pointer returns a pointer to a float64 with zero value.

func ZeroIntPointer

func ZeroIntPointer() *int

ZeroIntPointer returns a pointer to an int with zero value.

func ZeroStringPointer

func ZeroStringPointer() *string

ZeroStringPointer returns a *string pointer to an empty string.

Types

type Data

type Data struct {
	Timestamp         time.Time `json:"time"`
	Addr              string    `json:"mac"`
	Name              string    `json:"name"`
	Temperature       float64   `json:"temperature"`
	Humidity          float64   `json:"humidity"`
	DewPoint          float64   `json:"dew_point"`
	Pressure          float64   `json:"pressure"`
	BatteryVoltage    float64   `json:"battery_voltage"`
	TxPower           int       `json:"tx_power"`
	AccelerationX     int       `json:"acceleration_x"`
	AccelerationY     int       `json:"acceleration_y"`
	AccelerationZ     int       `json:"acceleration_z"`
	MovementCounter   int       `json:"movement_counter"`
	MeasurementNumber int       `json:"measurement_number"`
}

Data contains all fields of a RuuviTag v5 measurement.

func FromFields

func FromFields(f Fields) Data

FromFields creates a new Data struct by copying all non-zero pointer values from the given Fields struct.

type Fields

type Fields struct {
	Timestamp         time.Time `json:"time"`
	Addr              *string   `json:"mac,omitempty"`
	Name              *string   `json:"name,omitempty"`
	Temperature       *float64  `json:"temperature,omitempty"`
	Humidity          *float64  `json:"humidity,omitempty"`
	DewPoint          *float64  `json:"dew_point,omitempty"`
	Pressure          *float64  `json:"pressure,omitempty"`
	BatteryVoltage    *float64  `json:"battery_voltage,omitempty"`
	TxPower           *int      `json:"tx_power,omitempty"`
	AccelerationX     *int      `json:"acceleration_x,omitempty"`
	AccelerationY     *int      `json:"acceleration_y,omitempty"`
	AccelerationZ     *int      `json:"acceleration_z,omitempty"`
	MovementCounter   *int      `json:"movement_counter,omitempty"`
	MeasurementNumber *int      `json:"measurement_number,omitempty"`
}

Fields contains all fields of a RuuviTag v5 measurement, but only the time field is mandatory. To be used e.g. with REST APIs that do not need to return empty fields.

func AllZeroFields

func AllZeroFields() Fields

AllZeroFields creates a Fields struct with all pointer values set to a zero number.

func FieldsFromColumns

func FieldsFromColumns(d Data, columns []string) Fields

func FromData

func FromData(d Data) Fields

FromData copies all values from given Data struct regardless of whether they have nonzero value or not.

func NonZeroFields

func NonZeroFields(d Data) Fields

NonZeroFields copies fields with non-zero value from the given Data struct.

Jump to

Keyboard shortcuts

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