Coder Social home page Coder Social logo

mlnoga / rct Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 2.0 40 KB

A library for communication with solar power inverters of the RCT power brand, not endorsed by or affiliated with the eponymous company.

License: GNU Lesser General Public License v2.1

Go 99.50% Makefile 0.50%
rct-power golang pv solar battery

rct's People

Contributors

andig avatar matc17 avatar mlnoga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

andig matc17

rct's Issues

invalid response / Cmd Response (05)

siehe evcc #9146

folgende Fehlermeldungen:

battery 1 soc: invalid response: Cmd Response (05) Id #INVALID (4BC0F974) Data [70 60 232 0]

battery 1 soc: invalid response: Cmd Response (05) Id #INVALID (C0A7074F) Data [58 189 129 108 80 83 32 49 48 46 48 32 86 87 52 81 0 0 0 0 0 0 0 0 0 0 0 0 50 51 42 69 79 14 25 195 35 158 21 63 0 0 7 13 0 0 0 0 50 46 51 46 53 54 54 49 0 0 0 0 0 0 0 0 48 48 54 53 66 52 48 50 51 57 49 55 0 0 0 0 0 0 0 0 223 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

grid energy: invalid response: Cmd Response (05) Id #INVALID (C0A7074F) Data [71 240 52 38 80 83 32 56 46 48 32 68 83 76 69 0 0 0 0 0 0 0 0 0 0 0 0 0 119 61 110 69 200 249 61 193 0 0 0 63 0 0 5 13 0 0 0 0 50 46 51 46 53 54 54 49 0 0 0 0 0 0 0 0 48 48 54 53 66 52 56 50 51 50 52 54 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

Linter errors, mostly in tests

Here we go:

> golangci-lint run *.go

build_test.go:11:18: undeclared name: `BatteryPower` (typecheck)
	{Datagram{Read, BatteryPower, nil}, "[2B 01 04 40 0F 01 5B 58 B4]"},
	                ^
build_test.go:12:18: undeclared name: `InverterACPower` (typecheck)
	{Datagram{Read, InverterACPower, nil}, "[2B 01 04 DB 2D 2D 69 AE 55 AB]"},
	                ^
build_test.go:31:9: parser.Init undefined (type DatagramParser has no field or method Init) (typecheck)
	parser.Init()
	       ^
build_test.go:36:10: parser.Buffer undefined (type DatagramParser has no field or method Buffer, but does have buffer) (typecheck)
		parser.Buffer = builder.Bytes()
		       ^
build_test.go:37:10: parser.Len undefined (type DatagramParser has no field or method Len) (typecheck)
		parser.Len = len(builder.Bytes())

Invalid Response / Cmd Response - More stability needed

Quite often the response received by the rct power storage is flawed. As this behavior cannot be changed easily, I suggest to implement an effective error handling routine. I experimented with different approaches, the following (quickly translated by chatgpt into go) solved the issue and enabled stable performance:

// Query-Funktion mit robuster Fehlerbehandlung und Wiederholungslogik
func (c *Connection) Query(id Identifier) (*Datagram, error) {
	if dg, ok := c.cache.Get(id); ok {
		return dg, nil
	}

	const maxRetries = 10
	const startDelay = 100 * time.Millisecond
	const backoffMultiplier = 2
	var delay = startDelay

	for attempt := 0; attempt < maxRetries; attempt++ {
		c.builder.Build(&Datagram{Cmd: Read, Id: id, Data: nil})
		_, err := c.Send(c.builder)
		if err != nil {
			return nil, err
		}

		dg, err := c.Receive()
		if err != nil {
			if _, ok := err.(RecoverableError); ok {
				fmt.Printf("Recoverable error during parsing, attempt %d of %d: %v\n", attempt+1, maxRetries, err)
				time.Sleep(delay)
				delay *= time.Duration(backoffMultiplier)
				continue
			}
			return nil, err
		}

		if dg.Cmd == Response && dg.Id == id {
			c.cache.Put(dg)
			return dg, nil
		}

		err = RecoverableError{fmt.Sprintf("Mismatch of requested read of id: %v and response from source: %v", id, dg)}
		fmt.Println(err.Error())
		time.Sleep(delay)
		delay *= time.Duration(backoffMultiplier)
	}

	return nil, errors.New(fmt.Sprintf("Max retries reached for id: %v", id))
}

The idea behind the code:
By scheduling strategic delays between retries, the likelihood of subsequent requests being successful is increased, leading overall to a more resilient application.

What do you think about the suggestion? Can you implement such a routine or something else increasing reliability?

App using this module crashes every ~4-15 days

I am using this module to read Inverter state (8 values) every second with a Raspberry Pi Zero W in my garage in order to control the charger wall box for electric car. After few hours, but mostly after 4 to 15 days the app crashes while trying to read a value.

Split timeout and cache

Evcc connects with timeout: 1s per default. That value is applied to both the connection timeout as well as the cache duration. 1s is a very aggressive connection timeout. Simple approach would be to split these params or- alternatively- allow passing a Context as first param to use with DialContext.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.