Louisvdw / dbus-serialbattery

Battery Monitor driver for serial battery in VenusOS GX systems
MIT License
541 stars 165 forks source link

ANT BMS integration #5

Closed Louisvdw closed 3 years ago

Louisvdw commented 3 years ago

Add the ANT-BMS communication to the driver.

osantiano commented 3 years ago

Would be great !

JBecker32 commented 3 years ago

Would like to see that too :-))

pahorpet commented 3 years ago

Hi, any news here?

Louisvdw commented 3 years ago

I have not started to look at the ANT BMS. I don't have an example of the BMS to do testing with and all other users that has one does not seem to be able to connect the BMS to their controllers or PC. If we can solve that it should be fairly simple as the ANT protocol is about 90% to what we use for the LLT/JBD BMS already.

I'm looking for anyone that can help as a sponser for hardware I can do test with. Or if anyone has their ANT connected to a Pi or GX and is wiling to help with testing and technical debugging.

JBecker32 commented 3 years ago

Hi, any news here?

does your ANT BMS have a free serial interface? I have two of them but the serial is occupied by the internal BT module. The only external interface is that for the display.

pahorpet commented 3 years ago

Hi, any news here?

does your ANT BMS have a free serial interface? I have two of them but the serial is occupied by the internal BT module. The only external interface is that for the display.

300A version what I have have it the same, I have just ordered 450A version, so 7 days delivery, mean next week I should be able to check it.

JBecker32 commented 3 years ago

I will check the function of the display interface when I'm home after holidays in two weeks.

liufuyang commented 3 years ago

Hi there. Looking forward to this. I am very new to the solar/battery business and I am waiting the ANT BMS and raspberrypi to arrive, perhaps later I can help give some tests. I currently have a victron mppt 100V/30A and it works well to a small bluetti power station and I am waiting to get the ANT BMS to build my own LTO battery pack, and I hope later it can be all wired onto the victron VRM page via the raspberrypi.

Also, I saw some of the BMS (like this MGod one) saying they have the so called UART/RS485 connection port. Does that means as long as a BMS having this type of connections then we can use this driver to connect it to VenusOS?

Thank you and sorry for asking so many questions :)

Louisvdw commented 3 years ago

@liufuyang if the BMS has a UART, RS485 or other serial connection port that only mean you can connect it to another device via that serial port for communication. But unfortunately each manufacturer implement their own protocol. So to make a new BMS work with this driver we first need to write the code to implement their protocol and commands.

liufuyang commented 3 years ago

I see. Thank you for the info. I asked the seller of the MGod BMS and they say Daly is their cooperating entity so I guess it will probably work. While I am waiting for the Ant to arrive I will just order a MGod as well as I feel they having a better service than Daly on aliexpress. Will probably get it after a month and if I ever test it I will let you know how it goes :)

pahorpet commented 3 years ago

I have not started to look at the ANT BMS. I don't have an example of the BMS to do testing with and all other users that has one does not seem to be able to connect the BMS to their controllers or PC. If we can solve that it should be fairly simple as the ANT protocol is about 90% to what we use for the LLT/JBD BMS already.

I'm looking for anyone that can help as a sponser for hardware I can do test with. Or if anyone has their ANT connected to a Pi or GX and is wiling to help with testing and technical debugging.

Finally I am ready to test. ANT BMS connected via serial display interface to USB I have rpi to on.

osantiano commented 3 years ago

This guy did some work on ANT: https://github.com/juamiso/ANT_BMS (via Bluetooth)

pahorpet commented 3 years ago

An news here? I am ready to do some testing

Louisvdw commented 3 years ago

An news here? I am ready to do some testing

Hi @pahorpet. I need to finish a few pieces of work. I'll get a script to you to test as soon as I can.

JBecker32 commented 3 years ago

Hi Louis, you can send it to me too for testing. I still have the ANT lying around ....

Louisvdw commented 3 years ago

@pahorpet @JBecker32 I created a branch with the first changes to test the ANT. Give it a test and see if you get a response. It should read the SOC, Voltage and Current.

pahorpet commented 3 years ago

Great tomorrow I will test it.

Dne út 17. 8. 2021 22:45 uživatel Louis Van Der Walt < @.***> napsal:

@pahorpet https://github.com/pahorpet @JBecker32 https://github.com/JBecker32 I created a branch https://github.com/Louisvdw/dbus-serialbattery/tree/ant-bms with the first changes to test the ANT. Give it a test and see if you get a response. It should read the SOC, Voltage and Current.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Louisvdw/dbus-serialbattery/issues/5#issuecomment-900617978, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIISISB52BOMXOTF4TNSYYLT5LC7FANCNFSM4XDCZLGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

liufuyang commented 3 years ago

My ANT bms should soon arrive today or tomorrow as well. I would like to help give it a test as well but I haven't installed our driver/plug-in before, so all I need is to follow the installation doc and see how to test that branch @Louisvdw mentioned above? And what do you mean by it should read "SOC, V, A", where do I expected to see the readings? (From some logs via ssh into Venus OS or they will already show up on Victron VRM pages?)

I am not sure yet how to test a branch but I guess one could ssh into Venus OS (just tried this earlier and it works) and would it be possible to install git there and pull this code directly to some directory to install the pulg in(like restarting the system to trigger it)?

Louisvdw commented 3 years ago

The best would be to follow the install steps to install an released version first. This will set everything up and set the file permissions. Then you can copy the files from the branch over the existing install. You only need to update the *.py files in the dbus-serialbattery/etc/dbus-serialbattery/ directory. All the other files and folder does not change.

If it all works, then the battery will show up in the Remote Console of your GX device and SOC, V and A will be displayed. If not then look at the log files. See the troubleshoot section in the wiki.

liufuyang commented 3 years ago

Thank you. Sounds like something I can try. Do you or @JBecker32 @pahorpet perhaps knows how to wire the ANT BMS's serial display interface (4 pin or?) to the RS485->USB cable? I guess that is the suggested way to connect? The RS485->USB chip I have around is this one - which I used now to wire a Victron solar charger to Raspberry Pi and it works well. Do you know which pin on the BMS board is Rx/Tx/Gnd and so on? I am a bit unsure how to wire the BMS to the Raspberry Pi yet :)

JBecker32 commented 3 years ago

