-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Use SungrowModbusTcpClient to read encrypted comms #12
Comments
Hi how is this different to the codes in the code ? Is yours working ? |
Hi, mine is working, that is the same as in the code. Mine is working again now. Had some issue which i guess was related to a possible security update from sungrow closing port 502. #10 |
OK port 502 is open for me, and I can get a response just not recognisable by this app or pvstats |
I had it connected via Ethernet, which worked fine until suspected firmware upgrade. After i had issues i set up connection via Wifi module, which i don't like using due to security issue, it started working again on both interfaces. I am not using pvstats, i only use the influxdb aswell as mqtt services to get the information into Homeassistant, where i monitor the data and currently play around with automation. Like when battery is full and Solar is generating send me a notification so i can turn on the Washing machine, etc. |
If anyone finds their way here from google and is looking for some more modbus address mappings for the SH5k-20, there are some here: https://github.com/tjhowse/pvstats/blob/master/pvstats/pvinverter/sungrow_sh5k_20.py For the purpose of helping troubleshoot this issue: I'm running a modbus connection via ethernet to the port inside the inverter. It's running SH5K-V13_FW_V013 according to the info page on the LCD on the front. I manually installed M_WIFI_RAK475_V25_V01_C onto my solarinfo dongle for a test in 2020-03, but I can't say for certain whether this affected the modbus connection as it may have still been working via the ethernet connection. |
The Sungrow modbus encryption has been busted: https://github.com/rpvelloso/Sungrow-Modbus! I do not have the effected (or perhaps infected) firmware on my inverter. Any PR contributions to use this SungrowModbusTcpClient library will need to consider folks (like me) on older firmware versions (perhaps a config item) to switch between the different modbus tcp clients. |
@meltaxa SungrowModbusTcpClient should default to standard TCP client if encryption is not available on the device. Can you test this and confirm if it works (I only have the 'infected' firmware)? Thanks! |
Hey @rpvelloso, thanks for your hard work! You are correct, we need to test if encryption exists, perhaps if a pub key is returned use your lib otherwise default to the unencrypted modbus client. Will endeavor to provide a patch soon. |
My class already does it. But I can't test it. |
Branch created: https://github.com/meltaxa/solariot/tree/%2312-Use-SungrowModbusTcpClient with the changes. Tested on my inverter which doesn't have the encryption enabled:
Need someone to test these changes on an encrypted inverter comms before a merge. |
I'll test it tomorrow, it's night time here and my inverter is off. |
@flare04 Ping! Are you able to help with this testing? |
Hey guys, I'll assume I'm the problem..
|
Interestingly, it worked on the first encrypted packet, and then it seems to fail.
|
... and it was me, running 2.7. I have got it going in in 3 :) |
I have this working |
@kyrannian try increasing the scan_interval (in the config.py file). @chrisvivo & @flare04 thanks for testing. |
@meltaxa, thanks the the reply. tried upping to 60 seconds and still no luck. I'll try a longer again. |
Upon updating timeout to 2 minutes, still the second fetch fails. However, I can run, retrieve the results, exit the program and immediately rerun it and it will process the information again. This is using a fresh checkout of the branch and using the defaults in the config (other than changing addresses) |
That's what i did in the code. In the main while loop, |
Hey @kyrannian, that's not an ideal workaround - although that's how I run a customized version of Solariot - I've made telegraf kick it off on a schedule to produce a json file which is then picked up by telegraf's outputs influxdb extension. The advantage of this approach allows for caching of the telemetry in the event of a connection issue (to influxdb). You could also use MQTT to achieve the same. In the meantime, as per @cuong-pham suggestion, I've moved the connect and close statements to within the loop. |
Can you pull my last commit and see if it fixes these issues??? Haven't
tested (it is night, inverter is off).
Em ter, 15 de set de 2020 01:33, Dennis Mellican <notifications@github.com>
escreveu:
… Hey @kyrannian <https://github.com/kyrannian>, that's not an ideal
workaround - although that's how I run a customized version of Solariot -
I've made telegraf kick it off on a schedule to produce a json file which
is then picked up by telegraf's outputs influxdb extension. The advantage
of this approach allows for caching of the telemetry in the event of a
connection issue (to influxdb). You could also use MQTT to achieve the same.
In the meantime, as per @cuong-pham <https://github.com/cuong-pham>
suggestion, I've moved the connect and close statements to within the loop.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACX55SOXV46QRDVQZ37CZHTSF3VDBANCNFSM4NJD7EWQ>
.
|
Running solid for me the last couple of hours with the updates! I have a battery also, so it doesn't shut off at night. I use solariot to control the load of my Tesla charger (TWCManager) so that it only charges from excess solar, great to have this running again! Thanks so much guys! |
did some minor code clean up, home assistant modbus integration running smoothly so far. I think it is "stable" now. |
Thank you for the community effort in fixing this issue! Code branch has been merged to master. |
@meltaxa did you test it with non-sungrow inverter? I think the line below might not work in this case: |
Hi @rpvelloso, I may have misunderstood an earlier comment in regards to your class defaulting to ModbusTcpClient if encryption is not asserted. Easy enough to fix - if the model var in the config isn't "sungrow", then use the default client. I'll raise this as a separate ticket. Thanks for the heads up. |
@rpvelloso @kyrannian @chrisvivo How did you, get it to work? running with python3 I get this error: python3 solariot.py This is running on a RPi, directly connected to the SH5K-20 via LAN. Sungrow wireless adapter has been removed from inverter. |
https://github.com/meltaxa/solariot/blob/master/SungrowModbusTcpClient.py#L22 Maybe the inverter is not returning anything when it is asked for the 'public key'. Try changing the line https://github.com/meltaxa/solariot/blob/master/SungrowModbusTcpClient.py#L20 to |
It should fallback to ModbusTcpClient if key is empty. I heard someone say, at the forum, that the inverter does not use encryption via ETH connection, only via Wi-Fi. Maybe that's it. |
Starting to work I get the same errors when I run it in python or python3 Load config sungrow-sh5k |
ok, but I think the problem now is connecting to influxdb. Maybe @meltaxa can help there. I'm not familiar with this. |
@rpvelloso python3 solariot.py During handling of the above exception, another exception occurred: Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): |
looks like it's the same error (some SSL problem when connecting to db). |
Check if you are indeed running Influxdb with TLS encryption enabled (for v2 see: https://docs.influxdata.com/influxdb/v2.0/security/enable-tls/). If not, change influxdb_ssl to False in the Solariot config file. |
Seems to be getting closer. python3 solariot.py |
A database schema issue because the former update chose a different data type, possibly because it got a null or zero value from that troublesome modbus connection you had. Easiest fix is to drop that database or create a fresh (new) one and connect to that instead. Update influxdb_database field in the config file accordingly. |
@meltaxa @rpvelloso Thank you both for your help. One final thing, can you shed some light on the 65535 values? For instance: 'load_power': 59789 Is there a way of displaying this correctly in grafana? |
@Ruderbaker this is due to the
before the loop in |
@meltaxa I'm testing this modification to see if it solves the problem of not reconnecting to the inverter next sunrise, if you want to test it too: |
@meltaxa tested this morning when the inverter restarted. It is working. |
These are my findings from my inverter. Sorry, it is not an issue but more information.
The text was updated successfully, but these errors were encountered: