config

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthMethod

type AuthMethod string
const (
	AuthPassword AuthMethod = "password"
	AuthKey      AuthMethod = "key"
)

type Chip

type Chip struct {
	DigitalPins []Digital `yaml:"digital-pins" validate:"dive"`
	PWMPins     []PWM     `yaml:"pwm-pins" validate:"dive"`
	I2CDevices  []I2C     `yaml:"i2c-devices" validate:"dive"`
}

type Config

type Config struct {
	Name          string     `yaml:"device-name" validate:"required"`
	Mode          string     `yaml:"mode" validate:"omitempty,oneof=ssh local"`
	Url           string     `yaml:"url"`
	Port          string     `yaml:"port" validate:"omitempty,numeric"`
	Username      string     `yaml:"username"`
	AuthMethod    AuthMethod `yaml:"auth-method" validate:"omitempty,oneof=password key"`
	Password      string     `yaml:"password"`
	SSHKeyPath    string     `yaml:"ssh-key-path"`
	SSHKnownHosts string     `yaml:"ssh-known-hosts"`
	PoolSize      int        `yaml:"pool-size" validate:"min=1,max=10"`
	MaxRetries    int        `yaml:"max-retries" validate:"min=0,max=10"`
	RetryDelay    int        `yaml:"retry-delay" validate:"min=0"`
}

type Device

type Device interface {
	Start() error
	Stop() error

	Read(pin int) (int, error)
	Write(pin int, value int) error
	Watch(pin int) (<-chan PinEvent, error)
	StopWatch(pin int)

	SetDutyCycle(pin int, duty float64) error
	GetDutyCycle(pin int) (float64, error)
	StopPWM(pin int) error

	I2CProbe(bus int, address string) error
	I2CWrite(bus int, address string, data []byte) error
	I2CRead(bus int, address string, length int) ([]byte, error)
	I2CWriteRegister(bus int, address string, register byte, data []byte) error
	I2CReadRegister(bus int, address string, register byte, length int) ([]byte, error)

	ReadSensor(id string) (map[string]any, error)
	ReadSensors() (map[string]map[string]any, error)

	Health() HealthStatus
	Metrics() DeviceMetrics
	Info() DeviceInfo
	SystemMetrics() (SystemMetrics, error)
}

type DeviceConfig

type DeviceConfig struct {
	Config Config `yaml:"config" validate:"required"`
	Chip   *Chip  `yaml:"chip"`
	MQTT   *MQTT  `yaml:"mqtt"`
}

func Load

func Load(file *os.File) (*DeviceConfig, error)

func (*DeviceConfig) Validate

func (c *DeviceConfig) Validate() error

type DeviceInfo added in v1.1.3

type DeviceInfo struct {
	Name   string
	Mode   string
	Status string
}

type DeviceMetrics

type DeviceMetrics struct {
	TotalReads  int64
	TotalWrites int64
	TotalErrors int64
	SSHPoolSize int
	Reconnects  int64
}

type Digital

type Digital struct {
	Pin        int `yaml:"pin" validate:"required,gt=0,lt=54"`
	PinDefault `yaml:",inline"`
}

type Direction

type Direction int
const (
	INPUT Direction = iota
	OUTPUT
)

type Edge

type Edge int
const (
	NONE Edge = iota
	RISING
	FALLING
	BOTH
)

type HealthStatus

type HealthStatus struct {
	Connected      bool
	Reconnects     int
	ActiveWatchers int
	MQTTBound      bool
}

type I2C

type I2C struct {
	Id      string `yaml:"id" validate:"required"`
	Type    string `yaml:"type" validate:"required"`
	Bus     int    `yaml:"bus" validate:"required,oneof=0 1"`
	Address string `yaml:"address" validate:"required"`
}

type MQTT

type MQTT struct {
	Broker   string `yaml:"broker" validate:"required"`
	ClientID string `yaml:"client-id" validate:"required"`
	Topic    string `yaml:"topic" validate:"required"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	UseTLS   bool   `yaml:"use-tls"`
	CertFile string `yaml:"cert-file"`
	KeyFile  string `yaml:"key-file"`
	CAFile   string `yaml:"ca-file"`
	QOS      byte   `yaml:"qos"`
}

type PWM

type PWM struct {
	Id          string  `yaml:"id" validate:"required"`
	Pin         int     `yaml:"pin" validate:"required,gt=0,lt=54"`
	FrequencyHz int     `yaml:"frequency" validate:"required,gt=0"`
	DutyCycle   float64 `yaml:"duty-cycle" validate:"min=0,max=100"`
}

type PinDefault

type PinDefault struct {
	Id        string    `yaml:"id" validate:"required"`
	Value     Value     `yaml:"value" validate:"oneof=0 1"`
	Direction Direction `yaml:"direction" validate:"oneof=0 1"`
	Edge      Edge      `yaml:"edge" validate:"oneof=0 1 2 3"`
}

type PinEvent

type PinEvent struct {
	Pin      int
	OldValue int
	NewValue int
}

type SystemMetrics added in v1.1.3

type SystemMetrics struct {
	CPU    float64
	Memory float64
	Temp   float64
	Uptime string
}

type Value

type Value int
const (
	LOW Value = iota
	HIGH
)

Jump to

Keyboard shortcuts

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