ai-republic / bms-to-inverter

Use, monitor and control any battery brand with any inverter! Application to read and monitor data from BMSes and write data to an inverter using any protocol (e.g. UART, RS485, ModBus or CAN)
https://github.com/ai-republic/bms-to-inverter
Other
101 stars 14 forks source link

Growatt Inverter support via RS 485 / CAN #1

Closed sanitariu closed 3 months ago

sanitariu commented 1 year ago

Hello, Do you plan any support for Growatt Inverter support via RS 485 ?

ai-republic commented 1 year ago

I'm currently implementing a MQTT support with a little webserver to see the states of all battery cells in each battery pack.

To implement the Growatt protocol would be no problem but maybe in a couple of days. If you have the protocol at hand or could organize it, it would be helpful and speed up the process :)

Best regards, Torsten

sanitariu commented 1 year ago

I will help with all i can. I would like to make my Daly BMS speak with my Growatt inverter. Currently i am able to read info from the Daly via small python script i found here https://github.com/dreadnought/python-daly-bms.git

This is the information from my Daly:

daly-bms-cli --device /dev/ttyUSB2 --all

{ "soc": { "total_voltage": 53.9, "current": 39.0, "soc_percent": 76.4 }, "cell_voltage_range": { "highest_voltage": 3.379, "highest_cell": 16, "lowest_voltage": 3.372, "lowest_cell": 5 }, "temperature_range": { "highest_temperature": 28, "highest_sensor": 1, "lowest_temperature": 28, "lowest_sensor": 1 }, "mosfet_status": { "mode": "charging", "charging_mosfet": true, "discharging_mosfet": true, "capacity_ah": 213.92 }, "status": { "cells": 16, "temperature_sensors": 1, "charger_running": false, "load_running": false, "states": { "DI1": false }, "cycles": 63 }, "cell_voltages": { "1": 3.373, "2": 3.373, "3": 3.372, "4": 3.375, "5": 3.372, "6": 3.375, "7": 3.374, "8": 3.377, "9": 3.374, "10": 3.373, "11": 3.372, "12": 3.375, "13": 3.372, "14": 3.375, "15": 3.374, "16": 3.379 }, "temperatures": { "1": 28 }, "balancing_status": { "error": "not implemented" }, "errors": [] }

Also I am able to read data from my Growatt inverter and graph it using grafana via this: https://github.com/sdsolomo/growatt-x000ES

Daly is using this connection - ch341-uart converter now attached to ttyUSB2 (USB to UART cable connected to Daly device) Growatt is using this connection - cp210x converter now attached to ttyUSB1 (USB direct cable from the Inverter to Pi device)

If i can help you somehow i would do it even with some remote access if you like.

sanitariu commented 1 year ago

Here is Daly BMS protocol Part 4_ Daly RS485+UART Protocol.pdf

sanitariu commented 1 year ago

Here is Growatt protocol Growatt PV Inverter Modbus RS485 RTU Protocol v120.pdf

ai-republic commented 1 year ago

Hi Todor, sorry for the late reply. I've been away for a few days. I've had a look at the Growatt protocol but have not yet really understood everything as a lot of the knitty gritty stuff for the BMS data is in chinese. I will have to work through it with google translator and try to figure it out. Do you know which mandatory values the Growatt inverter needs from the BMS?

ai-republic commented 1 year ago

FYI: I've added a growatt module to the project. Just for the structure... there is no functionality yet!

ai-republic commented 1 year ago

Hi Todor, I've implemented the Growatt CAN protocol if you like to test it. Note: I do not have a Growatt Inverter so it is purely programmed by the Growatt CAN protocol specifiation for low voltage (12-96V) inverters. If you like to test it I would be thankful :)

sanitariu commented 1 year ago

Hi, Thanks for the support ! I am going to test it very soon. I must order CAN device to connect the inverter. I can connect now only via RS-485.

sanitariu commented 1 year ago

I have ordered the same CAN device model as yours. I found also one PYLON_EMU project with dbc file where you can see what you must report via the CAN to the inverter. I am attaching the file if you are interested. I am going to test tomorrow your version with my CAN device.

