diff --git a/cmd/configure/configure.go b/cmd/configure/configure.go index 78b031e4d..cf581762c 100644 --- a/cmd/configure/configure.go +++ b/cmd/configure/configure.go @@ -6,6 +6,7 @@ import ( "text/template" "github.com/Masterminds/sprig/v3" + "github.com/evcc-io/evcc/util/machine" "github.com/evcc-io/evcc/util/templates" ) @@ -43,6 +44,8 @@ type config struct { EEBUS string MQTT string SponsorToken string + Plant string + Telemetry bool } type Configure struct { @@ -120,6 +123,10 @@ func (c *Configure) RenderConfiguration() ([]byte, error) { panic(err) } + // Assign random plant id. Don't use actual machine-id as file might + // be copied around to a different machine. + c.config.Plant = machine.RandomID() + out := new(bytes.Buffer) err = tmpl.Execute(out, c.config) diff --git a/cmd/configure/configure.tpl b/cmd/configure/configure.tpl index 297613bc6..e439903b8 100644 --- a/cmd/configure/configure.tpl +++ b/cmd/configure/configure.tpl @@ -8,10 +8,17 @@ log: info levels: cache: error +# unique installation id +plant: {{ .Plant }} + interval: 10s # control cycle interval {{- if ne (len .SponsorToken) 0 }} sponsortoken: {{ .SponsorToken }} + +# sponsors can set telemetry: true to enable anonymous data aggregation +# see https://github.com/evcc-io/evcc/discussions/4554 +telemetry: {{ .Telemetry }} {{- end}} {{- if ne (len .Meters) 0 }} diff --git a/util/machine/machine.go b/util/machine/machine.go index fa62c6e57..b7037e2d3 100644 --- a/util/machine/machine.go +++ b/util/machine/machine.go @@ -30,16 +30,20 @@ func CustomID(cid string) error { return nil } +// RandomID creates a random id +func RandomID() string { + rnd := util.RandomString(512) + mac := hmac.New(sha256.New, []byte(rnd)) + return hex.EncodeToString(mac.Sum(nil)) +} + // ID returns the platform specific machine id of the current host OS. // If ID cannot be generated, a random value is suggested. func ID() (string, error) { if id == "" { var err error if id, err = machineid.ID(); err != nil { - rnd := util.RandomString(512) - mac := hmac.New(sha256.New, []byte(rnd)) - rid := hex.EncodeToString(mac.Sum(nil)) - + rid := RandomID() return "", fmt.Errorf("could not get %w; for manual configuration use plant: %s", err, rid) } }