diy solar

diy solar

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

This is the closest I have ever come to getting it working! I have this error... I'm sure it is because I have the location for the "getbms-ant.py" in the wrong location. Is anybody able to help me please?
View attachment 71579
I had this error because I didn't setup the influx database correctly and I messed about with the default location of the getbms-ant.py location.
 
Hello,
everyone tried out with new ANT BMS Version 2021 this BMS reqires new APP also see:
(this is not my youtube channel.)
With the command DBDB00000000 send we get nothing back. Only timeout after a few seconds. The old BMS works with this command.

Thanks
Stefan

Solved in #124.
 
Last edited:
Here are the registers for Status discharge, charge, balance:

data_Status_charge = (Antw33.encode('hex') [103*2:103*2+2])
data_Status_charge=int(data_Status_charge,16)
print (data_Status_charge)

data_Status_discharge = (Antw33.encode('hex') [104*2:104*2+2])
data_Status_discharge=int(data_Status_discharge,16)
print (data_Status_discharge)

data_Status_balance = (Antw33.encode('hex') [105*2:105*2+2])
data_Status_balance=int(data_Status_balance,16)
print (data_Status_balance)


The Status charge/discharge is:

0 is turn off
1 is turn on
2 under/ over charge / discharge protect
3 over current protect
4 battery is full charged (only charge)
5 the total voltage of battery pack is over
6 battery over temperature
7 the MOSFET over temperature
8 Abnormal current
9 Balanced string out (a battery is not detected)
10 Motherboard over temperature
11 charge MOSFET turn on (only discharge)
12 short protect (only discharge)
13 Discharge MOSFET abnormality
14 Start exception (only discharge)
15 Manually turn off

Status Balance:

0 turn off
1 Exceeding limit trigger balance
2 When charging, the voltage difference is too big, trigger balance
3 balance over temperature
4 Automatic balance
10 Motherboard over temperature
 
Last edited:
Helllo,
again i have sniffed the protocol and for the new version 2021 ANT BMS the command ist

insted of DBDB00000000

it is 5A5A5A00005A followed from DBDB00000000

Hope this helps someone.
As i can see, the rest is the same protocol.

Thanks
Stefan


#
test='5A5A5A00005A'
test2 ='DBDB00000000'
try:
ser.write(test.decode('hex'))
#time.sleep(0.03) <- Without pause better response.
ser.write(test2.decode('hex'))
except:
ser.close()
time.sleep(1)
Antw33 = ser.read(140)
#
 
Last edited:
Helllo,
again i have sniffed the protocol and for the new version 2021 ANT BMS the command ist

insted of DBDB00000000

it is 5A5A5A00005A followed from DBDB00000000

Hope this helps someone.
As i can see, the rest is the same protocol.

Thanks
Stefan


#
test='5A5A5A00005A'
test2 ='DBDB00000000'
try:
ser.write(test.decode('hex'))
#time.sleep(0.03) <- Without pause better response.
ser.write(test2.decode('hex'))
except:
ser.close()
time.sleep(1)
Antw33 = ser.read(140)
#
I didn't get it to work, the reply is an empty string. I tried the old test string , your suggestion and A5A5FC0000FC suggested in #112. I tried also the combo with your test string and then A5A5FC0000FC. But still the Antw33 string is empty. I have a Ant 20PHB-TB-8-20S-400A dated from 21-09-08. I am trying the python script on a ZeroW. I testted my PC running over the uSB interface and a terminalprogram. I can get wireshark to dump some conversion from the USB interface, but I have no skills to interpret the message. There seem to be a large overhead in adressing the USB port which Wireshark detects, then there is left over hexstring, which doesnt fit any of the suggestions. I sniffed finally the initialisationstring see #127.
 
Last edited:
Hi,

Thank you for your reply :)

Your code didnt quite work but certainly pointed me in the right direction.

This code below works. Thought I would share this if any one else has want to do the same. As everyone probaly knows that the balance current is not much and only enables when charging.

I wanted to set a automation that when my battery system is in idle to enable auto balancing if the cells are out of balance. Im using node red exec node to run this python script.

