Skip to content

About

Go client for the OpenEVSE WiFi firmware: websocket state, claims API, RAPI

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

go-openevse

Go client for the OpenEVSE WiFi firmware (4.1.9 or later).

  • State is received over the firmware's /ws websocket: the full status document on connect, then diffs with only the changed keys. The client merges them into one Status and reconnects with backoff if the connection drops.
  • Control goes through the firmware's claims API (POST/DELETE /claims/{client}) at the firmware's fixed API priority (500). The charger's own manual override, RFID, OCPP and limits win over the client; the client wins over the built-in solar divert, schedules and boost. The claim is re-asserted after a reconnect (a firmware reboot clears claims) and deleted on Close.
  • Optional 1p/3p phase switching for modified three-phase controllers that answer the $G7/$S7 RAPI commands. Stock OpenEVSE controllers do not.
c, err := openevse.New("http://openevse.local",
	openevse.WithHTTPClient(httpClient), // carries basic auth, if any
	openevse.WithLogger(logger),
)
if err != nil {
	return err
}

if err := c.Connect(ctx); err != nil { // waits for the first status frame
	return err
}
defer c.Close() // releases the claim

status, err := c.Status()  // ErrNotConnected while the websocket is down
err = c.SetCurrent(16)     // A
err = c.Enable(true)

info := c.Info()           // /config: WiFi firmware version, controller firmware, build, hostname
claims, err := c.Claims()  // every claim on the charger; claims[i].Name() names the holder

Connect reads /config first and fails with ErrFirmwareTooOld on WiFi firmware older than 4.1.9, so users get told why instead of a silent timeout. Development builds without a version number (master_abc123) are not checked.

Options: WithHTTPClient, WithLogger, WithClientID, WithStatusHandler (called with every merged frame), and WithPingInterval, WithReadTimeout, WithReadyTimeout, WithStableAfter for the timings.

The default client id is 262145 (vendor 0x0004 = evcc, client 0x0001), registered as EvseClient_evcc in the firmware. Other projects should use their own id (WithClientID) so they do not fight evcc for the same claim slot. A leftover claim after an unclean shutdown is removed with DeleteClaim, or DELETE /claims/<id>.

When a claim is written while the charger's manual override is active, one warning is logged naming every claim that outranks this client, for example outranked by manual override (priority 1000), limit (priority 1100).

CLI

go install github.com/OpenEVSE/go-openevse/cmd/openevse@latest

openevse -uri http://openevse.local [-user u -password p] status   # /config and current status
openevse ... watch                                                  # print every status change
openevse ... claims                                                 # list claims and who holds them
openevse ... claim -current 16 -enable                              # write a claim (persists after exit)
openevse ... release                                                # delete the claim
openevse ... rapi '$GV'                                             # raw RAPI command

OPENEVSE_URI, OPENEVSE_USER and OPENEVSE_PASSWORD are read as defaults.

Tests run against a fake firmware; go test -race ./....

About

Go client for the OpenEVSE WiFi firmware: websocket state, claims API, RAPI

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages