diy solar

diy solar

For those of you looking to monitor your ANT-BMS with Pi3 via Bluetooth.

How do you connect the bms? I am not asked for my password:

Make sure the MAC is not for the BLE interface. Does it see it when you do "scan on" and "devices". I was not able to connect to the BMS when I tablet was already talking to it, so if you have another device already talking to the BMS, pairing might fail.
 
Hello

thank you for your answer. pairing works now. But connect not. Is that needed?

connect AA:BB:CC:B1:23:45
Attempting to connect to AA:BB:CC:B1:23:45
Failed to connect: org.bluez.Error.Failed
 
Hello

thank you for your answer. pairing works now. But connect not. Is that needed?

After you pair the Pi with the BMS, you may also have to bind that connection to the driver:

rfcomm bind /dev/rfcomm2 [Mac-of-your-BMS]

You will know you need to do this when you run the python script and it complains about not being able to find the device.
 
I have the same problem as @lexxmm
My ANT-BMS is the same as his, its the 20S model (I'm using it as 16S, its configurable).
Also my MAC address is the same as his: AA:BB:CC:B1:23:45
I have configured the getbms-ant.py to look for my MAC (this is forgotten to say in the Youtube video)

Problem is that when I "sudo python getbms-ant.py" I've got error:
pi@raspberrypi:~/pybluez/examples/simple $ sudo python getbms-ant.py
File "getbms-ant.py", line 35
ser.write (test.decode('hex'))
^
IndentationError: expected an indented block

So, I'm thinking that there may be one of two problems:
1. The getbms-ant.py is not suitable for our BMS-20S model?
2. The bluetooth connection is not correct?

About the 2. - I already bind the connection to the driver with rfcomm code, and if I go to bluetoothctl and run "info" for my MAC, I got "Paired: yes", but "Connected: no"?
In the Youtube video Part 1, I see that after runnig the "pair" he got "paired" but after that in the scan code he got also "connected: no" for his MAC, althrough he proceeded with success?

Will be thankful for any help, also if the .py is not for our BMS, is there any options to scan our BMS-20S output and rewrite the code?
 
I have the same problem as @lexxmm
My ANT-BMS is the same as his, its the 20S model (I'm using it as 16S, its configurable).
Also my MAC address is the same as his: AA:BB:CC:B1:23:45
I have configured the getbms-ant.py to look for my MAC (this is forgotten to say in the Youtube video)

The Mac address in the file isn't actually used; If you look a few lines down, you will see that sock.connect is actually commented out.

Problem is that when I "sudo python getbms-ant.py" I've got error:

This is due to Python needing indents in the code. If you cut and pasted it into your Pi, it probably did not properly keep the indents (tabs) and that is what is triggering the error. The easiest way to fix this is to download the entire file, then delete all of the other stuff out of it, and then copy that file over to the Pi. The indents were in his file.

So, I'm thinking that there may be one of two problems:
1. The getbms-ant.py is not suitable for our BMS-20S model?

There is nothing in the code that is model specific as far as I can tell, but I have the 16s version as well, so I can't be sure that the 20S version responds to the 140 bytes of data is any different. However, even if that was the case, you should still be able to pair with it but the data you get is just junk.

2. The bluetooth connection is not correct?

About the 2. - I already bind the connection to the driver with rfcomm code, and if I go to bluetoothctl and run "info" for my MAC, I got "Paired: yes", but "Connected: no"?
In the Youtube video Part 1, I see that after runnig the "pair" he got "paired" but after that in the scan code he got also "connected: no" for his MAC, althrough he proceeded with success?

Will be thankful for any help, also if the .py is not for our BMS, is there any options to scan our BMS-20S output and rewrite the code?

This is the normal output:

[bluetooth]# list
Controller B8:27:EB:06:52:B9 antpi [default]
[bluetooth]# info AA:BB:DD:06:55:00
Device AA:BB:DD:06:55:00 (public)
Name: BMS-ANT16A-500
Alias: BMS-ANT16A-500
Class: 0x00001f00
Paired: yes
Trusted: yes
Blocked: no
Connected: no
LegacyPairing: no
UUID: Serial Port (00001101-0000-1000-8000-00805f9b34fb)
[CHG] Device AA:BB:DD:06:55:00 Connected: yes
[CHG] Device AA:BB:DD:06:55:00 Connected: no

It is only connected when your Pi and talked to the device, otherwise it will say no. Above, you see that it is not connected, then my script runs, and it connects for a few seconds, then disconnects.

If you fix your indents, I think it will work fine with your 20S.
 
@pjones - thank you, indeed there was a problem with indents... fixed them via copy to Geany editor (instead of "nano" in the console), but now I have another error?

pi@raspberrypi:~/pybluez $ sudo python getbms-ant.py
Traceback (most recent call last):
File "getbms-ant.py", line 7, in <module>
import bluetooth
File "/home/pi/pybluez/bluetooth/__init__.py", line 43, in <module>
from .bluez import *
File "/home/pi/pybluez/bluetooth/bluez.py", line 6, in <module>
import _bluetooth as _bt
ImportError: No module named _bluetooth
 
I figured this out... the second post on this thread has two different linked files!
The method on the first link (drive.google...) does NOT work. If you follow the steps from it, you will create the getbms-ant.py file in /pybluez and the code won't work from there!
The second link (.txt file) is the correct one, as its instructions are to create the getbms-ant.py file in /pybluez//examples/simple, from where the code works.
Now I get the voltage readings when running the script code, have to do the other steps for visualization.

@lexxmm - you are also on the right path, everything is OK with your post. Just follow the .txt link and you will be all good.

Another question - from the raw numbers of the python code, I don't think that there is the remaining Ah capacity of the battery, maybe this is not included in the code?
 
@pjones - thank you, indeed there was a problem with indents... fixed them via copy to Geany editor (instead of "nano" in the console), but now I have another error?

Did you do this step:

cd pybluez/
sudo python setup.py install

you don't actually have to run it from that directory if the module is installed.
 
Long shot... did anyone figure out how the checksum is calculated? Would like to be able to send commands to toggle the mosfets. Thanks
 
It works for me now. very cool project! Other question: I need that "remaining cap." Is that not possible?
 
Last edited:
It works for me now. very cool project! Other question: I need that "remaining cap." Is that not possible?

It is. Try this:

#AH Remaining
data = (Antw33.encode('hex') [(79*2):(82*2+2)])
data = float.fromhex(data)*0.000001
print "AH Remaining: ", data
 
I also tried to calculate the CRC but without success.
Here are some links I have around :

Did anyone success with the AntBMS checksum protocol?

Here are some packets:

AA55AAFF021D102A102A1027102A102A1028102810281026102910281029102C00000000000000000000000000000000000000000000000000000000000000000000000000000000000064025317C0025306110008C78E0008572000150015001400140014001401010003E8001701000000000D102C09102610280D00000073006F02A70000000011620B00
AA55AAFF021D102A102A1027102A102A1028102810281026102910281029102C00000000000000000000000000000000000000000000000000000000000000000000000000000000000064025317C0025306100008C78E0008572100150016001400140014001401010003E8001701000000000D102C09102610280D00000073006F02A70000000015620B00
AA55AAFF021D102A102A1027102A102A1028102810281026102910281029102C00000000000000000000000000000000000000000000000000000000000000000000000000000000000064025317C0025306110008C78E0008571F00150016001400140014001401010003E8001701000000000D102C09102610280D00000073006F02A7000000000D620B00

I am not having much luck either; The last 2 bytes is supposed to be the checksum, but from the 3 outputs above, the checksum doesn't change.

Since the original query uses 0000 as the checksum, I've tried that, and 1 out of 10 or so request does return the 140 bytes of data, but it does not seem to accept the change. I tried something harmless like changing the wheel circumference, but when I read it back, it's still null, so even when you get data back, it doesn't mean it accepted it.

I think JDK BMS uses crc16 (modbus) but that doesn't seem to be the case here.

I am kind of stuck at this point unless someone can scare up some documents.

...does anyone who know actually makes ANT BMS? It's not LLT, I think they make the JDK one.
 
It is. Try this:

#AH Remaining
data = (Antw33.encode('hex') [(79*2):(82*2+2)])
data = float.fromhex(data)*0.000001
print "AH Remaining: ", data

not work: ValueError: data = float.fromhex(data)*0.000001
invalid hexadecimal floating-point string
 
this works:

data = (Antw33.encode('hex') [79*2:82*2+2])
try:
data = float.fromhex(data)*0.000001
print "Remaining:",data
except:
pass


Thanks :)
 
Hello

i started integrating bms in my smarthome (smarthomeng / smartvisu) and this works fine with 4x ant-bms. more will follow later.

I would like to disconnect to individual blocks. can i send to the ant-bms?

Thanks
 

Attachments

  • screen.png
    screen.png
    149.8 KB · Views: 39
Hello

i started integrating bms in my smarthome (smarthomeng / smartvisu) and this works fine with 4x ant-bms. more will follow later.

I would like to disconnect to individual blocks. can i send to the ant-bms?

Thanks

Yes, you definitely can. Just come back when you figure out how to generate the checksum. :)
 
Guys, can we get the data for the MOS temperature?

Real temperature(91-102): short Celsius degree

You'd have to guess which temp is for which sensor. If you have the LCD, I suppose this could be pretty simple to do.
 
Back
Top