My ANT BMS has no RS485! The display interface you mention is certainly not RS485, but UART with 5V or even 3.3V level. An RS485<->USB adapter will not work! This is the problem with the ANT, that it has no dedicated (wired) interface for such things like we want to do ... (and atm this is what also prevents me from trying the new code :-(()

pahorpet commented 3 years ago

So I give it a try today but without succes I was trying to install from USB, so put in the root folder and place in cerbo gx. And after connect the usb from BMS I have got but disconnect 5V. So I will give it another try next week again.

liufuyang commented 3 years ago

I see. Sorry I mixed with RS485 with UART. The device I have at hands are these https://www.amazon.se/gp/product/B07TFSZ3ZP, so perhaps they are UART to USB? I used them on Victron Solar charger and it can connect. So perhaps Victron Solar charger has a UART output?

liufuyang commented 3 years ago

I still have some question for the installation process.

  1. Are we sure now that we will have to use an external USB stick to do this (on Raspbery Pi in my case)? If ssh login and downloading files can install the plugin then it would be perfect for me. In that case please neglect the question below.
  2. (As I can only find one USB stick around me, which has some files and movies saved in it) Does it require the USB stick to be formatted in some special format? I think the only USB storage I have now is used previously with Windows machines before (it has NTFS format), as when I just mount it on my Mac now I seem cannot write but only able to read from it. Perhaps I need to reformat it into something else or?

I tried to note down a few steps I will do later when the BMS arrives (also if I could somehow figure out how to wire the BMS to the Raspberry PI). Perhaps someone of you can check steps like these will install the plugin successfully? https://github.com/liufuyang/dbus-serialbattery/issues/1

And I actually also just tried those steps on the Venus OS (or Raspberry Pi) and also tried to restart the device. How can I check whether this plugin is loaded by the os? Is there some sort of logs I can use for verify?

I can see this file link is created, perhaps that means it is installed properly?

ls -al  /opt/victronenergy/dbus-serialbattery
lrwxrwxrwx    1 root     root            28 Aug 18 19:46 /opt/victronenergy/dbus-serialbattery -> /data/etc/dbus-serialbattery

Thank you :)

Ah... I missed the troubleshoot page... Let me see...

I can see our plugin is not mentioned in the file /data/log/serial-starter/current for me yet. Looks like now I just need to wait to test this until the BMS arrive and somehow wire it to the USB.

JBecker32 commented 3 years ago

I tried to understand the display interface of the ANT today, spying on the receive and transmit lines, but without success. This is certainly not using the documented ANT serial format. So for now I'm out as I do not have an ANT BMS with UART or RS485 interface ...

Louisvdw commented 3 years ago

That seem to be the problem with the ANT. To get a USB->serial connection to the BMS.

langepil commented 3 years ago

I'm really not a professional, but is the USB Adapter for PC possibly the solution?

https://de.aliexpress.com/item/32826820690.html

I have such one at home, but unfortunately currently less time to test.

Louisvdw commented 3 years ago

That USB adapter for PC will work, yes. But it seems that most ANT BMS does not come with the required connection to use that adapter.

langepil commented 3 years ago

The adapter is connected to the same port where the external display is connected. They should all have this port, right?

Louisvdw commented 3 years ago

@langepil it might be that the adapter has some conversion curcuit inside. Does it have a box as part of the cable and can you open it and take a few pictures?

langepil commented 3 years ago

Unfortunately, I don't know at the moment. I'll take a look this afternoon and report back.

liufuyang commented 3 years ago

After asking the seller several times to let him/her contact their tech people, I finally got this wiring connecting graph from them: image In the graph it says on the left is the BMS board, on the right is the back of the screen.

Perhaps my serial->USB connecting device can work there, will have to test it later.

langepil commented 3 years ago

Here are the pictures of the original Adapter

635B0C11-4F6B-4B0D-A77D-4FB1737B5E24 D9BE2B23-7296-4D07-BE37-50055CB1B129 954558EE-7254-4C98-B54A-696A8ECE6F39 773EC1DD-7A15-42D9-B67E-F87F8410B3AD

Louisvdw commented 3 years ago

That looks like a CH340G chip (the big one) which is a USB-serial chip. This can be RS232 or RS485 depending how it is set up. Most likely RS485 in theis instance.

JBecker32 commented 3 years ago

The adapter is connected to the same port where the external display is connected. They should all have this port, right?

Maybe you didn't read my comments above! The display port uses a completely different protocol! As long as nobody can provide the details, this is not usable at all!

pahorpet commented 3 years ago

http://mysharegadget.com/265290407 here is the pc sw and some docu i will give another try as soon possible

S pozdravem a přáním hezkého dne Petr Pahorecký www.g-kolo.cz

čt 19. 8. 2021 v 19:53 odesílatel JBecker32 @.***> napsal:

The adapter is connected to the same port where the external display is connected. They should all have this port, right?

Maybe you didn't read my comments above! The display port uses a completely different protocol! As long as nobody can provide the details, this is not usable at all!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Louisvdw/dbus-serialbattery/issues/5#issuecomment-902120301, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIISISCI46Q4WBZ53N77EVLT5VAIFANCNFSM4XDCZLGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

liufuyang commented 3 years ago

BTW you might need this change in order to test the ANT BMS https://github.com/Louisvdw/dbus-serialbattery/pull/35

pahorpet commented 3 years ago

I will, for connect battery to the pc the baudrate is 19200.

Dne čt 19. 8. 2021 22:03 uživatel Fuyang Liu @.***> napsal:

BTW you might need this change in order to test the ANT BMS #35 https://github.com/Louisvdw/dbus-serialbattery/pull/35

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Louisvdw/dbus-serialbattery/issues/5#issuecomment-902203939, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIISISBV46YPV5HHIGMEY6TT5VPQBANCNFSM4XDCZLGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

JBecker32 commented 3 years ago

Ok now when I try to connect to the ANT display port at 19200 Baud with a USB-adapter I have the following situation: When I send 0x5A 0x5A 0x00 0x00 0x01 0x01, I receive the following (the answer is 140 bytes long!): 0xAA 0x55 0xAA 0xFF 0x01 0x16 0x0D 0x97 0x0D 0x97 0x0D 0x97 0x0D 0x98 0x0D 0x97 0x0D 0x97 0x0D 0x98 0x0D 0x97 .... where the 0x0d 0x97 are the 8 cell voltages .... But this is a completely different protocol than what is documented for ANT serial communication!?!

JBecker32 commented 3 years ago

OK, same result when I send 0xDB 0xDB 0x00 0x00 0x00 0x00 (or 0xDB 0xDB 0x00 0x00 0x01 0x01 or 0xDB 0xDB 0x00 0x00 0x02 0x02 ... ) The length of 140 bytes is ok, but the position of e.g. voltage seems wrong!?!

pahorpet commented 3 years ago

What documentation are you looking at? S pozdravem a přáním hezkého dne Petr Pahorecký www.g-kolo.cz

pá 20. 8. 2021 v 17:01 odesílatel JBecker32 @.***> napsal:

OK, same result when I send 0xDB 0xDB 0x00 0x00 0x00 0x00 (or 0xDB 0xDB 0x00 0x00 0x01 0x01 or 0xDB 0xDB 0x00 0x00 0x02 0x02 ... ) The length of 140 bytes is ok, but the position of e.g. voltage seems wrong!?!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Louisvdw/dbus-serialbattery/issues/5#issuecomment-902756460, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIISISCEI5A2NEDH7LMB52DT5ZU3LANCNFSM4XDCZLGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

JBecker32 commented 3 years ago

??? is there a documentation of the display interface? I don't have it!

JBecker32 commented 3 years ago

could we please clarify something? Are we all connecting with the ANT BMS via the display interface? Or is anyone using a dedicated UART interface on an ANT? Or RS485?

liufuyang commented 3 years ago

My board is not arrived yet but I am planing to connect it via the display interface. They are also selling a USB connection device with that interface - which I didn't order previously.

pahorpet commented 3 years ago

Yes display interface, I don't have it as well, but where did you get: "But this is a completely different protocol than what is documented for ANT serial communication!?!"

I had asked the seller if they can provide a protocol.

JBecker32 commented 3 years ago

I have now managed to get the communication to work with some mods to the code. Not a final solution, but showing the basic values. I think that the display interface is not giving all information, but it is ok. I see the voltage, current, SOC, cell voltages, min and max cells, remaining capacity, state of the MOSFETs, temperature ...

pahorpet commented 3 years ago

Great, Looking forward to test it. It has to give all information as I am using with pc to set it. But not need it.

Dne so 21. 8. 2021 20:58 uživatel JBecker32 @.***> napsal:

I have now managed to get the communication to work with some mods to the code. Not a final solution, but showing the basic values. I think that the display interface is not giving all information, but it is ok. I see the voltage, current, SOC, cell voltages, min and max cells, remaining capacity, state of the MOSFETs, temperature ...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Louisvdw/dbus-serialbattery/issues/5#issuecomment-903161257, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIISISAIAAMRCWQQNOWBTTTT57ZMDANCNFSM4XDCZLGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

JBecker32 commented 3 years ago

Not sure how to use github correctly to make a pull request ... Therefore I will try to attach only the changed files here: ANT_BMS.zip

pahorpet commented 3 years ago

So I get to the testing instal new version in cerbo GX but I am getting : @4000000061226c7721d6ecfc INFO:main:Testing Ant @4000000061226c7732c5006c ERROR:utils:>>> ERROR: No reply - returning @4000000061226c773346174c INFO:utils:>>> ERROR: Incorrect Data @4000000061226c7815f9d8cc ERROR:main:ERROR >>> No battery connection at /dev/ttyUSB0

bdw I am using the original CH340 but the second side of it 24s-32s So I use Hercules to send 0xDB 0xDB 0x00 0x00 0x00 0x00 This is what I have got AA 55 AA 7B 46 46 7D FE 8C 5F 25 97 7A 7C 78 61 84 75 5A 81 8B 96 6F 7B A6 75 2A 2A 2D A8 DA B6 21 4A 7F 23 21 27 97 25 75 6C 69 AB FA Does it fit your parsing?

pahorpet commented 3 years ago

So I had made it to run with cerbo gx: First need to modify util a bit

while toread < (length_pos+1):
  **sleep(0.01)**
  toread = ser.inWaiting()
  count += 1
   if count > **150**:
    logger.error(">>> ERROR: No reply - returning")
   return False 
...

And the discharge current is divided by 4. only total capacity is missing. do you know how to get it from? And in details it shows number of modules blocking charging 1 what does it mean?

image image image