Version: v0.0.0-...-0ba0070 Latest Latest

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

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 16 Imported by: 0




View Source
const (
	EthernetCallbackID uint64 = math.MaxUint64


This section is empty.


func DeviceName

func DeviceName(id uint16) string


type BrickData

type BrickData struct {
	Address string
	Devices map[string]*Device
	Values  map[string]map[int]Value

BrickData are discovered devices and their values

type BrickdCollector

type BrickdCollector struct {
	Address        string
	Password       string
	Data           *BrickData
	Registry       map[string][]Register
	Connection     ipconnection.IPConnection
	Values         chan Value
	Devices        map[uint16]RegisterFunc
	CallbackPeriod uint32
	IgnoredUIDs    []string
	Labels         map[string]string
	SensorLabels   map[string]map[string]map[string]string
	EthernetState  chan interface{}

BrickdCollector does all the work

func NewCollector

func NewCollector(addr, password string, cbPeriod time.Duration, ignoredUIDs []string, labels map[string]string, sensorLabels map[string]map[string]map[string]string) *BrickdCollector

NewCollector creates a new collector for the given address (and authenticates with the password)

func (*BrickdCollector) CloseEthernetState

func (b *BrickdCollector) CloseEthernetState(_ uint64)

func (*BrickdCollector) Collect

func (b *BrickdCollector) Collect(ch chan<- prometheus.Metric)

Collect is part of the prometheus.Collector interface

func (*BrickdCollector) Describe

func (b *BrickdCollector) Describe(ch chan<- *prometheus.Desc)

Describe is part of the prometheus.Collector interface

func (*BrickdCollector) OnConnect

func (b *BrickdCollector) OnConnect(reason ipconnection.DisconnectReason)

OnConnect is called when the brickd collector (re-)connects to the brickd

func (*BrickdCollector) OnDisconnect

func (b *BrickdCollector) OnDisconnect(reason ipconnection.DisconnectReason)

OnDisconnect is called when the brickd collector disconnects from the brickd

func (*BrickdCollector) OnEnumerate

func (b *BrickdCollector) OnEnumerate(
	uid string,
	connectedUid string,
	position rune,
	hardwareVersion [3]uint8,
	firmwareVersion [3]uint8,
	deviceIdentifier uint16,
	enumerationType ipconnection.EnumerationType)

OnEnumerate receives the callbacks from the Enumerate() call

func (*BrickdCollector) PollEthernetState

func (b *BrickdCollector) PollEthernetState(m master_brick.MasterBrick, uid string)

func (*BrickdCollector) RegisterAirQualityBricklet

func (b *BrickdCollector) RegisterAirQualityBricklet(uid string) ([]Register, error)

func (*BrickdCollector) RegisterBarometerBricklet

func (b *BrickdCollector) RegisterBarometerBricklet(uid string) ([]Register, error)

func (*BrickdCollector) RegisterBarometerV2Bricklet

func (b *BrickdCollector) RegisterBarometerV2Bricklet(uid string) ([]Register, error)

func (*BrickdCollector) RegisterHumidityBricklet

func (b *BrickdCollector) RegisterHumidityBricklet(uid string) ([]Register, error)

func (*BrickdCollector) RegisterHumidityV2Bricklet

func (b *BrickdCollector) RegisterHumidityV2Bricklet(uid string) ([]Register, error)

func (*BrickdCollector) RegisterMasterBrick

func (b *BrickdCollector) RegisterMasterBrick(uid string) ([]Register, error)

func (*BrickdCollector) RegisterOutdoorWeatherBricklet

func (b *BrickdCollector) RegisterOutdoorWeatherBricklet(uid string) ([]Register, error)

func (*BrickdCollector) RegisterZeroHatBrick

func (b *BrickdCollector) RegisterZeroHatBrick(uid string) ([]Register, error)

func (*BrickdCollector) Update

func (b *BrickdCollector) Update()

Update runs in the background and discovers devices and collects the Values

type Device

type Device struct {
	UID             string
	ConnectedUID    string
	Position        rune
	HardwareVersion string
	FirmwareVersion string
	DeviceID        uint16
	Available       bool

Device is a discovered device

type Register

type Register struct {
	Deregister func(uint64)
	ID         uint64

Register is a callback register, the Deregister func will be called as reg.Deregister(reg.ID)

type RegisterFunc

type RegisterFunc func(string) ([]Register, error)

RegisterFunc is the funcion of BrickdCollector to register callbacks

type Value

type Value struct {
	Index    int                  // index in BrickData.Values, needs to be assigned by the callback
	DeviceID uint16               //
	UID      string               // UID as given from brickd
	SensorID int                  // sensor id in outdoor_weather_bricklet
	Type     prometheus.ValueType // probably just prometheus.GaugeValue
	Help     string               // help for users, i.e. prometheus' "# HELP brickd_humidity_value ..." line, (just the help text)
	Name     string               // value name, such as "usb_voltage" or "humidity"
	Value    float64              // the measurement value

Value is returned from the callbacks

Jump to

Keyboard shortcuts

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