Closed flanesi closed 2 years ago
Hi, I did not write this file, it's too verbose in debug (var_dump) Can you try this as protocols/abbuno.php ?
<?php
/**
* /srv/http/123solar/scripts/protocols/abbuno.php
*
* @package default
*/
if (!defined('checkaccess')) {
die('Direct access not permitted');
}
// For TCP Modbus https://www.modbusdriver.com/modpoll.html
$RET = '';
unset($CMD_RETURN);
if ($DEBUG) {
$CMD_POOLING = "modpoll -m tcp -r 41123 -c 26 -0 -a 1 -i -1 ${'ADR'.$invt_num} 2> /tmp/modpoll.err";
} else {
$CMD_POOLING = "modpoll -m tcp -r 41123 -c 26 -0 -a 1 -i -1 ${'ADR'.$invt_num}";
}
exec($CMD_POOLING, $CMD_RETURN);
if (isset($CMD_RETURN[11])) {
// String 1
$I1V = ((float) (substr($CMD_RETURN[12], 9)) / 10);
$I1A = ((float) (substr($CMD_RETURN[11], 9)) / 10);
$I1P = ((float) (substr($CMD_RETURN[13], 9)) * 10);
// String 2
$I2V = ((float) (substr($CMD_RETURN[32], 9)) / 10);
$I2A = ((float) (substr($CMD_RETURN[31], 9)) / 10);
$I2P = ((float) (substr($CMD_RETURN[33], 9)) * 10);
// Other strings are not present
$I3V = null;
$I3A = null;
$I3P = null;
$I4V = null;
$I4A = null;
$I4P = null;
// 2nd command to get grid parameters
unset($CMD_RETURN);
if ($DEBUG) {
$CMD_POOLING = "modpoll -m tcp -r 40072 -c 50 -0 -a 1 -i -1 ${'ADR'.$invt_num} 2> /tmp/modpoll.err";
} else {
$CMD_POOLING = "modpoll -m tcp -r 40072 -c 50 -0 -a 1 -i -1 ${'ADR'.$invt_num}";
}
exec($CMD_POOLING, $CMD_RETURN);
// Grid
if (!${'PHASE' . $invt_num}) {
$G1V = ((float) (substr($CMD_RETURN[19], 9)) / 10);
$G1A = ((float) (substr($CMD_RETURN[11], 9)) / 10);
$G1P = ((float) (substr($CMD_RETURN[23], 9)) * 10);
$G2V = null;
$G2A = null;
$G2P = null;
$G3V = null;
$G3A = null;
$G3P = null;
} else {
$G1V = ((float) (substr($CMD_RETURN[19], 9)) / 10);
$G1A = ((float) (substr($CMD_RETURN[12], 9)) / 10);
$G1P = round(($G1V * $G1A), 3);
$G2V = ((float) (substr($CMD_RETURN[20], 9)) / 10);
$G2A = ((float) (substr($CMD_RETURN[13], 9)) / 10);
$G2P = round(($G2V * $G2A), 3);
$G3V = ((float) (substr($CMD_RETURN[21], 9)) / 10);
$G3A = ((float) (substr($CMD_RETURN[14], 9)) / 10);
$G3P = round(($G3V * $G3A), 3);
}
$FRQ = ((float) (substr($CMD_RETURN[25], 9)) / 100);
$INVT = ((float) (substr($CMD_RETURN[42], 9)) / 10);
$BOOT = ((float) (substr($CMD_RETURN[45], 9)) / 10);
$EFF = round((100.0 * (float) (substr($CMD_RETURN[23], 9)) / (float) (substr($CMD_RETURN[40], 9))), 2);
if ($FRQ > 0 && $EFF > 0 && $EFF < 1.0) { // Avoid null values at early startup
$RET = 'OK';
} else {
$RET = 'NOK';
}
// 3 command to get total energy
unset($CMD_RETURN);
if ($DEBUG) {
$CMD_POOLING = "modpoll -m tcp -t4:int -r 40094 -c 1 -0 -a 1 -i -1 ${'ADR'.$invt_num} 2> /tmp/modpoll.err";
} else {
$CMD_POOLING = "modpoll -m tcp -t4:int -r 40094 -c 1 -0 -a 1 -i -1 ${'ADR'.$invt_num}";
}
exec($CMD_POOLING, $CMD_RETURN);
$KWHT = ((float) (substr($CMD_RETURN[11], 9)) / 100);
if ($KWHT > 0) { // Avoid null values due to communication error
$RET = 'OK';
} else {
$RET = 'NOK';
}
} else {
$RET = 'NOK';
if ($DEBUG) {
$time = date('Ymd-H:i:s');
exec('cp /tmp/modpoll.err ' . $INVTDIR . '/errors/modpoll' . $time . '.err');
file_put_contents($INVTDIR . '/errors/out' . $time . '.txt', $CMD_RETURN);
}
$CMD_RETURN = 'Error on Modpoll';
}
?>
Now works. Thank you
Great, can you try this one ?
This does not work.
Test from admin interface;
modpoll -m tcp -t4:int -r 40094 -c 1 -0 -a 1 -i -1 192.168.2.22 return : Array
Error in 123solar.err :
PHP Warning: trim() expects parameter 1 to be string, array given in /var/www/123solar/scripts/123solar.php on line 506
Maybe this ? test.txt
unfortunately it doesn't work..
Test from admin interface
modpoll -m tcp -r 40072 -c 50 -0 -a 1 -i -1 192.168.2.22 return : modpoll 3.10 - FieldTalk(tm) Modbus(R) Master Simulator,Copyright (c) 2002-2021 proconX Pty Ltd,Visit https://www.modbusdriver.com for Modbus libraries and tools.,,Protocol configuration: MODBUS/TCP, FC3,Slave configuration...: address = 1, start reference = 41123 (PDU), count = 26,Communication.........: 192.168.2.22, port 502, t/o 1.00 s, poll rate 1000 ms,Data type.............: 16-bit register, output (holding) register table,Word swapping.........: Slave configured as big-endian word machine,,-- Polling slave...,[41123]: 0,[41124]: 3012,[41125]: 2,[41126]: 0,[41127]: 0,[41128]: -1,[41129]: -1,[41130]: -32768,[41131]: 4,[41132]: 0,[41133]: 0,[41134]: -306,[41135]: 1,[41136]: 0,[41137]: -304,[41138]: 20,[41139]: 0,[41140]: 0,[41141]: 0,[41142]: 0,[41143]: 0,[41144]: 0,[41145]: 0,[41146]: -1,[41147]: 0,[41148]: 0,modpoll 3.10 - FieldTalk(tm) Modbus(R) Master Simulator,Copyright (c) 2002-2021 proconX Pty Ltd,Visit https://www.modbusdriver.com for Modbus libraries and tools.,,Protocol configuration: MODBUS/TCP, FC3,Slave configuration...: address = 1, start reference = 40072 (PDU), count = 50,Communication.........: 192.168.2.22, port 502, t/o 1.00 s, poll rate 1000 ms,Data type.............: 16-bit register, output (holding) register table,Word swapping.........: Slave configured as big-endian word machine,,-- Polling slave...,[40072]: 1,[40073]: 1,[40074]: -1,[40075]: -1,[40076]: -1,[40077]: -1,[40078]: -1,[40079]: -1,[40080]: 2402,[40081]: -1,[40082]: -1,[40083]: -1,[40084]: 0,[40085]: 1,[40086]: 5002,[40087]: -2,[40088]: 0,[40089]: 1,[40090]: 0,[40091]: 1,[40092]: 9979,[40093]: -4,[40094]: 1,[40095]: -15943,[40096]: 1,[40097]: 0,[40098]: -1,[40099]: -1,[40100]: -32768,[40101]: 2,[40102]: 1,[40103]: 226,[40104]: 196,[40105]: -32768,[40106]: 176,[40107]: -1,[40108]: 4,[40109]: 6,[40110]: 0,[40111]: 0,[40112]: 0,[40113]: 0,[40114]: 0,[40115]: 0,[40116]: 0,[40117]: 0,[40118]: 0,[40119]: 0,[40120]: 0,[40121]: 0
error : /
Error in 123solar.err :
PHP Warning: Division by zero in /var/www/123solar/scripts/protocols/abbuno.php on line 84
oh.. now it's should be ok test.txt ?
No, don't work.
Error in 123solar.err :
PHP Warning: trim() expects parameter 1 to be string, array given in /var/www/123solar/scripts/123solar.php on line 506
Hi, Hard to test without having access, now it should be ok.. i guess ;) test.txt
I'll try it tomorrow, inverter off.
Unfortunately I can't give you access. I currently have a mobile connection under NAT.
don't work.
Test from admin interface:
modpoll -m tcp -t4:int -r 40094 -c 1 -0 -a 1 -i -1 192.168.2.22 return : Array
error : /
Error in 123solar.err :
PHP Warning: trim() expects parameter 1 to be string, array given in /var/www/123solar/scripts/123solar.php on line 506
I don't get it.. Can you try this from command line 'php atest.php' and try with $DEBUG set to true and false ?
true:
PHP Notice: Undefined variable: invt_num in /var/www/MyScripts/atest.php on line 50
PHP Notice: Undefined variable: PHASE in /var/www/MyScripts/atest.php on line 50
PHP Notice: Array to string conversion in /var/www/MyScripts/atest.php on line 114
It's NOK Array
false:
PHP Notice: Undefined variable: invt_num in /var/www/MyScripts/atest.php on line 50
PHP Notice: Undefined variable: PHASE in /var/www/MyScripts/atest.php on line 50
PHP Notice: Array to string conversion in /var/www/MyScripts/atest.php on line 114
It's NOK Array
And that one ? atest.txt
It is also necessary to add this control in abbuno protocol:
if (!empty(substr($CMD_RETURN[40], 9))) {
$EFF = round((100.0 * (float) (substr($CMD_RETURN[23], 9)) / (float) (substr($CMD_RETURN[40], 9))), 2);
} else {
$EFF = 0;
}
to avoid a divide-by-zero error when shutting down the inverter.
ok, so i think it's ok with that one abbuno.txt
ok, now everything seems to work.
Only one mistake remains. But it doesn't seem to cause problems.
123solar starts before the inverter and modpoll generates the following error in the log:
Can't reach server/slave! Check TCP/IP and firewall settings.
there are 4-5 lines of this error every time the inverter is switched on in the morning
And in error folder:
Error on Modpoll: 1st command modpoll 3.10 - FieldTalk(tm) Modbus(R) Master Simulator,Copyright (c) 2002-2021 proconX Pty Ltd,Visit https://www.modbusdriver.com for Modbus libraries and tools.,,Protocol configuration: MODBUS/TCP, FC3,Slave configuration...: address = 1, start reference = 41123 (PDU), count = 26,Communication.........: 192.168.2.22, port 502, t/o 1.00 s, poll rate 1000 ms,Data type.............: 16-bit register, output (holding) register table,Word swapping.........: Slave configured as big-endian word machine,
there are many of these errors (1 per second) until the inverter starts
Great. For the errors, it's in data/invt1/infos/events.txt ? modpoll.err ? /data/invt1/errors/ ? or even /data/123solar.err ?
Error in /data/123solar.err :
Can't reach server/slave! Check TCP/IP and firewall settings.
Error in /data/invt1/errors/*.txt
Error on Modpoll: 1st command modpoll 3.10 - FieldTalk(tm) Modbus(R) Master Simulator,Copyright (c) 2002-2021 proconX Pty Ltd,Visit https://www.modbusdriver.com for Modbus libraries and tools.,,Protocol configuration: MODBUS/TCP, FC3,Slave configuration...: address = 1, start reference = 41123 (PDU), count = 26,Communication.........: 192.168.2.22, port 502, t/o 1.00 s, poll rate 1000 ms,Data type.............: 16-bit register, output (holding) register table,Word swapping.........: Slave configured as big-endian word machine,
Ather problem but not script dependent.
Power is read with a scale factor of 10 (modbus setting which I have no idea how to change - register 40085 = 1)
Modbus reading: 185 >>> 1850 W
Therefore we have a rounding to 10w, which makes the graph very "oscillating"
With this other script the power is read very accurately, but it is much slower (10 times slower, ~0.6 sec vs 0.06 sec) than the modpoll reading. The reading is extracted by accessing the web interface of the inverter, with IP, user and password GetABBData.txt
123solar.err, not an issue. It's normal as debug mode isn't intended to be permanent. Errors in /data/invt1/errors/*.txt, that's the aim of that folder. Get all details.
That say getting sample every seconds is sufficient, especially on ethernet. More can "saturate" your LAN, so using GetABBData is a good idea to me.
I use 123solar with the abbuno protocol for reading the inverter.
123solar works regularly, but if I enable debugging it fills up with abbuno readings, like these: