srcfl / srcful-gateway

Sourceful Energy Gateway: Connect your solar inverter or Utility meters to earn tokens.
https://sourceful.energy/
MIT License
5 stars 2 forks source link

Interpretation of modbus data #64

Closed h0bb3 closed 10 months ago

h0bb3 commented 10 months ago

As it seems it was more complicated to interpret the modbus data and there seems to be custom endianness and sizes of even the raw data.

One suggestion would be to interpret everything read from modbus as a 16bit number and name these Aa etc... and allow for a rearrangement of the the data. E.g. reading 4 registers and using the high bytes of each word to form a 32 bit integer big endian integer would then be ABCD using the low byte as little endian would give the string dcba etc.

This would at least give flexibility at the byte level.

Another idea would be to push this responsibility to the client and just allow for raw data reading.

h0bb3 commented 10 months ago

advice wanted from @davmoz

davmoz commented 10 months ago

According to the modbus protocol, registers are always in big-endian format (see 1 and 2). So perhaps, we can assume that all inverters that we will be working with will adhere to the standard.

From experience, we know that the following is true: Inverter model Register (Word) endianness
Sungrow Big-endian
Solaredge Big-endian
Huawei Big-endian
Growatt -
Fronius -
Ferroamp -

"-" = We don't know

So i suggest we continue assuming that each register is transferred as big-endian. Do you agree?

That said, we should still have some interpretation on the Gateway for logging/diagnostics, so L28 probably need to be tweaked.

h0bb3 commented 10 months ago

If big endian is what is in the spec then we go with that. The current implementation is flexible in regards to the higher level interpretation of the data, at least with big an little endian, though there may be variants there also i.e mid big endian, mid little endian for e.g. 32 bit values. But these can of course be added if needed.

I guess it is this part that should be big endian then? https://github.com/srcfl/srcful-gateway/blob/3cd427cb6d35fa7eba61ba5926ff6b5321148369/server/inverters/registerValue.py#L75

davmoz commented 10 months ago

I guess it is this part that should be big endian then?

Yup! :)

Fixed in b0fce8f9479d653579e23c96862e1d3e62deea48