pylon_CAN_210124.txt

sanitariu commented 10 months ago

Ok trying to simply connect Growatt to can0. I receive the following errors [1662498.588369] mcp251xfd spi0.0 can0: CRC read error at address 0x0010 (length=4, data=e0 80 af 70, CRC=0x01f5) retrying. I am connecting High to High and Low to Low pins. Here is my /boot/config.txt

i2c canhat

dtparam=spi=on dtoverlay=spi1-3cs dtoverlay=mcp251xfd,spi0-0,interrupt=25 dtoverlay=mcp251xfd,spi1-0,interrupt=24

Also doing this setup ...

link up

/usr/bin/ip link set can0 up type can bitrate 1000000 dbitrate 8000000 restart-ms 1000 berr-reporting on fd on /usr/bin/ip link set can1 up type can bitrate 1000000 dbitrate 8000000 restart-ms 1000 berr-reporting on fd on

buffers

/usr/sbin/ifconfig can0 txqueuelen 65536 /usr/sbin/ifconfig can1 txqueuelen 65536

If i loop can0 to can1 and send something like this

candump can0 cansend can1 000#11.22.33.44

I see the output. Can i have your settings for the same wave hat and can ? If i do not send any data will i receive something from the inverter ?

ai-republic commented 10 months ago

Hi Todor, which CAN adaptor are you using? Is it the Waveshare 2-CH CAN FD Hat? Since your boot.config setting suggest and you have can0 and can1 I guess it might be.

So I believe your Growatt will not have a baudrate of 1000000 but probably 500000. But I will check the documentation. Also you should not have FD on and also no berr reporting.

My settings for the SMA SI are like this:

sudo ip link set can0 up type can bitrate 500000 restart-ms 100
sudo ip link set can0 txqueuelen 65536

Also make sure you've connected the correct wires (PIN4 = CAN H and PIN 5 = CAN L) of the RJ45 plug to your CAN adaptor.

image

EDIT: I checked for the baudrate and think I've found that it is 500kb

sanitariu commented 10 months ago

Yes I have the exact same can model you suggested. I setup to 500kb now. Will I see any output from the inverter even if i did not setup program 36 at the inverter side ? I have the same schema in my Growatt book. Seems like the cables are blue and white-blue. As far as I know i should connect CANH to CANH and CANL to CANL ?

ai-republic commented 10 months ago

Yes, CAN H to CAN H and CAN L to CAN L.

I'm not sure if you need to set up your inverter to use 2 Lithium and then 36 mode 51 (Growatt) or 52 (Pylontech I think) for the inverter to activate the CAN communication on its BMS port.

You should see some output in the log about the inverter communication. If the Growatt inverter module (with mode 51 on the inverter) doesn't work you can also try to configure the SOLARK inverter since that is also a pure Pylontech CAN protocol implementation with mode 52 on the inverter.

sanitariu commented 9 months ago

Anyone did a voltage measurements for Growatt CAN H/L ? According to scheme blue/white and blue are pin numbers 4/5. Orange is the ground. I did measure mine and both H/L shows 2.25 voltage. Also resistance between H/L is 160 oms. Is this correct ? I thought CAN H should have more high voltage. If someone have values for his inverter please share...

ai-republic commented 9 months ago

As per CAN physical layer specification: CAN H (≥ 2.5 VDC) | 2.5 VDC (idle) | 2.5 to 3.5 VDC (active) CAN L (≤ 2.5 VDC) | 2.5 VDC (idle) | 2.5 to 1.5 VDC (active)

The CAN-L and CAN-H waveforms mirror each other about 2.5 V and have a 1 V peak to peak amplitude. The CAN-L waveform switches from 2.5 V down to 1.5 V and the CAN-H waveform switches from 2.5 V up to 3.5 V.

So 2.25V seems a bit low for CAN H even if its idle. Have you connected PIN 6 (GND) also?

sanitariu commented 9 months ago

No i have not connected Ground because i read that it is dangerous and you do not need it. Also i do not know how to test exactly if CAN is working at inverter side ... like i would like to send some command and see the result. If you have something in mind like commands i can try connect the ground and test them via cansend/candump ?

ai-republic commented 9 months ago

You could try to send a frame like:

  1. for Growatt CAN protocol
    0x13, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xE6, 0x14, 0x0F, 0x00, 0xDC, 0x00, 0x5E, 0x64

or

  1. for Pylontech CAN protocol
    0x55, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x5E, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00

That should send the follow values: Pack Voltage: 53.5V (only Growatt protocol) Pack Current: 1.5A (only Growatt protocol) Pack Temp: 22C (only Growatt protocol) Pack SOC: 94% (both protocols) Pack SOH: 100% (both protocols)

Be sure to choose the correct BMS setting in the Growatt inverter.

sanitariu commented 9 months ago

I tried but nothing happened. Growatt does not return anything. I do not know if this is normal ? Maybe i need to setup the Growatt first ?! Also i have tried direct in your code /dev/can1 and this is the output:

2024-02-22 10:45:23.680 | ERROR | 2-thread-1 | verter.core.Inverter:70 | Failed to send CAN frame java.lang.IndexOutOfBoundsException: fromIndex: 1 > toIndex: 0 at java.util.BitSet.checkRange(BitSet.java:369) ~[?:?] at java.util.BitSet.set(BitSet.java:484) ~[?:?] at com.airepublic.bmstoinverter.inverter.growatt.can.GrowattInverterCANProcessor.getChargeStates(GrowattInverterCANProcessor.java:224) ~[inverter-growatt-can-0.0.1-SNAPSHOT.jar:?] at com.airepublic.bmstoinverter.inverter.growatt.can.GrowattInverterCANProcessor.createAlarms(GrowattInverterCANProcessor.java:135) ~[inverter-growatt-can-0.0.1-SNAPSHOT.jar:?] at com.airepublic.bmstoinverter.inverter.growatt.can.GrowattInverterCANProcessor.createSendFrames(GrowattInverterCANProcessor.java:34) ~[inverter-growatt-can-0.0.1-SNAPSHOT.jar:?] at com.airepublic.bmstoinverter.core.Inverter.process(Inverter.java:62) ~[core-api-0.0.1-SNAPSHOT.jar:?] at com.airepublic.bmstoinverter.inverter.growatt.can.GrowattInverterCANProcessor$Proxy$_$$_WeldClientProxy.process(Unknown Source) ~[inverter-growatt-can-0.0.1-SNAPSHOT.jar:?] at com.airepublic.bmstoinverter.BmsToInverter.lambda$start$4(BmsToInverter.java:168) ~[bms-to-inverter-main-0.0.1-SNAPSHOT.jar:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [?:?] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [?:?] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [?:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?] at java.lang.Thread.run(Thread.java:840) [?:?]

I did not setup anything to growatt yet ! I am still not sure if these voltages 2.25 on blue/white and blue are correct.

ai-republic commented 9 months ago

Hi Todor, could you try to see what the inverter sends via candump? That way I can compare and see which protocol the inverter uses.

ai-republic commented 9 months ago

Hi, I updated the Configurator to allow setting a BMS Id. Also I changed the poll intervall to be a general BMS configuration (not for each).

You will need to download the new Configurator and re-configure your setup and do a clean install.

ai-republic commented 9 months ago

Hi Todor, FYI: the Growatt (Pylon) HV is now working if you like to test it on your setup

sanitariu commented 9 months ago

Hello, I am going to test very soon. Waiting to coordinate this with my wife :). If Growatt does not detect BMS it will shutdown the power in my house. ... and someone will be angry :). Also my PI is connected to the same battery and i will be in some sort of loop. So i bought an UPS for the pi. I hope next Sunday to test this setup and you will sure get some sponsor tips from me too !

jimmy737 commented 7 months ago

I'm currently implementing a MQTT support with a little webserver to see the states of all battery cells in each battery pack.

To implement the Growatt protocol would be no problem but maybe in a couple of days. If you have the protocol at hand or could organize it, it would be helpful and speed up the process :)

Best regards, Torsten

Hello, Have you succeeded to get cell information? I have the SPF 5000 ES with 6 Growatt ARK 2.5 batteries trying to get the same battery details as you. Thank you.

ai-republic commented 7 months ago

Hi Jimmy, yes, the Growatt binding is working :)

jimmy737 commented 7 months ago

Hi Jimmy, yes, the Growatt binding is working :)

Thank you. Is there any step by step documentation I can follow to be able to get cell details information from the inverter USB port to an Arduino or raspberry PI? Thank you.

ai-republic commented 7 months ago

I assume you want to get cell information from the BMS (Battery Management System) - not the inverter. Your Growatt ARK battery system should also have a CAN communication port. Via this port you can connect to a Raspberry PI with a 2 Chanel CAN hat, e.g. the Waveshare 2CH CAH hat on the first CAN bus. From the PI you connect also on the 2nd CAN bus to the inverter. To install this application see the Wiki.

If you have any questions feel free to ask :)

jimmy737 commented 7 months ago

Thank you Torsten for your help. Sorry I am not sure if the ARK battery has a CAN port. But maybe this is one in the picture below. I dont know it those things are helpful to my project of reading cell data but I purchased and used a J-LINK flash device to fix a corrupted boot loader and flash firmware on the BMS board. So the ARK battery has a USB port. When I put a CONFIG.txt file with down_fault in it, I get a spreadsheet with cell data. So obviously the BMS board has it. So it would be easier to connect the raspberry PI to the USB port but I dont know if that is possible. As far as the CAN port, is it this on the picture? Thanks again for your patience in helping me with my project. Based on what I read on forums other ARK battery owners can benefit from this.

On Sat, Apr 13, 2024 at 9:07 PM Torsten Oltmanns @.***> wrote:

I assume you want to get cell information from the BMS (Battery Management System) - not the inverter. Your Growatt ARK battery system should also have a CAN communication port. Via this port you can connect to a Raspberry PI with a 2 Chanel CAN hat, e.g. the Waveshare 2CH CAH hat on the first CAN bus. From the PI you connect also on the 2nd CAN bus to the inverter. To install this application see the Wiki https://github.com/ai-republic/bms-to-inverter/wiki.

If you have any questions feel free to ask :)

— Reply to this email directly, view it on GitHub https://github.com/ai-republic/bms-to-inverter/issues/1#issuecomment-2053831873, or unsubscribe https://github.com/notifications/unsubscribe-auth/BDMBOQW36J7YY6WYXIHAI4LY5HJGFAVCNFSM6AAAAAA4P7V24SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJTHAZTCOBXGM . You are receiving this because you commented.Message ID: @.***>

ai-republic commented 7 months ago

Ah but there is no image ;) This project reads the cell data and BMS state continuously with realtime data. The Excel file would just be a snapshot of a certain time and already outdated by the time you read it. Also how would you get refreshed data? You would probably need to simulate unplugging and re-connecting the USB.

jimmy737 commented 7 months ago

Sorry about that. Is this the CAN port? isthiscan

jimmy737 commented 7 months ago

I connected to that port to upgrade the firmware. Is this tool any good to retreive data in real time?
JLINK

ai-republic commented 7 months ago

No, this doesn't look like anything I know - not that it means much ;) The CAN port usually is a RJ45 normal network cable port like you use to connect your computer to your router. And should be freely accessible on your ARK battery case.

jimmy737 commented 7 months ago

Ah got it. Sorry for my ignorance. Yes. Great! I can test with just one battery standalone. I connect to the PCS RJ45 of the battery and the other end where? Thank you Torsten. I appreciate your help.

On Tue, Apr 16, 2024 at 3:13 AM Torsten Oltmanns @.***> wrote:

No, this doesn't look like anything I know - not that it means much ;) The CAN port usually is a RJ45 normal network cable port like you use to connect your computer to your router. And should be freely accessible on your ARK battery case.

— Reply to this email directly, view it on GitHub https://github.com/ai-republic/bms-to-inverter/issues/1#issuecomment-2058393146, or unsubscribe https://github.com/notifications/unsubscribe-auth/BDMBOQVOZG5EHWM5DDE7UZ3Y5TFRTAVCNFSM6AAAAAA4P7V24SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJYGM4TGMJUGY . You are receiving this because you commented.Message ID: @.***>

jimmy737 commented 7 months ago

here is a pic of my CAN bus CAN BUS

ai-republic commented 7 months ago

Well, the other end would connect to your Raspberry's CAN hatOn 16/4/24, 20:00 jimmy737 @.***> wrote:

Ah got it. Sorry for my ignorance. Yes. Great! I can test with just one battery standalone. I connect to the PCS RJ45 of the battery and the other end where? Thank you Torsten. I appreciate your help.

On Tue, Apr 16, 2024 at 3:13 AM Torsten Oltmanns @.***> wrote:

No, this doesn't look like anything I know - not that it means much ;) The CAN port usually is a RJ45 normal network cable port like you use to connect your computer to your router. And should be freely accessible on your ARK battery case.

— Reply to this email directly, view it on GitHub https://github.com/ai-republic/bms-to-inverter/issues/1#issuecomment-2058393146, or unsubscribe https://github.com/notifications/unsubscribe-auth/BDMBOQVOZG5EHWM5DDE7UZ3Y5TFRTAVCNFSM6AAAAAA4P7V24SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJYGM4TGMJUGY . You are receiving this because you commented.Message ID: @.***>

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

jimmy737 commented 7 months ago

Thank you for the quick reply. My Rasperry PI 4 has Solar Assistant but not useful for me. I can reload from scratch mt PI 4 and get where i can run sudo comands. I did install a music server once but I am not a java, json, Linux etc programmer. I am good at following instructions! So in your post it says to get everything run this below. But I am lost on how/where to run those commands on the PI4. Do I need to install a software called Daly ? Thank you for your patience. "Get everything possible:

daly-bms-cli -d /dev/ttyUSB0 --all

jimmy737 commented 7 months ago

I think i got it. I am going to try this: Installation From PyPI pip3 install dalybms

jimmy737 commented 7 months ago

Sorry me again! I cannot install daly. I get this error. Any idea how to resolve this? Thank you. daly

jimmy737 commented 7 months ago

Ok. I think I am ready to try connecting to the battery. Does it look ready? Thank you. IMG_1653

ai-republic commented 7 months ago

No, you don't need daly or python. Once you have connected the RJ45 to your BMS's CAN port you need to connect the other end to your CAN hat on your RPi. What CAN hat do you have? And have you already installed/configured it? And you need to know which cables of the 8 in the RJ45 are assigned for CAN H and CAN L. That should be in the manual of the ARK BMS. Then just follow the Wiki. You will need to install a Java JDK:

sudo apt install default-jdk

And then download and start the Configurator app as described in the Wiki.

jimmy737 commented 7 months ago

Thank you. I install the Configurator on my laptop and configured it. But in the drop list it dows not show an option for PI4 64 bits. Which option to choose? Also I found the correct pins for the cable to go from the CAN port to the PI4. Thank you.

Configurator RJ45

jimmy737 commented 7 months ago

Sorry one more thing. Yesterday we talked about one end of the custom made network cable to the battery and the other end to PI4. But what do I do with the Waveshare RS485 CAN HAT? I dont have one but if need to I`ll one. Thank you.

ai-republic commented 7 months ago

The PI4 has an AARCH64 OS platform. The RJ 45 goes right into your CAN port of the ARK. Then you will need to either cut the end off and use wire 4 and 5 (as seen above). Make sure you have the plug the right way around when determining the wires. Another option is to buy something like this screw terminal adaptor rj45 female to 8 pin connector:

image

You will need to connect the CAN H and CAN L wires to the Waveshare 2CH CAN hat respectively:

image

jimmy737 commented 7 months ago

Thank you for the clear explanation. I will try first option because I live on an island in the caribbean and buying electronic parts is not easy. I'll try that today and report back my progress. Thank you for all the help. Greatly appreciated.

jimmy737 commented 7 months ago

Hello Torsten, I made it this far but nothing shows on the webpage with port 8080. I attached all the details I have and logs maybe you see what is missing. Thank you. BMS-to-Inverter.log BMS-to-Inverter_Webserver.log IMG_1685 IMG_1686 IMG_1687 IMG_1688 IMG_1689 IMG_1691 IMG_1692

sanitariu commented 7 months ago

I also can not detect the inverter via my PI CanHat. Maybe the cabling is not correct. I am using standart RJ-45 cable with connectors and cut the cable. Using blue and white-blue cables for CANL and CANH. I tried setup the inverter to battery Li and type 51 or 52 and it goes to error 20/4 immediately. The bad thing is that I must connect my PI4 to other power source because when inverter errors it does not output energy. If someone have more success in connecting Growatt ES5000 inverter please share howto.

jimmy737 commented 7 months ago

I also can not detect the inverter via my PI CanHat. Maybe the cabling is not correct. I am using standart RJ-45 cable with connectors and cut the cable. Using blue and white-blue cables for CANL and CANH. I tried setup the inverter to battery Li and type 51 or 52 and it goes to error 20/4 immediately. The bad thing is that I must connect my PI4 to other power source because when inverter errors it does not output energy. If someone have more success in connecting Growatt ES5000 inverter please share howto.

I am connecting directly to the Growatt Ark battery the same way as you. But no success.

ai-republic commented 7 months ago

Hi Jimmy, the error message that is relevant here is: Failed to resolve the interface: can() - errorNumber=19, errorMessage='No such device'

What CAN ports show up if you use the command:

ifconfig -a

Usually they are call can0 and can1.

Another thing I noticed on your configuration you configure a Daly BMS. I would expect the Growatt ARK BMS to use the Growatt CAN protocol. If that doesn't work try the Pylon HV or the Pylon CAN protocol and see if you get some data.

Let me know if that helps.

@sanitariu have you checked the documentation which RJ45 wires are CAN H and CAN L for the inverter? I think they were pin 4 and pin 5. Maybe try to switch the cables.

Best regards, Torsten

jimmy737 commented 7 months ago

Thank you Torsten for the help and suggestions. I am extensively traveling for the next 3 weeks. Away from my inverter so I will try that command to see if I get any data as soon as I return home.

funkydeo commented 6 months ago

Hi there, im just wondering if you managed to get the Growatt SPF (48v) inverter working with the BMS-inverter. I have some Lithium Po4 batteries and it would be nice to input data for BMS on inverter. i have two batteries but they are not charging/discharging equally on bms setting (Li) and so others use (user2) and input own values problem i am facing is that when i set one particular parameter it resets and i have to input it again the next day for the batteries to charge. so far only the bms function works and i will have to swap cables from top battery to bottom as not charging/discharging equally. hope this is the right place i am searchimg for my answer. cheers

jimmy737 commented 6 months ago

Hi there, im just wondering if you managed to get the Growatt SPF (48v) inverter working with the BMS-inverter. I have some Lithium Po4 batteries and it would be nice to input data for BMS on inverter. i have two batteries but they are not charging/discharging equally on bms setting (Li) and so others use (user2) and input own values problem i am facing is that when i set one particular parameter it resets and i have to input it again the next day for the batteries to charge. so far only the bms function works and i will have to swap cables from top battery to bottom as not charging/discharging equally. hope this is the right place i am searchimg for my answer. cheers

Hello, I have set the settings 36 to 52. The built in BMS of my SPF 5000 ES does a ok job. I say ok because if I take a reading with a USB stick CONFIG.txt, and open the spreadsheet of each battery, i can see that of my 6 batteries some have different number of discharge cycle. So I plan on rotating the battery every 6 months otherwise some willl be much more used than other. My batteries are different than yours. I have 6 ARK 2.5 Kwh A01. Sorry not much help here.