import sys
import time
import serial
import struct
from binascii import unhexlify
import requests as req
import bluetooth
from bluetooth import *
import sys

#if sys.version < '3':
# input = raw_input

bd_addr = "AA:BB:CC:B1:23:45"

port = 1

#sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
#sock.connect((bd_addr, port))
#sock.close()
#time.sleep(1)

#Define RS485 serial port
ser = serial.Serial(
port='/dev/rfcomm2',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout = 1)

#while True :
test='A5A5FC0000FC'
try:
ser.write (test.decode('hex'))
except:
ser.close()
time.sleep(3)

s.close()


Thanks for your help :)

Cheers

Gareth
you have tried to turn off the mosfet with this code?
 
Hello
I sniffed the bluetooth for my unit Ant 20PHB-TB-8-20S-400A dated from 21-09-08 and got the follwing connection string
(test in the script) test='7EA1010000BE1855AA55' which gives and answer that however is partly scrambled. I have not checked the rest of the code, it could be that I have only 16 cells not 21. The only thing that is reasonable is MOS and balance temp
 
Is there any possibility of getting the data from the ANT BMS onto the rPi via a wired connection?
Hi, has anyone tried that meanwhile? According to this thread the original display wires just interface with the STM32 microcontroller on the BMS

I have the display but don't use it so I'm wondering if I can get this connected. On my RPi I'm running the Home Assistant OS image and can't connect to the BMS via bluetooth (for whatever stupid reason) so wiring it up would be handy, especially since the RPi is just next to my batteries. I don't want another RPi. Alternatively, I'll have to use an ESP32.
 
Hello!

I also have Ant 20PHB-TB-8-20S-400A and a pi ZeroW. ulrikk - did you mange to talk to the BMS ? Can you share the py script?
Thank you!
Adrian
 
Spent couple of hours yesterday trying to get it to work, but I had no success. I realized that I must install (legacy version) of PI OS, since the latest comes with python3. And as you can see in the picture in the attach, the errors are different with python2 or with python3. Well since right now, by default I have python2 installed on the PI, trying to get rid of the "ImportError: No module named serial", from google search I found that maybe pyserial is missing. I installed it but the pyserial now installed is for python3. And the error is the same! What can I do now?

Another thing that is confusing me, is that the scan for BT devices founds 2 devices related to ANTBMS. (see the picture in attach.) One is ANT-BLE20PHUB" and another is "BMS-ANT20PHUB"

If I connect to "ANT-BLE20PHUB" the pair is succesfully (BT led on the BMS - steady ON), but is not asking for the "1234" password, and after a couple of seconds (15-20sec) the pair is lost. (the BT led from the BMS starts flashing - indicating that it has no pair.

If I connect to "BMS-ANT20PHUB" now is asking for "1234" password and pair is succesfully, then it gets disconnected after a short period of time, and the BT led on the BMS keeps flashing (indicating that it has no pair - as you can see in the err5.jpg picture).

So, at wich device I must connect the PI? "ANT-BLE20PHUB" or "BMS-ANT20PHUB" ?
And why the connection is cut out from the bms after seconds? If I launch the antBMS app on the phone, it automatically connect and the pair remains active until I close the app.

Thank you!
Adrian.
 

Attachments

  • err4.jpg
    err4.jpg
    44.1 KB · Views: 14
  • Img022-01-16 at 01.27.03.jpeg
    Img022-01-16 at 01.27.03.jpeg
    44.5 KB · Views: 13
  • err5.jpg
    err5.jpg
    79.8 KB · Views: 13
Last edited:
Hello!

I also have Ant 20PHB-TB-8-20S-400A and a pi ZeroW. ulrikk - did you mange to talk to the BMS ? Can you share the py script?
Thank you!
Adrian
Hi Adrian I used the previous ant bms code, but modified the calling string, and commented out libraries not loading. with my RPI Zero W. As you noted the ant bms seees tobe python2. It seems however that frequently the RPI cannot read the entire string properly (304 bytes), when I compared with what I found on wireshark. Thus I analysed the string in wireshark with another python program in jupiter (python 3), reading 4 bytes incrementally and trying to compare with know data and realized that only a few of 16 batteries voltages were correct in each reading. I am suspecting that there is some sort of flag to tell when a reading is complete and that BMS responds only with a few correct readings every time, maybe the software displays the correct values only. At least I did never find 16 correct reading in one string. I also got two ants i Bluetooth and selected that with password. It work for while at least. I am starting to systematize the response and also asking for the protocol from the dealer without no success.
Ulrik
 

Attachments

  • antbmsstep.txt
    11.1 KB · Views: 47
  • Byte4decodingANT.txt
    409 bytes · Views: 35
Thank you for your response.
I've tested your code, with no success, since I am stuck at "no module named serial" error. (see picture).
How I resolve this?

I will ask my seller too, for the communication protocol. Maybe they will give me the protocol (since for old versions I saw somewhere on the internet). I will post back here if have the protocol.

Meantime I must resolve the python error, and I don't know how:(

Thank you!
Adrian
 

Attachments

  • err6.jpg
    err6.jpg
    19.1 KB · Views: 13
Meanwhile, Did you notice the DTU feauture in the ParameterSet settings? It says IOT there? It is what I think it is? Can we extract data via phoneapp and put it somewhere to a server? Where can we found more detailes about this? I haven't found any manual for this app. The support is very poor...
 

Attachments

  • Screenshot_20220116_145713_com.mayi.bms.jpg
    Screenshot_20220116_145713_com.mayi.bms.jpg
    75.7 KB · Views: 18
  • Screenshot_20220116_145745_com.mayi.bms.jpg
    Screenshot_20220116_145745_com.mayi.bms.jpg
    112.6 KB · Views: 19
Thank you for your response.
I've tested your code, with no success, since I am stuck at "no module named serial" error. (see picture).
How I resolve this?

I will ask my seller too, for the communication protocol. Maybe they will give me the protocol (since for old versions I saw somewhere on the internet). I will post back here if have the protocol.

Meantime I must resolve the python error, and I don't know how:(

Thank you!
Adrian
You need to load the serial library from internet to your RPI
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-serial
 
Meanwhile, Did you notice the DTU feauture in the ParameterSet settings? It says IOT there? It is what I think it is? Can we extract data via phoneapp and put it somewhere to a server? Where can we found more detailes about this? I haven't found any manual for this app. The support is very poor...
Yes I noted the DTU things, I thought it was something for connecting the GPS for some tracking. It is also on the BMS display (if I remember coorect), so it is probably more connected to the BMS than the phone.
 
Sorry I did not mention this, but I have tried the solution you suggest. This is the error after last one:
I need to install it from another repo or what?
 

Attachments

  • err7.jpg
    err7.jpg
    39.3 KB · Views: 12
OK I deliberatetly installed debian buster with raspberryimager, not the latest Bullseye, because I had trouble with Bullseye in other projects. Maybe the serial is not available in bullseye? I got the impression that the serial BT is shaky in python. Or google on your errorsmessage and see if others had the same trouble.
I am running python 2
python --version
Python 2.7.16
 
Last edited:
Well, I reinstall the RPI OS (legagy) again. Made progress with your string code. I have response from ANT (as you see in the pict), but as you said, there are incorrect. Well, the SOC is 15% and it shows 156%, maybe only the first 2 characters are correct... Anyways, what I trully want is the SOC and the POWER, Cell voltages is something that I want too, but it is not a must, since I can check them by phone every now and then.
I left a message to the seller asking for the protocol... Please post any update or progress. That string is the key!

The "MrLaptop" sugestion on post #124 it's not working! Maybe he will post back something, if he said that he discovered the solution for this model...

PS: temperature sensors are connected to the BMS correctly, but in the APP shows 0 value. you have values for temperature?

Best regards,
Adrian
 

Attachments

  • response.jpg
    response.jpg
    121.8 KB · Views: 27
Super, then we are at least two with this type o unit. Check string length, my was varying (insert and print len(str..)).
 
I have almoust zero experience in programming, since I am not a programmer. I will do anything you want to check if you give me the exact code and tell me where to put it :)
 
Back
Top