smartbridge/cmd/smartbridge/config.go
Felix Niederwanger 2a9df9a9db
Add influxdb
Adds influxdb data push
2023-05-31 22:00:33 +02:00

62 lines
1.4 KiB
Go

package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
Remote string `yaml:"remote"` // Remote IP address of the Smartbridge
Mqtt MqttConfig `yaml:"mqtt"` // mqtt configuration
Influx InfluxConfig `yaml:"influxdb"` // InfluxDB configuration
Delay int `yaml:"delay"`
Verbose bool `yaml:"verbose"`
}
type MqttConfig struct {
Remote string `yaml:"remote"`
Port int `yaml:"port"`
ClientID string `yaml:"clientid"`
topic string `yaml:"topic"`
Username string `yaml:"username"`
Password string `yaml:"password"`
}
type InfluxConfig struct {
URL string `yaml:"url"`
Token string `yaml:"token"`
Organization string `yaml:"organization"`
Bucket string `yaml:"bucket"`
Measurement string `yaml:"measurement"`
}
var cf Config
func (cf *Config) SetDefaults() {
cf.Remote = "127.0.0.1"
cf.Delay = 5
cf.Mqtt.Remote = "127.0.0.1"
cf.Mqtt.Port = 1883
cf.Mqtt.ClientID = "smartbridge"
cf.Mqtt.topic = "home/power"
cf.Mqtt.Username = ""
cf.Mqtt.Password = ""
cf.Influx.URL = ""
cf.Influx.Token = ""
cf.Influx.Organization = "home"
cf.Influx.Bucket = "home"
cf.Influx.Measurement = "power"
}
func (cf *Config) LoadYAML(filename string) error {
content, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
if err := yaml.Unmarshal(content, cf); err != nil {
return err
}
return nil
}