solmoller / eversolar-monitor

Script to capture data and create statistics from Eversolar/zeversolar Solar Inverters. Includes easy install image files for Raspberry Pi. Working edition since 2012 :-)
https://github.com/solmoller/eversolar-monitor/blob/wiki/Introduction.md
MIT License
30 stars 20 forks source link

Unending loop when registering inverters #48

Closed kiekerjan closed 4 years ago

kiekerjan commented 4 years ago

I encountered an unending loop which brought me quite a few gigabytes of logging ;) The log shows:

Severity 1, Inverter register acknowledgement incorrect for inverter FALSE. Expected 06, received 70
Severity 1, Found serial number: FALSE
[repeated millions of times]

This seems to be caused by send_request returning FALSE:

if (!$sock) {
      return FALSE;
    };

This FALSE is then evaluated by register_inverter:

$serial_num_response = send_request( 0x00, $CTRL_FUNC_CODES{"REGISTER"}{"OFFLINE_QUERY"} );
    if ($serial_num_response) {

Because Perl evaluates the FALSE value to true, register_inverter happily proceeds with trying to register a inverter with serial number FALSE. At which it fails because there is no socket (the reason that send_request returned FALSE to start with).

I think I fixed it by replacing FALSE with 0. Additionally, I added a break in the aggressive polling loop:

#aggresive polling when no inverters connected
        while(keys(%inverters)==0) {
                 register_inverter();
                 if ( !$sock) {
                     last;
                 }
               }

Without a socket, register_inverter will never succeed in registering inverters, keeping the %inverters empty and thus the while condition always true.

solmoller commented 4 years ago

Strange, any idea how this can work for the rest of us?

kiekerjan commented 4 years ago

Well, if the check for the sock value never triggers, you won't be hit by this. And that should not happen because the inverter connect happens just before it. I think it has to do with my specific installation. I have powered my rs485-2-Ethernet converter from the rs485 socket on the inverter. However, it seems that during startup (and shutdown) it can happen that not enough power is supplied to the converter, causing it to reboot. This means the socket is gone and would explain why the bug hits my situation. In the meantime I have been working on somewhat more robust code for the send_request sub as well. Once I have tested it enough, I'll share it here.

solmoller commented 4 years ago

Thanks for the workover, I was planning to look into tidy and code checking, nice work!