Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

realtime fronius_site_mppt_voltage & fronius_site_mppt_current_dc with bigger resolution #116

Closed
gitwasi opened this issue Feb 25, 2024 · 8 comments

Comments

@gitwasi
Copy link

gitwasi commented Feb 25, 2024

As far as I can understand from sources IDC and UDC are accrued from archive data which provide rather low resolution. I have Java code which gets this data from Modbus. It is also accessible directlly from inverter and data resolution is almost the sama as main inverter data (load, grid, pv) but id don't know how to implement this in GO.

I have Fronius Symo 8.2-3-M

My code uses:

		<!-- https://mvnrepository.com/artifact/com.ghgande/j2mod -->
		<dependency>
			<groupId>com.ghgande</groupId>
			<artifactId>j2mod</artifactId>
			<version>2.6.4</version>
		</dependency>

Procedure to acquire data looks as follows:

InetAddress addr = InetAddress.getByName("192.168.1.12"); //Inverter IP 
// Open the connection
con = new TCPMasterConnection(addr);
con.setPort(502);
con.connect();

// inverter
req = new ReadMultipleRegistersRequest(40069, 38);
trans = new ModbusTCPTransaction(con);
req.setUnitID(1);
trans.setRequest(req);
trans.execute();
res = (ReadMultipleRegistersResponse) trans.getResponse();

System.out.println("AC Power value=" + int16(res, 14, 15));
System.out.println("Apparent Power=" + int16(res, 18, 19));
System.out.println("Reactive Power=" + int16(res, 20, 21));
System.out.println("Power Factor=" + int16(res, 22, 23));

// string
req = new ReadMultipleRegistersRequest(40253, 43);
trans = new ModbusTCPTransaction(con);
req.setUnitID(1);
trans.setRequest(req);
trans.execute();
res = (ReadMultipleRegistersResponse) trans.getResponse();

System.out.println("String 1. DC Current=" + uint16(res, 19, 2));
System.out.println("String 1. DC Voltage=" + uint16(res, 20, 3));
System.out.println("String 1. DC Power=" + uint16(res, 21, 4));
System.out.println("String 1. Temperature=" + int16(res, 22, -1));

System.out.println("String 2. DC Current=" + uint16(res, 39, 2));
System.out.println("String 2. DC Voltage=" + uint16(res, 40, 3));
System.out.println("String 2. DC Power=" + uint16(res, 41, 4));
System.out.println("String 2. Temperature=" + int16(res, 42, -1));
// Close the connection
con.close();

And there are two functions thats converts modbus integers to floats:

    public static BigDecimal uint16(ReadMultipleRegistersResponse response, int valueRegisterIdx, int sfRegisterIdx) {
        Register vr = response.getRegister(valueRegisterIdx);
        Register sfr = sfRegisterIdx > -1 ? response.getRegister(sfRegisterIdx) : null;

        BigDecimal v = new BigDecimal(vr.toUnsignedShort()); // unsigned 16-bit value (unsigned short)
        if (sfr != null)
            v = v.movePointRight(sfr.toShort());
        return v;
    }

    public static BigDecimal int16(ReadMultipleRegistersResponse response, int valueRegisterIdx, int sfRegisterIdx) {
        Register vr = response.getRegister(valueRegisterIdx);
        Register sfr = sfRegisterIdx > -1 ? response.getRegister(sfRegisterIdx) : null;

        BigDecimal v = new BigDecimal(vr.toShort()); // unsigned 16-bit value (unsigned short)
        if (sfr != null)
            v = v.movePointRight(sfr.toShort());
        return v;
    }

Mabe somebody will implement this in the exporter to boost current and voltage data resolution.

@ccremer
Copy link
Owner

ccremer commented Feb 26, 2024

Hi.
I'm not sure if I understand your question.

Do you need more live data? Or is float64 (double in Java) too small for the values you have? Is this why you're using BigDecimal?

This exporter uses the Symo's JSON API over HTTP to access the values from Symo. Unless you can provide me with a sample JSON request that delivers the values you need, I fear you'll have to continue querying your Symo with your code via Modbus. You could extend your code with the Prometheus Client in Java and then combine the data in Prometheus or Grafana Dashboards.

@gitwasi
Copy link
Author

gitwasi commented Feb 26, 2024

That is not problem of datatype but count of archive data - time resolution. Voltage and current values changes only by every 1 minute when ie. load value gets new value for every metrics request. Chart in grafana of voltage and current looks like stairs.

obraz

@ccremer
Copy link
Owner

ccremer commented Feb 27, 2024

Ah I see.
I see the value of that, but unless I have a JSON sample response, there's nothing I can do.

@gitwasi
Copy link
Author

gitwasi commented Feb 27, 2024

So, that's the point - add another, parallel Modbus datasource and reads voltage values from Modbus instead of archives. There can be also this as an option defined.
GOlang has a libraries to comunicate with modbus (ie: simonvetter/modbus or goburrow/modbus) so it is possible to do that propably that simple like in my java example.

@ccremer
Copy link
Owner

ccremer commented Feb 27, 2024

Hi.
Unfortunately, I'm very reluctant to add Modbus to this project. First, I have zero experience with Modbus. Second, I don't want to spend time implementing something I personally don't have or need. I'm the only maintainer so far. What if people have a problem with Modbus and open issues? I won't be able to help them and fix bugs. Furthermore, I can't even test it since I don't have easy access to a device.

If you can figure out if the same values are accessible over HTTP/JSON, we can discuss it again, but otherwise I won't implement or accept a PR for Modbus...

@hudeldudel
Copy link

@gitwasi: Have you tried some generic modbus exporter? E. g. https://github.com/RichiH/modbus_exporter

@gitwasi
Copy link
Author

gitwasi commented Mar 1, 2024

I'm on the way. I try to figure it how to configure this.

@ccremer
Copy link
Owner

ccremer commented Sep 18, 2024

Going to close this as out-of-scope

@ccremer ccremer closed this as completed Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants