Initial commit — energy collector (AlphaEss + SDM630 → TimescaleDB)

This commit is contained in:
2026-04-18 11:12:40 +02:00
commit 8295d1cf47
12 changed files with 1186 additions and 0 deletions

52
config.go Normal file
View 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)
}