enbility / eebus-go

EEBUS protocol implementation in go
https://enbility.net
MIT License
52 stars 14 forks source link

How to subscribe to remote device? #20

Closed lukx closed 1 year ago

lukx commented 1 year ago

Hey Andi, thank you for the excellent work on making EEBUS available to the people :-) I am succeeding already in using it for a HVAC Use case with my Heat Pump (and have already added a couple of features on my local branch to make this possible).

I am struggling to understand a part of the code base: How do I subscribe (as a client) to a remote data point? I could only find the subscription implementation for when we are acting as a server... Could you point me to the right places, please?

Thanks again Lukas

DerAndereAndi commented 1 year ago

Hi Lukas,

I haven't had a lot of time lately to continue working on this. The interface for this library to be used e.g. in a HEMS is far yet and we are open to suggestions. I am working on a generic HEMS implementation as an example to explore this. I need to wrap some things up to commit a bunch of changes I only have locally. The repo for that is https://github.com/DerAndereAndi/eebus-go-cem

Could you elaborate on what exactly you want to subscribe to, or what it is that you need? Maybe describe the use-case/scenario?

Thanks, Andreas

P.S.: There is not really such a thing as a client or server in EEBUS

lukx commented 1 year ago

Hey, sure thing! See my draft #21 - it is a draft and buggy.

My use case is as follows:

I want to subscribe to the measurement values, rather than polling them every x Seconds.

I am also looking into the Binding mechanisms, as this is required for the HVAC Overrun Control Further, I am sending a Control Signal to the remote device, to actually control the HVAC Overrun (which is why I introduced the Sending methods)

About the Client/Server: True, of course. I was referring to the Roles that one side of a communication holds for a specific feature.

DerAndereAndi commented 1 year ago

Thanks Lukas, I saw the PR. Awesome!

Working with the data, e.g. measurements, shouldn't be done in this library as that is a use case implementation. Use Cases differ from the HEMS perspective and the actual device, I'd like to separate this from this "core".

I will have the same task in the HEMS when implementing the measurements use case for e-mobility. As I am not there yet, I haven't decided on how this could/should work. I am very open for suggestions on this.

Binding usually means that the device should check if the HEMS registered a binding and only allow writing of that is done (as far as I remember it). So that is "basically" a management and control feature, and an interface needs to exist for doing that. Maybe it makes sense to be able to define in the stack of a binding has to exist for writing and implement the check for that in the stack instead of requiring the use-case implementation to do that. But yes, adding writing (sending) is needed :)

Regarding the Use-Case:

DerAndereAndi commented 1 year ago

@lukx For getting updated data, please check spine/events.go. The EventPayload struct is used to pass updated data to all subscribers. I just pushed the current WIP state of the CEM and you can see how to use event handling here: https://github.com/DerAndereAndi/eebus-go-cem/blob/dev/cem/evse.go#L84-L131

Implement the HandleEvent interface and you'll get the data updates and (hopefully) everything else that is relevant to react to.