Saturday, 25 April 2015

Advanced: Communicating with the inverter

I wanted to be able to make my own gadgets that can communicate with the inverter, so the first step is to understand how the inverter's serial communication protocol works

After googling a bit I found this post, which is the inverter's rosetta stone
http://forums.aeva.asn.au/forums/pip4048ms-inverter_topic4332.html

I used two USB-serial cables and an arduino configured to AND the serial lines together to sniff the traffic between the supplied WatchPower application and the inverter.


Messages to the inverter follow this format:
<command string><CRC1><CRC2><CR>

Messages from the inverter follow this format:
<command string><CRC1><CRC2><CR>

Eg, to query the general status you'd send QPIGS. The CRC for QPIGS is B7 A9, so in hex you'd send 0x51 0x50 0x49 0x47 0x53 0xb7 0xa9 0x0d


The forum above contains info about how to generate the CRC, or get the C# code off my github.

Here's an example of the command messages for quick reference, see my github for the names of the fields:
QPI
(PI30
QSID
(1111111111111111111111
QPIRI
(230.0 21.7 230.0 50.0 21.7 5000 4000 48.0 46.0 42.0 56.4 54.0 0 10 010 1 0 0 6 01 0 0 54.0 0 1
QVFW
(VERFW:00052.30
QVFW2
(VERFW2:00000.00
QPIRI
(230.0 21.7 230.0 50.0 21.7 5000 4000 48.0 46.0 42.0 56.4 54.0 0 10 010 1 0 0 6 01 0 0 54.0 0 1
QMCHGCR
(010 020 030 040 050 060 070 080 090 100 110 120
QMUCHGCR
(002 010 020 030 040 050 060
QFLAG
(ExDabjkuvyz
QDI
(230.0 50.0 0030 42.0 54.0 56.4 46.0 60 0 0 2 0 0 0 0 0 1 1 0 0 1 0 54.0 0 1
QMOD
(S
QPIGS
(240.4 50.1 000.0 00.0 0000 0000 000 435 54.10 001 100 0027 0000 000.0 00.00 00000 00000101 00 00 00000 100

Using this, I wrote a C# app that emulates the inverter so that I can write other apps without having to connect to the inverter. This will let me test the fault codes etc.

github.com/scottwday/InverterEmulator


Let me know if you manage to build anything!

23 comments:

  1. Hi Very interesting and thank you for the emulator and sharing it. have you written any type of comms software that speaks directly to the inverter. Unfortunately I am only familiar with Visual Basic and I am having a problem sending the CRC to the inverter. eg if you use QPIGS command the CRC1 = b7 and CRC2 = a9 I do understand they are hex but does one have to send them as hex or do you convert them to the ASCII character of that hex value.

    Thanks hope to hear from you. you can also mail me at alondt@gibb.co.za if that would be easier. my programming skill are not that great as it is only something i do for a hobby.

    ReplyDelete
    Replies
    1. Hi, you send the characters as ascii, so the printouts look quite strange. There's a dump of the traffic as a text file on my github, it includes all the CRCs. If you only ever want to request messages then you could send a precomputed CRC and ignore the CRC on the reply message.

      There's also C code available to calculate the CRC, but C# is closer to VB.

      Delete
    2. Hi Scott

      Thanks for the reply, thought it to be text. I had a look at your text dump and the CRC characters for QPIGS is QPIGS·© I cannot make out what character the full stop goody is and then I am puzzled at how you generate the copyright symbol on my keyboard.
      I know the QPIGS command has a CRC of hex b7 AND a9. But if I send these characters as per the ASCII table it does not work as they do not equate to the symbols in your text dump.

      Delete
    3. Those characters are the ascii representation of 0xB7 and 0xA9. If you paste "QPIGS·©" here https://www.branah.com/ascii-converter, you'll see it comes out as
      0x51 : 'Q'
      0x50 : 'P'
      0x49 : 'I'
      0x47 : 'G'
      0x53 : 'S'
      0xb7 : '·'
      0xa9 : '©'

      If you need to enter them with your keyboard, convert them to decimal then hold left-alt then enter the number starting with a zero on the numpad.
      eg http://www.theworldofstuff.com/characters/

      eg, to enter the '·', hold left alt and enter 0 1 8 3 on the numpad
      to enter '©' hold left alt then enter 0 1 6 9

      Delete
    4. Hi Scott I also downloaded your .exe file from the link in the Power Forum, but when i run it I get a screen flashing up then disappearing. I tried downloading your source code and putting that into C# and it reacts the same. Any suggestions

      Delete
    5. It's a command line utility, you need to run it from the terminal to see or do anything interesting

      Delete
    6. Hi Scott

      Thanks for the help. I will persue with your suggestions. Thanks again for the help

      Delete
  2. Dear Scott,
    could you please let me know what versione of VC#.NET I've to use to open the project, with the 2k10 isn't possible.

    Thanks in advance and
    best regards

    Pow

    ReplyDelete
  3. ahh I'm just download the 2012...
    thanks

    ReplyDelete
  4. Hi Scott.

    I hope you can help me. I am struggling to get the CRC code to work in VB.Net

    I am building software to manage the inverters and I have come a far way but I hard coded the commands. I am now at a stage where I need to send command that I can not hard code

    This is what I have built so far.

    https://www.youtube.com/watch?v=ZMJpMsc2VyQ


    Here is the code.

    Private Shared Function GetMessageBytes(text As String) As Byte()
    'Get bytes for command
    Dim command As Byte() = System.Text.Encoding.Unicode.GetBytes(text)

    'Get CRC for command bytes
    Dim crc As UShort = CalculateCRC(command)

    'Append CRC and CR to command
    Dim result As Byte() = New Byte(command.Length + 3) {}
    command.CopyTo(result, 0)
    result(result.Length - 3) = CByte((crc >> 8) And &HFF)
    result(result.Length - 2) = CByte((crc >> 0) And &HFF)
    'result(result.Length - 1) = &HD

    Return result
    End Function


    Public Shared Function CalculateCRC(pin As Byte()) As UShort
    Dim crc As UShort
    Dim da As Byte
    Dim ptr As Byte
    Dim bCRCHign As Byte
    Dim bCRCLow As Byte

    Dim len As Integer = pin.Length

    Dim crc_ta As UShort() = New UShort() {&H0, &H1021, &H2042, &H3063, &H4084, &H50A5, &H60C6, &H70E7, &H8108, &H9129, &HA14A, &HB16B, &HC18C, &HD1AD, &HE1CE, &HF1EF}

    crc = 0
    For index As Integer = 0 To len - 1
    ptr = pin(index)
    da = CByte(CByte(crc >> 8) >> 4)
    crc <<= 4
    crc = crc Xor crc_ta(da Xor (ptr >> 4))
    da = CByte(CByte(crc >> 8) >> 4)
    crc <<= 4
    crc = crc Xor crc_ta(da Xor (ptr And &HF))
    Next

    'Escape CR,LF,'H' characters
    bCRCLow = CByte(crc And &HFF)
    bCRCHign = CByte(crc >> 8)
    If bCRCLow = &H28 OrElse bCRCLow = &HD OrElse bCRCLow = &HA Then
    bCRCLow += 1
    End If
    If bCRCHign = &H28 OrElse bCRCHign = &HD OrElse bCRCHign = &HA Then
    bCRCHign += 1
    End If
    crc = CUShort(CUShort(bCRCHign) << 8)
    crc = crc Or bCRCLow

    Return crc

    End Function

    ReplyDelete
    Replies
    1. Hi Jaco, looking good, I've been following your thread on PowerForum. Easiest would probably be to use my C# code and feed the same string into both, then step through the code and see where the differences are. https://github.com/scottwday/AxpertTest/blob/master/Program.cs

      Delete
  5. Hi, what code would you use to communicate via arduino?

    ReplyDelete
  6. Hi Scott

    Thanks for your informative article. Would you mind sharing how you physically connected the arduino to the inverter?

    Regards

    ReplyDelete
    Replies
    1. It came with a serial cable that plugs into the RJ45 connector. I used a MAX232 module to convert RS232 to TTL for the arduino.

      Delete
  7. I've built a complete set of boards to adjust my solar panel angle and to talk to the PIP4048 using the serial protocol. My code is for the Arduino and sends all of the monitored data to an MQTT server on a Raspberry Pi.

    I've also decoded the status word so that I can send MQTT messages such as 'Line Power Lost', 'Fan Failure' etc.

    You can have a look on my blog at www.offgrid.casa and I'm quit happy to share the code with anyone who is interested.

    The people at MPPSolar were very helpful in sending me the full serial protocol definition as well.

    Aidan

    ReplyDelete
    Replies
    1. Hello Aiden. I need a little help on this project. Can you please share your email address here?
      Muneeb
      muneebafzal@live.com

      Delete
  8. Hi, Aidan. Can you share the information about the RS232 protocol of MPP Solar inverters? I have a 5.5 Kw Hybrid MPI Inverter. and I'm working on my own application. I would greatly appreciate it.

    ReplyDelete
  9. Hi. Sorry, I've been away on holiday. You can email me as aidan@ruffs.org. My blog describes what I'm doing with the pip4048 at www.offgrid.casa. I'll make the protocol information as a file on the blog. I've written some functions for Arduino C to decode the serial data from the PIP

    ReplyDelete
  10. OK, chaps. I've put most of the info that you'll need into my blog - it's here http://www.offgrid.casa/talking-to-the-pip4048-mains-inverter/

    I've put the serial protocol description and enough of my code to get you going. The PIP uses 2400 baud BTW.

    ReplyDelete
  11. hello Scott,
    I trying to use your inverter emulator but I'm facing the problem that the emulator doesn't send anything via serial port.
    Can you tell what I have to do?

    Thanks,

    ReplyDelete
  12. Hi Scott,

    Do you perhaps know where I can get the parrelel communications protocol?

    ReplyDelete