Initial commit — energy collector (AlphaEss + SDM630 → TimescaleDB)
This commit is contained in:
52
config.go
Normal file
52
config.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
SampleRate int `json:"sample_rate"` // seconds
|
||||
AlphaEss AlphaConf `json:"alphaess"`
|
||||
MQTT MQTTConf `json:"mqtt"`
|
||||
DB DBConf `json:"db"`
|
||||
}
|
||||
|
||||
type AlphaConf struct {
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
SlaveID uint8 `json:"slave_id"`
|
||||
}
|
||||
|
||||
type MQTTConf struct {
|
||||
Broker string `json:"broker"`
|
||||
BrokerIP string `json:"broker_ip"` // optional scoped IPv6 e.g. fe80::1%eth0
|
||||
BrokerTLSName string `json:"broker_tls_name"` // TLS ServerName when broker_ip is set
|
||||
Port int `json:"port"`
|
||||
ClientID string `json:"client_id"`
|
||||
TopicPrefix string `json:"topic_prefix"`
|
||||
CACert string `json:"ca_cert"`
|
||||
ClientCert string `json:"client_cert"`
|
||||
ClientKey string `json:"client_key"`
|
||||
Devices []DeviceConf `json:"devices"`
|
||||
}
|
||||
|
||||
// DeviceConf describes one SDM630 meter reachable via the MQTT/Modbus bridge.
|
||||
type DeviceConf struct {
|
||||
SlaveAddress int `json:"slave_address"`
|
||||
Name string `json:"name"` // used as the 'device' column value in power_meter
|
||||
Segment string `json:"segment"` // MQTT topic segment
|
||||
}
|
||||
|
||||
type DBConf struct {
|
||||
DSN string `json:"dsn"` // PostgreSQL connection string
|
||||
}
|
||||
|
||||
func loadConfig(path string) (Config, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
var cfg Config
|
||||
return cfg, json.Unmarshal(data, &cfg)
|
||||
}
|
||||
Reference in New Issue
Block a user