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

Received invalid response #12

Closed
thrawnarn opened this issue Mar 27, 2022 · 1 comment
Closed

Received invalid response #12

thrawnarn opened this issue Mar 27, 2022 · 1 comment

Comments

@thrawnarn
Copy link

I'm having big problems when reading info from my inverter (GW8K-DT).

It seams that I receive incomplete packages from the inverter. My guess is that it only sends data until the changed value is represented. Part of my Home assistant log is attached here: inverter_log.txt

I've also made my own software in .net (I am a .net developer) and discovered the same thing there. I've discussed it more here: mletenay/home-assistant-goodwe-inverter#88 (comment)

I hope we can work this out together, I am a professional developer (.net) as of almost 15 years. I think I could be of good help fixing this issue (I've seen more people having issues with this).
This is not a network issue. Both inverter and client (both HA and a client computer) is on the same switch, same VLAN and all is cabled, I have even tried changing cables just to be sure.

@tweemeterjop
Copy link

I've got the same problem here but fixed it. Turns out the USB LAN stick is not answering to every UDP packet it receives. Not sure why but the flashed firmware of the E-port chip is really old and also significantly older than the firmware on the Wifi stick.

You can verify if you receive a response by sending the raw udp packet with this command. It should return immediately:
echo -n -e "\x7f\x03\x75\x94\x00\x49\xd5\xc2" | nc -u 192.168.1.15 8899 | xxd -ps

The Goodwe implementation only sends one UDP packet and waits for a response with a 1 second timeout and tries again if it fails. Since its UDP we can just sent out multiple UDP packets simultaneously and return on the first received response. This enables me to get a reply under a second with 100% success rate.

Im using the code below to request the UDP packet and use the Goodwe Processor to parse the received data. Works like a charm.

import socket
import time
import threading
import datetime

from goodwe import GoodWeXSProcessor


class GoodweUDPReader():
    def __init__(self, timeout=5):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sock.settimeout(timeout)
        self.timeout = False

    def send_req(self, ip):
        while True:
            msg = bytes.fromhex("7f0375940049d5c2")
            self.sock.sendto(msg, (ip, 8899))
            time.sleep(0.1)

            if self.timeout:
                break

    def read_data(self, ip):
        t = threading.Thread(target=self.send_req, args=(ip,))
        t.start()

        try:
            data, addr = self.sock.recvfrom(1024)

            self.timeout = True
            t.join()  # wait till close
            return data

        except socket.error as ex:
            self.timeout = True
            t.join()  # wait till exit
            raise ex


if __name__ == "__main__":
    r = GoodweUDPReader()
    data = r.read_data("192.168.1.15")

    processor = GoodWeXSProcessor()
    out = processor.process_data(data)

    snrs = {"vpv1": out.volts_dc,
            "ipv1": out.current_dc,
            "ppv": out.power,
            "temperature": out.temperature,
            "e_day": out.generation_today}

    fields = ",".join("{}={}".format(k, v) for (k, v) in snrs.items())
    ts = float(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) * (10**9)
    print("goodwe {} {}".format(fields, int(ts)))

This prints the following line which i use to import the data in telegraf:
goodwe vpv1=153.7,ipv1=2.4,ppv=374,temperature=36.7,e_day=9.0 1655830242128169984

Ideally this should be implemented into the goodwe code so we can set a flag somewere to sent more UDP packets if one is using the USB LAN stick...

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