T-Home
T-Home copied to clipboard
error: unpack_from requires a buffer of at least 12 bytes
Running full.py generates the following error.
python full.py
Traceback (most recent call last):
File "full.py", line 7, in <module>
r = T.sma.report.full( ip="192.168.1.181" )
File "/home/jonas/Documents/SMA/T-Home/python/tHome/sma/report.py", line 93, in full
obj.update( decoder.decode( bytes ) )
File "/home/jonas/Documents/SMA/T-Home/python/tHome/sma/Reply.py", line 39, in decode
offset += d.decodeItem( self, bytes, offset )
File "/home/jonas/Documents/SMA/T-Home/python/tHome/sma/Reply.py", line 143, in decodeItem
self.struct.unpack( self, bytes, offset )
File "/home/jonas/Documents/SMA/T-Home/python/tHome/util/NamedStruct.py", line 45, in unpack
data = self.struct.unpack_from( bytes, offset )
struct.error: unpack_from requires a buffer of at least 12 bytes
Looks like there is something in the acVoltage And if I comment out
# Reply.U32Item( "acGridVoltage", 28, mult=0.01 ),
# Reply.U32Item( "unknown1", 28, mult=0.01 ),
# Reply.U32Item( "unknown2", 28, mult=0.01 ),
In Link.py acVoltage It works. I have a STP 10000TL-10 Could it be that you are running another inverter?
In SBFspot
case SpotACVoltage:
// SPOT_UAC1, SPOT_UAC2, SPOT_UAC3, SPOT_IAC1, SPOT_IAC2, SPOT_IAC3
command = 0x51000200;
first = 0x00464800;
last = 0x004655FF;
break;
Only the six is listed and also last is 0x004655FF in your code it is different.
I have a 5000TL-US-22 - seems to work fine. I'll run some tests w/ the different last value on my data and see what I'm getting for those fields and data sizes (probably tomorrow night).
Hej Is there any good way to decode responses from the inverter? I just installed Sunny Explorer in a Windows Virtual box and I can see a lot of variables that is missing from your code and SBFspot.
I found out how to use tcpdump to dump the command from Sunny explorer Then I can easily decode the bytes using your code so I can read out the command, first and last.
But I have not figured out how to decode the response from the inverter. I have tried the functions in Reply but I have tried all the different things but just get errors. like
struct.error: unpack_from requires a buffer of at least NN bytes
Perhaps I can contact you via mail and get some guidance ? Or any tip would be nice. Cheers
-
Can you run the different reports in tHome/test/real/ and get them to work? Do any of them fail besides the ac current one?
-
If you look at tHome/report.py, you can see where the bytes are returned from the Link. The Link.py class sends the request, then passes whatever it receives as a reply back to those functions. Turn on logging for the 'sma' logger (uncomment the log line in the real/ test scripts) and it will print the received data in hex format. tcpdump may be including a bunch of header information that isn't part of the message. The test cases in tHome/test/.py are tests with recorded hex values that were returned by my inverter. You can compare hex values in test/.py files w/ your windows dump to see what's going on (or compare them against your results from running w/ logging).
Regarding your original report - I get good results with the last value in the code now or w/ the one you referenced (running test/real/full.py). The AC voltages and the grid voltage are correct. If I comment out those three lines, I get incorrect values for the AC currents and no value for the grid voltage - as expected since it won't be decoding the proper fields.
If want me to help decode your packets, uncomment the logging line in test/real/full.py, run it, and send me (or upload) the output. I'll paste each message hex into the test/*.py file for that message and see what happens.
Hej
I can get them to work only ac current one that fails for me. I think they are right values also.
Here is one response
'SMA\x00\x00\x04\x02\xa0\x00\x00\x00\x01\x00&\x00\x10
e\t\x90}\x00\xb0WF3\x00\xe0\x80\x00hm\xcb}\x00\x00\x15\x00\x00\x00\x01\x80\x01\x02\x00Q\x00\x00%\x00\xff\xff%\x00\x00\x00\x00\x00'
using
p = Request.Data( command=0x51000200, first=0x00250000, last=0x0025ffff )`
(But when decoding the response the command writes 0x51000201)
This is tcpdump from wireshark. I only copy the data part of the packet.
'534d4100000402a00000000100260010606509e0FFFFFFFFFFFF00007800375fd73a00000000000081f00002805300002500ffff260000000000'
Yes I have tried a lot of different Reply.Value for example
decoder = Reply.Value([])
Will always work since it wont try to decode anything from the data parts.
So I wonder more how I can read out how long the datapart is and how can I try to guess what kind of data there is in the response.
On my inverter I have two MPPT inputs A and B. A have 5 string inputs and B have only one. In Sunny explorer I can get the Current value of the strings individual as a array Current[1] to Current[6] I would like to try find out the command to get that list. (A.Ms.Amp, B.Ms.Amp, A1.Ms.Amp, A2.Ms.Amp, A3.Ms.Amp, A4.Ms.Amp, A5.Ms.Amp, B1.Ms.Amp from the PDF "Measured Values and Parameters")
Perhaps we can read out some difference in our inverters from this file: http://files.sma.de/dl/1348/NG_PAR-TB-en-22.pdf (Looks like your inverter is not on that list)
Nice will have a look at the tests but I guess it will be as hard since I do not have any idea what is returned. I just know what Sunny Explorer is sending. And Sunny Explorer looks like it is sending lots of commands and then collect replys later. Not in order.
I have attached the Follow UDP stream and a disect where the .245 is Sunny Explorer and 181 is my Tripower. sunnytotripower.txt SMAUDP.txt
cheers
FYI - my inverter is listed in the document, it's a 5000TL. But I don't think the document helps - as far as I can see, that file doesn't explain the protocol or the field definitions. It might help translate what a field value means in English but it doesn't help understand the structure of the messages.
If you add this line to a file in test/*.py:
T.util.log.get( 'sma', 10, 'stdout' )
then add this at the end of the file:
if __name__ == "__main__": unittest.main()
then you can run 'python acPower.py' and it will dump the request packet (cpu->inverter) and a valid reply (which I got from my inverter). Or write a small script that turns on logging and calls each of the methods to show the request packet for each command. Then take the output from your Sunny Exporer network traffic, split it up into packets, and match those to the requests that tHome produced. Once that is done, do the same w/ the reply packets. Be aware that there case specific fields like IP, source, and packet ID which might be different from my tests to your actual network traffic. They should be in order matching the requests I would assume (or the packet ID field might be needed to match them up). Whatever is left over is the requests and replies that are specific to that inverter and which the software doesn't know anything about yet. I'm afraid don't have time right now to do that but I can help and I might be able to take a look at it later this month.