diy solar

diy solar

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

Hi

I´m having problems.. bluetooth is paired and connected. bd_addr = "AA:BB:CC:A1:23:45"
when I run sudo python getbms-ant.py this come back....

sudo python getbms-ant.py
Traceback (most recent call last):
File "getbms-ant.py", line 41, in <module>
Antw33 = ser.read(140)
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 478, in read
raise portNotOpenError
serial.serialutil.SerialException: Attempting to use a port that is not open
Use : pip install PyBluez==0.22
V 23 is making problems
 
Hi Guys,

I've been working with the code from a couple of places, and built a Python3 version of the ANT-BMS python program. It's still in development, but mostly works on my RPI 4 (I'm using it a Chart Plotter / dashboard for my electrified sailboat). I've also included the communication parameters as a comment at the head of the program.
 
BTW, I can control the BMS now. The checksum is just the sum of the 3 bytes (address + data + data).

So.... sending it:

'A5A5FA0000FA' # Turn Off Charge MOSFET
'A5A5FA0001FB' # Turn On Charge MOSFET
'A5A5FE0000FE' # Reboot BMS
'A5A5F90000F9' # Turn Off DisCharge MOSFET
'A5A5F90001FA' # Turn On DisCharge MOSFET
'A5A5FC0000FC' # Toggles balancing

Adding this in case the future me forgets and has to google it. :)
Thank you for sharing.
How do you send to Bluetooth? Via python script or via Ble out in node red?
 
Thanks for the work on this. I did have a few problems though.

Bluetooth through rfcomm was very unreliable whenever Node Red was running. I changed to sockets and now it is stable. Just replace start of code as shown below. May be to many imports but I just responded to errors as they occurred and added.

Python:
#Create getbms-ant.py file
import socket
import time
import requests as req
from binascii import unhexlify
import struct
import sys
import serial
import bluetooth
from bluetooth import *

serverMACAddress = 'AA:BB:CC:A1:23:45'
port = 1
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFC$
s.connect((serverMACAddress,port))

#while True :
test='DBDB00000000'
try:

Node Red was also not generating any payload. I swapped the switch around and now it works. Just update YOUR IP ADDRESS in the following code. Am only using a Chronograf dashboard but all working fine.

Code:
#THIS IS MY MODIFED NODERED THAT WORKS WITH BLUETOOTH SOCKETS.
[{"id":"b38d617a.0070c","type":"influxdb out","z":"43a452c5.345b0c","influxdb":"2cdaee14.f67752","name":"","measurement":"Data1","precision":"","retentionPolicy":"","database":"","retentionPolicyV18Flux":"","org":"","bucket":"","x":1445.107162475586,"y":115.86908721923828,"wires":[]},{"id":"2cdaee14.f67752","type":"influxdb","hostname":"YOUR IP ADDRESS","port":"8086","protocol":"http","database":"ANTBMS","name":"","usetls":false,"tls":"","influxdbVersion":"1.x","url":"","rejectUnauthorized":false}]
 
Thank you,

maybe soemthing shortened by posting?
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)

rest of code: repalce ser by s?

Could you share whole py?

Thank you.
 
Sorry, cut & paste error. Should end in "BTPROTO_RFCOMM)". Full code attached.
 

Attachments

  • getbms-ant.txt
    6.2 KB · Views: 84
Hello, can you help me, I have a problem with node red it shows me this error: 04/30/2021, 18: 48: 47node: 47f0c63.0303238
msg: error
"TypeError: Cannot read property 'includes' of undefined"

however I followed the installation of the video
Thank you.
 
Are you getting data in the terminal when running "sudo python getbms-ant.py"?
 
I would get a response from the BMS but as soon as I started Node Red, bluetooth would not work properly. Check if the BMS responds in the terminal while Node Red is running?
 
J'obtiendrais une réponse du BMS mais dès que j'ai lancé Node Red, le bluetooth ne fonctionnait pas correctement. Vérifiez si le BMS répond dans le terminal pendant que Node Red est en cours d'exécution?
indeed the bms does not respond when node red is running but when I stop the node red service the bms responds well in the terminal, how did you do to solve the problem?
 
Last edited:
Hey guys. Great work! I can't figure out why I'm getting this error when I run "sudo python getbms-ant.py"

Traceback (most recent call last):
File "getbms-ant.py", line 4, in <module>
import serial
ImportError: No module named serial
 
Hey guys. Great work! I can't figure out why I'm getting this error when I run "sudo python getbms-ant.py"

Traceback (most recent call last):
File "getbms-ant.py", line 4, in <module>
import serial
ImportError: No module named serial
Hello for your problem you have to install pyserial by typing the command: "sudo apt-get install python-serial" in a terminal
 
indeed the bms does not respond when node red is running but when I stop the node red service the bms responds well in the terminal, how did you do to solve the problem?
Are you using the original code by chadhouser? I could not get a reliable bluetooth using pybluez so I change the code to use sockets. Have been connected for a week now without issue. My code is posted above. Once connected reliably I was still seeing no response in Node Red. I moved the msg.payload to the start of the flow where I was getting a response. I moved along the flow and found I had to swap the switch connection. No experience with any of this, just fumbled my way through.
 
Hello for your problem you have to install pyserial by typing the command: "sudo apt-get install python-serial" in a terminal
Thank you that worked! Now i'm try to open chronograf and node red but nothing. Getting this when try to start node red

To find more nodes and example flows - go to http://flows.nodered.org
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

Starting as a systemd service.
 
Are you using the original code by chadhouser? I could not get a reliable bluetooth using pybluez so I change the code to use sockets. Have been connected for a week now without issue. My code is posted above. Once connected reliably I was still seeing no response in Node Red. I moved the msg.payload to the start of the flow where I was getting a response. I moved along the flow and found I had to swap the switch connection. No experience with any of this, just fumbled my way through.
ok thanks for the info but now i got this message "data = struct.unpack ('> H', unhexlify (data)) [0] * 0.1
struct.error: unpack requires a string argument of length 2 "
how can i adjust it
 
ok thanks for the info but now i got this message "data = struct.unpack ('> H', unhexlify (data)) [0] * 0.1
struct.error: unpack requires a string argument of length 2 "
how can i adjust it
I don't think you are getting any data. I was getting this a lot and just trimmed the code right back for testing. I checked the code attached and it will return the state of charge. If it works then you can add the rest.
 

Attachments

  • testbms.py.txt
    613 bytes · Views: 54
I have gone back and checked the code I posted earlier. Think it has errors. The full code attached has been tested and returns correct data.
 

Attachments

  • getbms-ant.py.txt
    6.1 KB · Views: 92
I don't think you are getting any data. I was getting this a lot and just trimmed the code right back for testing. I checked the code attached and it will return the state of charge. If it works then you can add the rest.
Great, it works great
Thank you
 
Also, take note that my code is adding 0.7V to the pack voltage. My BMS reads low so this is a good way to correct.

#BMS V
data = (Antw33.encode('hex') [8:12])
data = struct.unpack('>H',unhexlify(data))[0]*0.1
data = data+0.7
#0.7 was added as BMS low.
print (data)
 
Back
Top