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

dabun

New Member
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
 

JohnInCT

New Member
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.
 

dabun

New Member
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?
 

Ellcon123

New Member
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}]
 

dabun

New Member
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.
 

Alpha60

New Member
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.
 

Ellcon123

New Member
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?
 

Alpha60

New Member
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:

Fahmula

Solar Enthusiast
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
 

Alpha60

New Member
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
 

Ellcon123

New Member
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.
 

Fahmula

Solar Enthusiast
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.
 
Top