basking-in-the-sun2000 / solar-logger

A datalogger for a solar inverter. Stores data in influxdb and displays it in grafana. Has load diverting capability, to use the inverter's excess power
GNU General Public License v3.0
99 stars 32 forks source link

Issues getting the app up and running #33

Closed verisgit closed 2 years ago

verisgit commented 2 years ago

Hi there,

Thanks again for your efforts with this project. I've spent some time tonight trying to get it up and running and ran into a number of issues, some I've worked around, but others I can't seem to solve as I'm somewhat new to python. Hopefully, you can point out where I'm going wrong.

I'm using an RPI 4 with Raspberry Pi OS Lite (CLI version). Ethernet to connect to the Pi and then the Pi is connected to the Inverter's WIFI AP so it can access the modbus on port 6607.

Changes I made to setting_up.md in order to get some of the steps to work:

sudo apt update && sudo apt upgrade
sudo apt install -y gnupg2 curl wget **git** **python3-pip**

Had to add pip and git to get the later steps to work

Issues I found when trying to startup the app:

  1. sudo service influxdb enable - doesn't work. It complains that it's an unrecognised service. But when I check the status it appears it's working so I skipped that
  2. When I tried to execute the influxdb user permission steps none of the commands from setting_up.md worked as they required the databases to exist first. So I assumed it would try create it and just tried to start the app. (it seems it did create two of the databases logger and logger_lt when i had a look at the databases listed in influx.
  3. FileNotFoundError: [Errno 2] No such file or directory: 'Huawei.py' - but resolved this by creating one from the template.
  4. Finally got it to start but then received these errors initially
    python3 main.py
    mailing not setup
    starting
    Fri Apr 22 22:48:35 2022
    huaweil inv_address error: timed out
    huaweil inv_address error: timed out
    huaweil inv_address error: timed out
    huaweil inv_address error: timed out
    huaweil inv_address error: timed out
    192.168.200.1
    192.168.200.1
    main 1 error: list index out of range
    main 2 error: list index out of range
    top error: database not found: logger_ds
    something went wrong
    done
    starting
    Fri Apr 22 22:50:03 2022
    huaweil inv_address error: timed out
    huaweil inv_address error: timed out
  5. I've tried the 0x00 and 0x01 options both seem to result in timeouts. I can successfully telnet from the RPI to the inverter on the Modbus port - that seems to work so at least it can see it and the port is open.
  6. I tried debug mode but couldn't find any additional info that I could make sense of
    
    python3 main.py
    mailing not setup
    starting
    Sat Apr 23 01:14:45 2022
    got it
    b'\xc0\xa8\x01\x85'

b'ZZZZ\x00A:\x04\xc0\xa8\x01\x85'

huaweil inv_address error: timed out --> resend

8. I have no logs in /var/log/solar - so wasn't able to get any additional info there.
9. Config inverter items are as follows
```inverter_ip = "192.168.200.1" # Default ip address in case it can't find it
inverter_port = 6607
slave = 0x00 # seems the dongle uses 0x01 for the slave id (also tried 0x01)

Hopefully not too difficult to resolve and I can get it up and running. Keen to play around with it. Thanks in advance for your assistance.

verisgit commented 2 years ago

I also made a random test to make sure the Pi can actually communicate with the inverter.

Nano modbustest.py

from pymodbus.client.sync import ModbusTcpClient as ModbusClient
import time

client = ModbusClient("192.168.200.1", port=6607)
client.connect()

if client.connect():
    time.sleep(1)
    rr = client.read_holding_registers(address=30000, count=15 ,unit=0)
    test = rr.registers[1]
    print(test)

python3 modbusttest.py

20018

Seems like it's at least reading values correctly. If I check the status (30000) it's 0 = Standby which it is right now.

basking-in-the-sun2000 commented 2 years ago

Guess it is a chicken and the egg issue. I might have gotten things running before and tried to write the setup guide after. So some steps might be missing. Also, things have probably changed since. Still need to find a good break to upgrade to influxdb 2, but don't have a dev system for such large changes.

Thanks, added the git and pip. The enable issue might be solved by the installer itself, thus not requiring you to do it. Will leave it in case it doesn't always enable it.

The DB creation is again part of the same chicken salad. The program creates the DB if these haven't been created, but makes it hard to set up things beforehand. lol

The huawei.py file is created by the application. The reason was that I kept changing it, and people might not have been aware of those changes, or they had made changes themselves. Thought it would be better that they added the changes manually after, so they would know. This is also the case for the config.py file.

Maybe Huawei changed things between our inverters, but mine only opens port 502. If you are using rs485 directly, the program isn't set up but for TCP. pymodbus allows for that but needs some changes to the code. Probably very straight-out, but didn't add it since I have no way of testing. Think you would start modbustcp.py with from pymodbus.client.sync import ModbusClient?

The first part of opening the Modbus connection is to see if it can find the inverter. That first timeout is that it isn't getting a reply to the broadcast. Wouldn't be too concerned about this error. It tries to figure out the address, in case it has changed. However, Huawei might have changed the way the broadcast works, and might no longer be compatible with your unit.

Made a couple of changes based on your findings, will give it a try before committing.

verisgit commented 2 years ago

I can confirm I'm still using the Wifi method currently. I do have a serial RS485 connector but I'd probably rather stay with Wifi if I can get it to work for the same reasons you outlined. Also, several people have reported that the WLAN/FE/Sdongle takes around 30 seconds to get the data for each request, whereas Wifi takes around 5 seconds.

Huawei did change the Modbus ports for some of the inverters so it's either 502 or 6607. I confirmed it with a Modbus client on my phone connected to the inverters wifi and 502 is closed, 6607 is open.

I did wonder if maybe it was an issue because it was nighttime, have tried again today and still getting the same results.

Any ideas to try?

basking-in-the-sun2000 commented 2 years ago

You just reminded me of a recent change by Huawei. Not sure if this might be related to your problem

https://forum.huawei.com/enterprise/en/modbus-tcp-guide/thread/789585-100027

verisgit commented 2 years ago

I don't have an SDongle and I already confirmed I can talk from the RPI to the Inverter over TCP Modbus via manual modbustest.py above.

For unknown reasons main.py times out, I have no logs, debug mode doesn't provide any debug, etc. Is there something I can do to troubleshoot this?

verisgit commented 2 years ago

I've done some more troubleshooting. The IP and port are definitely correct as a Modbus client connected to that WIFI network can query the registers and I've confirmed I'm getting valid results, so Modbus TCP is on and working (and I'm on the latest firmware).

Scanner_2.py returns all the register values and appears to be working as expected Scanner.py runs for some time but doesn't output anything No matter what I do or change Main.py reports the "huaweil inv_address error: timed out" - it reports this error under any and all config conditions. Even if I kill the wifi and the IP isn't reachable at all the same message is shown. It's like main.py isn't establishing the connection in the same way the scanner is. One works the other doesnt.

Sample output from scanner python3 scanner_2.py openning Sun, 24 Apr 2022 13:24:02 reading 30068 2 [5, 0] 327680 reading 30070 1 [344] 344 reading 30071 1 [2] 2 reading 30072 1 [2] 2 reading 30073 2 [0, 5000] 5000 reading 30075 2 [0, 4999] 4999 reading 30077 2 [0, 4999] 4999 reading 30079 2 [0, 2999] 2999 reading 30081 2 [65535, 62537] -2999 reading 30109 2 [0, 8224] 8224

Summary: I've tried lots of things for several hours today but given I can't figure out why main.py wont do anything other than show a timeout message so kinda stuck.

basking-in-the-sun2000 commented 2 years ago

Just pushed a new commit (https://github.com/basking-in-the-sun2000/solar-logger/commit/c46f3762a4da84c6f5556cb1dd8fbdbe363c31f1), hopefully this works out for you

You are the first to send a pull request. Not sure how to integrate them, specially after my changes. I added your change to main, and several to setup. Kept the apt lines separate, since I like to see what is going on. Thanks for all your help.

verisgit commented 2 years ago

Thanks, I've merged that into the version I'm tracking and it seems to run now.

mailing not setup
starting
Mon Apr 25 09:04:32 2022
192.168.200.1
main 1 error: list index out of range
main 2 error: list index out of range
starting
forcast info

0.19047619047619047 0.9082398044844923

Still seeing two 'list index out of range' errors? are they important?

verisgit commented 2 years ago

image image

basking-in-the-sun2000 commented 2 years ago

considering it is a new site, guess there are many things that need to be populated. Wait for a day to see if you get any further errors. These are errors that it couldn't grab the data from the db when setting the previous days values. Seems you have a meter, so these should get filled up

I'm glad the changes worked for you

verisgit commented 2 years ago

Thanks for your help with this. It's quite cool to see it working now and hopefully I can add some stuff and share it. One thing I have noticed is that the solar forecast appears to be offset to the wrong time.

In the config file example there were quotes are they intended to be there or should they be removed? It's like it's picking up the wrong time zone as my forecast is about 8 hours out.

Should it be

time_zone = 'Country/City' Or time_zone = Australia/Perth Or time_zone = GMT+X

basking-in-the-sun2000 commented 2 years ago

The config.py should be time_zone = 'Australia/Perth' Guess it is confusing when your country is a continent lol

Grafana makes things harder. There should be a tz option in most places. Also in dashboard > settings > variables, there is also a global variable tzone. Not sure if I pushed the changes over to github. Been tweaking the dashboads and haven't pushed these changes in the last commits. Will try to send the changes during the weekend

Will be closing this issue, since this is a new problem and unrelated to the previous problem

verisgit commented 2 years ago

Thanks