Skip to content

Commit

Permalink
Merge branch 'master' into fronius-wattpilot
Browse files Browse the repository at this point in the history
* master: (21 commits)
  ABB TACW fw ver 1.6.5 adaptions (evcc-io#4626)
  heidelberg: remove fw register diag (evcc-io#5125)
  chore: improve issue template (evcc-io#5116)
  Fix charger rater/timer logic for vehicle reconnect
  Enyaq: add soc limit
  eTron: fix api error
  Go-E: fix session energy reset on disconnect (BC) (evcc-io#5119)
  FritzDECT: increase session timeout
  Gokrazy: add sqlite to /perm
  increase community data update interval (5s > 10s)
  chore: improve proxy example by adding rtu
  Docker: expose mDNS (evcc-io#5093)
  Sessions: add odometer (evcc-io#5069)
  Docker: don't force master branch when releasing to enable bugfix releases
  chore: fix comment
  Fix race condition in loading templates
  Fix a race condition when stopping the charging session
  Show version in api
  chore: add some docs
  Publish savings data on startup (evcc-io#5048)
  ...
  • Loading branch information
mabunixda committed Nov 11, 2022
2 parents c0e361b + 03cf93f commit 63e9273
Show file tree
Hide file tree
Showing 38 changed files with 220 additions and 134 deletions.
9 changes: 8 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ body:
validations:
required: true
attributes:
value: |
1.
2.
3.
...
label: Steps to reproduce
description: >-
Steps to reproduce the behavior.
Expand All @@ -31,6 +36,7 @@ body:
required: true
attributes:
label: Configuration details
render: yaml
description: >
Show evcc configuration file <code>evcc.yaml</code>
Expand All @@ -39,6 +45,7 @@ body:
required: true
attributes:
label: Log details
render: text
description: >
Show evcc log output by running with <code>evcc --log debug</code>
Expand All @@ -54,7 +61,7 @@ body:
- Windows
- Docker container

- type: textarea
- type: input
attributes:
label: Version
description: >
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
ref: refs/heads/master # force master
fetch-depth: 0

- name: Login
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ COPY --from=builder /build/evcc /usr/local/bin/evcc

COPY docker/bin/* /app/

# mDNS
EXPOSE 5353/udp
# UI and /api
EXPOSE 7070/tcp
# KEBA charger
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ image::
go install github.com/gokrazy/tools/cmd/gokr-packer@main
mkdir -p flags/github.com/gokrazy/breakglass
echo "-forward=private-network" > flags/github.com/gokrazy/breakglass/flags.txt
mkdir -p flags/github.com/evcc-io/evcc
echo "--sqlite /perm/evcc.db" > flags/github.com/evcc-io/evcc/flags.txt
mkdir -p buildflags/github.com/evcc-io/evcc
echo "$(BUILD_TAGS),gokrazy" > buildflags/github.com/evcc-io/evcc/buildflags.txt
echo "-ldflags=$(LD_FLAGS)" >> buildflags/github.com/evcc-io/evcc/buildflags.txt
Expand Down
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

//go:generate mockgen -package mock -destination ../mock/mock_api.go github.com/evcc-io/evcc/api Charger,ChargeState,PhaseSwitcher,Identifier,Meter,MeterEnergy,Vehicle,ChargeRater,Battery

// ChargeMode are charge modes modeled after OpenWB
// ChargeMode is the charge operation mode. Valid values are off, now, minpv and pv
type ChargeMode string

// Charge modes
Expand Down
1 change: 1 addition & 0 deletions assets/i18n/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ title = "Ladevorgänge"
downloadCsv = "Als CSV herunterladen"
loadpoint = "Ladepunkt"
vehicle = "Fahrzeug"
odometer = "Kilometerstand"
energy = "Geladen"
date = "Zeitraum"

Expand Down
1 change: 1 addition & 0 deletions assets/i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ date = "Period"
[sessions.csv]
loadpoint = "Loadpoint"
vehicle = "Vehicle"
odometer = "Mileage (km)"
identifier = "Identifier"
chargedenergy = "Energy (kWh)"
meterstart = "Meter Start (kWh)"
Expand Down
6 changes: 4 additions & 2 deletions assets/js/components/LiveCommunity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import SavingsTile from "./SavingsTile.vue";
import formatter from "../mixins/formatter";
import communityApi from "../communityApi";
const UPDATE_INTERVAL_SECONDS = 10;
export default {
name: "LiveCommunity",
components: { SavingsTile },
Expand Down Expand Up @@ -80,10 +82,10 @@ export default {
},
},
async mounted() {
this.refresh = setInterval(this.update, 5000);
this.refresh = setInterval(this.update, UPDATE_INTERVAL_SECONDS * 1e3);
await this.update();
this.$nextTick(() => {
this.animationDuration = 5;
this.animationDuration = UPDATE_INTERVAL_SECONDS;
});
},
unmounted() {
Expand Down
57 changes: 19 additions & 38 deletions charger/abb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

// ABB charger implementation
type ABB struct {
log *util.Logger
conn *modbus.Connection
curr uint32
}
Expand All @@ -40,6 +39,7 @@ const (
abbRegFirmware = 0x4004 // Firmware version 2 unsigned RO available
abbRegMaxRated = 0x4006 // Max rated current 2 unsigned RO available
abbRegErrorCode = 0x4008 // Error Code 2 unsigned RO available
abbRegSocketLock = 0x400A // Socket Lock State 2 unsigned RO available
abbRegStatus = 0x400C // Charging state 2 unsigned RO available
abbRegGetCurrent = 0x400E // Current charging current limit 2 0.001 A unsigned RO
abbRegCurrents = 0x4010 // Charging current phases 6 0.001 A unsigned RO available
Expand All @@ -48,8 +48,6 @@ const (
abbRegSetCurrent = 0x4100 // Set charging current limit 2 0.001 A unsigned WO available
// abbRegSession = 0x4105 // Start/Stop Charging Session 1 unsigned WO available
// abbRegPhases = 0x4102 // Set charging phase 1 unsigned WO Not supported

abbMinCurrent = 0x1720 // 5920 mA
)

func init() {
Expand All @@ -59,21 +57,19 @@ func init() {
// NewABBFromConfig creates a ABB charger from generic config
func NewABBFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := modbus.Settings{
ID: 1,
Baudrate: 9600,
Comset: "8N1",
ID: 1,
}

if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}

return NewABB(cc.URI, cc.Device, cc.Comset, cc.Baudrate, cc.ID)
return NewABB(cc.URI, cc.Device, cc.Comset, cc.Baudrate, modbus.ProtocolFromRTU(cc.RTU), cc.ID)
}

// NewABB creates ABB charger
func NewABB(uri, device, comset string, baudrate int, slaveID uint8) (api.Charger, error) {
conn, err := modbus.NewConnection(uri, device, comset, baudrate, modbus.Rtu, slaveID)
func NewABB(uri, device, comset string, baudrate int, proto modbus.Protocol, slaveID uint8) (api.Charger, error) {
conn, err := modbus.NewConnection(uri, device, comset, baudrate, proto, slaveID)
if err != nil {
return nil, err
}
Expand All @@ -86,9 +82,8 @@ func NewABB(uri, device, comset string, baudrate int, slaveID uint8) (api.Charge
conn.Logger(log.TRACE)

wb := &ABB{
log: log,
conn: conn,
curr: abbMinCurrent, // assume min current
curr: 6000, // assume min current
}

// keep-alive
Expand All @@ -110,15 +105,6 @@ func (wb *ABB) status() (byte, error) {
return b[2] & 0x7f, nil
}

func (wb *ABB) session() (bool, error) {
s, err := wb.status()
if err != nil || s == 0 || s == 5 { // ToDo: check if 1 is active/inactive/unknown
return false, err
}

return true, err
}

// Status implements the api.Charger interface
func (wb *ABB) Status() (api.ChargeStatus, error) {
s, err := wb.status()
Expand All @@ -138,6 +124,13 @@ func (wb *ABB) Status() (api.ChargeStatus, error) {
case 4: // State C2: Charging Contact closed, energy delivering
return api.StatusC, nil
case 5: // Other: Session stopped
b, err := wb.conn.ReadHoldingRegisters(abbRegSocketLock, 2)
if err != nil {
return api.StatusNone, err
}
if binary.BigEndian.Uint32(b) >= 0x0101 {
return api.StatusB, nil
}
return api.StatusA, nil
default: // Other
return api.StatusNone, fmt.Errorf("invalid status: %0x", s)
Expand All @@ -146,26 +139,16 @@ func (wb *ABB) Status() (api.ChargeStatus, error) {

// Enabled implements the api.Charger interface
func (wb *ABB) Enabled() (bool, error) {
s, err := wb.session()
if err != nil || !s {
return false, err
}

b, err := wb.conn.ReadHoldingRegisters(abbRegGetCurrent, 2)
if err != nil {
return false, err
}

return binary.BigEndian.Uint32(b) >= abbMinCurrent, nil
return binary.BigEndian.Uint32(b) != 0, nil
}

// Enable implements the api.Charger interface
func (wb *ABB) Enable(enable bool) error {
s, err := wb.session()
if err != nil || !s {
return err
}

var current uint32
if enable {
current = wb.curr
Expand Down Expand Up @@ -196,11 +179,6 @@ func (wb *ABB) MaxCurrentMillis(current float64) error {
return fmt.Errorf("invalid current %.1f", current)
}

s, err := wb.session()
if err != nil || !s {
return err
}

wb.curr = uint32(current * 1e3)

return wb.setCurrent(wb.curr)
Expand Down Expand Up @@ -271,10 +249,13 @@ func (wb *ABB) Diagnose() {
fmt.Printf("\tFirmware:\t%d.%d.%d\n", b[0], b[1], b[2])
}
if b, err := wb.conn.ReadHoldingRegisters(abbRegMaxRated, 2); err == nil {
fmt.Printf("\tMax rated current:\t%.1fA\n", float32(binary.BigEndian.Uint32(b))/1e3)
fmt.Printf("\tMax rated current:\t%dmA\n", binary.BigEndian.Uint32(b))
}
if b, err := wb.conn.ReadHoldingRegisters(abbRegGetCurrent, 2); err == nil {
fmt.Printf("\tCharging current limit:\t%.1fA\n", float32(binary.BigEndian.Uint32(b))/1e3)
fmt.Printf("\tCharging current limit:\t%dmA\n", binary.BigEndian.Uint32(b))
}
if b, err := wb.conn.ReadHoldingRegisters(abbRegSocketLock, 2); err == nil {
fmt.Printf("\tSocket lock state:\t%x\n", b)
}
if b, err := wb.conn.ReadHoldingRegisters(abbRegStatus, 2); err == nil {
fmt.Printf("\tStatus:\t%x\n", b)
Expand Down
13 changes: 5 additions & 8 deletions charger/go-e.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,12 @@ func NewGoE(uri, token string, cache time.Duration) (api.Charger, error) {
c.api = goe.NewLocal(log, util.DefaultScheme(uri, "http"), cache)
}

if !sponsor.IsAuthorized() {
return nil, api.ErrSponsorRequired
}

if c.api.IsV2() {
var phases func(int) error
if sponsor.IsAuthorized() {
phases = c.phases1p3p
} else {
log.WARN.Println("automatic 1p3p phase switching requires sponsor token")
}

return decorateGoE(c, c.totalEnergy, phases), nil
return decorateGoE(c, c.totalEnergy, c.phases1p3p), nil
}

return c, nil
Expand Down
2 changes: 2 additions & 0 deletions charger/go-e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func TestGoEV1(t *testing.T) {
h := &handler{}
srv := httptest.NewServer(h)

sponsor.Subject = "foo"

wb, err := NewGoE(srv.URL, "", 0)
if err != nil {
t.Error(err)
Expand Down
4 changes: 0 additions & 4 deletions charger/heidelberg-ec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type HeidelbergEC struct {
}

const (
hecRegFirmware = 1 // Input
hecRegVehicleStatus = 5 // Input
hecRegTemperature = 9 // Input
hecRegPower = 14 // Input
Expand Down Expand Up @@ -262,9 +261,6 @@ var _ api.Diagnosis = (*HeidelbergEC)(nil)

// Diagnose implements the api.Diagnosis interface
func (wb *HeidelbergEC) Diagnose() {
if b, err := wb.conn.ReadInputRegisters(hecRegFirmware, 2); err == nil {
fmt.Printf("Firmware:\t%d.%d.%d\n", b[1], b[2], b[3])
}
if b, err := wb.conn.ReadInputRegisters(hecRegTemperature, 1); err == nil {
fmt.Printf("Temperature:\t%.1fC\n", float64(int16(binary.BigEndian.Uint16(b)))/10)
}
Expand Down
22 changes: 21 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import (
"github.com/evcc-io/evcc/core"
"github.com/evcc-io/evcc/push"
"github.com/evcc-io/evcc/server"
"github.com/evcc-io/evcc/server/modbus"
"github.com/evcc-io/evcc/server/updater"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/pipe"
"github.com/evcc-io/evcc/util/sponsor"
"github.com/evcc-io/evcc/util/telemetry"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -149,6 +151,23 @@ func runRoot(cmd *cobra.Command, args []string) {
err = configureEnvironment(cmd, conf)
}

// setup telemetry
if err == nil {
telemetry.Create(conf.Plant)
if conf.Telemetry {
err = telemetry.Enable(true)
}
}

// setup modbus proxy
if err == nil {
for _, cfg := range conf.ModbusProxy {
if err = modbus.StartProxy(cfg.Port, cfg.Settings, cfg.ReadOnly); err != nil {
break
}
}
}

// setup site and loadpoints
var site *core.Site
if err == nil {
Expand Down Expand Up @@ -220,7 +239,8 @@ func runRoot(cmd *cobra.Command, args []string) {
site.DumpConfig()
site.Prepare(valueChan, pushChan)

// version check
// show and check version
valueChan <- util.Param{Key: "version", Val: server.FormattedVersion()}
go updater.Run(log, httpd, tee, valueChan)

// capture log messages for UI
Expand Down
19 changes: 0 additions & 19 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import (
"github.com/evcc-io/evcc/server"
"github.com/evcc-io/evcc/server/db"
"github.com/evcc-io/evcc/server/db/settings"
"github.com/evcc-io/evcc/server/modbus"
"github.com/evcc-io/evcc/tariff"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/locale"
"github.com/evcc-io/evcc/util/machine"
"github.com/evcc-io/evcc/util/pipe"
"github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/sponsor"
"github.com/evcc-io/evcc/util/telemetry"
"github.com/libp2p/zeroconf/v2"
"github.com/samber/lo"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -94,28 +92,11 @@ func configureEnvironment(cmd *cobra.Command, conf config) (err error) {
err = configureDatabase(conf.Database)
}

// setup telemetry
if err == nil {
telemetry.Create(conf.Plant)
if conf.Telemetry {
err = telemetry.Enable(true)
}
}

// setup mqtt client listener
if err == nil && conf.Mqtt.Broker != "" {
err = configureMQTT(conf.Mqtt)
}

// setup modbus proxy listeners
if err == nil {
for _, cfg := range conf.ModbusProxy {
if err = modbus.StartProxy(cfg.Port, cfg.Settings, cfg.ReadOnly); err != nil {
break
}
}
}

// setup javascript VMs
if err == nil {
err = configureJavascript(conf.Javascript)
Expand Down

0 comments on commit 63e9273

Please sign in to comment.